geoops.augment — RS-safe augmentations¶
Curated augmentation operators for training on remote-sensing GeoArray
patches. Spatial operators preserve CRS and either preserve the existing
transform or update it consistently; radiometric operators treat bands as
physical measurements instead of generic RGB channels.
Quick pipeline¶
import geoops as gz
augment = gz.augment.Compose(
augmentations=[
gz.augment.RandomFlip(p_horizontal=0.5, p_vertical=0.5),
gz.augment.RandomRotate90(p=0.75),
gz.augment.BrightnessJitter(factor=(0.95, 1.05), per_band=True),
gz.augment.GaussianNoise(sigma=0.01),
]
)
augmented_patch = augment(training_patch, seed=0)
Before / after samples¶
| Family | Before | After |
|---|---|---|
| Geometry | patch |
RandomFlip(p_horizontal=1)(patch) mirrors pixels and updates the affine transform. |
| Geometry | patch |
RandomRotate90(p=1)(patch, seed=0) uses one of np.rot90(..., k=1..3) and updates transform orientation. |
| Geometry | patch |
RandomCrop(size=(256, 256))(patch, seed=0) returns a smaller georeferenced chip. |
| Geometry | patch |
RandomShift(max_shift=(8, 8))(patch, seed=0) reads a shifted fixed-size window with padding at edges. |
| Radiometric | patch |
BrightnessJitter(per_band=True)(patch, seed=0) samples one gain per band. |
| Radiometric | patch |
ContrastJitter(per_band=False)(patch, seed=0) applies one contrast factor to every band. |
| Noise | patch |
GaussianNoise(sigma=0.01)(patch, seed=0) adds reproducible additive sensor noise. |
| Noise | patch |
SpeckleNoise(sigma=0.05)(patch, seed=0) applies multiplicative SAR-style noise. |
| Band-level | patch |
BandDropout(p=0.1, fill_value=0)(patch, seed=0) independently masks bands. |
| Band-level | patch |
BandJitter(groups={"swir": ["B11", "B12"]})(patch, seed=0) only permutes configured band groups. |
| RS-specific | patch |
SunAngleJitter(delta_sza_deg=(-3, 3))(patch, seed=0) rescales reflectance for a simulated SZA shift. |
| RS-specific | patch |
AtmosphericHaze(intensity=(0, 0.05))(patch, seed=0) adds stronger haze to shorter wavelengths. |
| RS-specific | patch |
SimulatedClouds(coverage=(0, 0.2))(patch, seed=0) blends in a smooth synthetic cloud field. |
| Mixing | patch, *pool |
CutMix(p=0.5)(patch, other_patch, seed=0) pastes a rectangle from a donor drawn from the positional pool, every donor on the same pixel grid (shape, CRS and transform). |
Seeding contract¶
Every random operator accepts a constructor seed and a per-call seed
override. The constructor seed starts a stream held on the instance: each
call draws the next augmentation, so a seeded operator varies from sample
to sample while two operators built with the same seed replay the same
sequence. A per-call seed is a deterministic one-off draw that leaves the
stream untouched:
import geoops as gz
op = gz.augment.GaussianNoise(sigma=0.01, seed=1)
a, b = op(patch), op(patch) # different noise, reproducible sequence
same_a = op(patch, seed=42)
same_b = op(patch, seed=42) # identical to same_a
get_config only records the constructor seed, so a reloaded operator
restarts its stream. A seeded Compose owns its children's draws (it
forwards a derived per-call seed to each child whose _apply accepts a
seed); an unseeded one lets each child use its own stream.
Compose is a probability-gated pipekit_ops.Sequential. It lives only at
gz.augment.Compose (not gz.Compose, which would read as pipekit's
right-to-left compose). compose | op keeps the gate, but pipekit
flattens a Sequential on the right of |, so write
gz.Sequential([op, compose]) rather than op | compose.
Use the same seed for multiple geometric pipelines when different modalities must receive identical spatial transforms (call them in lockstep).
Composer¶
geoops.augment._src.operators.Compose
¶
Bases: Sequential
Apply augmentations sequentially behind a pipeline probability gate.
A :class:pipekit_ops.Sequential whose whole chain runs with probability
p and whose children can be seeded from one top-level seed.
Seeding follows the module contract. When Compose is seeded — by
a per-call seed (one-off) or a constructor seed (its own
stream, advancing each call) — it owns the randomness of the whole
chain: it draws one child seed per augmentation and forwards it as
that child's per-call seed, so the same top-level seed always
reproduces the same chain of inner draws and the children's own
streams are left untouched. An unseeded Compose forwards nothing,
so each child draws from its own stream (honouring any child
seed). A child receives a seed only when its _apply
accepts one (the per-call seed goes to _apply, not
__init__), so deterministic operators and samplers whose seed is
constructor-only are called plainly.
get_config emits the children's nested configs (via
:class:~pipekit_ops.Sequential) under augmentations. Compose is
a container, so it is not forbid_in_yaml itself; a flagged child
is found structurally by pipekit's walker.
Composition: compose | op keeps the gate (Sequential([compose,
op])), but pipekit flattens a Sequential on the right of |,
so op | compose would splice the children in without the gate —
write Sequential([op, compose]) instead. Slicing (compose[1:])
likewise returns an ungated Sequential of the children.
The carrier is whatever the children accept: a plain np.ndarray
input passes through unchanged when the probability check skips the
pipeline, and is otherwise handed to the children as-is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
augmentations
|
list[Operator]
|
Operators applied in order. |
required |
p
|
float
|
Probability of applying the whole pipeline. Default |
1.0
|
seed
|
int | None
|
Seed of the pipeline's own stream (see above); |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If a child is not an |
Examples:
>>> import geoops as gz
>>> pipe = gz.augment.Compose(
... augmentations=[
... gz.augment.RandomFlip(),
... gz.augment.GaussianNoise(sigma=0.01),
... ],
... p=1.0,
... seed=0,
... )
>>> out = pipe(patch)
Source code in packages/geotoolz-ops/src/geoops/augment/_src/operators.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | |
augmentations: list[Operator]
property
¶
The child operators, in application order.
__or__(other: Operator) -> Sequential
¶
compose | op -> Sequential([compose, op]) (the gate is kept).
Source code in packages/geotoolz-ops/src/geoops/augment/_src/operators.py
Geometry¶
geoops.augment._src.operators.RandomFlip
¶
Bases: Operator
Randomly flip a GeoArray horizontally and/or vertically.
Preserves the CRS and updates the affine transform so the output
pixel grid still maps to the same physical extent (identical
bounds/footprint; the mirrored axis is anchored at the far pixel
edge). Each axis flips independently with probability
p_horizontal / p_vertical.
The pixel math is metadata-free, so a plain np.ndarray input is
also accepted and returns the flipped plain array (no transform
bookkeeping).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_horizontal
|
float
|
Probability of flipping the last (x) axis. |
0.5
|
p_vertical
|
float
|
Probability of flipping the second-to-last (y) axis. |
0.5
|
seed
|
int | None
|
Seed of the operator's own draw stream, which advances on
every call; a per-call |
None
|
Examples:
>>> import geoops as gz
>>> op = gz.augment.RandomFlip(p_horizontal=1.0, p_vertical=0.0, seed=0)
>>> out = op(patch)
Source code in packages/geotoolz-ops/src/geoops/augment/_src/operators.py
geoops.augment._src.operators.RandomRotate90
¶
Bases: Operator
Randomly rotate by 90, 180, or 270 degrees.
Uses np.rot90 over the trailing two axes and composes the input
transform with the matching rigid rotation so every output pixel
still maps to its world location and the footprint is unchanged.
The pixel math is metadata-free, so a plain np.ndarray input is
also accepted and returns the rotated plain array (no transform
bookkeeping).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
Probability of rotating; when triggered, k is drawn uniformly from {1, 2, 3} quarter-turns. |
0.75
|
seed
|
int | None
|
Seed of the operator's own draw stream, which advances on
every call; a per-call |
None
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/augment/_src/operators.py
geoops.augment._src.operators.RandomCrop
¶
Bases: Operator
Randomly crop a spatial window and update the transform.
Slices the GeoArray (gt[..., rows, cols]), so the output
transform's translation reflects the crop origin (affine_of(gt) *
(left, top) is the new upper-left world coordinate). CRS, dtype and
band metadata are preserved.
The crop itself is pixel-space math, so a plain np.ndarray input
is also accepted and returns the cropped plain array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
tuple[int, int]
|
|
required |
seed
|
int | None
|
Seed of the operator's own draw stream, which advances on
every call; a per-call |
None
|
Examples:
Source code in packages/geotoolz-ops/src/geoops/augment/_src/operators.py
geoops.augment._src.operators.RandomShift
¶
Bases: Operator
Randomly shift a fixed-size spatial window in pixel units.
Reads a boundless window (gt.read_window(..., boundless=True)), so
pixels shifted in from outside the original extent are padded with the
carrier's fill_value and the transform tracks the new window
origin. Geo-dependent: requires a georeferenced GeoArray input; a
plain array raises TypeError, and a carrier without a
fill_value raises ValueError when padding is needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_shift
|
tuple[int, int]
|
|
required |
seed
|
int | None
|
Seed of the operator's own draw stream, which advances on
every call; a per-call |
None
|
Source code in packages/geotoolz-ops/src/geoops/augment/_src/operators.py
Radiometric¶
geoops.augment._src.operators.BrightnessJitter
¶
Bases: Operator
Scale reflectance values by a sampled scalar or per-band factor.
Pure per-pixel math: accepts a GeoArray or a plain
np.ndarray and returns the same carrier kind, cast back to the
input dtype.
Nodata: fill / non-finite pixels are left untouched and hold the output's fill value (see the module docstring).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factor
|
Range
|
|
(0.9, 1.1)
|
per_band
|
bool
|
Draw an independent factor per band (the band
axis, |
True
|
seed
|
int | None
|
Seed of the operator's own draw stream, which advances on
every call; a per-call |
None
|
Source code in packages/geotoolz-ops/src/geoops/augment/_src/operators.py
geoops.augment._src.operators.ContrastJitter
¶
Bases: Operator
Scale deviations from the per-band spatial mean.
Pure per-pixel math: accepts a GeoArray or a plain
np.ndarray and returns the same carrier kind, cast back to the
input dtype.
Nodata: the per-band mean is taken over valid pixels only, and fill / non-finite pixels hold the output's fill value (see the module docstring).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factor
|
Range
|
|
(0.9, 1.1)
|
per_band
|
bool
|
Draw an independent factor per band (the band
axis, |
True
|
seed
|
int | None
|
Seed of the operator's own draw stream, which advances on
every call; a per-call |
None
|
Source code in packages/geotoolz-ops/src/geoops/augment/_src/operators.py
geoops.augment._src.operators.GaussianNoise
¶
Bases: Operator
Add zero-mean Gaussian sensor noise.
Pure per-pixel math: accepts a GeoArray or a plain
np.ndarray and returns the same carrier kind, cast back to the
input dtype.
Nodata: fill / non-finite pixels are left untouched and hold the output's fill value (see the module docstring).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sigma
|
ScalarOrRange
|
Noise standard deviation, either a scalar or a
|
0.01
|
per_band
|
bool
|
Draw an independent sigma per band (the band
axis, |
True
|
seed
|
int | None
|
Seed of the operator's own draw stream, which advances on
every call; a per-call |
None
|
Source code in packages/geotoolz-ops/src/geoops/augment/_src/operators.py
geoops.augment._src.operators.SpeckleNoise
¶
Bases: Operator
Apply multiplicative Gaussian speckle noise, useful for SAR.
Pure per-pixel math: accepts a GeoArray or a plain
np.ndarray and returns the same carrier kind, cast back to the
input dtype.
Nodata: fill / non-finite pixels are left untouched and hold the output's fill value (see the module docstring).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sigma
|
ScalarOrRange
|
Speckle standard deviation, either a scalar or a
|
0.05
|
seed
|
int | None
|
Seed of the operator's own draw stream, which advances on
every call; a per-call |
None
|
Source code in packages/geotoolz-ops/src/geoops/augment/_src/operators.py
Band-level¶
geoops.augment._src.operators.BandDropout
¶
Bases: Operator
Fill each band independently with probability p.
Pure per-band math: accepts a GeoArray or a plain
np.ndarray and returns the same carrier kind. A 2-D input is
treated as a single band.
Nodata: pixels that were fill / non-finite on input keep the output's
fill value rather than fill_value (see the module docstring).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
Per-band dropout probability. Default |
0.1
|
fill_value
|
float
|
Value written into dropped bands. Default |
0.0
|
seed
|
int | None
|
Seed of the operator's own draw stream, which advances on
every call; a per-call |
None
|
Source code in packages/geotoolz-ops/src/geoops/augment/_src/operators.py
geoops.augment._src.operators.BandJitter
¶
Bases: Operator
Permute bands within explicitly configured groups.
Metadata-dependent: band names are resolved through the carrier's
attrs by the package-wide resolver (band_names, then
descriptions, then bands), so named groups on a plain
np.ndarray raise TypeError and on a GeoArray without those
names raise ValueError. Integer indices work on any carrier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
groups
|
dict[str, list[str]] | list[list[Any]] | None
|
Mapping of group label to the band names (or integer
indices) permuted within that group, or the equivalent
|
None
|
seed
|
int | None
|
Seed of the operator's own draw stream, which advances on
every call; a per-call |
None
|
Source code in packages/geotoolz-ops/src/geoops/augment/_src/operators.py
RS-specific¶
geoops.augment._src.operators.SunAngleJitter
¶
Bases: Operator
Rescale TOA reflectance for a simulated solar-zenith change.
Metadata-dependent: the base solar zenith angle is read from the
carrier's attrs (solar_zenith_angle or sza_deg), so a
plain np.ndarray input (or a GeoArray without those attrs)
raises ValueError.
Nodata: fill / non-finite pixels are left untouched and hold the output's fill value (see the module docstring).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delta_sza_deg
|
ScalarOrRange
|
Solar-zenith perturbation in degrees, either a
scalar or a |
(-5.0, 5.0)
|
seed
|
int | None
|
Seed of the operator's own draw stream, which advances on
every call; a per-call |
None
|
Source code in packages/geotoolz-ops/src/geoops/augment/_src/operators.py
geoops.augment._src.operators.AtmosphericHaze
¶
Bases: Operator
Add a sampled haze term following an inverse fourth-power spectrum.
Wavelengths are read from attrs["wavelengths"] (the package-wide
key, in nanometers; values below 10 are treated as micrometers and
converted to nanometers). Accepts a GeoArray or a plain
np.ndarray; when the carrier has no wavelengths attr, a
default 450-850 nm linspace is assumed.
Nodata: fill / non-finite pixels are left untouched and hold the output's fill value (see the module docstring).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intensity
|
ScalarOrRange
|
Haze amplitude added to the shortest wavelength,
either a scalar or a |
(0.0, 0.05)
|
seed
|
int | None
|
Seed of the operator's own draw stream, which advances on
every call; a per-call |
None
|
Source code in packages/geotoolz-ops/src/geoops/augment/_src/operators.py
geoops.augment._src.operators.SimulatedClouds
¶
Bases: Operator
Overlay a smooth synthetic cloud field onto reflectance imagery.
Pure per-pixel math: accepts a GeoArray or a plain
np.ndarray and returns the same carrier kind, cast back to the
input dtype.
Nodata: the cloud brightness (max / percentile of the scene) is taken over valid pixels only, and fill / non-finite pixels hold the output's fill value (see the module docstring).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coverage
|
ScalarOrRange
|
Fraction of pixels covered by cloud, either a scalar
or a |
(0.0, 0.3)
|
feather
|
int
|
Gaussian smoothing sigma (pixels) applied to the random
cloud field; |
5
|
seed
|
int | None
|
Seed of the operator's own draw stream, which advances on
every call; a per-call |
None
|
Source code in packages/geotoolz-ops/src/geoops/augment/_src/operators.py
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 | |
geoops.augment._src.operators.CutMix
¶
Bases: Operator
Paste a random rectangle from a pool donor on the input's pixel grid.
Called as op(gt, *pool) -- the donors are positional carriers after
the input (or one list of them, op(gt, [d1, d2])), so the operator
wires into a pipekit_ops.Graph as CutMix()(Input("x"), Input("d1"),
Input("d2")). With no donors the input passes through unchanged.
Every donor must share the input's pixel grid exactly
(:func:geoops._src.geo.grid_matches with spatial_only=False:
the full shape, and -- when both carry georeferencing -- the CRS and
every transform coefficient, origin included). The paste is
pixel-space math: pixel (i, j) of the donor lands on pixel
(i, j) of the input, so requiring the same grid keeps the result
geographically coherent (e.g. a donor from another acquisition date
or sensor over the same tile). A donor at a different origin, scale
or CRS is rejected rather than pasted at the wrong location.
Plain np.ndarray carriers (input and/or donors) are accepted:
the georeferencing check applies only when both the input and the
drawn donor carry a transform; plain arrays are compared by shape.
Sampling: with probability p one donor is drawn uniformly from
the pool; the rectangle's height and width are drawn independently
and uniformly from [1, H] and [1, W], and its top-left corner
uniformly among the positions that keep it inside the raster. This
is not the Beta(alpha, alpha) area-ratio convention of Yun et al.
(2019) and no label-mixing ratio is returned (see #141).
Nodata: donor pixels that are fill / non-finite under the donor's fill value are written as the input's fill value, so a pasted hole stays a hole for the output carrier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
Probability of applying the paste. Default |
0.5
|
seed
|
int | None
|
Seed of the operator's own draw stream, which advances on
every call; a per-call |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
At apply time, if any donor is not on the input's pixel grid. |
Examples:
Source code in packages/geotoolz-ops/src/geoops/augment/_src/operators.py
1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 | |
Tier-A primitives¶
geoops.augment._src.array.rot90_transform(transform: Affine, height: int, width: int, k: int) -> Affine
¶
Compose transform with the pixel map of np.rot90(..., k).
The affine maps pixel corners, so the mirrored axes are anchored at
the far edge (width / height), not the last pixel index; the
rotated grid then covers exactly the input footprint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
Affine
|
Affine of the input grid. |
required |
height
|
int
|
Input height in pixels. |
required |
width
|
int
|
Input width in pixels. |
required |
k
|
int
|
Number of counter-clockwise quarter turns (any integer). |
required |
Returns:
| Type | Description |
|---|---|
Affine
|
The affine of |
Examples:
Source code in packages/geotoolz-ops/src/geoops/augment/_src/array.py
geoops.augment._src.array.sun_angle_scale(base_sza_deg: float, delta_deg: float) -> float
¶
TOA-reflectance factor for a solar-zenith change.
s = cos(θ + Δθ) / cos(θ)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_sza_deg
|
float
|
Solar zenith angle |
required |
delta_deg
|
float
|
Perturbation |
required |
Returns:
| Type | Description |
|---|---|
float
|
The multiplicative factor |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
Source code in packages/geotoolz-ops/src/geoops/augment/_src/array.py
geoops.augment._src.array.rayleigh_weights(wavelengths: Float[np.ndarray, ' c'] | None, n_bands: int) -> Float[np.ndarray, ' c']
¶
Per-band inverse-fourth-power haze weights, peak-normalised.
w_c = λ_c⁻⁴ / max_c λ_c⁻⁴
Wavelengths are nanometres; values below 10 are taken as
micrometres and converted. None assumes a 450-850 nm linspace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wavelengths
|
Float[ndarray, ' c'] | None
|
Band-centre wavelengths, or |
required |
n_bands
|
int
|
Number of bands. |
required |
Returns:
| Type | Description |
|---|---|
Float[ndarray, ' c']
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
Source code in packages/geotoolz-ops/src/geoops/augment/_src/array.py
geoops.augment._src.array.cloud_alpha(field: Float[np.ndarray, 'h w'], coverage: float, *, feather: float = 0.0) -> Float[np.ndarray, 'h w']
¶
Cloud opacity map covering coverage of the pixels.
The (random) field is Gaussian-smoothed with feather,
min-max normalised to f ∈ [0, 1] and thresholded at its
1 − coverage quantile q; opacity ramps linearly above it:
α = clip((f − q) / (max f − q), 0, 1)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Float[ndarray, 'h w']
|
|
required |
coverage
|
float
|
Fraction of pixels with |
required |
feather
|
float
|
Gaussian smoothing sigma in pixels; |
0.0
|
Returns:
| Type | Description |
|---|---|
Float[ndarray, 'h w']
|
|
Examples:
>>> alpha = cloud_alpha(np.random.default_rng(0).normal(size=(64, 64)), 0.25)
>>> 0.2 < float((alpha > 0).mean()) < 0.3
True