def get_channels(self, traj, ins=None, depths=None): if depths is None: depths = SITES_COORDINATES[:, 1] if traj['provenance'] == 'Planned' or traj['provenance'] == 'Micro-manipulator': ins = atlas.Insertion.from_dict(traj) # Deepest coordinate first xyz = np.c_[ins.tip, ins.entry].T xyz_channels = histology.interpolate_along_track(xyz, (depths + TIP_SIZE_UM) / 1e6) else: if ins is None: ins_idx = np.where(traj['probe_insertion'] == self.ins['ids'])[0][0] xyz = np.array(self.ins['insertions'][ins_idx]['json']['xyz_picks']) / 1e6 else: xyz = np.array(ins['json']['xyz_picks']) / 1e6 if traj['provenance'] == 'Histology track': xyz = xyz[np.argsort(xyz[:, 2]), :] xyz_channels = histology.interpolate_along_track(xyz, (depths + TIP_SIZE_UM) / 1e6) else: if ins is None: align_key = (self.ins['insertions'][ins_idx]['json']['extended_qc'] ['alignment_stored']) else: align_key = ins['json']['extended_qc']['alignment_stored'] feature = traj['json'][align_key][0] track = traj['json'][align_key][1] ephysalign = EphysAlignment(xyz, depths, track_prev=track, feature_prev=feature, brain_atlas=self.ba, speedy=True) xyz_channels = ephysalign.get_channel_locations(feature, track) return xyz_channels
def get_subjects(self): """ Finds all subjects that have a histology track trajectory registered :return subjects: list of subjects :type: list of strings """ # All sessions that have a histology track all_hist = self.one.alyx.rest('trajectories', 'list', provenance='Histology track') # Some do not have tracing, exclude these ones self.sess_with_hist = [ sess for sess in all_hist if sess['x'] is not None ] self.subj_with_hist = [ sess['session']['subject'] for sess in self.sess_with_hist ] # For all histology tracks find the trajectory and coordinates of active part (where # electrodes are located). Used in get_nearby trajectories to find sessions close-by # insertions depths = np.arange(200, 4100, 20) / 1e6 trajectories = [ atlas.Insertion.from_dict(sess) for sess in self.sess_with_hist ] self.traj_ids = [sess['id'] for sess in self.sess_with_hist] self.traj_coords = np.empty((len(self.traj_ids), len(depths), 3)) for iT, traj in enumerate(trajectories): self.traj_coords[iT, :] = (histology.interpolate_along_track( np.vstack([traj.tip, traj.entry]), depths)) self.subjects = np.unique(self.subj_with_hist) return self.subjects
def __init__(self, xyz_picks, chn_depths=None, track_prev=None, feature_prev=None, brain_atlas=None): if not brain_atlas: self.brain_atlas = atlas.AllenAtlas(25) else: self.brain_atlas = brain_atlas self.xyz_track, self.track_extent = self.get_insertion_track(xyz_picks) self.chn_depths = chn_depths if np.any(track_prev): self.track_init = track_prev self.feature_init = feature_prev else: self.track_init = np.copy(self.track_extent) self.feature_init = np.copy(self.track_extent) self.sampling_trk = np.arange(self.track_extent[0], self.track_extent[-1] - 10 * 1e-6, 10 * 1e-6) self.xyz_samples = histology.interpolate_along_track(self.xyz_track, self.sampling_trk - self.sampling_trk[0]) self.region, self.region_label, self.region_colour, self.region_id\ = self.get_histology_regions(self.xyz_samples, self.sampling_trk, self.brain_atlas)
def get_channel_locations(self, feature, track, depths=None): """ Gets 3d coordinates from a depth along the electrophysiology feature. 2 steps 1) interpolate from the electrophys features depths space to the probe depth space 2) interpolate from the probe depth space to the true 3D coordinates if depths is not provided, defaults to channels local coordinates depths """ if depths is None: depths = self.chn_depths / 1e6 # nb using scipy here so we can change to cubic spline if needed channel_depths_track = self.feature2track(depths, feature, track) - self.track_extent[0] xyz_channels = histology.interpolate_along_track(self.xyz_track, channel_depths_track) return xyz_channels
def get_channels(self, alf_object, collection): electrodes = {} try: electrodes = self.one.load_object(self.eid, alf_object, collection=collection) electrodes['axial_um'] = electrodes['localCoordinates'][:, 1] except ALFObjectNotFound: _logger.warning(f'{alf_object} does not yet exist') if self.hist_lookup[self.histology_status] == 3: try: electrodes['atlas_id'] = electrodes['brainLocationIds_ccf_2017'] electrodes['mlapdv'] = electrodes['mlapdv'] / 1e6 except KeyError: _logger.warning('Insertion resolved but brainLocationIds_ccf_2017 attribute do not exist') if self.hist_lookup[self.histology_status] > 0 and 'atlas_id' not in electrodes.keys(): if not self.brain_atlas: self.brain_atlas = AllenAtlas() self.brain_regions = self.brain_regions or self.brain_atlas.regions if 'localCoordinates' not in electrodes.keys(): geometry = trace_header(version=1) electrodes['localCoordinates'] = np.c_[geometry['x'], geometry['y']] electrodes['axial_um'] = electrodes['localCoordinates'][:, 1] depths = electrodes['localCoordinates'][:, 1] xyz = np.array(self.ins['json']['xyz_picks']) / 1e6 if self.hist_lookup[self.histology_status] >= 2: traj = self.one.alyx.rest('trajectories', 'list', provenance='Ephys aligned histology track', probe_insertion=self.pid)[0] align_key = self.ins['json']['extended_qc']['alignment_stored'] feature = traj['json'][align_key][0] track = traj['json'][align_key][1] ephysalign = EphysAlignment(xyz, depths, track_prev=track, feature_prev=feature, brain_atlas=self.brain_atlas, speedy=True) electrodes['mlapdv'] = ephysalign.get_channel_locations(feature, track) electrodes['atlas_id'] = self.brain_atlas.regions.get(self.brain_atlas.get_labels(electrodes['mlapdv']))['id'] if self.hist_lookup[self.histology_status] == 1: xyz = xyz[np.argsort(xyz[:, 2]), :] electrodes['mlapdv'] = interpolate_along_track(xyz, (depths + TIP_SIZE_UM) / 1e6) electrodes['atlas_id'] = self.brain_atlas.regions.get(self.brain_atlas.get_labels(electrodes['mlapdv']))['id'] return electrodes
def __init__(self, xyz_picks, chn_depths=None, track_prev=None, feature_prev=None, brain_atlas=None, speedy=False): if not brain_atlas: self.brain_atlas = atlas.AllenAtlas(25) else: self.brain_atlas = brain_atlas self.xyz_track, self.track_extent = self.get_insertion_track( xyz_picks, speedy=speedy) self.chn_depths = chn_depths if np.any(track_prev): self.track_init = track_prev self.feature_init = feature_prev else: start_lims = 6000 / 1e6 self.track_init = np.array([-1 * start_lims, start_lims]) self.feature_init = np.array([-1 * start_lims, start_lims]) self.sampling_trk = np.arange(self.track_extent[0], self.track_extent[-1] - 10 * 1e-6, 10 * 1e-6) self.xyz_samples = histology.interpolate_along_track( self.xyz_track, self.sampling_trk - self.sampling_trk[0]) # ensure none of the track is outside the y or x lim of atlas xlim = np.bitwise_and( self.xyz_samples[:, 0] > self.brain_atlas.bc.xlim[0], self.xyz_samples[:, 0] < self.brain_atlas.bc.xlim[1]) ylim = np.bitwise_and( self.xyz_samples[:, 1] < self.brain_atlas.bc.ylim[0], self.xyz_samples[:, 1] > self.brain_atlas.bc.ylim[1]) rem = np.bitwise_and(xlim, ylim) self.xyz_samples = self.xyz_samples[rem] self.region, self.region_label, self.region_colour, self.region_id\ = self.get_histology_regions(self.xyz_samples, self.sampling_trk, self.brain_atlas)
# Find the trajectory of the id that you want to find closeby probe insertions for subject = 'CSH_ZAD_029' date = '2020-09-19' probe_label = 'probe01' traj_origin_id = one.alyx.rest('trajectories', 'list', provenance='Ephys aligned histology track', subject=subject, date=date, probe=probe_label)[0]['id'] # Find the index of this trajectory in the list of all trajectories chosen_traj = traj_ids.index(traj_origin_id) # Define active part of probe ~ 200um from tip and ~ (200 + 3900)um to top of channels depths = np.arange(200, 4100, 20) / 1e6 traj_coords = np.empty((len(traj_ids), len(depths), 3)) # For each trajectory compute the xyz coords at positions depths along trajectory for iT, traj in enumerate(trajectories): traj_coords[iT, :] = histology.interpolate_along_track(np.vstack([traj.tip, traj.entry]), depths) # Find the average distance between all positions compared to trjaectory of interest avg_dist = np.mean(np.sqrt(np.sum((traj_coords - traj_coords[chosen_traj]) ** 2, axis=2)), axis=1) # Sort according to those that are closest closest_traj = np.argsort(avg_dist) close_sessions = [] # Make a 3D plot showing trajectory of interest (in black) and the 10 nearest trajectories (blue) fig = rendering.figure(grid=False) for iSess, sess_idx in enumerate(closest_traj[0:10]): mlapdv = brain_atlas.xyz2ccf(traj_coords[sess_idx]) if iSess == 0: mlab.plot3d(mlapdv[:, 1], mlapdv[:, 2], mlapdv[:, 0],
eqc_buts = viewseis(bshift.T, si=1 / sr.fs, h=h, t0=t0, title='shift', taxis=0) ## from oneibl.one import ONE import alf.io pid = "8413c5c6-b42b-4ec6-b751-881a54413628" one = ONE() dtypes = [ 'spikes.amps', 'spikes.clusters', 'spikes.times', 'clusters.channels', 'clusters.mlapdv' ] from ibllib.atlas import atlas from ibllib.pipes import histology from ibllib.ephys import neuropixel import numpy as np neuropixel.TIP_SIZE_UM neuropixel.SITES_COORDINATES len(one.alyx.rest('datasets', 'list', insertion=pid)) # if we don't have the data on the flatiron pi = one.alyx.rest('insertions', 'read', id=pid) traj = one.alyx.rest('trajectories', 'list', probe_insertion=pid)[-1] ins = atlas.Insertion.from_dict(traj) xyz_channels = histology.interpolate_along_track( ins.xyz, (neuropixel.SITES_COORDINATES[:, 1] + neuropixel.TIP_SIZE_UM) / 1e6)