Skip to content

Commit

Permalink
Merge branch 'master' into fix_edf_handle
Browse files Browse the repository at this point in the history
  • Loading branch information
h-mayorquin committed Oct 16, 2024
2 parents 1e3c6bc + de6b3b5 commit ade13db
Show file tree
Hide file tree
Showing 23 changed files with 81 additions and 33 deletions.
2 changes: 1 addition & 1 deletion neo/io/igorproio.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _wave_to_analogsignal(self, content, dirpath):
_time_unit_structure = header["dimUnits"].ravel()
# For the files we've seen so far, the first element of _time_unit_structure contains the units.
# If someone has a file for which this assumption does not hold an Exception will be raised.
if not all([element == b'' for element in _time_unit_structure[1:]]):
if not all([element == b"" for element in _time_unit_structure[1:]]):
raise Exception(
"Neo cannot yet handle the units in this file. "
"Please create a new issue in the Neo issue tracker at "
Expand Down
12 changes: 11 additions & 1 deletion neo/rawio/axographrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,17 @@ def _scan_axograph_file(self):
# channel_info will be cast to _signal_channel_dtype
buffer_id = ""
stream_id = "0"
channel_info = (name, str(i), 1 / sampling_period, f.byte_order + dtype, units, gain, offset, stream_id, buffer_id)
channel_info = (
name,
str(i),
1 / sampling_period,
f.byte_order + dtype,
units,
gain,
offset,
stream_id,
buffer_id,
)

self.logger.debug("channel_info: {channel_info}")
self.logger.debug("")
Expand Down
4 changes: 3 additions & 1 deletion neo/rawio/axonrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ def _parse_header(self):
gain, offset = 1.0, 0.0
stream_id = "0"
buffer_id = "0"
signal_channels.append((name, str(chan_id), self._sampling_rate, sig_dtype, units, gain, offset, stream_id, buffer_id))
signal_channels.append(
(name, str(chan_id), self._sampling_rate, sig_dtype, units, gain, offset, stream_id, buffer_id)
)

signal_channels = np.array(signal_channels, dtype=_signal_channel_dtype)

Expand Down
5 changes: 4 additions & 1 deletion neo/rawio/baserawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@
_signal_stream_dtype = [
("name", "U64"), # not necessarily unique
("id", "U64"), # must be unique
("buffer_id", "U64"), # should be "" (empty string) when the stream is not nested under a buffer or the buffer is undefined for some reason.
(
"buffer_id",
"U64",
), # should be "" (empty string) when the stream is not nested under a buffer or the buffer is undefined for some reason.
]

_signal_channel_dtype = [
Expand Down
4 changes: 3 additions & 1 deletion neo/rawio/brainvisionrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ def _parse_header(self):
offset = 0
stream_id = "0"
buffer_id = "0"
sig_channels.append((name, chan_id, self._sampling_rate, sig_dtype, units, gain, offset, stream_id, buffer_id))
sig_channels.append(
(name, chan_id, self._sampling_rate, sig_dtype, units, gain, offset, stream_id, buffer_id)
)
sig_channels = np.array(sig_channels, dtype=_signal_channel_dtype)

# No spikes
Expand Down
13 changes: 11 additions & 2 deletions neo/rawio/elanrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ def _parse_header(self):
# unique buffer and stream
signal_buffers = np.array([("Signals", "0")], dtype=_signal_buffer_dtype)
signal_streams = np.array([("Signals", "0", "0")], dtype=_signal_stream_dtype)


sig_channels = []
for c, chan_info in enumerate(channel_infos[:-2]):
Expand All @@ -172,7 +171,17 @@ def _parse_header(self):
stream_id = "0"
buffer_id = "0"
sig_channels.append(
(chan_name, chan_id, self._sampling_rate, sig_dtype, chan_info["units"], gain, offset, stream_id, buffer_id)
(
chan_name,
chan_id,
self._sampling_rate,
sig_dtype,
chan_info["units"],
gain,
offset,
stream_id,
buffer_id,
)
)

sig_channels = np.array(sig_channels, dtype=_signal_channel_dtype)
Expand Down
1 change: 0 additions & 1 deletion neo/rawio/intanrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ def _parse_header(self):

stream_ids = np.unique(signal_channels["stream_id"])
signal_streams = np.zeros(stream_ids.size, dtype=_signal_stream_dtype)


# we need to sort the data because the string of stream_index 10 is mis-sorted.
buffer_ids = []
Expand Down
8 changes: 4 additions & 4 deletions neo/rawio/maxwellrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,12 @@ def _parse_header(self):
raise NotImplementedError(f"This version {version} is not supported")

signal_streams = np.array(signal_streams, dtype=_signal_stream_dtype)

# one stream per buffer
signal_buffers = np.zeros(signal_streams.size, dtype=_signal_buffer_dtype)
signal_buffers["id"] = signal_streams["id"]
signal_buffers["name"] = signal_streams["name"]


# create signal channels
max_sig_length = 0
self._signals = {}
Expand Down Expand Up @@ -160,7 +159,6 @@ def _parse_header(self):
warnings.warn(f"No 'routed' group found for well {stream_id}")
well_indices_to_remove.append(stream_index)
continue


channel_ids = np.array(mapping["channel"])
electrode_ids = np.array(mapping["electrode"])
Expand All @@ -173,7 +171,9 @@ def _parse_header(self):
ch_name = f"ch{chan_id} elec{elec_id}"
offset_uV = 0
buffer_id = stream_id
sig_channels.append((ch_name, str(chan_id), sr, "uint16", "uV", gain_uV, offset_uV, stream_id, buffer_id))
sig_channels.append(
(ch_name, str(chan_id), sr, "uint16", "uV", gain_uV, offset_uV, stream_id, buffer_id)
)

self._signals[stream_id] = sigs
max_sig_length = max(max_sig_length, sigs.shape[1])
Expand Down
4 changes: 3 additions & 1 deletion neo/rawio/micromedrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ def _parse_header(self):
chan_id = str(c)
stream_id = "0"
buffer_id = "0"
signal_channels.append((chan_name, chan_id, sampling_rate, sig_dtype, units, gain, offset, stream_id, buffer_id))
signal_channels.append(
(chan_name, chan_id, sampling_rate, sig_dtype, units, gain, offset, stream_id, buffer_id)
)

signal_channels = np.array(signal_channels, dtype=_signal_channel_dtype)

Expand Down
12 changes: 11 additions & 1 deletion neo/rawio/neuralynxrawio/neuralynxrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,17 @@ def _parse_header(self):
gain *= -1
offset = 0.0
signal_channels.append(
(chan_name, str(chan_id), info["sampling_rate"], "int16", units, gain, offset, stream_id, buffer_id)
(
chan_name,
str(chan_id),
info["sampling_rate"],
"int16",
units,
gain,
offset,
stream_id,
buffer_id,
)
)
self.ncs_filenames[chan_uid] = filename
keys = [
Expand Down
4 changes: 2 additions & 2 deletions neo/rawio/neuronexusrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def _parse_header(self):
1, # no gain
0, # no offset
stream_id,
buffer_id
buffer_id,
)
)

Expand All @@ -203,7 +203,7 @@ def _parse_header(self):
stream_ids = np.unique(signal_channels["stream_id"])
signal_streams = np.zeros(stream_ids.size, dtype=_signal_stream_dtype)
signal_streams["id"] = [str(stream_id) for stream_id in stream_ids]
# One unique buffer
# One unique buffer
signal_streams["buffer_id"] = buffer_id

for stream_index, stream_id in enumerate(stream_ids):
Expand Down
4 changes: 3 additions & 1 deletion neo/rawio/neuroscoperawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ def _parse_header(self):
offset = 0.0
stream_id = "0"
buffer_id = "0"
sig_channels.append((name, chan_id, self._sampling_rate, sig_dtype, units, gain, offset, stream_id, buffer_id))
sig_channels.append(
(name, chan_id, self._sampling_rate, sig_dtype, units, gain, offset, stream_id, buffer_id)
)
sig_channels = np.array(sig_channels, dtype=_signal_channel_dtype)

# No events
Expand Down
2 changes: 1 addition & 1 deletion neo/rawio/openephysrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def _parse_header(self):
signal_streams = []
signal_streams = np.array(signal_streams, dtype=_signal_stream_dtype)
# no buffer handling in this format because one channel per file
signal_buffers = np.array( [], dtype=_signal_buffer_dtype)
signal_buffers = np.array([], dtype=_signal_buffer_dtype)

# scan for spikes files
spike_channels = []
Expand Down
5 changes: 3 additions & 2 deletions neo/rawio/plexonrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,12 @@ def _parse_header(self):
)
offset = 0.0


