Skip to main content

preprocessing.tile_geotiff

preprocessing.tile_geotiff(
    input_tiff,
    output_dir,
    tile_size=256,
    stride='auto',
    add_padding=False,
    augment=False,
    output_mode='geotiff',
    train_val_test_split=(0.8, 0.1, 0.1),
    split_method='block',
    split_block_size_tiles=None,
    split_stripe_axis='horizontal',
    split_stripe_size_tiles=None,
    split_regions=None,
    nan_handling='auto',
    nan_max_fraction=0.1,
    nan_interp_max_dist=3,
    nan_strategy_per_kind=None,
    nan_strategy_per_band=None,
    mission_name=None,
    cloud_mask=False,
    cloud_mask_dilation_px=0,
)

Tile a multi-band GeoTIFF into AI-ready patches with a chosen split strategy.

Beyond the simple random per-tile coin flip, three spatially-aware methods are available:

  • block (default) – whole K-tile x K-tile blocks go to one split. Removes near-neighbour leakage. Tune via split_block_size_tiles; leaving it as None auto-scales the block size so the train/val/test buckets stay populated even on small AOIs.
  • stripes – N-tile-wide rows or columns go to one split. Tune via split_stripe_axis (“horizontal”/“vertical”) and split_stripe_size_tiles. Auto-scales when None.
  • regions – explicit train/val/test AOIs (uses the same aoi.py spec language as main.py). Tiles outside every region are skipped. Tune via split_regions={"train":..., "val":..., "test":...}.

Augmentation

The augment argument accepts either a boolean or a sequence of augmentation names from :data:AVAILABLE_AUGMENTATIONS:

  • augment=False (default) – no augmentation.
  • augment=True – all five augmentations: flipH, flipV, rot90, rot270, noise.
  • augment=("flipH", "flipV") – just the two flips (the case you want when rotations would introduce wrong-orientation features, e.g. detecting buildings from overhead where rotation is still meaningful but reflection isn’t.)
  • augment=("noise",) – noise only.

Unknown names raise ValueError before any tiling work begins.

Cloud mask dilation

SCL / QA masks tend to under-flag thin cloud edges and shadows, most of all over dark water, which leaves a halo of partly contaminated pixels around every masked cloud. cloud_mask_dilation_px=N grows the combined cloud mask by N pixels before it is applied; 1-2 is usually enough. The halo is read from beyond each tile’s window, so the result does not depend on where tile edges fall.

Dilation adds NaN pixels before NaN handling runs, so tiles near clouds are more likely to exceed nan_max_fraction (and, for "interpolate", to fall outside nan_interp_max_dist) and be dropped. Re-check those two settings when you turn dilation on.