From e54402684da7daeb1fa2ba407f2c4b4f918f7530 Mon Sep 17 00:00:00 2001 From: Theodore Papadopoulo Date: Sun, 1 Jun 2025 17:06:11 +0200 Subject: [PATCH 1/6] Implement FIFF_DATA_SKIP_SAMP. --- mne/io/fiff/raw.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/mne/io/fiff/raw.py b/mne/io/fiff/raw.py index f9e10a0039d..5d4abe98d26 100644 --- a/mne/io/fiff/raw.py +++ b/mne/io/fiff/raw.py @@ -281,6 +281,8 @@ def _read_raw_file( FIFF.FIFFT_COMPLEX_DOUBLE: "double", } + nskip = 0 + nskip_in_samples = 0 for k in range(first, nent): ent = directory[k] # There can be skips in the data (e.g., if the user unclicked) @@ -305,16 +307,20 @@ def _read_raw_file( # Do we have a skip pending? if nskip > 0: + nskip_in_samples += nskip * nsamp + nskip = 0 + + if nskip_in_samples > 0: raw_extras.append( dict( ent=None, first=first_samp, - nsamp=nskip * nsamp, - last=first_samp + nskip * nsamp - 1, + nsamp=nskip_in_samples, + last=first_samp + nskip_in_samples - 1, ) ) - first_samp += nskip * nsamp - nskip = 0 + first_samp += nskip_in_samples + nskip_in_samples = 0 # Add a data buffer raw_extras.append( @@ -328,7 +334,10 @@ def _read_raw_file( first_samp += nsamp elif ent.kind == FIFF.FIFF_DATA_SKIP: tag = read_tag(fid, ent.pos) - nskip = int(tag.data.item()) + nskip += int(tag.data.item()) + elif ent.kind == FIFF.FIFF_DATA_SKIP_SAMP: + tag = read_tag(fid, ent.pos) + nskip_in_samples += int(tag.data.item()) next_fname = _get_next_fname(fid, _path_from_fname(fname), tree) From ed085903409ecaaa3d26993033dfae4bc45b759e Mon Sep 17 00:00:00 2001 From: Theodore Papadopoulo Date: Sun, 1 Jun 2025 17:24:36 +0200 Subject: [PATCH 2/6] Also handle multiple skip at start. Small simplification. --- mne/io/fiff/raw.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/mne/io/fiff/raw.py b/mne/io/fiff/raw.py index 5d4abe98d26..f6b2027d8f5 100644 --- a/mne/io/fiff/raw.py +++ b/mne/io/fiff/raw.py @@ -231,7 +231,6 @@ def _read_raw_file( nchan = int(info["nchan"]) first = 0 first_samp = 0 - first_skip = 0 # Get first sample tag if it is there if directory[first].kind == FIFF.FIFF_FIRST_SAMPLE: @@ -240,14 +239,6 @@ def _read_raw_file( first += 1 _check_entry(first, nent) - # Omit initial skip - if directory[first].kind == FIFF.FIFF_DATA_SKIP: - # This first skip can be applied only after we know the bufsize - tag = read_tag(fid, directory[first].pos) - first_skip = int(tag.data.item()) - first += 1 - _check_entry(first, nent) - raw = _RawShell() raw.first_samp = first_samp if info["meas_date"] is None and annotations is not None: @@ -283,6 +274,7 @@ def _read_raw_file( nskip = 0 nskip_in_samples = 0 + first_data_buffer = True for k in range(first, nent): ent = directory[k] # There can be skips in the data (e.g., if the user unclicked) @@ -299,12 +291,6 @@ def _read_raw_file( if orig_format is None: orig_format = _orig_format_dict[ent.type] - # Do we have an initial skip pending? - if first_skip > 0: - first_samp += nsamp * first_skip - raw.first_samp = first_samp - first_skip = 0 - # Do we have a skip pending? if nskip > 0: nskip_in_samples += nskip * nsamp @@ -322,6 +308,12 @@ def _read_raw_file( first_samp += nskip_in_samples nskip_in_samples = 0 + # Handle an initial skip. + + if first_data_buffer: + raw.first_samp = first_samp + first_data_buffer = False + # Add a data buffer raw_extras.append( dict( From 614bda41796ea271179ba4db424605e3300bd7dd Mon Sep 17 00:00:00 2001 From: Theodore Papadopoulo Date: Sun, 1 Jun 2025 17:49:09 +0200 Subject: [PATCH 3/6] Add ChangeLog entry. --- doc/changes/devel/13270.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changes/devel/13270.bugfix.rst diff --git a/doc/changes/devel/13270.bugfix.rst b/doc/changes/devel/13270.bugfix.rst new file mode 100644 index 00000000000..b57312efde1 --- /dev/null +++ b/doc/changes/devel/13270.bugfix.rst @@ -0,0 +1 @@ +Fix bug where the tag FIFF_DATA_SKIP_SAMP was not handled as well as the use of multiple succesive uses of FIFF_DATA_SKIP and/or FIFF_DATA_SKIP_SAMP, by :newcontrib:`Théodore Papadopoulo`. From 412d18c144e786e53e19af9741f17cb39a7e3d32 Mon Sep 17 00:00:00 2001 From: Theodore Papadopoulo Date: Mon, 2 Jun 2025 10:26:12 +0200 Subject: [PATCH 4/6] Fix typo. --- doc/changes/devel/13270.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changes/devel/13270.bugfix.rst b/doc/changes/devel/13270.bugfix.rst index b57312efde1..80718eaaedc 100644 --- a/doc/changes/devel/13270.bugfix.rst +++ b/doc/changes/devel/13270.bugfix.rst @@ -1 +1 @@ -Fix bug where the tag FIFF_DATA_SKIP_SAMP was not handled as well as the use of multiple succesive uses of FIFF_DATA_SKIP and/or FIFF_DATA_SKIP_SAMP, by :newcontrib:`Théodore Papadopoulo`. +Fix bug where the tag FIFF_DATA_SKIP_SAMP was not handled as well as the use of multiple successive uses of FIFF_DATA_SKIP and/or FIFF_DATA_SKIP_SAMP, by :newcontrib:`Théodore Papadopoulo`. From 659783cd2b77f1e8b0cbf721ac58503ab5af40d3 Mon Sep 17 00:00:00 2001 From: Theodore Papadopoulo Date: Mon, 2 Jun 2025 12:17:49 +0200 Subject: [PATCH 5/6] Avoid adding an empty slot before any data block. --- mne/io/fiff/raw.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mne/io/fiff/raw.py b/mne/io/fiff/raw.py index f6b2027d8f5..7c7ba647139 100644 --- a/mne/io/fiff/raw.py +++ b/mne/io/fiff/raw.py @@ -297,14 +297,15 @@ def _read_raw_file( nskip = 0 if nskip_in_samples > 0: - raw_extras.append( - dict( - ent=None, - first=first_samp, - nsamp=nskip_in_samples, - last=first_samp + nskip_in_samples - 1, + if not first_data_buffer: + raw_extras.append( + dict( + ent=None, + first=first_samp, + nsamp=nskip_in_samples, + last=first_samp + nskip_in_samples - 1, + ) ) - ) first_samp += nskip_in_samples nskip_in_samples = 0 From 1a6c476b369814f3e2b86e44186eb5ff1b0abceb Mon Sep 17 00:00:00 2001 From: Theodore Papadopoulo Date: Mon, 2 Jun 2025 17:01:37 +0200 Subject: [PATCH 6/6] Update ChangeLog. --- doc/changes/devel/13270.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changes/devel/13270.bugfix.rst b/doc/changes/devel/13270.bugfix.rst index 80718eaaedc..d84c8aaa737 100644 --- a/doc/changes/devel/13270.bugfix.rst +++ b/doc/changes/devel/13270.bugfix.rst @@ -1 +1 @@ -Fix bug where the tag FIFF_DATA_SKIP_SAMP was not handled as well as the use of multiple successive uses of FIFF_DATA_SKIP and/or FIFF_DATA_SKIP_SAMP, by :newcontrib:`Théodore Papadopoulo`. +Fix bug where the tag FIFF_DATA_SKIP_SAMP was not handled as well as the use of multiple successive uses of FIFF_DATA_SKIP and/or FIFF_DATA_SKIP_SAMP, by `Théodore Papadopoulo`_.