neuralib.atlas.ibl.plot.IBLAtlasPlotWrapper
- class neuralib.atlas.ibl.plot.IBLAtlasPlotWrapper[source]
Bases:
AllenAtlasDEPRECATED.Wrapper for iblatlas plotting usage
- regions: BrainRegions
- __init__(res_um=10, scaling=(1, 1, 1), mock=False, source_path=None, alpha=1.0)[source]
- Parameters:
res_um (int) – The Atlas resolution in micrometres; one of 10, 25 or 50um
scaling (tuple[int, int, int]) – Scale factor along ml, ap, dv for squeeze and stretch (default: [1, 1, 1])
mock (bool) – For testing purposes, return atlas object with image comprising zeros
source_path (str | Path | bytes | BinaryIO | BufferedIOBase | BufferedReader | None) – The location of the image volume. By default, use
IBL_CACHE_DIRECTORYalpha (float)
- get_acronym_list(mapping)[source]
get acronym list from different mapping type
- Parameters:
mapping (Literal['Allen', 'Beryl', 'Cosmos', 'Swanson']) – IBL_MAPPING_TYPE
- Return type:
list[str]
- plot_scalar_on_slice(regions, *, values=None, coord=-570, plane='coronal', mapping='Allen', hemisphere='left', background='image', cmap='viridis', clevels=None, show_cbar=False, empty_color='silver', ax=None, vector=False, slice_files=None, auto_merge=True, verbose=True, **kwargs)[source]
Plot the slice view.
See detail in
iblatlas.plots.plot_scalar_on_sliceSee also
https://int-brain-lab.github.io/iblenv/notebooks_external/atlas_plotting_scalar_on_slice.html
- Parameters:
regions (ndarray[Any, dtype[str_]] | list[str] | tuple[str, ...] | Series | Series) – ArrayLike[str, R]
values (ndarray[Any, dtype[T]] | list[T] | tuple[T, ...] | Series | Series | None) – ArrayLike[float, R]
coord (int)
plane (Literal['coronal', 'sagittal', 'horizontal', 'top']) –
IBL_PLANE_TYPE. {‘coronal’, ‘sagittal’, ‘horizontal’, ‘top’}mapping (Literal['Allen', 'Beryl', 'Cosmos', 'Swanson']) –
IBL_MAPPING_TYPE. {‘Allen’, ‘Beryl’, ‘Cosmos’, ‘Swanson’}hemisphere (Literal['left', 'right', 'both']) –
HEMISPHERE_TYPE. {‘left’, ‘right’, ‘both’}background (Literal['image', 'boundary']) –
IBL_BG_TYPE. {‘image’, ‘boundary’}cmap (str)
clevels (ndarray[Any, dtype[T]] | list[T] | tuple[T, ...] | Series | Series | None)
show_cbar (bool)
empty_color (str)
ax (Axes | None)
vector (bool)
slice_files (ndarray | None)
auto_merge (bool) – merge for the certain mapping
verbose (bool)
kwargs
- Returns:
- Return type:
tuple[Figure, Axes] | tuple[Figure, Axes, colorbar]
- plot_points_on_slice(xyz, values=None, coord=-570, plane='coronal', mapping='Allen', background='boundary', cmap='Reds', clevels=None, show_cbar=True, aggr='count', fwhm=0, ax=None)[source]
- Parameters:
xyz (ndarray)
values (ndarray[Any, dtype[T]] | list[T] | tuple[T, ...] | Series | Series | None)
coord (int)
plane (Literal['coronal', 'sagittal', 'horizontal', 'top'])
mapping (Literal['Allen', 'Beryl', 'Cosmos', 'Swanson'])
background (Literal['image', 'boundary'])
cmap (str)
clevels (ndarray[Any, dtype[T]] | list[T] | tuple[T, ...] | Series | Series | None)
show_cbar (bool)
aggr (Literal['sum', 'count', 'mean', 'std', 'median', 'min', 'max'])
fwhm (int)
ax (Axes | None)
- Returns:
- Return type:
tuple[Figure, Axes] | tuple[Figure, Axes, colorbar]
- atlas_rel_path = PurePosixPath('histology/ATLAS/Needles/Allen')
numpy.array: A diffusion weighted imaging (DWI) image volume.
This average template brain was created from images of 1,675 young adult C57BL/6J mouse brains acquired using serial two-photon tomography. This volume has a C-ordered shape of (ap, ml, dv) and contains uint16 values.
- ccf2xyz(ccf, ccf_order='mlapdv')
Convert anatomical coordinates from CCF coordinates.
Anatomical coordinates are in meters, relative to bregma, which CFF coordinates are assumed to be the volume indices multiplied by the spacing in micormeters.
Parameters
- ccfnumpy.array
An N by 3 array of coordinates in CCF space (atlas volume indices * um resolution). The origin is the front left top corner of the data volume.
- ccf_order{‘mlapdv’, ‘apdvml’}, default=’mlapdv’
The order of the CCF coordinates given. For IBL (the default) this is (ML, AP, DV), for Allen MCC vertices, this is (AP, DV, ML).
Returns
- numpy.array
The MLAPDV coordinates in meters, relative to bregma.
- compute_boundaries(values)
Compute the boundaries between regions on slice :param values: :return:
- compute_regions_volume(cumsum=False)
Sums the number of voxels in the labels volume for each region. Then compute volumes for all of the levels of hierarchy in cubic mm. :param: cumsum: computes the cumulative sum of the volume as per the hierarchy (defaults to False) :return:
- compute_surface()
Get the volume top, bottom, left and right surfaces, and from these the outer surface of the image volume. This is needed to compute probe insertions intersections.
NOTE: In places where the top or bottom surface touch the top or bottom of the atlas volume, the surface will be set to np.nan. If you encounter issues working with these surfaces check if this might be the cause.
- extent(axis)
- Parameters:
axis – direction along which the volume is stacked: (2 = z for horizontal slice) (1 = y for coronal slice) (0 = x for sagittal slice)
- Returns:
- get_labels(xyz, mapping=None, radius_um=None, mode='raise')
Performs a 3D lookup from real world coordinates to the volume labels and return the regions ids according to the mapping :param xyz: [n, 3] array of coordinates :param mapping: brain region mapping (defaults to original Allen mapping) :param radius_um: if not null, returns a regions ids array and an array of proportion
of regions in a sphere of size radius around the coordinates.
- Parameters:
mode – {‘raise’, ‘clip’} determines what to do when determined index lies outside the atlas volume
‘raise’ will raise a ValueError (default) ‘clip’ will replace the index with the closest index inside the volume :return: n array of region ids
- image = None
numpy.array: An annotation label volume.
The Allen atlas label volume has with the shape (ap, ml, dv) and contains uint16 indices of the Allen CCF brain regions to which each voxel belongs.
- label = None
numpy.array: One or several optional data volumes, the 3 last dimensions should match the image and the label volumes dimensions
- mask()
Returns a Boolean mask volume of the brain atlas, where 1 is inside the convex brain and 0 is outside This returns an ovoid volume shaped like the brain and this will contain void values in the ventricules. :return: np.array Bool (nap, nml, ndv)
- plot_cslice(ap_coordinate, volume='image', mapping=None, region_values=None, **kwargs)
Plot coronal slice through atlas at given ap_coordinate
- Param:
ap_coordinate (m)
- Parameters:
volume –
‘image’ - allen image volume
’annotation’ - allen annotation volume
’surface’ - outer surface of mesh
’boundary’ - outline of boundaries between all regions
’volume’ - custom volume, must pass in volume of shape ba.image.shape as regions_value argument
’value’ - custom value per allen region, must pass in array of shape ba.regions.id as regions_value argument
mapping – mapping to use. Options can be found using ba.regions.mappings.keys()
region_values – custom values to plot - if volume=’volume’, region_values must have shape ba.image.shape - if volume=’value’, region_values must have shape ba.regions.id
mapping – mapping to use. Options can be found using ba.regions.mappings.keys()
**kwargs –
matplotlib.pyplot.imshow kwarg arguments
- Returns:
matplotlib ax object
- plot_hslice(dv_coordinate, volume='image', mapping=None, region_values=None, **kwargs)
Plot horizontal slice through atlas at given dv_coordinate
- Param:
dv_coordinate (m)
- Parameters:
volume –
‘image’ - allen image volume
’annotation’ - allen annotation volume
’surface’ - outer surface of mesh
’boundary’ - outline of boundaries between all regions
’volume’ - custom volume, must pass in volume of shape ba.image.shape as regions_value argument
’value’ - custom value per allen region, must pass in array of shape ba.regions.id as regions_value argument
mapping – mapping to use. Options can be found using ba.regions.mappings.keys()
region_values – custom values to plot - if volume=’volume’, region_values must have shape ba.image.shape - if volume=’value’, region_values must have shape ba.regions.id
mapping – mapping to use. Options can be found using ba.regions.mappings.keys()
**kwargs –
matplotlib.pyplot.imshow kwarg arguments
- Returns:
matplotlib ax object
- plot_slices(xyz, *args, **kwargs)
From a single coordinate, plots the 3 slices that intersect at this point in a single matplotlib figure :param xyz: mlapdv coordinate in m :param args: arguments to be forwarded to plot slices :param kwargs: keyword arguments to be forwarded to plot slices :return: 2 by 2 array of axes
- plot_sslice(ml_coordinate, volume='image', mapping=None, region_values=None, **kwargs)
Plot sagittal slice through atlas at given ml_coordinate
- Param:
ml_coordinate (m)
- Parameters:
volume –
‘image’ - allen image volume
’annotation’ - allen annotation volume
’surface’ - outer surface of mesh
’boundary’ - outline of boundaries between all regions
’volume’ - custom volume, must pass in volume of shape ba.image.shape as regions_value argument
’value’ - custom value per allen region, must pass in array of shape ba.regions.id as regions_value argument
mapping – mapping to use. Options can be found using ba.regions.mappings.keys()
region_values – custom values to plot - if volume=’volume’, region_values must have shape ba.image.shape - if volume=’value’, region_values must have shape ba.regions.id
mapping – mapping to use. Options can be found using ba.regions.mappings.keys()
**kwargs –
matplotlib.pyplot.imshow kwarg arguments
- Returns:
matplotlib ax object
- plot_tilted_slice(xyz, axis, volume='image', cmap=None, ax=None, return_sec=False, **kwargs)
From line coordinates, extracts the tilted plane containing the line from the 3D volume :param xyz: np.array: points defining a probe trajectory in 3D space (xyz triplets) if more than 2 points are provided will take the best fit :param axis:
0: along ml = sagittal-slice 1: along ap = coronal-slice 2: along dv = horizontal-slice
- Parameters:
volume – ‘image’ or ‘annotation’
- Returns:
matplotlib axis
- plot_top(volume='annotation', mapping=None, region_values=None, ax=None, **kwargs)
Plot top view of atlas :param volume:
‘image’ - allen image volume
‘annotation’ - allen annotation volume
‘boundary’ - outline of boundaries between all regions
‘volume’ - custom volume, must pass in volume of shape ba.image.shape as regions_value argument
‘value’ - custom value per allen region, must pass in array of shape ba.regions.id as regions_value argument
- Parameters:
mapping – mapping to use. Options can be found using ba.regions.mappings.keys()
region_values
ax
kwargs
- Returns:
- slice(coordinate, axis, volume='image', mode='raise', region_values=None, mapping=None, bc=None)
Get slice through atlas
- Parameters:
coordinate – coordinate to slice in metres, float
axis – xyz convention: 0 for ml, 1 for ap, 2 for dv - 0: sagittal slice (along ml axis) - 1: coronal slice (along ap axis) - 2: horizontal slice (along dv axis)
volume –
‘image’ - allen image volume
’rindex’ - brain region index value
’annotation’ - allen annotation volume
’surface’ - outer surface of mesh
’boundary’ - outline of boundaries between all regions
’volume’ - custom volume, must pass in volume of shape ba.image.shape as regions_value argument
’value’ - custom value per allen region, must pass in array of shape ba.regions.id as regions_value argument
mode – error mode for out of bounds coordinates - ‘raise’ raise an error - ‘clip’ gets the first or last index
region_values – custom values to plot - if volume=’volume’, region_values must have shape ba.image.shape - if volume=’value’, region_values must have shape ba.regions.id
mapping – mapping to use. Options can be found using ba.regions.mappings.keys()
- Returns:
2d array or 3d RGB numpy int8 array of dimensions: - 0: nap x ndv (sagittal slice) - 1: nml x ndv (coronal slice) - 2: nap x nml (horizontal slice)
- tilted_slice(xyz, axis, volume='image')
From line coordinates, extracts the tilted plane containing the line from the 3D volume :param xyz: np.array: points defining a probe trajectory in 3D space (xyz triplets) if more than 2 points are provided will take the best fit :param axis:
0: along ml = sagittal-slice 1: along ap = coronal-slice 2: along dv = horizontal-slice
- Parameters:
volume – ‘image’ or ‘annotation’
- Returns:
np.array, abscissa extent (width), ordinate extent (height),
squeezed axis extent (depth)
- volumes = None
- xyz2ccf(xyz, ccf_order='mlapdv', mode='raise')
Converts anatomical coordinates to CCF coordinates.
Anatomical coordinates are in meters, relative to bregma, which CFF coordinates are assumed to be the volume indices multiplied by the spacing in micormeters.
Parameters
- xyznumpy.array
An N by 3 array of anatomical coordinates in meters, relative to bregma.
- ccf_order{‘mlapdv’, ‘apdvml’}, default=’mlapdv’
The order of the CCF coordinates returned. For IBL (the default) this is (ML, AP, DV), for Allen MCC vertices, this is (AP, DV, ML).
- mode{‘raise’, ‘clip’, ‘wrap’}, default=’raise’
How to behave if the coordinate lies outside of the volume: raise (default) will raise a ValueError; ‘clip’ will replace the index with the closest index inside the volume; ‘wrap’ will return the index as is.
Returns
- numpy.array
Coordinates in CCF space (um, origin is the front left top corner of the data
volume, order determined by ccf_order