neurocarto.util.atlas_slice

class neurocarto.util.atlas_slice.Projection
coronal = (0, 2, 1)
sagittal = (2, 0, 1)
transverse = (1, 2, 0)
final class neurocarto.util.atlas_slice.SliceView

Atlas brain slice view. Here provide three kinds of view (‘coronal’, ‘sagittal’, ‘transverse’).

__init__(brain, projection, reference=None)
Parameters:
  • name – view

  • reference (NDArray[np.uint]) – reference brain volume with shape (AP, DL, ML)

  • resolution – um/pixel

  • brain (BrainGlobeAtlas)

  • projection (PROJECTION | Projection)

brain

Atlas brain

projection: Final[Projection]

slice plane projection

reference: Final[ndarray[tuple[int, ...], dtype[uint64]]]

Image Array[uint, AP, DV, ML]

resolution: Final[list[int]]

um/pixel

grid_y: Final[ndarray[tuple[int, ...], dtype[int64]]]
grid_x: Final[ndarray[tuple[int, ...], dtype[int64]]]
property n_ap: int

Number of slices in AP axis

property n_dv: int

Number of slices in DV axis

property n_ml: int

Number of slices in ML axis

property n_plane: int

Number of plane (pixel) in this view

property width: int

width (pixel) in this view

property height: int

height (pixel) in this view

property plane_um: float

total plane length (um)

property width_um: float

width (um) in this view

property height_um: float

height (um) in this view

property project_index: tuple[int, int, int]

index order of (ap, dv, ml).

Returns:

(p, x, y)

plane(o, image=None)

Get brain image on plane o.

Parameters:
  • o (int | tuple[int, int, int] | ndarray[tuple[int, ...], dtype[int64]]) – plane, tuple (plane, dh, dv) or Array[plane:int, H, W]

  • image (ndarray[tuple[int, ...], dtype[uint64]] | None) – brain volume with shape (AP, DL, ML)

Returns:

brain slice image with shape (height, width)

Return type:

ndarray[tuple[int, …], dtype[uint64]]

pull_back(plane: int, o: tuple[int, int] | tuple[float, float], *, um=False) tuple[int, int, int] | tuple[float, float, float]
pull_back(plane: int | ndarray[tuple[int, ...], dtype[int64]], o: tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]]], *, um=False) tuple[ndarray[tuple[int, ...], dtype[int64]], ndarray[tuple[int, ...], dtype[int64]], ndarray[tuple[int, ...], dtype[int64]]]
pull_back(plane: int | ndarray[tuple[int, ...], dtype[int64]], o: ndarray[tuple[int, ...], dtype[int64]], *, um=False) ndarray[tuple[int, ...], dtype[int64]]

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

Parameters:
  • plane – plane number of array

  • o – tuple of (x, y) or Array[int|float, N, (x, y)]

  • um – use um?

Returns:

index (ap, dv, ml) or Array[int, N, (ap, dv, ml)]

project(t: tuple[int, int, int] | tuple[float, float, float], *, um=False) tuple[int, int, int]
project(t: ndarray[tuple[int, ...], dtype[_ScalarType_co]], *, um=False) ndarray[tuple[int, ...], dtype[int64]]

project volume point (ap, dv, ml) onto slice point (plane, x, y)

Parameters:
  • t – (ap, dv, ml) or Array[int, [N,], (ap, dv, ml)].

  • um – use um?

Returns:

(plane, x, y) or Array[int, [N,], (plane, x, y)]

offset(h, v)

plane index offset according to horizontal difference h and vertical difference v.

Parameters:
  • h (int) – horizontal plane diff to the center. right side positive.

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

Returns:

Array[int, H, W] array

Return type:

ndarray[tuple[int, …], dtype[int64]]

angle_offset(a)

plane index offset according to angle difference a.

Parameters:

a (tuple[float, float, float]) – radian rotation of (ap, dv, ml)-axis.

Returns:

tuple of (dw, dh)

Return type:

tuple[int, int]

offset_angle(dw, dh)

plane index offset according to angle difference a.

Parameters:
  • dw (int)

  • dh (int)

Returns:

radian rotation of (ap, dv, ml)-axis.

Return type:

tuple[float, float, float]

plane_at(c, um=False)
Parameters:
  • c (int | tuple[int, int, int] | tuple[float, float, float] | ndarray[tuple[int, ...], dtype[int64]] | SlicePlane) – plane index (int) or volume point (ap, dv, ml)

  • um – does the unit of the values used in c are um?

Returns:

correspond slice view.

Return type:

SlicePlane

class neurocarto.util.atlas_slice.SlicePlane

Just a wrapper of SliceView that keep the information of volume point (ap, dv, ml) and rotate (dw, dh).

plane: int

Alias for field number 0

ax: int

Alias for field number 1

static __new__(_cls, plane, ax, ay, dw, dh, slice)

Create new instance of SlicePlane(plane, ax, ay, dw, dh, slice)

Parameters:
  • plane (int)

  • ax (int)

  • ay (int)

  • dw (int)

  • dh (int)

  • slice (SliceView)

ay: int

Alias for field number 2

dw: int

Alias for field number 3

dh: int

Alias for field number 4

slice: SliceView

Alias for field number 5

property projection: Projection
property resolution: list[int]
property width: float

width (um) in this view

property height: float

height (um) in this view

property image: ndarray[tuple[int, ...], dtype[uint64]]
image_of(image)
Parameters:

image (ndarray[tuple[int, ...], dtype[uint64]])

Return type:

ndarray[tuple[int, …], dtype[uint64]]

property plane_offset: ndarray[tuple[int, ...], dtype[int64]]
plane_idx_at(x: int | float, y: int | float, *, um=False) int
plane_idx_at(x: ~numpy.ndarray[tuple[int, ...], ~numpy.dtype[<module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/neurocarto/envs/latest/lib/python3.10/site-packages/numpy/__init__.py'>]], y: ~numpy.ndarray[tuple[int, ...], ~numpy.dtype[<module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/neurocarto/envs/latest/lib/python3.10/site-packages/numpy/__init__.py'>]], *, um=False) ndarray[tuple[int, ...], dtype[int64]]
pull_back(o: tuple[int, int] | tuple[float, float] = None, *, um=False) tuple[int, int, int] | tuple[float, float, float]
pull_back(o: tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]]], *, um=False) tuple[ndarray[tuple[int, ...], dtype[int64]], ndarray[tuple[int, ...], dtype[int64]], ndarray[tuple[int, ...], dtype[int64]]]
pull_back(o: ndarray[tuple[int, ...], dtype[_ScalarType_co]], *, um=False) ndarray[tuple[int, ...], dtype[int64]]
Parameters:

o – tuple (x,y) or Array[int|float, [N,], (x, y)] position

Returns:

index (ap, dv, ml) or Array[int, N, (ap, dv, ml)]

offset_angle()
Return type:

tuple[float, float, float]

with_plane(plane)
Parameters:

plane (int)

Return type:

Self

with_anchor(x, y)
Parameters:
  • x (int)

  • y (int)

Return type:

Self

with_offset(dw, dh)
Parameters:
  • dw (int)

  • dh (int)

Return type:

Self

with_rotate(a)

plane index offset according to angle difference a.

Parameters:

a (tuple[float, float]) – (vertical, horizontal)-axis radian rotation.

Returns:

tuple of (dw, dh) or (rot, dw, dh)

Return type:

Self