Skip to content

Micromed: read the samples before the first TRONCA entry, put events on the segment clock, read header version 5 - #1966

Open
soheilrayatdoost wants to merge 2 commits into
NeuralEnsemble:masterfrom
soheilrayatdoost:micromed-tronca-first-segment-and-v5
Open

soheilrayatdoost wants to merge 2 commits into
NeuralEnsemble:masterfrom
soheilrayatdoost:micromed-tronca-first-segment-and-v5

Conversation

@soheilrayatdoost

Copy link
Copy Markdown

Fixes #1965

MicromedRawIO loses the start of a file that has a TRONCA table, puts its events at the wrong time, and refuses header version 5. The issue has the details and a reproduction that needs no file. Two commits, so that the second can be dropped if #1858 is preferred for version 5.

1. The samples before the first trace_offset are a segment (first commit)

A TRONCA entry is (seg_start, trace_offset): the sample at index trace_offset of the data block is at sample seg_start of the recording clock, which is the time axis of the segment. Segments were built from the entries only, so when the first trace_offset is above 0 the samples before it belonged to no segment. They now form a first segment starting at time 0, where the clock and the data block agree. A table whose first trace_offset is 0, like the one of File_mircomed2_2segments.TRC, gets no extra segment.

2. Event times (first commit)

An event start is an index in the data block, the same coordinate as trace_offset. The time of an event was start + seg_start of the first segment, whatever its own segment. It is now seg_start + start - trace_offset of the segment that holds it, which is the time of the sample it labels. This only changes files where seg_start - trace_offset differs between segments or from the first seg_start, so the existing test files read as before (the table of File_mircomed2_2segments.TRC is [(5, 0), (24837, 24832)]: the offset is 5 in both entries). t_start and t_stop of get_event_timestamps use the same axis.

3. Header version 5 (second commit)

The version check accepts 5. The other thing that stopped version 5 files is that their zone names are padded with NULs (b"IMPED_B\x00") instead of spaces, so the name check raised expected the zone name to match; it now strips both. On the version 5 files I have, nothing else was needed: channel names and data equal those of an independent reader (maximum difference 0.0 V over six files). This overlaps #1858, which relaxes the same check. I did not need to skip the IMPED_B/IMPED_E entries or to seek to 288 for these files, but I can't tell whether the files of #1858 differ from mine. I'm happy to rebase on #1858 or to drop this commit.

Tests

  • TestMicromedSyntheticFiles writes small files with write_micromed_trc (no patient data), so it needs no download. 12 tests: the segments and their t_start for one cut, two cuts and a table that starts at sample 0, the time of notes, triggers and epochs in each segment, t_start/t_stop filtering, MicromedIO.read_block, version 5, and that other versions and a wrongly named zone are still refused. On current master the 7 tests of the fixed behaviour fail and the 5 that guard unchanged behaviour pass.
  • The existing TestMicromedRawIO on the three Micromed files of ephy_testing_data passes before and after. datalad is not installed here, so I ran its two tests by hand against local copies of the files.
  • I have no real file I can share (they are clinical recordings), which is why the files are synthetic. If you would rather have files in ephy_testing_data, the writer produces them: the two I would add are a version 4 file with two cuts and a version 5 file with one.

black --line-length 120 is clean.

@zm711

zm711 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Thanks @soheilrayatdoost one of us will try to look at this soon. I have a work deadline so I won't be able to look at this for a week, but if someone else on the team can we will follow up. We tend to like to involve as many people in the project as possible so my gut tells me we will probably try to incorporate both this and #1858.

…ts on the segment clock

A TRONCA table lists the segments that follow each cut. When its first trace_offset is
above 0 the samples before it are a segment of their own (the recording clock and the data
block agree there), but no segment was built for them, so they were never read.

Event positions are indices in the data block, the coordinate of trace_offset, while the
time axis of a segment starts at its seg_start. Events were placed at start + the first
seg_start for every segment, which is right only when seg_start - trace_offset is the same
in every entry and the first trace_offset is 0 (as in File_mircomed2_2segments.TRC). They
are now placed at seg_start + start - trace_offset, which is the time of their sample.
A file without a table, or with a constant offset, reads as before.

The tests write their own files, so they need no downloaded data.
Header version 5 has the same layout as version 4 for everything the reader uses. The zone
table differs in one detail: the zone names are padded with NULs instead of spaces, so the
name check failed even with the version check relaxed.
@soheilrayatdoost
soheilrayatdoost force-pushed the micromed-tronca-first-segment-and-v5 branch from a1b2a37 to b5b4b86 Compare November 9, 2026 16:09

This branch has not been deployed

No deployments
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.

Micromed: TRONCA tables drop the start of the recording and misplace events; header version 5 is not read

2 participants