Skip to content

Commit 15ce1f6

Browse files
committed
great, inline-inline-inline!
1 parent f367cac commit 15ce1f6

File tree

1 file changed

+22
-52
lines changed

1 file changed

+22
-52
lines changed

neo/rawio/neuralynxrawio/neuralynxrawio.py

Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -206,56 +206,6 @@ def __init__(
206206
def _source_name(self):
207207
return self.dirname
208208

209-
def _build_stream_key(self, header_info, chan_index):
210-
"""
211-
Build stream key based on acquisition parameters only.
212-
213-
Stream keys are used to group channels that share the same acquisition
214-
configuration. Channels with the same stream key will be placed in the
215-
same stream and can be read together.
216-
217-
Parameters
218-
----------
219-
header_info : dict
220-
Header information from NlxHeader
221-
chan_index : int
222-
Channel index for multi-channel parameters
223-
224-
Returns
225-
-------
226-
StreamKey
227-
Named tuple containing acquisition parameters:
228-
(sampling_rate, input_range, filter_params)
229-
"""
230-
# Core acquisition parameters (already normalized by NlxHeader)
231-
sampling_rate = float(header_info["sampling_rate"])
232-
233-
# Get InputRange - could be int (single-channel) or list (multi-channel)
234-
input_range = header_info.get("InputRange")
235-
if isinstance(input_range, list):
236-
# Multi-channel file: get value for this channel
237-
input_range = input_range[chan_index] if chan_index < len(input_range) else input_range[0]
238-
# Already converted to int by NlxHeader._normalize_types()
239-
240-
# Note: gain is not included in stream key as it's derived from InputRange (gain = InputRange / 32768)
241-
# Note: input_inverted is not included in stream key as it's a whole-dataset property
242-
# that never differentiates streams (all channels have the same value)
243-
244-
# Build filter parameters tuple (already normalized by NlxHeader)
245-
filter_params = []
246-
for key in self._filter_keys:
247-
if key in header_info:
248-
filter_params.append((key, header_info[key]))
249-
250-
# Create hashable stream key using namedtuple for readability
251-
stream_key = StreamKey(
252-
sampling_rate=sampling_rate,
253-
input_range=input_range,
254-
filter_params=tuple(sorted(filter_params)),
255-
)
256-
257-
return stream_key
258-
259209
def _parse_header(self):
260210

261211
stream_channels = []
@@ -340,8 +290,27 @@ def _parse_header(self):
340290
if info.get("input_inverted", False):
341291
gain *= -1
342292

343-
# Build stream key from acquisition parameters only
344-
stream_key = self._build_stream_key(info, idx)
293+
# Build stream key from acquisition parameters
294+
sampling_rate = float(info["sampling_rate"])
295+
296+
# Get InputRange for this specific channel
297+
# Normalized by NlxHeader to always be a list
298+
input_range = info.get("InputRange")
299+
if isinstance(input_range, list):
300+
input_range = input_range[idx] if idx < len(input_range) else input_range[0]
301+
302+
# Build filter parameters tuple
303+
filter_params = []
304+
for key in self._filter_keys:
305+
if key in info:
306+
filter_params.append((key, info[key]))
307+
308+
# Create stream key (channels with same key go in same stream)
309+
stream_key = StreamKey(
310+
sampling_rate=sampling_rate,
311+
input_range=input_range,
312+
filter_params=tuple(sorted(filter_params)),
313+
)
345314

346315
if stream_key not in stream_props:
347316
stream_props[stream_key] = {
@@ -476,6 +445,7 @@ def _parse_header(self):
476445
self._dsp_filter_configurations = _dsp_filter_configurations
477446

478447
# Order streams by sampling rate (high to low)
448+
# This is to keep some semblance of stability
479449
ordered_stream_keys = sorted(stream_props.keys(), reverse=True, key=lambda x: x.sampling_rate)
480450

481451
stream_names = []

0 commit comments

Comments
 (0)