Skip to content

Fix automatic calibration of missing and expanded physical signals - #787

Merged
tompollard merged 1 commit into
mainfrom
fix/physical-calibration
Nov 30, 2026
Merged

tompollard merged 1 commit into
mainfrom
fix/physical-calibration

Conversation

@tompollard

Copy link
Copy Markdown
Member

Summary

Fixes #786.

Automatic format selection now ignores NaN samples when estimating physical signal resolution. An all-NaN or constant channel gets the lowest estimated resolution, while its missing samples still use the format's digital missing-value marker. Infinite samples give a clear calibration error.

Expanded physical signals now calculate adc_gain and baseline after selecting a format, matching the uniform signal path. This works through both wrsamp and write_record without requiring callers to supply calibration fields.

Verification

  • Added round-trip regression tests for both writers with uniform and expanded physical signals containing NaN, including all-NaN channels, and a test for the infinite-value error.
  • Full offline suite: 1,145 passed, 4 skipped, 22 network tests deselected.
  • Ruff check and format pass; Sphinx HTML docs build passes with warnings treated as errors.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct and ready to merge. Thanks for fixing #786.

  • Missing samples. Dropping nan in est_res before taking the minimum increment fixes the IndexError, which came from a nan increment. It also fixes constant channels, which previously failed on min() of an empty sequence.
  • Expanded signals. That branch now calls calc_adc_params(), just like the uniform branch. calc_adc_params already handles e_p_signal and ignores nan through fmin/fmax.

Checked locally:

  • nan positions survive a round trip for:
    • a channel containing its minimum, its maximum and a nan;
    • 500 random samples with 5% nan;
    • an all-nan channel next to a normal one;
    • a constant channel;
    • float32 input.
  • The minimum value is never written as the missing-value marker.
  • Rounding error stays within half a step (0.5 / adc_gain) in every case.
  • A three-channel expanded record with samps_per_frame=[2, 1, 1] and one all-nan channel round-trips with nan positions intact, and check_record reports no issues.
  • -inf gets the same clear error as inf.
  • set_d_features is the only caller of est_res, so nothing else is affected.
  • The offline suite and ruff pass.

Optional: the tests use atol=0.01. Asserting against half a step (0.5 / adc_gain) would also catch a calibration that gets worse while staying under 0.01.

@tompollard
tompollard merged commit 9302f82 into main Nov 30, 2026
19 checks passed
@tompollard
tompollard deleted the fix/physical-calibration branch November 30, 2026 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wrsamp cannot calculate calibration for physical signals with NaN or expanded layout

1 participant