Find the nearest volume image index to a given x-axis coordinate.
Parameters:
x (float, numpy.array) – One or more x-axis coordinates, relative to the origin, x0.
round (bool) – If true, round to the nearest index, replacing NaN values with 0.
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:
The nearest indices of the image volume along the first dimension.
Return type:
numpy.array
Raises:
ValueError – At least one x value lies outside of the atlas volume. Change ‘mode’ input to ‘wrap’ to
keep these values unchanged, or ‘clip’ to return the nearest valid indices.
Find the nearest volume image index to a given y-axis coordinate.
Parameters:
y (float, numpy.array) – One or more y-axis coordinates, relative to the origin, y0.
round (bool) – If true, round to the nearest index, replacing NaN values with 0.
mode ({'raise', 'clip', 'wrap'}) – 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:
The nearest indices of the image volume along the second dimension.
Return type:
numpy.array
Raises:
ValueError – At least one y value lies outside of the atlas volume. Change ‘mode’ input to ‘wrap’ to
keep these values unchanged, or ‘clip’ to return the nearest valid indices.
Find the nearest volume image index to a given z-axis coordinate.
Parameters:
z (float, numpy.array) – One or more z-axis coordinates, relative to the origin, z0.
round (bool) – If true, round to the nearest index, replacing NaN values with 0.
mode ({'raise', 'clip', 'wrap'}) – 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:
The nearest indices of the image volume along the third dimension.
Return type:
numpy.array
Raises:
ValueError – At least one z value lies outside of the atlas volume. Change ‘mode’ input to ‘wrap’ to
keep these values unchanged, or ‘clip’ to return the nearest valid indices.
Find the nearest volume image indices to the given Cartesian coordinates.
Parameters:
xyz (array_like) – One or more Cartesian coordinates, relative to the origin, xyz0.
round (bool) – If true, round to the nearest index, replacing NaN values with 0.
mode ({'raise', 'clip', 'wrap'}) – How to behave if any 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:
The nearest indices of the image volume.
Return type:
numpy.array
Raises:
ValueError – At least one coordinate lies outside of the atlas volume. Change ‘mode’ input to ‘wrap’
to keep these values unchanged, or ‘clip’ to return the nearest valid indices.
Objects that holds image, labels and coordinate transforms for a brain Atlas.
Currently this is designed for the AllenCCF at several resolutions,
yet this class can be used for other atlases arises.
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)
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.
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
’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)
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()
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()
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()
Computes the minimum distance to the trajectory line for one or a set of points.
If bounds are provided, computes the minimum distance to the segment instead of an
infinite line.
Parameters:
xyz – […, 3]
bounds – defaults to None. np.array [2, 3]: segment boundaries, inf line if None
Given a Trajectory and a BrainAtlas object, computes the brain exit coordinate as the
intersection of the trajectory and the brain surface (brain_atlas.surface)
Given a Trajectory and a BrainAtlas object, computes the brain entry coordinate as the
intersection of the trajectory and the brain surface (brain_atlas.surface)
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.
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:
xyz (numpy.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
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:
ccf (numpy.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:
The MLAPDV coordinates in meters, relative to bregma.
Instantiates an atlas.BrainAtlas corresponding to the Allen CCF at the given resolution
using the IBL Bregma and coordinate system. The Needles atlas defines a stretch along AP
axis and a squeeze along the DV axis.
Parameters:
res_um ({10, 25, 50} int) – The Atlas resolution in micrometres; one of 10, 25 or 50um.
**kwargs – See AllenAtlas.
Returns:
An Allen atlas object with MRI atlas scaling applied.
The scaling was determined by manually transforming the DSURQE atlas [1]_ onto the Allen CCF.
The DSURQE atlas is an MRI atlas acquired from 40 C57BL/6J mice post-mortem, with 40um
isometric resolution. The alignment was performed by Mayo Faulkner.
The atlas data can be found here.
More information on the dataset and segmentation can be found
here.
Instantiates an atlas.BrainAtlas corresponding to the Allen CCF at the given resolution
using the IBL Bregma and coordinate system. The MRI Toronto atlas defines a stretch along AP
a squeeze along DV and a squeeze along ML. These are based on 12 p65 mice MRIs averaged [1]_.
Parameters:
res_um ({10, 25, 50} int) – The Atlas resolution in micrometres; one of 10, 25 or 50um.
**kwargs – See AllenAtlas.
Returns:
An Allen atlas object with MRI atlas scaling applied.