Skip to content

Commit

Permalink
Change how sample num is read
Browse files Browse the repository at this point in the history
  • Loading branch information
withmywoessner committed Jan 29, 2024
1 parent 4ccd30f commit ea2f4aa
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mne/io/cnt/cnt.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def _get_cnt_info(input_fname, eog, ecg, emg, misc, data_format, date_format, he
# Header has a field for number of samples, but it does not seem to be
# too reliable. That's why we have option for setting n_bytes manually.
fid.seek(864)
n_samples = np.fromfile(fid, dtype="<i4", count=1).item()
n_samples = np.fromfile(fid, dtype="<u4", count=1).item()
fid.seek(869)
lowcutoff = np.fromfile(fid, dtype="f4", count=1).item()
fid.seek(2, 1)
Expand Down Expand Up @@ -548,6 +548,7 @@ def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
channel_offset = self._raw_extras[fi]["channel_offset"]
baselines = self._raw_extras[fi]["baselines"]
n_bytes = self._raw_extras[fi]["n_bytes"]
n_samples = self._raw_extras[fi]["n_samples"]
dtype = "<i4" if n_bytes == 4 else "<i2"
chunk_size = channel_offset * f_channels # Size of chunks in file.
# The data is divided into blocks of samples / channel.
Expand All @@ -562,9 +563,9 @@ def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
with open(self._filenames[fi], "rb", buffering=0) as fid:
fid.seek(900 + f_channels * (75 + (start - s_offset) * n_bytes))
for sample_start in np.arange(0, data_left, block_size) // f_channels:
sample_stop = sample_start + min(
(block_size // f_channels, data_left // f_channels - sample_start)
)
# Earlier comment says n_samples is unreliable, but I think it
# is because it needed to be changed to unsigned int.
sample_stop = sample_start + min((n_samples, block_size // f_channels, data_left // f_channels - sample_start))
n_samps = sample_stop - sample_start
one = np.zeros((n_channels, n_samps))

Expand Down

0 comments on commit ea2f4aa

Please sign in to comment.