Skip to content

Commit 26cc249

Browse files
committed
update extract_files to compute metrics
1 parent d36f499 commit 26cc249

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

.flake8

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ exclude =
66
__pycache__,
77
__init__.py,
88
data_exploration_gui/
9-
dlc/
109
launch_phy/
1110
histology/
1211

atlaselectrophysiology/extract_files.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
from ibllib.ephys.spikes import ks2_to_alf
21
from ibllib.io import spikeglx
32
import numpy as np
43
import ibllib.dsp as dsp
54
from scipy import signal
65
from ibllib.misc import print_progress
76
from pathlib import Path
8-
import alf.io
7+
import alf.io as aio
98
import logging
9+
import ibllib.ephys.ephysqc as ephysqc
10+
from phylib.io import alf
1011

1112
_logger = logging.getLogger('ibllib')
1213

@@ -87,11 +88,11 @@ def extract_rmsmap(fbin, out_folder=None, spectra=True):
8788
if not out_folder.exists():
8889
out_folder.mkdir()
8990
tdict = {'rms': rms['TRMS'].astype(np.single), 'timestamps': rms['tscale'].astype(np.single)}
90-
alf.io.save_object_npy(out_folder, object=alf_object_time, dico=tdict)
91+
aio.save_object_npy(out_folder, object=alf_object_time, dico=tdict)
9192
if spectra:
9293
fdict = {'power': rms['spectral_density'].astype(np.single),
9394
'freqs': rms['fscale'].astype(np.single)}
94-
alf.io.save_object_npy(out_folder, object=alf_object_freq, dico=fdict)
95+
aio.save_object_npy(out_folder, object=alf_object_freq, dico=fdict)
9596

9697

9798
def _sample2v(ap_file):
@@ -103,13 +104,28 @@ def _sample2v(ap_file):
103104
return s2v['ap'][0]
104105

105106

107+
def ks2_to_alf(ks_path, bin_path, out_path, bin_file=None, ampfactor=1, label=None, force=True):
108+
"""
109+
Convert Kilosort 2 output to ALF dataset for single probe data
110+
:param ks_path:
111+
:param bin_path: path of raw data
112+
:param out_path:
113+
:return:
114+
"""
115+
m = ephysqc.phy_model_from_ks2_path(ks2_path=ks_path, bin_path=bin_path, bin_file=bin_file)
116+
ephysqc.unit_metrics_ks2(ks_path, m, save=True)
117+
ac = alf.EphysAlfCreator(m)
118+
ac.convert(out_path, label=label, force=force, ampfactor=ampfactor)
119+
120+
106121
def extract_data(ks_path, ephys_path, out_path):
107122
efiles = spikeglx.glob_ephys_files(ephys_path)
108123

109124
for efile in efiles:
110125
if efile.get('ap') and efile.ap.exists():
111126
ks2_to_alf(ks_path, ephys_path, out_path, bin_file=efile.ap,
112127
ampfactor=_sample2v(efile.ap), label=None, force=True)
128+
113129
extract_rmsmap(efile.ap, out_folder=out_path, spectra=False)
114130
if efile.get('lf') and efile.lf.exists():
115131
extract_rmsmap(efile.lf, out_folder=out_path)

0 commit comments

Comments
 (0)