Skip to content

Commit d7a714c

Browse files
committed
improvements
1 parent e5b67a8 commit d7a714c

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

neo/rawio/neuralynxrawio/neuralynxrawio.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def _build_stream_key(self, header_info, chan_index, gain):
224224
-------
225225
tuple
226226
Hashable stream key containing acquisition parameters:
227-
(sampling_rate, input_range, gain, input_inverted, filter_params_tuple)
227+
(sampling_rate, input_range, gain, filter_params_tuple)
228228
"""
229229
# Core acquisition parameters (already normalized by NlxHeader)
230230
sampling_rate = float(header_info["sampling_rate"])
@@ -238,7 +238,6 @@ def _build_stream_key(self, header_info, chan_index, gain):
238238

239239
gain = float(gain)
240240

241-
input_inverted = header_info.get("input_inverted", False)
242241

243242
# Build filter parameters tuple (already normalized by NlxHeader)
244243
filter_params = []
@@ -251,7 +250,6 @@ def _build_stream_key(self, header_info, chan_index, gain):
251250
sampling_rate,
252251
input_range,
253252
gain,
254-
input_inverted,
255253
tuple(sorted(filter_params)),
256254
)
257255

@@ -465,20 +463,12 @@ def _parse_header(self):
465463

466464
if signal_channels.size > 0:
467465
# Build DSP filter configuration registry: filter_id -> filter parameters dict
468-
# Use temporary dict to deduplicate filter configs while building
469-
_dsp_filter_configurations = {} # filter_id -> filter parameters dict
470-
seen_filters = {} # filter_params_tuple -> filter_id (temporary)
466+
# Extract unique filter configurations from stream keys
467+
unique_filter_tuples = {stream_key[3] for stream_key in stream_props.keys()} # stream_key[3] is filter_params_tuple
468+
_dsp_filter_configurations = {i: dict(filt) for i, filt in enumerate(sorted(unique_filter_tuples))}
471469

472-
for stream_key, stream_info in stream_props.items():
473-
# Extract filter parameters from stream_key
474-
# stream_key = (sampling_rate, input_range, gain, input_inverted, filter_params_tuple)
475-
sampling_rate, input_range, gain, input_inverted, filter_params_tuple = stream_key
476-
477-
# Assign filter ID (deduplicated by filter_params_tuple)
478-
if filter_params_tuple not in seen_filters:
479-
filter_id = len(_dsp_filter_configurations)
480-
seen_filters[filter_params_tuple] = filter_id
481-
_dsp_filter_configurations[filter_id] = dict(filter_params_tuple)
470+
# Create reverse mapping for looking up filter IDs during stream name construction
471+
seen_filters = {filt: i for i, filt in enumerate(sorted(unique_filter_tuples))}
482472

483473
# Store DSP filter configurations as private instance attribute
484474
# Keeping private for now - may expose via annotations or public API in future
@@ -496,7 +486,7 @@ def _parse_header(self):
496486
stream_id = stream_info["stream_id"]
497487

498488
# Unpack stream_key and format stream name
499-
sampling_rate, input_range, gain, input_inverted, filter_params_tuple = stream_key
489+
sampling_rate, input_range, gain, filter_params_tuple = stream_key
500490
dsp_filter_id = seen_filters[filter_params_tuple]
501491
voltage_mv = int(input_range / 1000) if input_range is not None else 0
502492
stream_name = f"stream{stream_id}_{int(sampling_rate)}Hz_{voltage_mv}mVRange_DSPFilter{dsp_filter_id}"

0 commit comments

Comments
 (0)