Skip to content

Commit a8fd571

Browse files
authored
Merge branch 'master' into uv_pyproject_remove_friction
2 parents f7ad79d + d6a649e commit a8fd571

6 files changed

Lines changed: 49 additions & 163 deletions

File tree

‎neo/io/spikeglxio.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ class SpikeGLXIO(SpikeGLXRawIO, BaseFromRaw):
66
__doc__ = SpikeGLXRawIO.__doc__
77
mode = "dir"
88

9-
def __init__(self, dirname, load_sync_channel=False, load_channel_location=False):
10-
SpikeGLXRawIO.__init__(
11-
self, dirname=dirname, load_sync_channel=load_sync_channel, load_channel_location=load_channel_location
12-
)
9+
def __init__(self, dirname, load_channel_location=False):
10+
SpikeGLXRawIO.__init__(self, dirname=dirname, load_channel_location=load_channel_location)
1311
BaseFromRaw.__init__(self, dirname)

‎neo/rawio/baserawio.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ def _get_analogsignal_chunk(
16981698
else:
16991699
raise NotImplementedError()
17001700

1701-
# this is a pre slicing when the stream do not contain all channels (for instance spikeglx when load_sync_channel=False)
1701+
# this is a pre slicing when the stream does not contain all channels in the buffer (for instance spikeglx -SYNC streams)
17021702
if buffer_slice is not None:
17031703
raw_sigs = raw_sigs[:, buffer_slice]
17041704

‎neo/rawio/openephysbinaryrawio.py‎

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ class OpenEphysBinaryRawIO(BaseRawWithBufferApiIO):
3636
----------
3737
dirname : str
3838
Path to Open Ephys directory
39-
load_sync_channel : bool
40-
If False (default) and a SYNC channel is present (e.g. Neuropixels), this is not loaded.
41-
If True, the SYNC channel is loaded and can be accessed in the analog signals.
4239
experiment_names : str or list or None
4340
If multiple experiments are available, this argument allows users to select one
4441
or more experiments. If None, all experiements are loaded as blocks.
@@ -109,21 +106,13 @@ class OpenEphysBinaryRawIO(BaseRawWithBufferApiIO):
109106
extensions = ["xml", "oebin", "txt", "dat", "npy"]
110107
rawmode = "one-dir"
111108

112-
def __init__(self, dirname="", load_sync_channel=False, experiment_names=None):
109+
def __init__(self, dirname="", experiment_names=None):
113110
BaseRawWithBufferApiIO.__init__(self)
114111
self.dirname = dirname
115112
if experiment_names is not None:
116113
if isinstance(experiment_names, str):
117114
experiment_names = [experiment_names]
118115
self.experiment_names = experiment_names
119-
self.load_sync_channel = load_sync_channel
120-
if load_sync_channel:
121-
warn(
122-
"The load_sync_channel=True option is deprecated and will be removed in version 0.15. "
123-
"Use load_sync_channel=False instead, which will add sync channels as separate streams.",
124-
DeprecationWarning,
125-
stacklevel=2,
126-
)
127116
self.folder_structure = None
128117
self._use_direct_evt_timestamps = None
129118

@@ -200,7 +189,7 @@ def _parse_header(self):
200189
units = "uV" if "ADC" not in chan_id else "V"
201190

202191
# Special cases for stream
203-
if "SYNC" in chan_id and not self.load_sync_channel:
192+
if "SYNC" in chan_id:
204193
# Every stream sync channel is added as its own stream
205194
sync_stream_id = f"{stream_name}SYNC"
206195
sync_stream_id_to_buffer_id[sync_stream_id] = buffer_id
@@ -296,12 +285,6 @@ def _parse_header(self):
296285

297286
has_sync_trace = self._sig_streams[block_index][seg_index][stream_index]["has_sync_trace"]
298287

299-
# check sync channel validity (only for AP and LF)
300-
if not has_sync_trace and self.load_sync_channel and "NI-DAQ" not in info["stream_name"]:
301-
raise ValueError(
302-
"SYNC channel is not present in the recording. " "Set load_sync_channel to False"
303-
)
304-
305288
# Check if ADC and non-ADC channels are contiguous
306289
is_channel_adc = ["ADC" in ch["channel_name"] for ch in info["channels"]]
307290
if any(is_channel_adc):
@@ -343,7 +326,7 @@ def _parse_header(self):
343326
num_adc_channels = 0
344327

345328
if num_adc_channels == 0:
346-
if has_sync_trace and not self.load_sync_channel:
329+
if has_sync_trace:
347330
# Exclude the sync channel from the main stream
348331
self._stream_buffer_slice[stream_id] = slice(None, -1)
349332

@@ -358,7 +341,7 @@ def _parse_header(self):
358341

359342
self._stream_buffer_slice[stream_id_neural] = slice(0, num_neural_channels)
360343

361-
if has_sync_trace and not self.load_sync_channel:
344+
if has_sync_trace:
362345
# Exclude the sync channel from the non-neural stream
363346
self._stream_buffer_slice[stream_id_non_neural] = slice(num_neural_channels, -1)
364347

@@ -564,7 +547,7 @@ def _parse_header(self):
564547
if has_sync_trace:
565548
values = values[:-1]
566549

567-
if "SYNC" in stream_name and not self.load_sync_channel:
550+
if "SYNC" in stream_name:
568551
# This is the sync stream, we only keep the last value
569552
values = values[-1:]
570553

‎neo/rawio/spikeglxrawio.py‎

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ class SpikeGLXRawIO(BaseRawWithBufferApiIO):
7676
----------
7777
dirname: str, default: ''
7878
The spikeglx folder containing meta/bin files
79-
load_sync_channel: bool, default: False
80-
Can be used to load the synch stream as the last channel of the neural data.
81-
This option is deprecated and will be removed in version 0.15.
82-
From versions higher than 0.14.1 the sync channel is always loaded as a separate stream.
8379
load_channel_location: bool, default: False
8480
If True probeinterface is used to load the channel locations from the directory
8581
@@ -108,17 +104,9 @@ class SpikeGLXRawIO(BaseRawWithBufferApiIO):
108104
extensions = ["meta", "bin"]
109105
rawmode = "one-dir"
110106

111-
def __init__(self, dirname="", load_sync_channel=False, load_channel_location=False):
107+
def __init__(self, dirname="", load_channel_location=False):
112108
BaseRawWithBufferApiIO.__init__(self)
113109
self.dirname = dirname
114-
self.load_sync_channel = load_sync_channel
115-
if load_sync_channel:
116-
warn(
117-
"The load_sync_channel=True option is deprecated and will be removed in version 0.15 \n"
118-
"The sync channel is now loaded as a separate stream by default and should be accessed as such. ",
119-
DeprecationWarning,
120-
stacklevel=2,
121-
)
122110
self.load_channel_location = load_channel_location
123111

124112
def _source_name(self):
@@ -179,10 +167,8 @@ def _parse_header(self):
179167
chan_name = info["channel_names"][local_channel_index]
180168
chan_id = f"{stream_name}#{chan_name}"
181169

182-
# Separate sync channel in its own stream
183-
is_sync_channel = "SY" in chan_name and not self.load_sync_channel
184-
if is_sync_channel:
185-
# This is a sync channel and should be added as its own stream
170+
# Separate sync channel in its own stream.
171+
if "SY" in chan_name:
186172
sync_stream_id = f"{stream_name}-SYNC"
187173
sync_stream_id_to_buffer_id[sync_stream_id] = buffer_id
188174
stream_id_for_chan = sync_stream_id
@@ -207,19 +193,12 @@ def _parse_header(self):
207193
# None here means that the all the channels in the buffer will be included
208194
self._stream_buffer_slice[stream_id] = None
209195

210-
# Then we modify this if sync channel is present to slice the last channel
211-
# out of the stream buffer
212-
if "nidq" not in stream_name:
213-
if not self.load_sync_channel and info["has_sync_trace"]:
214-
# the last channel is removed from the stream but not from the buffer
215-
self._stream_buffer_slice[stream_id] = slice(0, -1)
216-
217-
# Add a buffer slice for the sync channel
218-
sync_stream_id = f"{stream_name}-SYNC"
219-
self._stream_buffer_slice[sync_stream_id] = slice(-1, None)
220-
221-
if self.load_sync_channel and not info["has_sync_trace"]:
222-
raise ValueError("SYNC channel is not present in the recording. " "Set load_sync_channel to False")
196+
# If a sync trace is present, slice the last channel out of the parent
197+
# stream and expose it as the companion -SYNC stream sharing the same buffer.
198+
if "nidq" not in stream_name and info["has_sync_trace"]:
199+
self._stream_buffer_slice[stream_id] = slice(0, -1)
200+
sync_stream_id = f"{stream_name}-SYNC"
201+
self._stream_buffer_slice[sync_stream_id] = slice(-1, None)
223202

224203
signal_buffers = np.array(signal_buffers, dtype=_signal_buffer_dtype)
225204

@@ -318,9 +297,6 @@ def _parse_header(self):
318297
# only for ap channel
319298
probe = probeinterface.read_spikeglx(info["meta_file"])
320299
loc = probe.contact_positions
321-
if self.load_sync_channel:
322-
# one fake channel for "sys0"
323-
loc = np.concatenate((loc, [[0.0, 0.0]]), axis=0)
324300
for ndim in range(loc.shape[1]):
325301
sig_ann["__array_annotations__"][f"channel_location_{ndim}"] = loc[:, ndim]
326302

‎neo/test/rawiotest/test_openephysbinaryrawio.py‎

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,21 @@ class TestOpenEphysBinaryRawIO(BaseTestRawIO, unittest.TestCase):
2121
]
2222

