Add capability to write signal with unique samps_per_frame to wfdb.io.wrsamp#510
Add capability to write signal with unique samps_per_frame to wfdb.io.wrsamp#510
samps_per_frame to wfdb.io.wrsamp#510Conversation
| if p_signal is not None and d_signal is not None: | ||
| signal_list = [p_signal, d_signal, e_p_signal, e_d_signal] | ||
| signals_set = sum(1 for var in signal_list if var is not None) | ||
| if signals_set != 1: |
There was a problem hiding this comment.
Is this intentionally changing behavior for calls where p_signal=None and d_signal=None? In the past, this would evaluate to False when e_p_signal=None and e_d_signal=None, but it now evaluates to True.
There was a problem hiding this comment.
@tompollard , if all signals are passed as None a failure will occur further down the line. @bemoody , do we want to allow all signals to be None when calling wfdb.io.wrsamp? If we don't want to allow that then I will leave the code as I have it which requires that one of the signals is set.
There was a problem hiding this comment.
If passing None for both signals (p_signal and d_signal) previously resulted in an error, then the new behavior is an improvement. Unless people were intentioanlly calling the function with both signals set to None previously, this change isn't a problem.
wfdb/io/record.py
Outdated
| # required features. | ||
|
|
||
| # If samps_per_frame is a list, check that it aligns as expected with the channels in the signal | ||
| if len(samps_per_frame) > 1: |
There was a problem hiding this comment.
If samps_per_frame is not a list (e.g. it's an int), this will error out.
len(4)
TypeError: object of type 'int' has no len()
wfdb/io/record.py
Outdated
| raise TypeError("Unsupported signal format. Must be ndarray or list of lists.") | ||
|
|
||
| # Check that the number of channels matches the number of samps_per_frame entries | ||
| if num_sig_channels != len(samps_per_frame): |
There was a problem hiding this comment.
as above, len(samps_per_frame) will error if samps_per_frame is an int.
866fe10 to
def62e9
Compare
|
@tompollard , if this failing test is of concern, could you guide me on what to do to resolve it: |
It looks like the style checks are failing (https://github.com/MIT-LCP/wfdb-python/actions/runs/11408864264/job/31747939807?pr=510). To fix, you'll need to make sure that the code conforms to black (install black, run black over the code to reformat). |
|
The following raises an error: In this case, wrsamp should raise an exception to say that if |
|
The following raises an error: The problem here is that I think it should be straightforward to restructure |
@bemoody , thanks for catching this. I think this also applies for I've also updated the check to make sure Finally, I think we should allow passing
Please let me know if you disagree, or have other thoughts with respect to this case. |
|
This pull request adds a changelog for `v4.2.0`. The changelog is based on the following auto-generated summary of merge commits generated by GitHub: ``` ## What's Changed * bug-fix: Numpy ValueError when cheking empty list equality by @ajadczaksunriselabs in #459 * bug-fix: Pandas set indexing error by @ajadczaksunriselabs in #460 * fix for /issues/452 by @tecamenz in #465 * Use numpydoc to render documentation by @SnoopJ in #472 * build(deps): bump readthedocs-sphinx-search from 0.1.1 to 0.3.2 in /docs by @dependabot in #477 * Update style by @bemoody in #482 * Fix NaN handling in Record.adc, and other fixes by @bemoody in #481 * Set upper bound on Numpy version (numpy = ">=1.10.1,<2.0.0"). Ref #493. by @tompollard in #494 * Update actions to use actions/checkout@v3 and actions/setup-python@v4. by @tompollard in #495 * Fix: Indent code to ensure 'j' is within for-loop in GQRS algorithm by @tompollard in #499 * Add write_dir argument to csv_to_wfdb. Fixes #67. by @tompollard in #492 * Fix warnings by @cbrnr in #502 * README improvements by @bemoody in #503 * Change in type promotion. Fixes to annotation.py by @tompollard in #506 * Use uv by @cbrnr in #504 * Change in type promotion. Fixes to _signal.py by @tompollard in #507 * Test round-trip write/read of supported binary formats by @bemoody in #509 * Corrected typo and extended allowed types for MultiSegmentRecord by @agent3gatech in #514 * Allow expanded physical signal in `calc_adc_params` by @briangow in #512 * Add capability to write signal with unique `samps_per_frame` to `wfdb.io.wrsamp` by @briangow in #510 * Fix selection of channels when converting to EDF by @SamJelfs in #519 * Change in type promotion introduced in Numpy 2.0. Fixes to edf.py. by @tompollard in #527 * Bump dependencies for NumPy 2 compatibility by @cbrnr in #511 * Bump version to v4.2.0 and update notes on creating new releases by @tompollard in #497 ## New Contributors * @ajadczaksunriselabs made their first contribution in #459 * @tecamenz made their first contribution in #465 * @SnoopJ made their first contribution in #472 * @dependabot made their first contribution in #477 * @agent3gatech made their first contribution in #514 * @SamJelfs made their first contribution in #519 **Full Changelog**: v4.1.2...v4.2.0 ```
This PR adds the capability for writing signals with unique samples per frame (
samps_per_frame) towfdb.io.wrsamp. This is typically the function that is used to write WFDB files. This was previously only possible to do by creating a Record first and using itswrsampmethod to do the write.@bemoody , I do feel like checking that the frames were uniform took a bit of extra code. I'm happy to leave it like this but also open to discussing other approaches.
I've added a couple of tests to check that this continues to work as expected.