Skip to content

Commit a0889f5

Browse files
committed
add channel files to spikesorting task
1 parent f27dfc4 commit a0889f5

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

ibllib/pipes/ephys_preprocessing.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from ibllib.pipes import tasks
2121
from ibllib.pipes.training_preprocessing import TrainingRegisterRaw as EphysRegisterRaw
2222
from ibllib.pipes.misc import create_alyx_probe_insertions
23+
from ibllib.qc.alignment_qc import get_aligned_channels
2324
from ibllib.qc.task_extractors import TaskQCExtractor
2425
from ibllib.qc.task_metrics import TaskQC
2526
from ibllib.qc.camera import run_all_qc as run_camera_qc
@@ -406,6 +407,18 @@ def _run(self, probes=None):
406407
tar_dir.mkdir(parents=True, exist_ok=True)
407408
out = spikes.ks2_to_tar(ks2_dir, tar_dir, force=self.FORCE_RERUN)
408409
out_files.extend(out)
410+
411+
if self.one:
412+
eid = self.one.path2eid(self.session_path, query_type='remote')
413+
ins = self.one.alyx.rest('insertions', 'list', session=eid, name=label)
414+
if len(ins) != 0:
415+
resolved = ins[0].get('json', {'temp': 0}).get('extended_qc', {'temp': 0}). \
416+
get('alignment_resolved', False)
417+
if resolved:
418+
chns = np.load(probe_out_path.joinpath('channels.localCoordinates.npy'))
419+
out = get_aligned_channels(ins[0], chns, one=self.one, save_dir=probe_out_path)
420+
out_files.extend(out)
421+
409422
except BaseException:
410423
_logger.error(traceback.format_exc())
411424
self.status = -1

ibllib/qc/alignment_qc.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22

33
import numpy as np
4+
from pathlib import Path
45

56
from ibllib.atlas import AllenAtlas
67
from ibllib.pipes import histology
@@ -387,3 +388,32 @@ def update_experimenter_evaluation(self, prev_alignments=None, override=False):
387388
else:
388389
self.log.warning(f'No experimenter qc found, qc field of probe insertion {self.eid} '
389390
f'will not be updated')
391+
392+
393+
def get_aligned_channels(ins, chn_coords, one, ba=None, save_dir=None):
394+
395+
ba = ba or AllenAtlas(25)
396+
depths = chn_coords[:, 1]
397+
xyz = np.array(ins['json']['xyz_picks']) / 1e6
398+
traj = one.alyx.rest('trajectories', 'list', probe_insertion=ins['id'],
399+
provenance='Ephys aligned histology track')[0]
400+
align_key = ins['json']['extended_qc']['alignment_stored']
401+
feature = traj['json'][align_key][0]
402+
track = traj['json'][align_key][1]
403+
ephysalign = EphysAlignment(xyz, depths, track_prev=track,
404+
feature_prev=feature,
405+
brain_atlas=ba, speedy=True)
406+
channels_mlapdv = np.int32(ephysalign.get_channel_locations(feature, track) * 1e6)
407+
channels_atlas_ids = ephysalign.get_brain_locations(channels_mlapdv / 1e6)['id']
408+
409+
out_files = []
410+
if save_dir is not None:
411+
f_name = Path(save_dir).joinpath('channels.mlapdv.npy')
412+
np.save(f_name, channels_mlapdv)
413+
out_files.append(f_name)
414+
415+
f_name = Path(save_dir).joinpath('channels.brainLocationIds_ccf_2017.npy')
416+
np.save(f_name, channels_atlas_ids)
417+
out_files.append(f_name)
418+
419+
return out_files

0 commit comments

Comments
 (0)