Skip to content

Commit 9272ee6

Browse files
authored
Merge pull request #73 from ttngu207/no-curation
update openephys loader - handling open ephys v0.6.0
2 parents 747c15f + 4e367d7 commit 9272ee6

File tree

1 file changed

+43
-15
lines changed

1 file changed

+43
-15
lines changed

element_array_ephys/readers/openephys.py

Lines changed: 43 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
@@ -179,6 +198,15 @@ def __init__(self, processor, probe_index=0):
179198
self.probe_info = processor['EDITOR']['NP_PROBE'][probe_index]
180199
self.probe_SN = self.probe_info['@probe_serial_number']
181200
self.probe_model = _probe_model_name_mapping[self.probe_info['@probe_name']]
201+
202+
if 'ELECTRODE_XPOS' in self.probe_info:
203+
self.probe_info['ELECTRODE_XPOS'] = {int(re.search(r'\d+$', k).group()): int(v)
204+
for k, v in self.probe_info.pop('ELECTRODE_XPOS').items()}
205+
self.probe_info['ELECTRODE_YPOS'] = {int(re.search(r'\d+$', k).group()): int(v)
206+
for k, v in self.probe_info.pop('ELECTRODE_YPOS').items()}
207+
self.probe_info['ELECTRODE_SHANK'] = {int(re.search(r'\d+$', k).group()): int(v)
208+
for k, v in self.probe_info['CHANNELS'].items()}
209+
182210
self._channels_connected = {int(re.search(r'\d+$', k).group()): 1
183211
for k in self.probe_info.pop('CHANNELS')}
184212

0 commit comments

Comments
 (0)