Skip to content

Implement data skip in samples #13270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/devel/13270.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +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 `Théodore Papadopoulo`_.
52 changes: 27 additions & 25 deletions mne/io/fiff/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -281,6 +272,9 @@ def _read_raw_file(
FIFF.FIFFT_COMPLEX_DOUBLE: "double",
}

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)
Expand All @@ -297,25 +291,30 @@ 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:
raw_extras.append(
dict(
ent=None,
first=first_samp,
nsamp=nskip * nsamp,
last=first_samp + nskip * nsamp - 1,
)
)
first_samp += nskip * nsamp
nskip_in_samples += nskip * nsamp
nskip = 0

if nskip_in_samples > 0:
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

# 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(
Expand All @@ -328,7 +327,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)

Expand Down