ibl_alignment_gui.handlers.alignment_handler
Classes
Handles the alignment of electrophysiology data to histology data. |
|
A class to manage circular buffer indexing. |
- class ibl_alignment_gui.handlers.alignment_handler.AlignmentHandler(xyz_picks, chn_depths, brain_atlas)[source]
Bases:
objectHandles the alignment of electrophysiology data to histology data.
The location of the electrodes along the probe trajectory are adjusted according user defined reference lines that are placed on the electrophysiology (feature) and histology (track) data. Uses a circular buffer to keep a history of the alignment steps the user performs to adjust the locations of the electrodes in the brain to match the observed features in th ephys data.
- Parameters:
xyz_picks (np.ndarray) – An array of xyz coordinates in 3D space that define the trajectory of the probe through the brain. The most ventral point defines the initial estimate of the probe tip.
chn_depths (np.ndarray) – An array containing the depths of the recording channels along the probe.
brain_atlas (AllenAtlas) – An AllenAtlas object containing a volume to do a lookup between xyz coordinates and brain region.
- buffer
Circular buffer to store and manage multiple alignments steps.
- Type:
- brain_atlas
An AllenAtlas object
- Type:
AllenAtlas
- ephysalign
An EphysAlignment object used to perform alignment logic
- Type:
EphysAlignment
- hist_mapping
Defines histology mapping mode, e.g. ‘Allen’
- Type:
str
- tracks
A list of arrays, each containing the position of the track reference lines along the probe at a specific alignment step
- Type:
list
- features
A list of arrays, each containing the position of the feature reference lines along the probe at a specific alignment step
- Type:
list
- property current_idx
See
CircularIndexTracker.current_idx()for details.
- property feature: ndarray
Feature array at the current index of the circular buffer.
- Returns:
An array of positions of the feature reference lines for the current index
- Return type:
np.ndarray
- get_scaled_histology()[source]
Compute the brain regions along the probe track using the current alignment.
- Return type:
tuple[Bunch,Bunch,Bunch]- Returns:
hist_data (Bunch) – Scaled histology regions and axis labels for the current track.
hist_data_ref (Bunch) – Reference histology data for comparison.
scale_data (Bunch) – Scaling factors applied to the histology regions.
- property idx: int
The current index in the circular buffer.
- Returns:
The current index
- Return type:
int
- property idx_prev: int
The previous index in the circular buffer.
- Returns:
The previous index
- Return type:
int
- next_idx()[source]
See
CircularIndexTracker.next_idx()for details.- Return type:
bool
- offset_hist_data(offset)[source]
Apply an offset to the brain regions along the probe track.
Adds the new alignment state into next buffer index of the feature and track arrays.
- Parameters:
offset (float) – Offset value to apply to the track alignment.
- Return type:
None
- prev_idx()[source]
See
CircularIndexTracker.prev_idx()for details.- Return type:
bool
- reset_features_and_tracks()[source]
Reset features and tracks to their initial alignment state.
- Return type:
None
- scale_hist_data(line_track, line_feature, extend_feature=1, lin_fit=True)[source]
Scale brain regions along the probe track.
Scales based on location of the user chosen track and feature reference lines. Adds the new alignment state into next buffer index of the feature and track arrays.
- Parameters:
line_track (np.ndarray) – An array of positions of the track reference lines
line_feature (np.ndarray) – An array of positions of the feature reference lines
extend_feature (int, optional) – Factor for extending the feature alignment beyond original extremes.
lin_fit (bool, optional) – Whether to apply linear fitting to adjust extremes. Only applied when number of fit lines >= 5
- Return type:
None
- set_init_feature_track(feature=None, track=None)[source]
Set the initial feature and track values for the current buffer index.
- Parameters:
feature (np.ndarray, optional) – Initial feature alignment.
track (np.ndarray, optional) – Initial track alignment.
- Return type:
None
- property total_idx: int
See
CircularIndexTracker.total_idx()for details.
- property track
Track array at the current index of the circular buffer.
- Returns:
An array of positions of the track reference lines for the current index
- Return type:
np.ndarray
- property track_lines: list[ndarray]
Return the perpendicular vectors (lines) at the position of each track reference line.
Estimates using the values stored at the current index of the circular buffer.
- Returns:
List of arrays containing points defining perpendicular vector at each track reference line
- Return type:
list of np.ndarray
- property xyz_channels: ndarray
Return xyz channel locations estimated using the fit from the track and feature arrays.
Estimates using the values stored at the current index of the circular buffer.
- Returns:
xyz positions of channels in 3D space
- Return type:
np.ndarray
- property xyz_samples: ndarray
Return the xyz coordinates along the probe trajectory.
The coordinates are extended to the full extent of the Atlas volume sampled at 10 um intervals.
- Returns:
xyz positions of samples in 3D space
- Return type:
np.ndarray
- property xyz_track: ndarray
Return the xyz coordinates along the probe trajectory.
The coordinates are extended to the top and bottom of the brain surface.
- Returns:
xyz positions of trajctory in 3D space
- Return type:
np.ndarray
- class ibl_alignment_gui.handlers.alignment_handler.CircularIndexTracker(max_idx)[source]
Bases:
objectA class to manage circular buffer indexing.
- Parameters:
max_idx (int) – Size of the circular buffer.
- max_idx
Size of the circular buffer.
- Type:
int
- current_idx
The current index in logical (non-wrapped) space.
- Type:
int
- total_idx
The highest index filled so far in logical space.
- Type:
int
- last_idx
The last recorded total index.
- Type:
int
- diff_idx
Offset between current index and last index used in reset logic.
- Type:
int
- idx
The wrapped index used in the circular buffer.
- Type:
int
- idx_prev
The previous wrapped index.
- Type:
int
- next_idx()[source]
Move to the next index in the buffer.
If no further index is available, remain at current index.
- Return type:
bool
- Returns: bool
Whether the tracker moved to the next index.
- next_idx_to_fill()[source]
Advance to the next index.
If the next index doesn’t exist create it.
- Return type:
None