Skip to content

Commit 07604e2

Browse files
author
Thinh Nguyen
committed
update open ephys loader to handle "STREAM" in latest format
1 parent f11e016 commit 07604e2

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

element_array_ephys/readers/openephys.py

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,31 @@ def load_probe_data(self):
7676
if isinstance(sigchain['PROCESSOR'], list)
7777
else [sigchain['PROCESSOR']])
7878
for processor in processor_iter:
79-
if processor['@pluginName'] in ('Neuropix-PXI', 'Neuropix-3a'):
79+
if processor['@pluginName'] in ('Neuropix-3a', 'Neuropix-PXI'):
80+
if 'STREAM' in processor: # only on version >= 0.6.0
81+
ap_streams = [stream for stream in processor['STREAM'] if not stream['@name'].endswith('LFP')]
82+
else:
83+
ap_streams = None
84+
8085
if (processor['@pluginName'] == 'Neuropix-3a'
8186
or 'NP_PROBE' not in processor['EDITOR']):
8287
if isinstance(processor['EDITOR']['PROBE'], dict):
83-
probe = Probe(processor, 0)
84-
probes[probe.probe_SN] = probe
88+
probe_indices = (0,)
8589
else:
86-
for probe_index in range(len(processor['EDITOR']['PROBE'])):
87-
probe = Probe(processor, probe_index)
88-
probes[probe.probe_SN] = probe
89-
else: # Neuropix-PXI
90-
for probe_index in range(len(processor['EDITOR']['NP_PROBE'])):
91-
probe = Probe(processor, probe_index)
92-
probes[probe.probe_SN] = probe
93-
90+
probe_indices = range(len(processor['EDITOR']['PROBE']))
91+
elif processor['@pluginName'] == 'Neuropix-PXI':
92+
probe_indices = range(len(processor['EDITOR']['NP_PROBE']))
93+
else:
94+
raise NotImplementedError
95+
else: # not a processor for Neuropixels probe
96+
continue
97+
98+
for probe_index in probe_indices:
99+
probe = Probe(processor, probe_index)
100+
if ap_streams:
101+
probe.probe_info['ap_stream'] = ap_streams[probe_index]
102+
probes[probe.probe_SN] = probe
103+
94104
for probe_index, probe_SN in enumerate(probes):
95105

96106
probe = probes[probe_SN]
@@ -106,17 +116,26 @@ def load_probe_data(self):
106116
if continuous_info['source_processor_id'] != probe.processor_id:
107117
continue
108118

109-
# determine if this is continuous data for AP or LFP
110-
if 'source_processor_sub_idx' in continuous_info:
119+
# determine if this is continuous data for AP or LFP for the current probe
120+
if 'ap_stream' in probe.probe_info:
121+
if probe.probe_info['ap_stream']['@name'].split('-')[0] != continuous_info['stream_name'].split('-')[0]:
122+
continue # not continuous data for the current probe
123+
match = re.search('-(AP|LFP)$', continuous_info['stream_name'])
124+
if match:
125+
continuous_type = match.groups()[0].lower()
126+
else:
127+
continuous_type = 'ap'
128+
elif 'source_processor_sub_idx' in continuous_info:
111129
if continuous_info['source_processor_sub_idx'] == probe_index * 2: # ap data
112130
assert continuous_info['sample_rate'] == analog_signal.sample_rate == 30000
113131
continuous_type = 'ap'
114132
elif continuous_info['source_processor_sub_idx'] == probe_index * 2 + 1: # lfp data
115133
assert continuous_info['sample_rate'] == analog_signal.sample_rate == 2500
116134
continuous_type = 'lfp'
135+
else:
136+
continue # not continuous data for the current probe
117137
else:
118-
match = re.search('-(AP|LFP)$', continuous_info['folder_name'].strip('/'))
119-
continuous_type = match.groups()[0].lower()
138+
raise ValueError(f'Unable to infer type (AP or LFP) for the continuous data from:\n\t{continuous_info}')
120139

121140
if continuous_type == 'ap':
122141
probe.recording_info['recording_count'] += 1

0 commit comments

Comments
 (0)