chuchichaestli.data.transforms
N-dimensional data transforms built on torchvision transforms v2.
Modules:
| Name | Description |
|---|---|
basis |
Separable projection onto truncated tensor-product bases. |
channel |
Channel dimension expansion/collapse transforms. |
complex |
Complex/real view transforms. |
compose |
Composition of v2 transforms with a single shared per-batch param draw. |
crop |
N-dimensional cropping transforms. |
geometric |
N-dimensional geometric augmentations (exact, interpolation-free). |
intensity |
Value transforms acting on pixel/voxel intensities (stretches and scalers). |
resize |
N-dimensional resize and pad transforms. |
wavelet |
Discrete wavelet transforms over the trailing spatial dimensions. |
Classes:
| Name | Description |
|---|---|
Affine |
Affine value transform $(x - b) / a$ (location-scale form). |
BasisProjection |
Project selected axes onto truncated bases, and reconstruct back. |
CenterCropND |
Deterministic centered crop over the trailing N spatial dims. |
ChannelCollapse |
Inverse of |
ChannelExpand |
Insert (and optionally replicate) a channel dimension. |
Clamp |
Clamp values to |
ComplexCollapse |
Inverse of |
ComplexExpand |
Expand a complex tensor into a real one with an axis of 2. |
HEPTransform |
High-energy-physics stretch for a more Gaussian-like value distribution. |
HounsfieldClamp |
Clamp Hounsfield units to a window (lossy, no inverse). |
HounsfieldScale |
Rescale raw CT stored values to Hounsfield units: |
InvBasisProjection |
Inverse of |
InvHEPTransform |
Inverse of |
InvHounsfieldScale |
Inverse of |
InvLogP1Transform |
Inverse of |
InvLogTransform |
Inverse of |
InvMinMaxScale |
Inverse of |
InvWaveletDecompose |
Inverse of |
InvWaveletPacket |
Inverse of |
LogP1Transform |
Log1p-style stretch $\hat{x} = \log(x + 1)$ (handles zeros). |
LogTransform |
Logarithmic stretch $\hat{x} = \log(x)$ (invertible by exponentiation). |
MinMaxScale |
Affine rescale from |
PadND |
Pad the trailing N spatial dims via |
RandomCropND |
Random crop over the trailing N spatial dims (leading dims pass through). |
RandomFlipND |
Randomly flip each eligible trailing spatial axis with probability |
RandomRot90ND |
Random k*90 degree rotation in a random trailing spatial axis-plane. |
ResizeND |
Resize the trailing N spatial dims via |
SequentialTransform |
Chain v2 transforms, sampling each child's params once per batch. |
WaveletDecompose |
Replace the trailing |
WaveletPacket |
|
ZScale |
Adaptive IRAF zscale normalization: clip to zscale limits, then rescale. |
ZScaleInterval |
Compute IRAF zscale display limits |
Affine
Affine(a: float = 1.0, b: float = 0.0)
Bases: Transform
Affine value transform $(x - b) / a$ (location-scale form).
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
The scale, i.e. the divisor (e.g. a data range). |
1.0
|
b
|
float
|
The loc, i.e. the offset subtracted (e.g. a data minimum). |
0.0
|
Methods:
| Name | Description |
|---|---|
get_inverse |
Return the inverse affine map. |
revert |
Invert the affine map. |
transform |
Apply the affine map. |
Source code in src/chuchichaestli/data/transforms/intensity.py
41 42 43 44 45 46 47 48 49 50 | |
get_inverse
get_inverse() -> Transform
Return the inverse affine map.
Source code in src/chuchichaestli/data/transforms/intensity.py
60 61 62 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Invert the affine map.
Source code in src/chuchichaestli/data/transforms/intensity.py
56 57 58 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Apply the affine map.
Source code in src/chuchichaestli/data/transforms/intensity.py
52 53 54 | |
BasisProjection
BasisProjection(
bases: dict[int, tuple[str, int] | int | torch.Tensor],
basis: str = "chebyshev",
weights: dict[int, torch.Tensor] | None = None,
rcond: float | None = None,
lengths: dict[int, int] | None = None,
cond_warn: float | None = 1000000.0,
)
Bases: Transform
Project selected axes onto truncated bases, and reconstruct back.
The forward pass replaces each selected axis of length N by M
coefficients of a truncated expansion, revert reconstructs the original
length. With a design matrix B_k per axis this is a decomposition
with fixed (non-learned) factor matrices:
C = X x_1 B_1^+ x_2 B_2^+ ... (project)
X = C x_1 B_1 x_2 B_2 ... (reconstruct)
Complex input is supported: the real design matrices are promoted to the input dtype, so real and imaginary parts project independently.
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bases
|
dict[int, tuple[str, int] | int | torch.Tensor]
|
Maps an axis of the input to its basis. Each value is either
an |
required |
basis
|
str
|
Default family for entries given as a bare order. One of
|
'chebyshev'
|
weights
|
dict[int, torch.Tensor] | None
|
Optional per-axis 1-D non-negative weights of length
|
None
|
rcond
|
float | None
|
Relative cutoff for small singular values in the
pseudoinverse, forwarded to |
None
|
lengths
|
dict[int, int] | None
|
Original length |
None
|
cond_warn
|
float | None
|
Warn when the fitted matrix's condition number exceeds
this. |
1000000.0
|
Methods:
| Name | Description |
|---|---|
design_matrix |
Return the |
revert |
Reconstruct from the coefficients (ignores |
transform |
Project onto the truncated bases (ignores |
Source code in src/chuchichaestli/data/transforms/basis.py
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 | |
design_matrix
design_matrix(axis: int, n: int) -> torch.Tensor
Return the (n, M) design matrix for axis, in float64.
Built-in families are built on the CPU; an explicit design matrix is returned on whichever device the caller supplied it on.
Source code in src/chuchichaestli/data/transforms/basis.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Reconstruct from the coefficients (ignores params).
Source code in src/chuchichaestli/data/transforms/basis.py
330 331 332 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Project onto the truncated bases (ignores params).
Source code in src/chuchichaestli/data/transforms/basis.py
326 327 328 | |
CenterCropND
CenterCropND(
size: int | Sequence[int], ndim: int | None = None
)
Bases: Transform
Deterministic centered crop over the trailing N spatial dims.
Symmetrically zero-pads any axis whose target size exceeds the input.
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int | Sequence[int]
|
Per-axis crop size (e.g. |
required |
ndim
|
int | None
|
Number of trailing spatial dims when |
None
|
Methods:
| Name | Description |
|---|---|
transform |
Crop (and pad if needed) the trailing spatial dims about the center. |
Source code in src/chuchichaestli/data/transforms/crop.py
75 76 77 78 79 80 81 82 83 84 85 | |
transform
transform(x: Any, params: dict[str, Any]) -> Any
Crop (and pad if needed) the trailing spatial dims about the center.
Source code in src/chuchichaestli/data/transforms/crop.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
ChannelCollapse
ChannelCollapse(
channel_first: bool = True, replicate: int = 0
)
Bases: ChannelExpand
Inverse of ChannelExpand.
Methods:
| Name | Description |
|---|---|
revert |
Expand the channel dimension. |
transform |
Collapse the channel dimension. |
Source code in src/chuchichaestli/data/transforms/channel.py
22 23 24 25 26 27 28 29 30 31 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Expand the channel dimension.
Source code in src/chuchichaestli/data/transforms/channel.py
63 64 65 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Collapse the channel dimension.
Source code in src/chuchichaestli/data/transforms/channel.py
59 60 61 | |
ChannelExpand
ChannelExpand(
channel_first: bool = True, replicate: int = 0
)
Bases: Transform
Insert (and optionally replicate) a channel dimension.
Maps (W, H)/(B, W, H) tensors to a channel-first (B, C, W, H) (or
channel-last) layout.
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel_first
|
bool
|
If |
True
|
replicate
|
int
|
If |
0
|
Methods:
| Name | Description |
|---|---|
revert |
Collapse the channel dimension. |
transform |
Expand the channel dimension. |
Source code in src/chuchichaestli/data/transforms/channel.py
22 23 24 25 26 27 28 29 30 31 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Collapse the channel dimension.
Source code in src/chuchichaestli/data/transforms/channel.py
44 45 46 47 48 49 50 51 52 53 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Expand the channel dimension.
Source code in src/chuchichaestli/data/transforms/channel.py
33 34 35 36 37 38 39 40 41 42 | |
Clamp
Clamp(min: float | None = None, max: float | None = None)
Bases: Transform
Clamp values to [min, max] (lossy, no inverse).
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min
|
float | None
|
Lower bound ( |
None
|
max
|
float | None
|
Upper bound ( |
None
|
Methods:
| Name | Description |
|---|---|
transform |
Clamp the input. |
Source code in src/chuchichaestli/data/transforms/intensity.py
269 270 271 272 273 274 275 276 277 278 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Clamp the input.
Source code in src/chuchichaestli/data/transforms/intensity.py
280 281 282 | |
ComplexCollapse
ComplexCollapse(dim: int = -1, strict: bool = True)
Bases: ComplexExpand
Inverse of ComplexExpand: collapse to complex, expand on revert.
Methods:
| Name | Description |
|---|---|
revert |
Expand complex to real. |
transform |
Collapse real to complex. |
Source code in src/chuchichaestli/data/transforms/complex.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Expand complex to real.
Source code in src/chuchichaestli/data/transforms/complex.py
105 106 107 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Collapse real to complex.
Source code in src/chuchichaestli/data/transforms/complex.py
101 102 103 | |
ComplexExpand
ComplexExpand(dim: int = -1, strict: bool = True)
Bases: Transform
Expand a complex tensor into a real one with an axis of 2.
The real/imaginary axis is appended by torch.view_as_real and then moved
to dim, so it is trailing only for the default dim=-1.
Use this if complex data should work with SharedArray.
Both directions are zero-copy views wherever the strides allow it; only
revert on a non-contiguous input falls back to a copy.
Note that the real dtype follows the complex one
complex128expands tofloat64complex64expands tofloat32complex32expands tofloat16(incompatible withSharedArray)
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim
|
int
|
Position of the real/imaginary axis in the expanded tensor.
The default |
-1
|
strict
|
bool
|
If |
True
|
Methods:
| Name | Description |
|---|---|
revert |
Collapse real back to complex (ignores |
transform |
Expand complex to real (ignores |
Source code in src/chuchichaestli/data/transforms/complex.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Collapse real back to complex (ignores params).
Source code in src/chuchichaestli/data/transforms/complex.py
93 94 95 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Expand complex to real (ignores params).
Source code in src/chuchichaestli/data/transforms/complex.py
89 90 91 | |
HEPTransform
HEPTransform(
gamma: float = 1.0, b: float = 0.0, C: float = 1.0
)
Bases: Transform
High-energy-physics stretch for a more Gaussian-like value distribution.
Computes $\hat{x} = ((x - b) / C)^{1/\gamma}$, where $C$ is roughly the data range and $b$ the bias (data minimum).
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gamma
|
float
|
Inverse-power exponent of the stretch. |
1.0
|
b
|
float
|
Bias, i.e. the global data minimum. |
0.0
|
C
|
float
|
A number around the global data range. |
1.0
|
Methods:
| Name | Description |
|---|---|
get_inverse |
Return the inverse transform. |
revert |
Invert the stretch. |
transform |
Apply the stretch. |
Source code in src/chuchichaestli/data/transforms/intensity.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
get_inverse
get_inverse() -> Transform
Return the inverse transform.
Source code in src/chuchichaestli/data/transforms/intensity.py
97 98 99 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Invert the stretch.
Source code in src/chuchichaestli/data/transforms/intensity.py
93 94 95 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Apply the stretch.
Source code in src/chuchichaestli/data/transforms/intensity.py
89 90 91 | |
HounsfieldClamp
HounsfieldClamp(center: float, width: float)
Bases: Clamp
Clamp Hounsfield units to a window (lossy, no inverse).
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
float
|
Window center (level) in HU, e.g. 40 for soft tissue. |
required |
width
|
float
|
Window width in HU, e.g. 400 for soft tissue. |
required |
Source code in src/chuchichaestli/data/transforms/intensity.py
334 335 336 337 338 339 340 341 342 343 | |
HounsfieldScale
HounsfieldScale(
slope: float = 1.0, intercept: float = -1024.0
)
Bases: Transform
Rescale raw CT stored values to Hounsfield units: slope * x + intercept.
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slope
|
float
|
DICOM |
1.0
|
intercept
|
float
|
DICOM |
-1024.0
|
Methods:
| Name | Description |
|---|---|
get_inverse |
Return the inverse transform. |
revert |
Map Hounsfield units back to stored values. |
transform |
Map stored values to Hounsfield units. |
Source code in src/chuchichaestli/data/transforms/intensity.py
290 291 292 293 294 295 296 297 298 299 300 | |
get_inverse
get_inverse() -> Transform
Return the inverse transform.
Source code in src/chuchichaestli/data/transforms/intensity.py
310 311 312 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Map Hounsfield units back to stored values.
Source code in src/chuchichaestli/data/transforms/intensity.py
306 307 308 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Map stored values to Hounsfield units.
Source code in src/chuchichaestli/data/transforms/intensity.py
302 303 304 | |
InvBasisProjection
InvBasisProjection(
bases: dict[int, tuple[str, int] | int | torch.Tensor],
basis: str = "chebyshev",
weights: dict[int, torch.Tensor] | None = None,
rcond: float | None = None,
lengths: dict[int, int] | None = None,
cond_warn: float | None = 1000000.0,
)
Bases: BasisProjection
Inverse of BasisProjection: reconstruct forward, project on revert.
The original axis lengths cannot be inferred from coefficients alone, so
every axis needs one of: an entry in lengths, an explicit design matrix
(whose row count supplies it), or a prior projection through this instance.
Methods:
| Name | Description |
|---|---|
revert |
Project onto the truncated bases. |
transform |
Reconstruct from the coefficients. |
Source code in src/chuchichaestli/data/transforms/basis.py
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 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Project onto the truncated bases.
Source code in src/chuchichaestli/data/transforms/basis.py
347 348 349 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Reconstruct from the coefficients.
Source code in src/chuchichaestli/data/transforms/basis.py
343 344 345 | |
InvHEPTransform
InvHEPTransform(
gamma: float = 1.0, b: float = 0.0, C: float = 1.0
)
Bases: HEPTransform
Inverse of HEPTransform.
Methods:
| Name | Description |
|---|---|
get_inverse |
Return the inverse transform. |
revert |
Apply the forward stretch. |
transform |
Apply the inverse stretch. |
Source code in src/chuchichaestli/data/transforms/intensity.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
get_inverse
get_inverse() -> Transform
Return the inverse transform.
Source code in src/chuchichaestli/data/transforms/intensity.py
113 114 115 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Apply the forward stretch.
Source code in src/chuchichaestli/data/transforms/intensity.py
109 110 111 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Apply the inverse stretch.
Source code in src/chuchichaestli/data/transforms/intensity.py
105 106 107 | |
InvHounsfieldScale
InvHounsfieldScale(
slope: float = 1.0, intercept: float = -1024.0
)
Bases: HounsfieldScale
Inverse of HounsfieldScale (Hounsfield units -> stored values).
Methods:
| Name | Description |
|---|---|
get_inverse |
Return the inverse transform. |
revert |
Map stored values to Hounsfield units. |
transform |
Map Hounsfield units to stored values. |
Source code in src/chuchichaestli/data/transforms/intensity.py
290 291 292 293 294 295 296 297 298 299 300 | |
get_inverse
get_inverse() -> Transform
Return the inverse transform.
Source code in src/chuchichaestli/data/transforms/intensity.py
326 327 328 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Map stored values to Hounsfield units.
Source code in src/chuchichaestli/data/transforms/intensity.py
322 323 324 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Map Hounsfield units to stored values.
Source code in src/chuchichaestli/data/transforms/intensity.py
318 319 320 | |
InvLogP1Transform
InvLogP1Transform(log_fn: Callable = torch.log)
Bases: LogP1Transform
Inverse of LogP1Transform.
Methods:
| Name | Description |
|---|---|
get_inverse |
Return the inverse transform. |
revert |
Apply the forward log1p stretch. |
transform |
Apply the inverse log1p stretch. |
Source code in src/chuchichaestli/data/transforms/intensity.py
127 128 129 130 131 132 133 134 135 136 137 | |
get_inverse
get_inverse() -> Transform
Return the inverse transform.
Source code in src/chuchichaestli/data/transforms/intensity.py
195 196 197 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Apply the forward log1p stretch.
Source code in src/chuchichaestli/data/transforms/intensity.py
191 192 193 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Apply the inverse log1p stretch.
Source code in src/chuchichaestli/data/transforms/intensity.py
187 188 189 | |
InvLogTransform
InvLogTransform(log_fn: Callable = torch.log)
Bases: LogTransform
Inverse of LogTransform.
Methods:
| Name | Description |
|---|---|
get_inverse |
Return the inverse transform. |
revert |
Apply the log. |
transform |
Apply the exponentiation. |
Source code in src/chuchichaestli/data/transforms/intensity.py
127 128 129 130 131 132 133 134 135 136 137 | |
get_inverse
get_inverse() -> Transform
Return the inverse transform.
Source code in src/chuchichaestli/data/transforms/intensity.py
163 164 165 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Apply the log.
Source code in src/chuchichaestli/data/transforms/intensity.py
159 160 161 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Apply the exponentiation.
Source code in src/chuchichaestli/data/transforms/intensity.py
155 156 157 | |
InvMinMaxScale
InvMinMaxScale(
vmin: float | None = None,
vmax: float | None = None,
feature_range: tuple[float, float] = (0.0, 1.0),
)
Bases: MinMaxScale
Inverse of MinMaxScale (requires fixed vmin/vmax).
Methods:
| Name | Description |
|---|---|
get_inverse |
Return the inverse transform. |
revert |
Apply the forward rescale. |
transform |
Apply the inverse rescale. |
Source code in src/chuchichaestli/data/transforms/intensity.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
get_inverse
get_inverse() -> Transform
Return the inverse transform.
Source code in src/chuchichaestli/data/transforms/intensity.py
257 258 259 260 261 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Apply the forward rescale.
Source code in src/chuchichaestli/data/transforms/intensity.py
253 254 255 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Apply the inverse rescale.
Source code in src/chuchichaestli/data/transforms/intensity.py
249 250 251 | |
InvWaveletDecompose
InvWaveletDecompose(
wavelet: str | Wavelet = "haar",
ndim: int = 2,
mode: ExtensionModeTypes = "zero",
stack_dim: int | None = None,
sizes: Sequence[int] | None = None,
)
Bases: WaveletDecompose
Inverse of WaveletDecompose: reconstruct forward, decompose on revert.
Methods:
| Name | Description |
|---|---|
get_inverse |
Return the transform that decomposes what this one reconstructs. |
make_params |
Report the recorded spatial shape; the forward pass reads, not writes. |
revert |
Decompose the trailing spatial axes. |
transform |
Reconstruct the trailing spatial axes. |
Source code in src/chuchichaestli/data/transforms/wavelet.py
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 | |
get_inverse
get_inverse() -> WaveletDecompose
Return the transform that decomposes what this one reconstructs.
Source code in src/chuchichaestli/data/transforms/wavelet.py
234 235 236 237 238 | |
make_params
make_params(flat_inputs: list[Any]) -> dict[str, Any]
Report the recorded spatial shape; the forward pass reads, not writes.
Source code in src/chuchichaestli/data/transforms/wavelet.py
230 231 232 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Decompose the trailing spatial axes.
Source code in src/chuchichaestli/data/transforms/wavelet.py
225 226 227 228 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Reconstruct the trailing spatial axes.
Source code in src/chuchichaestli/data/transforms/wavelet.py
221 222 223 | |
InvWaveletPacket
InvWaveletPacket(
wavelet: str | Wavelet = "haar",
ndim: int = 2,
mode: ExtensionModeTypes = "zero",
levels: int = 2,
stack_dim: int | None = None,
sizes: Sequence[int] | None = None,
)
Bases: WaveletPacket, InvWaveletDecompose
Inverse of WaveletPacket: reconstruct forward, decompose on revert.
Takes the level count from WaveletPacket and the swapped direction from
InvWaveletDecompose, in that order.
Methods:
| Name | Description |
|---|---|
get_inverse |
Return the transform that decomposes what this one reconstructs. |
Source code in src/chuchichaestli/data/transforms/wavelet.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
get_inverse
get_inverse() -> WaveletPacket
Return the transform that decomposes what this one reconstructs.
Source code in src/chuchichaestli/data/transforms/wavelet.py
294 295 296 297 298 299 300 301 302 303 | |
LogP1Transform
LogP1Transform(log_fn: Callable = torch.log)
Bases: LogTransform
Log1p-style stretch $\hat{x} = \log(x + 1)$ (handles zeros).
Methods:
| Name | Description |
|---|---|
get_inverse |
Return the inverse transform. |
revert |
Invert the log1p stretch. |
transform |
Apply the log1p stretch. |
Source code in src/chuchichaestli/data/transforms/intensity.py
127 128 129 130 131 132 133 134 135 136 137 | |
get_inverse
get_inverse() -> Transform
Return the inverse transform.
Source code in src/chuchichaestli/data/transforms/intensity.py
179 180 181 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Invert the log1p stretch.
Source code in src/chuchichaestli/data/transforms/intensity.py
175 176 177 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Apply the log1p stretch.
Source code in src/chuchichaestli/data/transforms/intensity.py
171 172 173 | |
LogTransform
LogTransform(log_fn: Callable = torch.log)
Bases: Transform
Logarithmic stretch $\hat{x} = \log(x)$ (invertible by exponentiation).
Pure nonlinearity; compose with Affine (e.g. via SequentialTransform) to
normalize the log-space range.
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_fn
|
Callable
|
Logarithm function fixing the base (default: natural log). |
torch.log
|
Methods:
| Name | Description |
|---|---|
get_inverse |
Return the inverse transform. |
revert |
Invert the log by exponentiation. |
transform |
Apply the log. |
Source code in src/chuchichaestli/data/transforms/intensity.py
127 128 129 130 131 132 133 134 135 136 137 | |
get_inverse
get_inverse() -> Transform
Return the inverse transform.
Source code in src/chuchichaestli/data/transforms/intensity.py
147 148 149 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Invert the log by exponentiation.
Source code in src/chuchichaestli/data/transforms/intensity.py
143 144 145 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Apply the log.
Source code in src/chuchichaestli/data/transforms/intensity.py
139 140 141 | |
MinMaxScale
MinMaxScale(
vmin: float | None = None,
vmax: float | None = None,
feature_range: tuple[float, float] = (0.0, 1.0),
)
Bases: Transform
Affine rescale from [vmin, vmax] into feature_range.
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vmin
|
float | None
|
Input minimum; |
None
|
vmax
|
float | None
|
Input maximum; |
None
|
feature_range
|
tuple[float, float]
|
Target |
(0.0, 1.0)
|
Methods:
| Name | Description |
|---|---|
get_inverse |
Return the inverse rescale (requires fixed |
revert |
Invert the rescale (requires fixed |
transform |
Rescale the input into |
Source code in src/chuchichaestli/data/transforms/intensity.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
get_inverse
get_inverse() -> Transform
Return the inverse rescale (requires fixed vmin/vmax).
Source code in src/chuchichaestli/data/transforms/intensity.py
237 238 239 240 241 242 243 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Invert the rescale (requires fixed vmin/vmax).
Source code in src/chuchichaestli/data/transforms/intensity.py
230 231 232 233 234 235 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Rescale the input into feature_range.
Source code in src/chuchichaestli/data/transforms/intensity.py
223 224 225 226 227 228 | |
PadND
PadND(
padding: Sequence[Sequence[int]],
mode: str = "constant",
value: float = 0.0,
)
Bases: Transform
Pad the trailing N spatial dims via torch.nn.functional.pad.
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
padding
|
Sequence[Sequence[int]]
|
One |
required |
mode
|
str
|
Padding mode ( |
'constant'
|
value
|
float
|
Fill value for |
0.0
|
Methods:
| Name | Description |
|---|---|
transform |
Apply the padding to the trailing spatial dims. |
Source code in src/chuchichaestli/data/transforms/resize.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
transform
transform(inpt: Any, params: dict[str, Any]) -> Any
Apply the padding to the trailing spatial dims.
Source code in src/chuchichaestli/data/transforms/resize.py
90 91 92 93 94 95 | |
RandomCropND
RandomCropND(
size: int | Sequence[int], ndim: int | None = None
)
Bases: Transform
Random crop over the trailing N spatial dims (leading dims pass through).
Randomness lives in make_params, so a SequenceCollate draws one crop box
per batch and applies it identically to every paired field/step.
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int | Sequence[int]
|
Per-axis crop size (e.g. |
required |
ndim
|
int | None
|
Number of trailing spatial dims when |
None
|
Methods:
| Name | Description |
|---|---|
make_params |
Sample one in-bounds crop origin from the first tensor's shape. |
transform |
Slice the shared crop box on the trailing spatial dims. |
Source code in src/chuchichaestli/data/transforms/crop.py
38 39 40 41 42 43 44 45 46 47 | |
make_params
make_params(flat_inputs: list[Any]) -> dict[str, Any]
Sample one in-bounds crop origin from the first tensor's shape.
Source code in src/chuchichaestli/data/transforms/crop.py
49 50 51 52 53 54 55 56 57 | |
transform
transform(x: Any, params: dict[str, Any]) -> Any
Slice the shared crop box on the trailing spatial dims.
Source code in src/chuchichaestli/data/transforms/crop.py
59 60 61 62 63 64 | |
RandomFlipND
RandomFlipND(
ndim: int,
p: float = 0.5,
axes: Sequence[int] | None = None,
)
Bases: Transform
Randomly flip each eligible trailing spatial axis with probability p.
The per-axis draws happen in make_params, so a SequenceCollate flips
every paired field/step identically.
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ndim
|
int
|
Number of trailing spatial dims. |
required |
p
|
float
|
Per-axis flip probability. |
0.5
|
axes
|
Sequence[int] | None
|
Spatial axes eligible for flipping (default: all |
None
|
Methods:
| Name | Description |
|---|---|
make_params |
Sample which axes to flip. |
transform |
Flip the chosen axes (identity when none were sampled). |
Source code in src/chuchichaestli/data/transforms/geometric.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
make_params
make_params(flat_inputs: list[Any]) -> dict[str, Any]
Sample which axes to flip.
Source code in src/chuchichaestli/data/transforms/geometric.py
50 51 52 53 | |
transform
transform(x: Any, params: dict[str, Any]) -> Any
Flip the chosen axes (identity when none were sampled).
Source code in src/chuchichaestli/data/transforms/geometric.py
55 56 57 | |
RandomRot90ND
RandomRot90ND(ndim: int, axes: Sequence[int] | None = None)
Bases: Transform
Random k*90 degree rotation in a random trailing spatial axis-plane.
Exact (no interpolation). k and the plane are drawn in make_params, so a
SequenceCollate rotates every paired field/step identically.
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ndim
|
int
|
Number of trailing spatial dims (must be >= 2). |
required |
axes
|
Sequence[int] | None
|
Spatial axes eligible to form rotation planes (default: all). |
None
|
Methods:
| Name | Description |
|---|---|
make_params |
Sample the rotation count |
transform |
Rotate by |
Source code in src/chuchichaestli/data/transforms/geometric.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
make_params
make_params(flat_inputs: list[Any]) -> dict[str, Any]
Sample the rotation count k and the axis-plane.
Source code in src/chuchichaestli/data/transforms/geometric.py
87 88 89 90 91 | |
transform
transform(x: Any, params: dict[str, Any]) -> Any
Rotate by k*90 degrees in the chosen plane (identity when k%4==0).
Source code in src/chuchichaestli/data/transforms/geometric.py
93 94 95 96 97 | |
ResizeND
ResizeND(
size: int | Sequence[int],
ndim: int | None = None,
mode: str = "nearest",
)
Bases: Transform
Resize the trailing N spatial dims via torch.nn.functional.interpolate.
Bare (*spatial) and (C, *spatial) leaves are supported by temporarily
unsqueezing to the (N, C, *spatial) layout interpolate expects.
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int | Sequence[int]
|
Target per-axis size (e.g. |
required |
ndim
|
int | None
|
Number of trailing spatial dims when |
None
|
mode
|
str
|
Interpolation mode passed to |
'nearest'
|
Methods:
| Name | Description |
|---|---|
transform |
Interpolate to |
Source code in src/chuchichaestli/data/transforms/resize.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
transform
transform(inpt: Any, params: dict[str, Any]) -> Any
Interpolate to size, restoring the input's rank afterwards.
Source code in src/chuchichaestli/data/transforms/resize.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
SequentialTransform
SequentialTransform(
*transforms: Transform | Sequence[Transform],
)
Bases: Transform
Chain v2 transforms, sampling each child's params once per batch.
Unlike torchvision's Compose (which re-samples per call and exposes no
make_params/transform), this drives the child make_params/transform
hooks directly, so it plugs into SequenceCollate and applies the same
draw to every paired field/step. It is invertible when all children are.
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transforms
|
Transform | Sequence[Transform]
|
The child transforms to apply in order, given either as positional arguments or a single sequence. |
()
|
Methods:
| Name | Description |
|---|---|
get_inverse |
Return the reversed chain of child inverses. |
make_params |
Sample each child's params once, threading the running leaves through. |
revert |
Invert every child in reverse order (all children must be invertible). |
transform |
Apply every child in order with its shared params. |
Source code in src/chuchichaestli/data/transforms/compose.py
24 25 26 27 28 29 30 31 32 33 34 | |
get_inverse
get_inverse() -> SequentialTransform
Return the reversed chain of child inverses.
Source code in src/chuchichaestli/data/transforms/compose.py
61 62 63 | |
make_params
make_params(flat_inputs: list[Any]) -> dict[str, Any]
Sample each child's params once, threading the running leaves through.
Later children see the (intermediate) shape produced by earlier ones, so e.g. a crop before a flip is accounted for.
Source code in src/chuchichaestli/data/transforms/compose.py
36 37 38 39 40 41 42 43 44 45 46 47 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Invert every child in reverse order (all children must be invertible).
Source code in src/chuchichaestli/data/transforms/compose.py
55 56 57 58 59 | |
transform
transform(inpt: Any, params: dict[str, Any]) -> Any
Apply every child in order with its shared params.
Source code in src/chuchichaestli/data/transforms/compose.py
49 50 51 52 53 | |
WaveletDecompose
WaveletDecompose(
wavelet: str | Wavelet = "haar",
ndim: int = 2,
mode: ExtensionModeTypes = "zero",
stack_dim: int | None = None,
sizes: Sequence[int] | None = None,
)
Bases: Transform
Replace the trailing ndim axes by the subbands of a wavelet transform.
The subbands are stacked on one new axis, so the result stays a single
tensor and collates like any other field. Leading axes pass through. Only
one level is taken: recursing on the coarsest subband alone would leave the
levels at different resolutions, which no single tensor can hold. See
WaveletPacket for the deeper decomposition that does keep one resolution.
Reverting needs the spatial shape the coefficients came from, which the
transform records as it runs; pass sizes to fix it up front instead.
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wavelet
|
str | Wavelet
|
Wavelet to decompose with, by name or as a |
'haar'
|
ndim
|
int
|
Number of trailing spatial dims to transform. |
2
|
mode
|
ExtensionModeTypes
|
Signal extension mode; |
'zero'
|
stack_dim
|
int | None
|
Position of the subband axis in the result; immediately before the spatial axes if omitted. |
None
|
sizes
|
Sequence[int] | None
|
Spatial shape the coefficients revert to, if it is known. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Methods:
| Name | Description |
|---|---|
get_inverse |
Return the transform that reconstructs what this one decomposes. |
make_params |
Record the spatial shape of the first tensor, shared by every leaf. |
revert |
Reconstruct the trailing spatial axes. |
transform |
Decompose the trailing spatial axes. |
Attributes:
| Name | Type | Description |
|---|---|---|
axes |
tuple[int, ...]
|
Axes the transform runs over, as trailing indices. |
subbands |
int
|
Number of subbands the transform produces. |
Source code in src/chuchichaestli/data/transforms/wavelet.py
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 | |
axes
property
axes: tuple[int, ...]
Axes the transform runs over, as trailing indices.
subbands
property
subbands: int
Number of subbands the transform produces.
get_inverse
get_inverse() -> InvWaveletDecompose
Return the transform that reconstructs what this one decomposes.
Source code in src/chuchichaestli/data/transforms/wavelet.py
211 212 213 214 215 | |
make_params
make_params(flat_inputs: list[Any]) -> dict[str, Any]
Record the spatial shape of the first tensor, shared by every leaf.
Source code in src/chuchichaestli/data/transforms/wavelet.py
195 196 197 198 199 200 | |
revert
revert(x: Any, params: dict[str, Any] | None = None) -> Any
Reconstruct the trailing spatial axes.
Source code in src/chuchichaestli/data/transforms/wavelet.py
207 208 209 | |
transform
transform(
x: Any, params: dict[str, Any] | None = None
) -> Any
Decompose the trailing spatial axes.
Source code in src/chuchichaestli/data/transforms/wavelet.py
202 203 204 205 | |
WaveletPacket
WaveletPacket(
wavelet: str | Wavelet = "haar",
ndim: int = 2,
mode: ExtensionModeTypes = "zero",
levels: int = 2,
stack_dim: int | None = None,
sizes: Sequence[int] | None = None,
)
Bases: WaveletDecompose
WaveletDecompose that keeps splitting every subband, not only the coarsest.
A packet decomposition of l levels leaves 2 ** (ndim * l) subbands, all
at the same resolution, which is what makes the result a single tensor.
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wavelet
|
str | Wavelet
|
Wavelet to decompose with, by name or as a |
'haar'
|
ndim
|
int
|
Number of trailing spatial dims to transform. |
2
|
mode
|
ExtensionModeTypes
|
Signal extension mode. |
'zero'
|
levels
|
int
|
Number of levels to decompose. |
2
|
stack_dim
|
int | None
|
Position of the subband axis in the result. |
None
|
sizes
|
Sequence[int] | None
|
Spatial shape the coefficients revert to, if it is known. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Methods:
| Name | Description |
|---|---|
get_inverse |
Return the transform that reconstructs what this one decomposes. |
Source code in src/chuchichaestli/data/transforms/wavelet.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
get_inverse
get_inverse() -> InvWaveletPacket
Return the transform that reconstructs what this one decomposes.
Source code in src/chuchichaestli/data/transforms/wavelet.py
275 276 277 278 279 280 281 282 283 284 | |
ZScale
ZScale(
interval: ZScaleInterval | None = None,
feature_range: tuple[float, float] = (0.0, 1.0),
)
Bases: Transform
Adaptive IRAF zscale normalization: clip to zscale limits, then rescale.
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interval
|
ZScaleInterval | None
|
The |
None
|
feature_range
|
tuple[float, float]
|
Target |
(0.0, 1.0)
|
Methods:
| Name | Description |
|---|---|
make_params |
Compute the shared |
transform |
Clip to |
Source code in src/chuchichaestli/data/transforms/intensity.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 | |
make_params
make_params(flat_inputs: list[Any]) -> dict[str, Any]
Compute the shared (z1, z2) limits from the first tensor.
Source code in src/chuchichaestli/data/transforms/intensity.py
460 461 462 463 464 | |
transform
transform(x: Any, params: dict[str, Any]) -> Any
Clip to [z1, z2] and rescale into feature_range.
Source code in src/chuchichaestli/data/transforms/intensity.py
466 467 468 469 470 | |
ZScaleInterval
ZScaleInterval(
nsamples: int = 1000,
contrast: float = 0.25,
max_reject: float = 0.5,
min_npixels: int = 5,
krej: float = 2.5,
max_iterations: int = 5,
)
Compute IRAF zscale display limits (z1, z2) from a tensor.
Samples the data, fits a line to the sorted samples with iterative k-sigma
rejection, and derives cut limits about the median (see IRAF/astropy
ZScaleInterval).
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nsamples
|
int
|
Number of pixels to sample from the input. |
1000
|
contrast
|
float
|
Scales the fitted slope; smaller means higher contrast. |
0.25
|
max_reject
|
float
|
Minimum fraction of samples that must survive rejection for the fit to be used (IRAF convention; despite the name). |
0.5
|
min_npixels
|
int
|
Minimum number of surviving samples for a valid fit. |
5
|
krej
|
float
|
k-sigma rejection threshold on the fit residuals. |
2.5
|
max_iterations
|
int
|
Maximum number of rejection iterations. |
5
|
Methods:
| Name | Description |
|---|---|
get_limits |
Return the |
Source code in src/chuchichaestli/data/transforms/intensity.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | |
get_limits
get_limits(
x: torch.Tensor,
) -> tuple[torch.Tensor, torch.Tensor]
Return the (z1, z2) cut limits for x.
Source code in src/chuchichaestli/data/transforms/intensity.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | |