ibllib.pipes.ephys_alignment
Classes
- 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
- Parameters:
xyz_picks (np.array((n, 3)) - n: no. of unique points) – points defining probe trajectory in 3D space (xyz)
- Return xyz_track:
points defining extended trajectory in 3D space (xyz)
- 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))
- static feature2track(trk, feature, track)[source]
Estimate new values of trk according to interpolated fit between feature and track space
- Parameters:
trk (np.array) – points in track space to convert feature space
feature (np.array((n_lines + 2)) n_lines: no. of user reference lines) – reference coordinates in feature space (ephys plots)
track (np.array((n_lines + 2))) – reference coordinates in track space (histology track)
- Return fcn(trk):
interpolated values of trk
- static track2feature(ft, feature, track)[source]
Estimate new values of ft according to interpolated fit between track and feature space
- Parameters:
ft (np.array) – points in feature space to convert track space
feature (np.array((n_lines + 2)) n_lines: no. of user reference lines) – reference coordinates in feature space (ephys plots)
track (np.array((n_lines + 2))) – reference coordinates in track space (histology track)
- Return fcn(ft):
interpolated values of ft
- 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
- Parameters:
trk (np.array) – points in track space to convert feature space
feature (np.array((n_lines + 2)) n_lines: no. of user reference lines) – reference coordinates in feature space (ephys plots)
track (np.array((n_lines + 2))) – reference coordinates in track space (histology track)
- Return fcn(trk):
linear fit values of trk
- 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
- Parameters:
feature (np.array((n_lines + 2)) n_lines: no. of user reference lines) – reference coordinates in feature space (ephys plots)
track (np.array((n_lines + 2))) – reference coordinates in track space (histology track)
- Return track:
reference coordinates in track space with first and last value adjusted
- 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
- Parameters:
feature (np.array((n_lines + 2))) – reference coordinates in feature space (ephys plots)
track (np.array((n_lines + 2))) – reference coordinates in track space (histology track)
extend_feature (float) – amount to extend extreme coordinates before applying linear fit
- Return feature:
reference coordinates in feature space with first and last value adjusted
- Return track:
reference coordinates in track space with first and last value adjusted
- scale_histology_regions(feature, track, region=None, region_label=None)[source]
Recompute locations of brain region boundaries using interpolated fit based on reference lines
- Parameters:
feature (np.array((n_lines + 2)) n_lines: no. of user reference lines) – reference coordinates in feature space (ephys plots)
track (np.array((n_lines + 2))) – reference coordinates in track space (histology track)
- Return region:
new coordinates of histology boundaries after applying interpolation
- Return region_label:
new coordinates of histology labels positions after applying interpolation
- static get_histology_regions(xyz_coords, depth_coords, brain_atlas=None, mapping=None)[source]
Find all brain regions and their boundaries along the depth of probe or track
- Parameters:
xyz_coords (np.array((n_points, 3)) n_points: no. of points) – 3D coordinates of points along probe or track
depth_coords (np.array((n_points))) – depth along probe or track where each xyz_coord is located
- Return region:
coordinates bounding each brain region
- Return region_label:
label for each brain region and coordinate of where to place label
- Return region_colour:
allen atlas rgb colour for each brain region along track
- Return region_id:
allen atlas id for each brain region along track
- 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.
- Parameters:
xyz_coords (np.array((n_points, 3)) n_points: no. of points) – 3D coordinates of points along probe or track
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
- Parameters:
depth_coords (np.array((n_points))) – depth along probe or track where each point is located
region_ids – brain region id at each depth along probe
distance (np.array((n_points))) – distance to nearest boundary in plane at each point
region_colours (list of strings len(n_points)) – allen atlas hex colour for each region id
- Return all_x:
dist values for each region along probe track
- Return all_y:
depth values for each region along probe track
- Return all_colour:
colour assigned to each region along probe track
- get_scale_factor(region, region_orig=None)[source]
Find how much each brain region has been scaled following interpolation
- Parameters:
region (np.array((n_bound, 2)) n_bound: no. of histology boundaries) – scaled histology boundaries
- Return scaled_region:
regions that have unique scaling applied
- Return scale_factor:
scale factor applied to each scaled region
- 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
- Parameters:
xyz_channels (np.array((n_elec, 3)) n_elec: no. of electrodes (384)) – 3D coordinates of electrodes on probe
- 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
- Parameters:
feature (np.array((n_lines + 2)) n_lines: no. of user reference lines) – reference coordinates in feature space (ephys plots)
track (np.array((n_line+2))) – reference coordinates in track space (histology track)
- Return slice_lines:
coordinates of perpendicular lines