Skip to content

Commit 74a7a56

Browse files
Merge pull request #17 from ttngu207/main
specify a separate `get_clustering_root_data_dir()` - handle cases where raw ephys and clustering results are stored at different root locations (e.g. different mount points)
2 parents cf39185 + 99d761f commit 74a7a56

File tree

6 files changed

+169
-145
lines changed

6 files changed

+169
-145
lines changed

element_array_ephys/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
__author__ = "DataJoint NEURO"
2-
__date__ = "December 15, 2020"
3-
__version__ = "0.0.1"
1+
import datajoint as dj
42

5-
__all__ = ['__author__', '__version__', '__date__']
3+
dj.config['enable_python_native_blobs'] = True

element_array_ephys/ephys.py

Lines changed: 117 additions & 106 deletions
Large diffs are not rendered by default.

element_array_ephys/probe.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ def activate(schema_name, create_schema=True, create_tables=True):
1717
"""
1818
schema.activate(schema_name, create_schema=create_schema, create_tables=create_tables)
1919

20+
# Add neuropixels probes
21+
for probe_type in ('neuropixels 1.0 - 3A', 'neuropixels 1.0 - 3B',
22+
'neuropixels 2.0 - SS', 'neuropixels 2.0 - MS'):
23+
ProbeType.create_neuropixels_probe(probe_type)
24+
2025

2126
@schema
2227
class ProbeType(dj.Lookup):

element_array_ephys/readers/openephys.py

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class OpenEphys:
3333
def __init__(self, experiment_dir):
3434
self.sess_dir = pathlib.Path(experiment_dir)
3535

36-
oe_file = pyopenephys.File(self.sess_dir.parent) # this is on the Record Node level
36+
openephys_file = pyopenephys.File(self.sess_dir.parent) # this is on the Record Node level
3737

3838
# extract the "recordings" for this session
39-
self.experiment = next(experiment for experiment in oe_file.experiments
39+
self.experiment = next(experiment for experiment in openephys_file.experiments
4040
if pathlib.Path(experiment.absolute_foldername) == self.sess_dir)
4141

4242
self.recording_time = self.experiment.datetime
@@ -58,47 +58,50 @@ def load_probe_data(self):
5858
probes = {}
5959
for processor in self.experiment.settings['SIGNALCHAIN']['PROCESSOR']:
6060
if processor['@pluginName'] in ('Neuropix-PXI', 'Neuropix-3a'):
61-
if processor['@pluginName'] == 'Neuropix-3a':
62-
oe_probe = Probe(processor)
63-
probes[oe_probe.probeSN] = oe_probe
61+
if (processor['@pluginName'] == 'Neuropix-3a'
62+
or 'NP_PROBE' not in processor['EDITOR']):
63+
probe = Probe(processor)
64+
probes[probe.probe_SN] = probe
6465
else:
6566
for probe_index in range(len(processor['EDITOR']['NP_PROBE'])):
66-
oe_probe = Probe(processor, probe_index)
67-
probes[oe_probe.probe_SN] = oe_probe
67+
probe = Probe(processor, probe_index)
68+
probes[probe.probe_SN] = probe
6869

69-
for probe_index, probe_SN in enumerate(probes.keys()):
70+
for probe_index, probe_SN in enumerate(probes):
7071

71-
oe_probe = probes[probe_SN]
72+
probe = probes[probe_SN]
7273

7374
for rec in self.experiment.recordings:
74-
for cont_info, analog_signal in zip(rec._oebin['continuous'],
75-
rec.analog_signals):
76-
if cont_info['source_processor_id'] != oe_probe.processor_id:
75+
for continuous_info, analog_signal in zip(rec._oebin['continuous'],
76+
rec.analog_signals):
77+
if continuous_info['source_processor_id'] != probe.processor_id:
7778
continue
7879

79-
if cont_info['source_processor_sub_idx'] == probe_index * 2: # ap data
80-
assert cont_info['sample_rate'] == analog_signal.sample_rate == 30000
81-
cont_type = 'ap'
80+
if continuous_info['source_processor_sub_idx'] == probe_index * 2: # ap data
81+
assert continuous_info['sample_rate'] == analog_signal.sample_rate == 30000
82+
continuous_type = 'ap'
8283

83-
oe_probe.recording_info['recording_count'] += 1
84-
oe_probe.recording_info['recording_datetimes'].append(
84+
probe.recording_info['recording_count'] += 1
85+
probe.recording_info['recording_datetimes'].append(
8586
rec.datetime)
86-
oe_probe.recording_info['recording_durations'].append(
87+
probe.recording_info['recording_durations'].append(
8788
float(rec.duration))
88-
oe_probe.recording_info['recording_files'].append(
89-
rec.absolute_foldername / 'continuous' / cont_info['folder_name'])
89+
probe.recording_info['recording_files'].append(
90+
rec.absolute_foldername / 'continuous' / continuous_info['folder_name'])
9091

91-
elif cont_info['source_processor_sub_idx'] == probe_index * 2 + 1: # lfp data
92-
assert cont_info['sample_rate'] == analog_signal.sample_rate == 2500
93-
cont_type = 'lfp'
92+
elif continuous_info['source_processor_sub_idx'] == probe_index * 2 + 1: # lfp data
93+
assert continuous_info['sample_rate'] == analog_signal.sample_rate == 2500
94+
continuous_type = 'lfp'
9495

95-
if getattr(oe_probe, cont_type + '_meta') is None:
96-
cont_info['channels_ids'] = analog_signal.channel_ids
97-
cont_info['channels_names'] = analog_signal.channel_names
98-
cont_info['channels_gains'] = analog_signal.gains
99-
setattr(oe_probe, cont_type + '_meta', cont_info)
96+
meta = getattr(probe, continuous_type + '_meta')
97+
if not meta:
98+
meta.update(**continuous_info,
99+
channels_ids=analog_signal.channel_ids,
100+
channels_names=analog_signal.channel_names,
101+
channels_gains=analog_signal.gains)
100102

101-
oe_probe.__dict__[f'{cont_type}_analog_signals'].append(analog_signal)
103+
signal = getattr(probe, continuous_type + '_analog_signals')
104+
signal.append(analog_signal)
102105

103106
return probes
104107

@@ -108,18 +111,19 @@ class Probe:
108111
def __init__(self, processor, probe_index=0):
109112
self.processor_id = int(processor['@NodeId'])
110113

111-
if processor['@pluginName'] == 'Neuropix-3a':
112-
114+
if processor['@pluginName'] == 'Neuropix-3a' or 'NP_PROBE' not in processor['EDITOR']:
113115
self.probe_info = processor['EDITOR']['PROBE']
114116
self.probe_SN = self.probe_info['@probe_serial_number']
115-
self.probe_model = "Neuropixels 3A"
117+
self.probe_model = {
118+
"Neuropix-PXI": "neuropixels 1.0 - 3B",
119+
"Neuropix-3a": "neuropixels 1.0 - 3A"}[processor['@pluginName']]
116120
else:
117121
self.probe_info = processor['EDITOR']['NP_PROBE'][probe_index]
118122
self.probe_SN = self.probe_info['@probe_serial_number']
119123
self.probe_model = self.probe_info['@probe_name']
120124

121-
self.ap_meta = None
122-
self.lfp_meta = None
125+
self.ap_meta = {}
126+
self.lfp_meta = {}
123127

124128
self.ap_analog_signals = []
125129
self.lfp_analog_signals = []

element_array_ephys/version.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"""Package metadata."""
2+
__version__ = '0.1.1'

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from setuptools import setup, find_packages
22
from os import path
33

4+
pkg_name = 'element_array_ephys'
45
here = path.abspath(path.dirname(__file__))
56

67
long_description = """"
@@ -10,9 +11,12 @@
1011
with open(path.join(here, 'requirements.txt')) as f:
1112
requirements = f.read().splitlines()
1213

14+
with open(path.join(here, pkg_name, 'version.py')) as f:
15+
exec(f.read())
16+
1317
setup(
1418
name='element-array-ephys',
15-
version='0.0.1',
19+
version=__version__,
1620
description="DataJoint Element for Extracellular Array Electrophysiology",
1721
long_description=long_description,
1822
author='DataJoint NEURO',

0 commit comments

Comments
 (0)