Skip to content

Write dat files from captured channel fields - #877

Merged
tompollard merged 1 commit into
mainfrom
refactor/explicit-dat-encoding
Dec 3, 2026
Merged

tompollard merged 1 commit into
mainfrom
refactor/explicit-dat-encoding

Conversation

@tompollard

Copy link
Copy Markdown
Member

Summary

Continue #866 by moving .dat file grouping onto captured channel fields and explicit digital arrays. The per-format wr_dat_file encoder already accepts explicit inputs; the remaining Record dependency was in wr_dat_files, which selected file groups, formats, offsets, and samples per frame from mutable attributes. The prepared write path now passes its channel snapshot and arrays to _write_dat_files.

The previous wr_dat_files implementation remains temporarily for the differential tests and direct calls without a snapshot. This is an internal refactor with no intended output or public API change, so there is no changelog entry.

Checks

  • The differential test compares complete files and error outcomes through the old and new write paths. It now switches the .dat grouping path too.
  • New cases cover all eight writable formats in uniform and expanded layouts, expanded channels with different samples per frame and missing values in separate formats, and a declared byte offset.
  • Differential tests: 359 passed, 44 known unreadable sample cases skipped.
  • Full offline suite: 2,167 passed, 48 skipped, 23 deselected.
  • Ruff and the warning-as-error Sphinx build pass.

The next #866 step is to let modern writers pass their model directly through these explicit functions, then remove the temporary Record adapter and legacy paths once the comparisons and benchmark pass.

@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 step is correct, and it can merge. The parity test passes (359 passed, 44 expected skips), as do the offline suite (2,167 passed, 48 skipped) and Ruff.

What I checked

  • Grouping matches the legacy path. _write_dat_files builds the same file groups with describe_list_indices, takes each file's format and byte offset from its first channel, uses offset 0 when byte_offset wasn't captured, and passes samps_per_frame or 1 for expanded channels. All of that comes from the snapshot rather than self.
  • The uniform slice is safe. values[:, channels[0] : channels[-1] + 1] assumes a file's channels are adjacent. The legacy path makes the same assumption, and check_field already rejects non-adjacent channels before writing ("Signals in a record that share a given file must be consecutive", record.py:803). So nothing changes here.
  • Nothing is shared without a comparison. The per-format encoder wr_dat_file is called by both sides but isn't modified in this PR, so the comparison really tests the grouping change. The new cases cover all eight writable formats in both layouts, mixed formats with gaps across separate files, and a declared byte offset.

For the next step

wr_dat_files still falls back to _legacy_wr_dat_files when it's called without a snapshot. That fallback, and the other legacy paths, are what the "model passes directly" step should remove. When it does, the parity test will lose its legacy side. Before deleting them, it would help to freeze the outputs as reference bytes for a few representative cases: formats 16 and 212, expanded mixed frames, a gap in each format and a multi-segment master. That way the end state is still checked against something.

@tompollard

Copy link
Copy Markdown
Member Author

Thanks for checking the grouping and format coverage. I agree on preserving reference bytes before the legacy side goes away. I’ll add fixed outputs from the pinned #866 baseline for formats 16 and 212, expanded mixed frames, missing samples in each format, and a multi-segment master before removing the fallback paths. I’ll keep the live old-versus-new comparison through the model handoff so that step can still be checked directly.

@tompollard
tompollard merged commit 4e98cb4 into main Dec 3, 2026
19 checks passed
@tompollard
tompollard deleted the refactor/explicit-dat-encoding branch December 3, 2026 05:49
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.

1 participant