2323
def test_sync(self):
24-
with self.assertWarns(DeprecationWarning):
25-
rawio_with_sync = OpenEphysBinaryRawIO(
26-
self.get_local_path("openephysbinary/v0.6.x_neuropixels_with_sync"), load_sync_channel=True
27-
)
28-
rawio_with_sync.parse_header()
29-
stream_name = [s_name for s_name in rawio_with_sync.header["signal_streams"]["name"] if "AP" in s_name][0]
30-
stream_index = list(rawio_with_sync.header["signal_streams"]["name"]).index(stream_name)
31-
32-
# AP stream has 385 channels
33-
chunk = rawio_with_sync.get_analogsignal_chunk(
34-
block_index=0, seg_index=0, i_start=0, i_stop=100, stream_index=stream_index
35-
)
36-
assert chunk.shape[1] == 385
37-
38-
rawio_no_sync = OpenEphysBinaryRawIO(
39-
self.get_local_path("openephysbinary/v0.6.x_neuropixels_with_sync"), load_sync_channel=False
40-
)
41-
rawio_no_sync.parse_header()
24+
# The sync trace is always split off into its own -SYNC stream; the parent
25+
# AP stream has 384 channels (384 neural, SYNC excluded).
26+
rawio = OpenEphysBinaryRawIO(self.get_local_path("openephysbinary/v0.6.x_neuropixels_with_sync"))
27+
rawio.parse_header()
28+
stream_name = [s_name for s_name in rawio.header["signal_streams"]["name"] if "AP" in s_name][0]
29+
stream_index = list(rawio.header["signal_streams"]["name"]).index(stream_name)
4230

