Repository navigation
Document signal precedence and fix flattened writes - #773
Conversation
tompollard
left a comment
There was a problem hiding this comment.
The documentation matches the code for ordinary records, and the tests capture the behaviour well. While checking it, I found a related bug on main for flattened multi-segment records, now #774.
Checked:
to_dataframetriesp_signal,d_signal,e_p_signalande_d_signalin that order, as documented.wrsampconvertsp_signalonly whend_signalisNone, and likewisee_p_signalwhene_d_signalisNone, as documented.- Tests:
tests/test_record_signal_precedence.py(3 passed) and CI pass.
Related bug, for flattened records (#774). _prepare_flattened_write can recalculate a flattened record's calibration (switching to format 32 when channels sharing a file have different formats). wrsamp then writes the existing d_signal, computed with the old calibration, under the new gains. With 200 samples of 041s, all channels in one file and channel 0 changed to format 16, reading back gives errors of 0.384, 0.892, 0.386 and 44.175 in the first four channels, with no warning. Without d_signal, the same record reads back exactly. That needs a code fix, so it's separate from this PR. Until then, the new section could note that flattened records can be an exception to "writes d_signal when present", or this could wait until the fix lands.
Minor:
- Expanded arrays of different lengths: "Expanded arrays must have equal lengths to form a DataFrame" is correct. It could also say that records with different samples per frame, like
mixedsignals, can't make a DataFrame from their expanded arrays. - One more test:
to_dataframechoosingd_signalovere_p_signalwould cover the remaining part of the documented order. - Readability:
test_write_uses_existing_digital_until_refreshedbranches onexpandedin several places. Separate uniform and expanded tests might be easier to follow.
|
Thanks for finding #774. I fixed it in 95cf608 rather than leaving a caveat in the docs. For flattened records, the selected digital array now remains authoritative when incompatible signal formats have to be changed to format 32. The writer recodes its missing-value markers but keeps its calibration, so readback no longer interprets old digital values using newly calculated gains. Physical-only flattened records still calculate new calibration as before. I added regression tests for both uniform and expanded flattened writes, plus a physical-only test. I also clarified the DataFrame limitation for channels with different samples per frame, added the missing |
Summary
Document how legacy
Recordmethods choose signal arrays when physical and digital forms coexist:to_dataframe()uses the first available ofp_signal,d_signal,e_p_signal, ande_d_signal.wrsamp(expanded=False)writesd_signalwhen present, otherwise convertsp_signal. Withexpanded=True, it usese_d_signalbeforee_p_signal.set_d_features(do_adc=True)before writing.Fix #774 as part of this PR. When a flattened multi-segment record needs format 32 because channels sharing a file have incompatible formats, an existing digital array now remains the source of written values. It is recoded to the new format while retaining its calibration. Previously, the writer recalculated calibration from the physical array but wrote the old digital array, changing the physical values on readback without warning. A physical-only flattened record still calculates suitable new calibration.
The tests cover uniform and expanded write/readback, DataFrame precedence, differing expanded channel lengths, and the flattened-record regression in both layouts.
Closes #768 and #774.
Verification
MPLBACKEND=Agg).