Skip to content

Commit 623a381

Browse files
authored
Merge pull request #120 from kushalbakshi/main
Docstring changes for docs API
2 parents 0f518f1 + 523f2e9 commit 623a381

File tree

4 files changed

+120
-65
lines changed

4 files changed

+120
-65
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and
44
[Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention.
55

6+
## [0.2.2] - Unreleased
7+
8+
+ Bugfix - Update docstrings to render API for documentation website.
9+
610
## [0.2.1] - 2022-01-06
711

812
+ Add - `build_electrode_layouts` function in `probe.py` to compute the electrode layout for all types of probes.
@@ -66,6 +70,7 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and
6670
+ Add - Probe table supporting: Neuropixels probes 1.0 - 3A, 1.0 - 3B, 2.0 - SS,
6771
2.0 - MS
6872

73+
[0.2.2]: https://github.com/datajoint/element-array-ephys/releases/tag/0.2.2
6974
[0.2.1]: https://github.com/datajoint/element-array-ephys/releases/tag/0.2.1
7075
[0.2.0]: https://github.com/datajoint/element-array-ephys/releases/tag/0.2.0
7176
[0.1.4]: https://github.com/datajoint/element-array-ephys/releases/tag/0.1.4

element_array_ephys/ephys_acute.py

Lines changed: 59 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ def auto_generate_entries(cls, session_key):
185185

186186
probe_dir = meta_filepath.parent
187187
try:
188-
probe_number = re.search("(imec)?\d{1}$", probe_dir.name).group()
188+
probe_number = re.search(
189+
"(imec)?\d{1}$", probe_dir.name).group()
189190
probe_number = int(probe_number.replace("imec", ""))
190191
except AttributeError:
191192
probe_number = meta_fp_idx
@@ -214,7 +215,8 @@ def auto_generate_entries(cls, session_key):
214215
}
215216
)
216217
else:
217-
raise NotImplementedError(f"Unknown acquisition software: {acq_software}")
218+
raise NotImplementedError(
219+
f"Unknown acquisition software: {acq_software}")
218220

219221
probe.Probe.insert(probe_list, skip_duplicates=True)
220222
cls.insert(probe_insertion_list, skip_duplicates=True)
@@ -231,8 +233,7 @@ class InsertionLocation(dj.Manual):
231233
ml_location (decimal (6, 2) ): Medial-lateral location in micrometers. Reference is zero with right side values positive.
232234
depth (decimal (6, 2) ): Manipulator depth relative to the surface of the brain at zero. Ventral is negative.
233235
Theta (decimal (5, 2) ): elevation - rotation about the ml-axis in degrees relative to positive z-axis.
234-
phi (decimal (5, 2) ): azimuth - rotation about the dv-axis in degrees relative to the positive x-axis
235-
236+
phi (decimal (5, 2) ): azimuth - rotation about the dv-axis in degrees relative to the positive x-axis.
236237
"""
237238

238239
definition = """
@@ -322,12 +323,14 @@ def make(self, key):
322323
break
323324
else:
324325
raise FileNotFoundError(
325-
"No SpikeGLX data found for probe insertion: {}".format(key)
326+
"No SpikeGLX data found for probe insertion: {}".format(
327+
key)
326328
)
327329

328330
if spikeglx_meta.probe_model in supported_probe_types:
329331
probe_type = spikeglx_meta.probe_model
330-
electrode_query = probe.ProbeType.Electrode & {"probe_type": probe_type}
332+
electrode_query = probe.ProbeType.Electrode & {
333+
"probe_type": probe_type}
331334

332335
probe_electrodes = {
333336
(shank, shank_col, shank_row): key
@@ -360,9 +363,11 @@ def make(self, key):
360363
}
361364
)
362365