43-
# AP stream has 384 channels
44-
chunk = rawio_no_sync.get_analogsignal_chunk(
31+
chunk = rawio.get_analogsignal_chunk(
4532
block_index=0, seg_index=0, i_start=0, i_stop=100, stream_index=stream_index
4633
)
4734
assert chunk.shape[1] == 384
4835

4936
def test_sync_channel_access(self):
50-
"""Test that sync channels can be accessed as separate streams when load_sync_channel=False."""
51-
rawio = OpenEphysBinaryRawIO(
52-
self.get_local_path("openephysbinary/v0.6.x_neuropixels_with_sync"), load_sync_channel=False
53-
)
37+
"""Sync channels are exposed as their own streams."""
38+
rawio = OpenEphysBinaryRawIO(self.get_local_path("openephysbinary/v0.6.x_neuropixels_with_sync"))
5439
rawio.parse_header()
5540

5641
# Find sync channel streams
@@ -68,28 +53,14 @@ def test_sync_channel_access(self):
6853
# Sync channel should have only one channel
6954
assert chunk.shape[1] == 1, f"Expected sync channel to have 1 channel, got {chunk.shape[1]}"
7055

71-
def test_no_sync(self):
72-
# requesting sync channel when there is none raises an error
73-
with self.assertRaises(ValueError):
74-
with self.assertWarns(DeprecationWarning):
75-
rawio_no_sync = OpenEphysBinaryRawIO(
76-
self.get_local_path("openephysbinary/v0.6.x_neuropixels_multiexp_multistream"),
77-
load_sync_channel=True,
78-
)
79-
rawio_no_sync.parse_header()
80-
8156
def test_missing_folders(self):
82-
# missing folders should raise an error
57+
# missing folders should raise a warning
8358
with self.assertWarns(UserWarning):
84-
rawio = OpenEphysBinaryRawIO(
85-
self.get_local_path("openephysbinary/v0.6.x_neuropixels_missing_folders"), load_sync_channel=False
86-
)
59+
rawio = OpenEphysBinaryRawIO(self.get_local_path("openephysbinary/v0.6.x_neuropixels_missing_folders"))
8760
rawio.parse_header()
8861

8962
def test_multiple_ttl_events_parsing(self):
90-
rawio = OpenEphysBinaryRawIO(
91-
self.get_local_path("openephysbinary/v0.6.x_neuropixels_with_sync"), load_sync_channel=False
92-
)
63+
rawio = OpenEphysBinaryRawIO(self.get_local_path("openephysbinary/v0.6.x_neuropixels_with_sync"))
9364
rawio.parse_header()
9465
rawio.header = rawio.header
9566
# Testing co
@@ -106,9 +77,7 @@ def test_multiple_ttl_events_parsing(self):
10677
assert np.allclose(ttl_events["durations"][ttl_events["labels"] == "7"], 0.016666, atol=0.001)
10778

10879
def test_separating_stream_for_non_neural_data(self):
109-
rawio = OpenEphysBinaryRawIO(
110-
self.get_local_path("openephysbinary/neural_and_non_neural_data_mixed"), load_sync_channel=False
111-
)
80+
rawio = OpenEphysBinaryRawIO(self.get_local_path("openephysbinary/neural_and_non_neural_data_mixed"))
11281
rawio.parse_header()
11382
# Check that the non-neural data stream is correctly separated
11483
assert len(rawio.header["signal_streams"]["name"]) == 2

‎neo/test/rawiotest/test_spikeglxrawio.py‎

Lines changed: 19 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -75,46 +75,25 @@ def test_with_location(self):
7575
assert any(have_location)
7676

7777
def test_sync(self):
78-
rawio_with_sync = SpikeGLXRawIO(self.get_local_path("spikeglx/NP2_with_sync"), load_sync_channel=True)
79-
rawio_with_sync.parse_header()
80-
stream_index = list(rawio_with_sync.header["signal_streams"]["name"]).index("imec0.ap")
81-
82-
# AP stream has 385 channels
83-
chunk = rawio_with_sync.get_analogsignal_chunk(
84-
block_index=0, seg_index=0, i_start=0, i_stop=100, stream_index=stream_index
85-
)
86-
assert chunk.shape[1] == 385
87-
88-
rawio_no_sync = SpikeGLXRawIO(self.get_local_path("spikeglx/NP2_with_sync"), load_sync_channel=False)
89-
rawio_no_sync.parse_header()
78+
# The sync trace is always split off into its own -SYNC stream; the parent
79+
# AP stream has 384 channels (384 neural channels, SY0 excluded).
80+
rawio = SpikeGLXRawIO(self.get_local_path("spikeglx/NP2_with_sync"))
81+
rawio.parse_header()
82+
stream_index = list(rawio.header["signal_streams"]["name"]).index("imec0.ap")
9083

91-
# AP stream has 384 channels
92-
chunk = rawio_no_sync.get_analogsignal_chunk(
84+
chunk = rawio.get_analogsignal_chunk(
9385
block_index=0, seg_index=0, i_start=0, i_stop=100, stream_index=stream_index
9486
)
9587
assert chunk.shape[1] == 384
9688

97-
def test_no_sync(self):
98-
# requesting sync channel when there is none raises an error
99-
with self.assertRaises(ValueError):
100-
rawio_no_sync = SpikeGLXRawIO(self.get_local_path("spikeglx/NP2_no_sync"), load_sync_channel=True)
101-
rawio_no_sync.parse_header()
102-
10389
def test_subset_with_sync(self):
104-
rawio_sub = SpikeGLXRawIO(self.get_local_path("spikeglx/NP2_subset_with_sync"), load_sync_channel=True)
105-
rawio_sub.parse_header()
106-
stream_index = list(rawio_sub.header["signal_streams"]["name"]).index("imec0.ap")
107-
108-
# AP stream has 121 channels
109-
chunk = rawio_sub.get_analogsignal_chunk(
110-
block_index=0, seg_index=0, i_start=0, i_stop=100, stream_index=stream_index
111-
)
112-
assert chunk.shape[1] == 121
90+
# Channel-subset recording with SY: 121 saved channels total, 120 neural plus
91+
# one SY that is split into the -SYNC stream, leaving 120 in the parent.
92+
rawio = SpikeGLXRawIO(self.get_local_path("spikeglx/NP2_subset_with_sync"))
93+
rawio.parse_header()
94+
stream_index = list(rawio.header["signal_streams"]["name"]).index("imec0.ap")
11395

114-
rawio_sub_no_sync = SpikeGLXRawIO(self.get_local_path("spikeglx/NP2_subset_with_sync"), load_sync_channel=False)
115-
rawio_sub_no_sync.parse_header()
116-
# AP stream has 120 channels
117-
chunk = rawio_sub_no_sync.get_analogsignal_chunk(
96+
chunk = rawio.get_analogsignal_chunk(
11897
block_index=0, seg_index=0, i_start=0, i_stop=100, stream_index=stream_index
11998
)
12099
assert chunk.shape[1] == 120
@@ -135,32 +114,13 @@ def test_nidq_digital_channel(self):
135114
assert np.allclose(on_diff, 1, atol=atol)
136115

137116
def test_sync_channel_as_separate_stream(self):
138-
"""Test that sync channel is added as its own stream when load_sync_channel=False."""
139-
import warnings
140-
141-
# Test with load_sync_channel=False (default)
142-
rawio_no_sync = SpikeGLXRawIO(self.get_local_path("spikeglx/NP2_with_sync"), load_sync_channel=False)
143-
rawio_no_sync.parse_header()
144-
145-
# Get stream names
146-
stream_names = rawio_no_sync.header["signal_streams"]["name"].tolist()
147-
148-
# Check if there's a sync channel stream (should contain "SY0" or "SYNC" in the name)
149-
sync_streams = [name for name in stream_names if "SY0" in name or "SYNC" in name]
150-
assert len(sync_streams) > 0, "No sync channel stream found when load_sync_channel=False"
151-
152-
# Test deprecation warning when load_sync_channel=True
153-
with warnings.catch_warnings(record=True) as w:
154-
warnings.simplefilter("always")
155-
rawio_with_sync = SpikeGLXRawIO(self.get_local_path("spikeglx/NP2_with_sync"), load_sync_channel=True)
156-
157-
# Check if deprecation warning was raised
158-
assert any(
159-
issubclass(warning.category, DeprecationWarning) for warning in w
160-
), "No deprecation warning raised"
161-
assert any(
162-
"will be removed in version 0.15" in str(warning.message) for warning in w
163-
), "Deprecation warning message is incorrect"
117+
"""Sync trace is always exposed as its own -SYNC stream."""
118+
rawio = SpikeGLXRawIO(self.get_local_path("spikeglx/NP2_with_sync"))
119+
rawio.parse_header()
120+
121+
stream_names = rawio.header["signal_streams"]["name"].tolist()
122+
sync_streams = [name for name in stream_names if "SYNC" in name]
123+
assert len(sync_streams) > 0, "No -SYNC stream found"
164124

165125
def test_t_start_reading(self):
166126
"""Test that t_start values are correctly read for all streams and segments."""

0 commit comments

Comments
 (0)