11import logging
22
33import numpy as np
4+ from pathlib import Path
45
56from ibllib .atlas import AllenAtlas
67from 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