channel_prefix = re.match(regex_prefix_pattern, name).group(0)
stream_id = channel_prefix
buffer_id = ""
signal_channels.append((name, str(chan_id), sampling_rate, sig_dtype, units, gain, offset, stream_id, buffer_id))
signal_channels.append(
(name, str(chan_id), sampling_rate, sig_dtype, units, gain, offset, stream_id, buffer_id)
)

signal_channels = np.array(signal_channels, dtype=_signal_channel_dtype)

Expand Down
2 changes: 1 addition & 1 deletion neo/rawio/rawbinarysignalrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _parse_header(self):
self.signal_gain,
self.signal_offset,
stream_id,
buffer_id
buffer_id,
)
)

Expand Down
4 changes: 3 additions & 1 deletion neo/rawio/spike2rawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ def _parse_header(self):
sig_dtype = "float32"
stream_id = "0" # set it after the loop
buffer_id = ""
signal_channels.append((name, str(chan_id), sampling_rate, sig_dtype, units, gain, offset, stream_id, buffer_id))
signal_channels.append(
(name, str(chan_id), sampling_rate, sig_dtype, units, gain, offset, stream_id, buffer_id)
)

elif chan_info["kind"] in [2, 3, 4, 5, 8]:
# Event
Expand Down
1 change: 0 additions & 1 deletion neo/rawio/spikegadgetsrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ def _parse_header(self):
self._mask_channels_bytes[stream_id] = mask
self._mask_streams[stream_id] = np.any(mask, axis=0)


