Reshape Array
Utilities for reshaping arrays between original and transformed space.
AxesTransform
dataclass
Transformation between original and transformed space axes.
All transformation decisions are derived from the original axes string, shape.
Attributes:
| Name | Type | Description |
|---|---|---|
original_axes |
str
|
User defined attribute. Axes string of the input data (e.g. "YXC", "STCZYX"). |
original_shape |
tuple[int, ...]
|
User defined attribute. Shape corresponding to |
sample_dims |
list[str]
|
Computed property. Original dimensions merged into S. Spatial (Y, X and Z), as well as channels, are never considered sample dimensions. |
c_added |
bool
|
Computed property. Whether C is added as a singleton. |
has_z |
bool
|
Computed property. Whether original data contains a Z axis. |
dim_sizes |
dict[str, int]
|
Computed property. Map from axis name to original size. |
transformed_axes |
str
|
Computed property. Transformed axes string: "SC(Z)YX". |
transformed_shape |
tuple[int, ...]
|
Computed property. Expected shape after forward transformation. |
order_permutation |
list[int]
|
Computed property. Permutation to reorder original axes to STCZYX reference order in SC(Z)YX space. |
c_added
property
C is added as a singleton dimension.
Returns:
| Type | Description |
|---|---|
bool
|
True if C is not in original axes, False otherwise. |
dim_sizes
property
has_z
property
Original data contains a Z axis.
Returns:
| Type | Description |
|---|---|
bool
|
True if Z is in original axes, False otherwise. |
order_permutation
property
sample_dims
property
transformed_axes
property
Transformed axes string, SC(Z)YX or SCYX.
Returns:
| Type | Description |
|---|---|
str
|
Transformed axes string. Will be |
get_original_stitch_slices(original_axes, original_shape, sample_idx, stitch_coords, crop_size)
Get slices to stitch tile back into original array.
sample_idx andstitch_coords` are expressed with respect to the transformed space
(SCZYX or SCYX). The returned slices will index into the original array for
stitching the tile back in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original_axes
|
str
|
Original axes string of the full data. |
required |
original_shape
|
Sequence[int]
|
Original shape of the full data. |
required |
sample_idx
|
int
|
Index of the sample in transformed space (S axis) to stitch back. |
required |
stitch_coords
|
Sequence[int]
|
Starting coordinates of the tile in the original spatial axes (Y, X and Z if present). |
required |
crop_size
|
Sequence[int]
|
Size of the tile in the original spatial axes (Y, X and Z if present). |
required |
Returns:
| Type | Description |
|---|---|
tuple[slice | int, ...]
|
Slices to index into the original array for stitching the tile back in place. |
reshape_array(array, original_axes)
Reshape array from arbitrary axes order to SC(Z)YX.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ndarray
|
Input array. |
required |
original_axes
|
str
|
Original axes string describing current dimension order (e.g. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Array reshaped to |
restore_array(array, original_axes, original_shape)
Restore array from SC(Z)YX space back to original axes and shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ndarray
|
Array in |
required |
original_axes
|
str
|
Original axes string (e.g. |
required |
original_shape
|
Sequence[int]
|
Original shape of the data. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Array with original axes order and shape restored. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If input array is not 4D (SCYX) or 5D (SCZYX), or if restoring shape is not supported for the given original axes (e.g. T as Z with CZI format). |
restore_tile(tile, original_axes, original_shape)
Restore single tile from C(Z)YX space back to original axes and shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
ndarray
|
Tile in |
required |
original_axes
|
str
|
Original axes string of the full data. |
required |
original_shape
|
Sequence[int]
|
Original shape of the full data. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Tile with original spatial axes order restored. |