ibllib.pipes.ephys_alignment

Classes

EphysAlignment

class EphysAlignment(xyz_picks, chn_depths=None, track_prev=None, feature_prev=None, brain_atlas=None, speedy=False)[source]

Bases: object

get_insertion_track(xyz_picks, speedy=False)[source]

Extends probe trajectory from bottom of brain to upper bound of allen atlas :param xyz_picks: points defining probe trajectory in 3D space (xyz) :type xyz_picks: np.array((n, 3)) - n: no. of unique points :return xyz_track: points defining extended trajectory in 3D space (xyz) :type xyz_track: np.array((n+2, 3)) :return track_extent: cumulative distance between two extremes of xyz_track (bottom of brain and top of atlas) offset by distance to probe tip :type track_extent: np.array((2))

get_track_and_feature()[source]

Return track, feature and xyz_track variables

static feature2track(trk, feature, track)[source]

Estimate new values of trk according to interpolated fit between feature and track space :param trk: points in track space to convert feature space :type trk: np.array :param feature: reference coordinates in feature space (ephys plots) :type feature: np.array((n_lines + 2)) n_lines: no. of user reference lines :param track: reference coordinates in track space (histology track) :type track: np.array((n_lines + 2)) :return fcn(trk): interpolated values of trk :type fcn(trk): np.array

static track2feature(ft, feature, track)[source]

Estimate new values of ft according to interpolated fit between track and feature space :param ft: points in feature space to convert track space :type ft: np.array :param feature: reference coordinates in feature space (ephys plots) :type feature: np.array((n_lines + 2)) n_lines: no. of user reference lines :param track: reference coordinates in track space (histology track) :type track: np.array((n_lines + 2)) :return fcn(ft): interpolated values of ft :type fcn(ft): np.array

static feature2track_lin(trk, feature, track)[source]

Estimate new values of trk according to linear fit between feature and track space, only implemented if no. of reference points >= 3 :param trk: points in track space to convert feature space :type trk: np.array :param feature: reference coordinates in feature space (ephys plots) :type feature: np.array((n_lines + 2)) n_lines: no. of user reference lines :param track: reference coordinates in track space (histology track) :type track: np.array((n_lines + 2)) :return fcn(trk): linear fit values of trk :type fcn(trk): np.array

static adjust_extremes_uniform(feature, track)[source]

Change the value of the first and last reference points (non user chosen points) such that coordinates outside user picked regions are left unchanged :param feature: reference coordinates in feature space (ephys plots) :type feature: np.array((n_lines + 2)) n_lines: no. of user reference lines :param track: reference coordinates in track space (histology track) :type track: np.array((n_lines + 2)) :return track: reference coordinates in track space with first and last value adjusted :type track: np.array((n_lines + 2))

adjust_extremes_linear(feature, track, extend_feature=1)[source]

Change the value of the first and last reference points (non user chosen points) such that coordinates outside user picked regions have a linear fit applied :param feature: reference coordinates in feature space (ephys plots) :type feature: np.array((n_lines + 2)) n_lines: no. of user reference lines :param track: reference coordinates in track space (histology track) :type track: np.array((n_lines + 2)) :param extend_feature: amount to extend extreme coordinates before applying linear fit :type extend_feature: float :return feature: reference coordinates in feature space with first and last value adjusted :type feature: np.array((n_lines + 2)) :return track: reference coordinates in track space with first and last value adjusted :type track: np.array((n_lines + 2))

scale_histology_regions(feature, track)[source]

Recompute locations of brain region boundaries using interpolated fit based on reference lines :param feature: reference coordinates in feature space (ephys plots) :type feature: np.array((n_lines + 2)) n_lines: no. of user reference lines :param track: reference coordinates in track space (histology track) :type track: np.array((n_lines + 2)) :return region: new coordinates of histology boundaries after applying interpolation :type region: np.array((n_bound, 2)) n_bound: no. of histology boundaries :return region_label: new coordinates of histology labels positions after applying

interpolation

static get_histology_regions(xyz_coords, depth_coords, brain_atlas=None, mapping='Allen')[source]

Find all brain regions and their boundaries along the depth of probe or track :param xyz_coords: 3D coordinates of points along probe or track :type xyz_coords: np.array((n_points, 3)) n_points: no. of points :param depth_coords: depth along probe or track where each xyz_coord is located :type depth_coords: np.array((n_points)) :return region: coordinates bounding each brain region :type region: np.array((n_bound, 2)) n_bound: no. of histology boundaries :return region_label: label for each brain region and coordinate of where to place label :type region_label: np.array((n_bound)) of tuples (coordinate - float, label - str) :return region_colour: allen atlas rgb colour for each brain region along track :type region_colour: np.array((n_bound, 3)) :return region_id: allen atlas id for each brain region along track :type region_id: np.array((n_bound))

static get_nearest_boundary(xyz_coords, allen, extent=100, steps=8, parent=True, brain_atlas=None)[source]

Finds distance to closest neighbouring brain region along trajectory. For each point in xyz_coords computes the plane passing through point and perpendicular to trajectory and finds all brain regions that lie in that plane up to a given distance extent from specified point. Additionally, if requested, computes distance between the parents of regions. :param xyz_coords: 3D coordinates of points along probe or track :type xyz_coords: np.array((n_points, 3)) n_points: no. of points :param allen: dataframe containing allen info. Loaded from allen_structure_tree in ibllib/atlas :type allen: pandas Dataframe :param extent: extent of plane in each direction from origin in (um) :type extent: float :param steps: no. of steps to discretise plane into :type steps: int :param parent: Whether to also compute nearest distance between parents of regions :type parent: bool :return nearest_bound: dict containing results :type nearest_bound: dict

static arrange_into_regions(depth_coords, region_ids, distance, region_colours)[source]

Arrange output from get_nearest_boundary into a form that can be plot using pyqtgraph or matplotlib :param depth_coords: depth along probe or track where each point is located :type depth_coords: np.array((n_points)) :param region_ids: brain region id at each depth along probe :type regions_ids: np.array((n_points)) :param distance: distance to nearest boundary in plane at each point :type distance: np.array((n_points)) :param region_colours: allen atlas hex colour for each region id :type region_colours: list of strings len(n_points) :return all_x: dist values for each region along probe track :type all_x: list of np.array :return all_y: depth values for each region along probe track :type all_y: list of np.array :return all_colour: colour assigned to each region along probe track :type all_colour: list of str

get_scale_factor(region)[source]

Find how much each brain region has been scaled following interpolation :param region: scaled histology boundaries :type region: np.array((n_bound, 2)) n_bound: no. of histology boundaries :return scaled_region: regions that have unique scaling applied :type scaled_region: np.array((n_scale, 2)) n_scale: no. of uniquely scaled regions :return scale_factor: scale factor applied to each scaled region :type scale_factor: np.array((n_scale))

get_channel_locations(feature, track, depths=None)[source]

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

get_brain_locations(xyz_channels)[source]

Finds the brain regions from 3D coordinates of electrode locations :param xyz_channels: 3D coordinates of electrodes on probe :type xyz_channels: np.array((n_elec, 3)) n_elec: no. of electrodes (384) :return brain_regions: brain region object for each electrode :type dict

get_perp_vector(feature, track)[source]

Finds the perpendicular vector along the trajectory at the depth of reference lines :param feature: reference coordinates in feature space (ephys plots) :type feature: np.array((n_lines + 2)) n_lines: no. of user reference lines :param track: reference coordinates in track space (histology track) :type track: np.array((n_line+2)) :return slice_lines: coordinates of perpendicular lines :type slice_lines: np.array((n_lines, 2))