signal_streams = np.array(signal_streams, dtype=_signal_stream_dtype)
signal_channels = np.array(signal_channels, dtype=_signal_channel_dtype)
# no buffer concept here data are too fragmented
Expand Down
4 changes: 3 additions & 1 deletion neo/rawio/tdtrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ def _parse_header(self):
gain = 1.0
offset = 0.0
buffer_id = ""
signal_channels.append((chan_name, str(chan_id), sampling_rate, dtype, units, gain, offset, stream_id, buffer_id))
signal_channels.append(
(chan_name, str(chan_id), sampling_rate, dtype, units, gain, offset, stream_id, buffer_id)
)

if missing_sev_channels:
warnings.warn(f"Could not identify sev files for channels {missing_sev_channels}.")
Expand Down
6 changes: 4 additions & 2 deletions neo/rawio/winedrrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def _parse_header(self):
offset = -YZ * gain
stream_id = "0"
buffer_id = "0"
signal_channels.append((name, str(chan_id), self._sampling_rate, "int16", units, gain, offset, stream_id, buffer_id))
signal_channels.append(
(name, str(chan_id), self._sampling_rate, "int16", units, gain, offset, stream_id, buffer_id)
)

signal_channels = np.array(signal_channels, dtype=_signal_channel_dtype)

Expand All @@ -104,7 +106,7 @@ def _parse_header(self):
for i in range(unique_characteristics.size):
mask = unique_characteristics[i] == characteristics
signal_channels["stream_id"][mask] = str(i)
# unique buffer for all streams
# unique buffer for all streams
buffer_id = "0"
signal_streams.append((f"stream {i}", str(i), buffer_id))
signal_streams = np.array(signal_streams, dtype=_signal_stream_dtype)
Expand Down
6 changes: 4 additions & 2 deletions neo/rawio/winwcprawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ def _parse_header(self):
offset = 0.0
stream_id = "0"
buffer_id = "0"
signal_channels.append((name, chan_id, self._sampling_rate, "int16", units, gain, offset, stream_id, buffer_id))
signal_channels.append(
(name, chan_id, self._sampling_rate, "int16", units, gain, offset, stream_id, buffer_id)
)

signal_channels = np.array(signal_channels, dtype=_signal_channel_dtype)

Expand All @@ -129,7 +131,7 @@ def _parse_header(self):
for i in range(unique_characteristics.size):
mask = unique_characteristics[i] == characteristics
signal_channels["stream_id"][mask] = str(i)
# unique buffer for all streams
# unique buffer for all streams
buffer_id = "0"
signal_streams.append((f"stream {i}", str(i), buffer_id))
signal_streams = np.array(signal_streams, dtype=_signal_stream_dtype)
Expand Down
3 changes: 2 additions & 1 deletion neo/test/rawiotest/rawio_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def header_is_total(reader):
for k, _ in _event_channel_dtype:
assert k in dt.fields, f"{k} not in event_channels.dtype"


def check_signal_stream_buffer_hierachy(reader):
# rules:
# * a channel always belong to a stream
Expand All @@ -95,7 +96,7 @@ def check_signal_stream_buffer_hierachy(reader):
assert channel["stream_id"] in h["signal_streams"]["id"]
if channel["buffer_id"] != "":
assert channel["buffer_id"] in h["signal_buffers"]["id"]

stream_ids = h["signal_streams"]["id"]
if stream_ids.size > 0:
assert stream_ids.size == np.unique(stream_ids).size
Expand Down
2 changes: 1 addition & 1 deletion neo/test/rawiotest/test_neuronexusrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ class TestNeuroNexusRawIO(


if __name__ == "__main__":
unittest.main()
unittest.main()
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ iocache = [
]

test = [
"dhn_med_py>=1.0.0",
"dhn_med_py<2.0", # ci failing with 2.0 test future version when stable
"pytest",
"pytest-cov",
# datalad # this dependency is covered by conda (environment_testing.yml)
Expand Down Expand Up @@ -100,13 +100,13 @@ ced = ["sonpy"]
nwb = ["pynwb"]
maxwell = ["h5py"]
biocam = ["h5py"]
med = ["dhn_med_py>=1.0.0"]
med = ["dhn_med_py<2.0"] # ci failing with 2.0 test future version when stable
plexon2 = ["zugbruecke>=0.2; sys_platform!='win32'", "wenv; sys_platform!='win32'"]

all = [
"coverage",
"coveralls",
"dhn_med_py>=1.0.0",
"dhn_med_py<2.0", # ci failing with 2.0 test future version when stable
"h5py",
"igor2",
"ipython",
Expand Down

0 comments on commit ade13db

Please sign in to comment.