reshape_arrays
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. |
Source code in src/careamics/lightning/dataset_ng/prediction/reshape_arrays.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
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 #
Map from axis name to original size.
Returns:
| Type | Description |
|---|---|
dict[str, int] | Dictionary mapping axis name to its size in the original shape. |
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 #
Permutation to reorder original axes to STCZYX reference order.
Returns:
| Type | Description |
|---|---|
list[int] | List of indices representing the permutation to reorder original axes to STCZYX reference order. Only includes axes present in the original axes. |
sample_dims property #
Original dimensions merged into S.
Spatial (Y, X and Z), as well as channels, are never considered sample dimensions.
Returns:
| Type | Description |
|---|---|
list[str] | List of original axes that are considered sample dimensions and merged into S. Will be in the order they appear in the reference STCZYX. |
transformed_axes property #
Transformed axes string, SC(Z)YX or SCYX.
Returns:
| Type | Description |
|---|---|
str | Transformed axes string. Will be |
transformed_shape property #
Expected shape in transformed space.
Returns:
| Type | Description |
|---|---|
tuple[int, ...] | Expected shape after forward transformation, in the order of |
__post_init__() #
Validate original axes and shape.
Source code in src/careamics/lightning/dataset_ng/prediction/reshape_arrays.py
get_original_stitch_slices(array_shape, 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 transofrmed 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 |
|---|---|---|---|
array_shape | Sequence[int] | Shape of the array in transformed space (e.g. SCZYX). | required |
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. |
Source code in src/careamics/lightning/dataset_ng/prediction/reshape_arrays.py
reshape_array(array, original_axes, original_shape) #
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 |
original_shape | Sequence[int] | Original shape of the array. | required |
Returns:
| Type | Description |
|---|---|
ndarray | Array reshaped to |
Source code in src/careamics/lightning/dataset_ng/prediction/reshape_arrays.py
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). |
Source code in src/careamics/lightning/dataset_ng/prediction/reshape_arrays.py
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. |