363-
root_dir = find_root_directory(get_ephys_root_data_dir(), meta_filepath)
366+
root_dir = find_root_directory(
367+
get_ephys_root_data_dir(), meta_filepath)
364368
self.EphysFile.insert1(
365-
{**key, "file_path": meta_filepath.relative_to(root_dir).as_posix()}
369+
{**key,
370+
"file_path": meta_filepath.relative_to(root_dir).as_posix()}
366371
)
367372
elif acq_software == "Open Ephys":
368373
dataset = openephys.OpenEphys(session_dir)
@@ -371,7 +376,8 @@ def make(self, key):
371376
break
372377
else:
373378
raise FileNotFoundError(
374-
"No Open Ephys data found for probe insertion: {}".format(key)
379+
"No Open Ephys data found for probe insertion: {}".format(
380+
key)
375381
)
376382

377383
if not probe_data.ap_meta:
@@ -381,7 +387,8 @@ def make(self, key):
381387

382388
if probe_data.probe_model in supported_probe_types:
383389
probe_type = probe_data.probe_model
384-
electrode_query = probe.ProbeType.Electrode & {"probe_type": probe_type}
390+
electrode_query = probe.ProbeType.Electrode & {
391+
"probe_type": probe_type}
385392

386393
probe_electrodes = {
387394
key["electrode"]: key for key in electrode_query.fetch("KEY")
@@ -394,7 +401,8 @@ def make(self, key):
394401
else:
395402
raise NotImplementedError(
396403
"Processing for neuropixels"
397-
" probe model {} not yet implemented".format(probe_data.probe_model)
404+
" probe model {} not yet implemented".format(
405+
probe_data.probe_model)
398406
)
399407

400408
self.insert1(
@@ -456,7 +464,7 @@ class LFP(dj.Imported):
456464

457465
class Electrode(dj.Part):
458466
"""Saves local field potential data for each electrode.
459-
467+
460468
Attributes:
461469
LFP (foreign key): LFP primary key.
462470
probe.ElectrodeConfig.Electrode (foreign key): probe.ElectrodeConfig.Electrode primary key.
@@ -476,24 +484,27 @@ class Electrode(dj.Part):
476484

477485
def make(self, key):
478486
"""Populates the LFP tables."""
479-
acq_software = (EphysRecording * ProbeInsertion & key).fetch1("acq_software")
487+
acq_software = (EphysRecording * ProbeInsertion &
488+
key).fetch1("acq_software")
480489

481490
electrode_keys, lfp = [], []
482491

483492
if acq_software == "SpikeGLX":
484493
spikeglx_meta_filepath = get_spikeglx_meta_filepath(key)
485-
spikeglx_recording = spikeglx.SpikeGLX(spikeglx_meta_filepath.parent)
494+
spikeglx_recording = spikeglx.SpikeGLX(
495+
spikeglx_meta_filepath.parent)
486496

487497
lfp_channel_ind = spikeglx_recording.lfmeta.recording_channels[
488-
-1 :: -self._skip_channel_counts
498+
-1:: -self._skip_channel_counts
489499
]
490500

491501
# Extract LFP data at specified channels and convert to uV
492502
lfp = spikeglx_recording.lf_timeseries[
493503
:, lfp_channel_ind
494504
] # (sample x channel)
495505
lfp = (
496-
lfp * spikeglx_recording.get_channel_bit_volts("lf")[lfp_channel_ind]
506+
lfp *
507+
spikeglx_recording.get_channel_bit_volts("lf")[lfp_channel_ind]
497508
).T # (channel x sample)
498509

499510
self.insert1(
@@ -525,18 +536,21 @@ def make(self, key):
525536
shank, shank_col, shank_row, _ = spikeglx_recording.apmeta.shankmap[
526537
"data"
527538
][recorded_site]
528-
electrode_keys.append(probe_electrodes[(shank, shank_col, shank_row)])
539+
electrode_keys.append(
540+
probe_electrodes[(shank, shank_col, shank_row)])
529541
elif acq_software == "Open Ephys":
530542
oe_probe = get_openephys_probe_data(key)
531543

532544
lfp_channel_ind = np.r_[
533545
len(oe_probe.lfp_meta["channels_indices"])
534-
- 1 : 0 : -self._skip_channel_counts
546+
- 1: 0: -self._skip_channel_counts
535547
]
536548

537-
lfp = oe_probe.lfp_timeseries[:, lfp_channel_ind] # (sample x channel)
549+
# (sample x channel)
550+
lfp = oe_probe.lfp_timeseries[:, lfp_channel_ind]
538551
lfp = (
539-
lfp * np.array(oe_probe.lfp_meta["channels_gains"])[lfp_channel_ind]
552+
lfp *
553+
np.array(oe_probe.lfp_meta["channels_gains"])[lfp_channel_ind]
540554
).T # (channel x sample)
541555
lfp_timestamps = oe_probe.lfp_timestamps
542556

@@ -608,7 +622,7 @@ class ClusteringParamSet(dj.Lookup):
608622
ClusteringMethod (dict): ClusteringMethod primary key.
609623
paramset_desc (varchar(128) ): Description of the clustering parameter set.
610624
param_set_hash (uuid): UUID hash for the parameter set.
611-
params (longblob)
625+
params (longblob): Parameters for clustering with Kilosort.
612626
"""
613627

614628
definition = """
@@ -764,7 +778,8 @@ def auto_generate_entries(cls, ephys_recording_key: dict, paramset_idx: int = 0)
764778
key = {**ephys_recording_key, "paramset_idx": paramset_idx}
765779

766780
processed_dir = get_processed_root_data_dir()
767-
output_dir = ClusteringTask.infer_output_dir(key, relative=False, mkdir=True)
781+
output_dir = ClusteringTask.infer_output_dir(
782+
key, relative=False, mkdir=True)
768783

769784
try:
770785
kilosort.Kilosort(
@@ -811,7 +826,8 @@ def make(self, key):
811826
)
812827

813828
if not output_dir:
814-
output_dir = ClusteringTask.infer_output_dir(key, relative=True, mkdir=True)
829+
output_dir = ClusteringTask.infer_output_dir(
830+
key, relative=True, mkdir=True)
815831
# update clustering_output_dir
816832
ClusteringTask.update1(
817833
{**key, "clustering_output_dir": output_dir.as_posix()}
@@ -1022,7 +1038,8 @@ def make(self, key):
10221038
"acq_software", "sampling_rate"
10231039
)
10241040

1025-
sample_rate = kilosort_dataset.data["params"].get("sample_rate", sample_rate)
1041+
sample_rate = kilosort_dataset.data["params"].get(
1042+
"sample_rate", sample_rate)
10261043

10271044
# ---------- Unit ----------
10281045
# -- Remove 0-spike units
@@ -1034,7 +1051,8 @@ def make(self, key):
10341051
valid_units = kilosort_dataset.data["cluster_ids"][withspike_idx]
10351052
valid_unit_labels = kilosort_dataset.data["cluster_groups"][withspike_idx]
10361053
# -- Get channel and electrode-site mapping
1037-
channel2electrodes = get_neuropixels_channel2electrode_map(key, acq_software)
1054+
channel2electrodes = get_neuropixels_channel2electrode_map(
1055+
key, acq_software)
10381056

10391057
# -- Spike-times --
10401058
# spike_times_sec_adj > spike_times_sec > spike_times
@@ -1201,7 +1219,8 @@ def yield_unit_waveforms():
12011219
else:
12021220
if acq_software == "SpikeGLX":
12031221
spikeglx_meta_filepath = get_spikeglx_meta_filepath(key)
1204-
neuropixels_recording = spikeglx.SpikeGLX(spikeglx_meta_filepath.parent)
1222+
neuropixels_recording = spikeglx.SpikeGLX(
1223+
spikeglx_meta_filepath.parent)
12051224
elif acq_software == "Open Ephys":
12061225
session_dir = find_full_path(
12071226
get_ephys_root_data_dir(), get_session_directory(key)
@@ -1249,9 +1268,11 @@ def yield_unit_waveforms():
12491268
self.insert1(key)
12501269
for unit_peak_waveform, unit_electrode_waveforms in yield_unit_waveforms():
12511270
if unit_peak_waveform:
1252-
self.PeakWaveform.insert1(unit_peak_waveform, ignore_extra_fields=True)
1271+
self.PeakWaveform.insert1(
1272+
unit_peak_waveform, ignore_extra_fields=True)
12531273
if unit_electrode_waveforms:
1254-
self.Waveform.insert(unit_electrode_waveforms, ignore_extra_fields=True)
1274+
self.Waveform.insert(
1275+
unit_electrode_waveforms, ignore_extra_fields=True)
12551276

12561277

12571278
@schema
@@ -1396,7 +1417,8 @@ def get_spikeglx_meta_filepath(ephys_recording_key: dict) -> str:
13961417
ProbeInsertion * probe.Probe & ephys_recording_key
13971418
).fetch1("probe")
13981419

1399-
spikeglx_meta_filepaths = [fp for fp in session_dir.rglob("*.ap.meta")]
1420+
spikeglx_meta_filepaths = [
1421+
fp for fp in session_dir.rglob("*.ap.meta")]
14001422
for meta_filepath in spikeglx_meta_filepaths:
14011423
spikeglx_meta = spikeglx.SpikeGLXMeta(meta_filepath)
14021424
if str(spikeglx_meta.probe_SN) == inserted_probe_serial_number:
@@ -1436,7 +1458,8 @@ def get_neuropixels_channel2electrode_map(
14361458
) -> dict:
14371459
"""Get the channel map for neuropixels probe."""
14381460
if acq_software == "SpikeGLX":
1439-
spikeglx_meta_filepath = get_spikeglx_meta_filepath(ephys_recording_key)
1461+
spikeglx_meta_filepath = get_spikeglx_meta_filepath(
1462+
ephys_recording_key)
14401463
spikeglx_meta = spikeglx.SpikeGLXMeta(spikeglx_meta_filepath)
14411464
electrode_config_key = (
14421465
EphysRecording * probe.ElectrodeConfig & ephys_recording_key
@@ -1491,7 +1514,8 @@ def generate_electrode_config(probe_type: str, electrode_keys: list) -> dict:
14911514
dict: representing a key of the probe.ElectrodeConfig table
14921515
"""
14931516
# compute hash for the electrode config (hash of dict of all ElectrodeConfig.Electrode)
1494-
electrode_config_hash = dict_to_uuid({k["electrode"]: k for k in electrode_keys})
1517+
electrode_config_hash = dict_to_uuid(
1518+
{k["electrode"]: k for k in electrode_keys})
14951519

14961520
electrode_list = sorted([k["electrode"] for k in electrode_keys])
14971521
electrode_gaps = (
@@ -1561,9 +1585,11 @@ def get_recording_channels_details(ephys_recording_key: dict) -> np.array:
15611585
channels_details["num_channels"] = len(channels_details["channel_ind"])
15621586

15631587
if acq_software == "SpikeGLX":
1564-
spikeglx_meta_filepath = get_spikeglx_meta_filepath(ephys_recording_key)
1588+
spikeglx_meta_filepath = get_spikeglx_meta_filepath(
1589+
ephys_recording_key)
15651590
spikeglx_recording = spikeglx.SpikeGLX(spikeglx_meta_filepath.parent)
1566-
channels_details["uVPerBit"] = spikeglx_recording.get_channel_bit_volts("ap")[0]
1591+
channels_details["uVPerBit"] = spikeglx_recording.get_channel_bit_volts("ap")[
1592+
0]
15671593
channels_details["connected"] = np.array(
15681594
[v for *_, v in spikeglx_recording.apmeta.shankmap["data"]]
15691595
)

0 commit comments

Comments
 (0)