neuralib.atlas.view

neuralib.atlas.view.load_slice_view(source, plane_type, *, output_dir=None, allen_annotation_res=10)[source]

Load the mouse brain slice view

Parameters:
  • source (DATA_SOURCE_TYPE) – DATA_SOURCE_TYPE. {‘ccf_annotation’, ‘ccf_template’, ‘allensdk_annotation’}

  • plane_type (PLANE_TYPE) – PLANE_TYPE. {‘coronal’, ‘sagittal’, ‘transverse’}

  • output_dir (PathLike | None) – Output directory for caching

  • allen_annotation_res (int) – Volume resolution in um. default is 10 um

Returns:

AbstractSliceView

Return type:

AbstractSliceView

class neuralib.atlas.view.AbstractSliceView[source]

SliceView ABC for different plane type

Dimension parameters:

AP = anterior-posterior

DV = dorsal-ventral

ML = medial-lateral

W = view width

H = view height

REFERENCE_FROM: ClassVar[str] = ''

reference from which axis

static __new__(cls, source_type, plane, resolution, reference)[source]
Parameters:
  • source_type (Literal['ccf_annotation', 'ccf_template', 'allensdk_annotation'])

  • plane (Literal['coronal', 'sagittal', 'transverse'])

  • resolution (int)

  • reference (ndarray)

__init__(source_type, plane, resolution, reference)[source]
Parameters:
  • source_type (Literal['ccf_annotation', 'ccf_template', 'allensdk_annotation']) – DATA_SOURCE_TYPE. {‘ccf_annotation’, ‘ccf_template’, ‘allensdk_annotation’}

  • plane (Literal['coronal', 'sagittal', 'transverse']) – PLANE_TYPE`. {‘coronal’, ‘sagittal’, ‘transverse’}

  • resolution (int) – um/pixel

  • reference (ndarray) – Array[uint16, [AP, DV, ML]]

source_type: Final[Literal['ccf_annotation', 'ccf_template', 'allensdk_annotation']]

DATA_SOURCE_TYPE. {‘ccf_annotation’, ‘ccf_template’, ‘allensdk_annotation’}

plane_type: Final[Literal['coronal', 'sagittal', 'transverse']]

PLANE_TYPE`. {‘coronal’, ‘sagittal’, ‘transverse’}

resolution: Final[int]

um/pixel

reference: Final[ndarray]

Array[float, [AP, DV, ML]]

grid_y: Final[ndarray]

Array[int, [W, H]]

grid_x: Final[ndarray]

Array[int, [W, H]]

property bregma: ndarray
property n_ap: int

number of slices along AP axis

property n_dv: int

number of slices along DV axis

property n_ml: int

number of slices along ML axis

abstract property n_planes: int

number of planes in a specific plane view

abstract property width: int

width (pixel) in a specific plane view

abstract property height: int

height (pixel) in a specific plane view

property width_mm: float

width (um) in a specific plane view

property height_mm: float

height (um) in a specific plane view

abstract property reference_point: int

reference point in a specific plane view. aka, bregma plane index

abstract property project_index: tuple[int, int, int]

plane(p), x, y of index order in (AP, DV, ML)

Returns:

(p, x, y)

plane_at(slice_index)[source]
Parameters:

slice_index (int)

Return type:

SlicePlane

offset(h, v)[source]
Parameters:
  • h (int) – horizontal plane diff to the center. right side positive.

  • v (int) – vertical plane diff to the center. bottom side positive.

Returns:

(H, W) array

Return type:

ndarray

plane(offset)[source]

Get image plane.

Parameters:

offset (int | tuple[int, int, int] | np.ndarray) – Array[int, height, width] or tuple (plane, dh, dv)

Returns:

Return type:

np.ndarray

coor_on(plane, o)[source]

map slice point (x, y) at plane plane back to volume point (ap, dv, ml)

Parameters:
  • plane (ndarray) – plane number of array

  • o (tuple[ndarray, ndarray]) – tuple of (x, y)

Returns:

(ap, dv, ml)

Return type:

tuple[ndarray, …]

class neuralib.atlas.view.SlicePlane[source]

2D Wrapper for a specific plane

slice_index: int

anchor index

ax: int

anchor x

__init__(slice_index, ax, ay, dw, dh, view, unit='a.u.')

Method generated by attrs for class SlicePlane.

Parameters:
  • slice_index (int)

  • ax (int)

  • ay (int)

  • dw (int)

  • dh (int)

  • view (AbstractSliceView)

  • unit (str)

Return type:

None

ay: int

anchor y

dw: int

dw in um

dh: int

dh in um

view: AbstractSliceView

AbstractSliceView

property image: ndarray
property plane_offset: ndarray
property reference_value: float

relative to reference point

with_offset(dw, dh, debug=False)[source]
Parameters:
  • dw (int)

  • dh (int)

  • debug (bool)

Return type:

Self

with_angle_offset(deg_x, deg_y)[source]

with degree offset

Parameters:
  • deg_x (float) – degree in x axis (width)

  • deg_y (float) – degree in y axis (height)

Returns:

Return type:

Self

plot(ax=None, to_um=True, with_annotation=False, cbar=False, with_title=False, affine_transform=False, customized_trans=False, extent=None, **kwargs)[source]
Parameters:
  • ax (Axes | None) – The Axes object on which to plot. If None, a new figure and axes are created.

  • to_um (bool) – A boolean flag indicating whether the coordinates should be converted to micrometers. Defaults to True. Only applicable if extent is None.

  • with_annotation (bool) – A boolean indicating whether to include annotations in the plot.

  • cbar (bool) – A boolean indicating whether to include a color bar in the plot.

  • with_title (bool) – A boolean indicating whether to include a title in the plot.

  • affine_transform (bool) – A boolean indicating whether to apply an affine transformation to the plot.

  • customized_trans (bool) – A boolean indicating whether to use a customized affine transformation.

  • extent (tuple[float, float, float, float] | None) – A tuple defining the image boundaries (left, right, bottom, top). If None, boundaries are computed internally.

  • kwargs – Additional keyword arguments passed to ax.imshow.

Returns:

A tuple containing the main AxesImage, the annotation AxesImage if any, and the Affine2D transformation.

Return type:

tuple[AxesImage, AxesImage | None, CompositeGenericTransform]

unit: str
plot_annotation(ax, *, aff_trans=None, to_um=True, cmap='binary', alpha=0.3, extent=None)[source]

Plot the annotation image

Parameters:
  • ax (Axes) – Axes

  • aff_trans (Axes.transData | None) – The transformation applied to the annotation image. If None, defaults to the Axes’ transformation.

  • to_um (bool) – A boolean flag indicating whether the coordinates should be converted to micrometers. Defaults to True. Only applicable if extent is None.

  • cmap (str) – Colormap to be used for the annotation image. Defaults to ‘binary’.

  • alpha (float) – The imshow alpha, between 0 (transparent) and 1 (opaque). Defaults to 0.3.

  • extent (tuple[float, float, float, float] | None) – A tuple defining the image boundaries (left, right, bottom, top). If None, boundaries are computed internally.

Returns:

The AxesImage object created by imshow, representing the plotted annotation image.

Return type:

AxesImage