Resample

To ensure data from various satellites and sources are comparable, it is essential to standardize key attributes such as pixel resolution, spatial transform, image shape, scaling, and offsets. This process is called resampling and requires a reference GeoTIFF file with the same spatial extent. Resampling can handle both upsampling (increasing resolution) and downsampling (reducing resolution).

Resampling Methods¤

When resampling a raster image, the pixel values must be interpolated to fit the new bounds. The resampling method determines how these values are calculated. Available methods are provided by rasterio.warp.Resampling. Common options include:

  • Nearest Neighbor: Assigns the value of the nearest pixel (fastest, but may introduce pixelated results).
  • Bilinear: Uses the average of the nearest four pixels (smooth interpolation).
  • Cubic: A higher-order method that considers the nearest 16 pixels (produces smoother results, but slower).
  • Lanczos: A high-quality resampling method (particularly for large transformations, but slower).

Side note: In GDAL warp the default resampling method is nearest. To preserve BIT_MAP data like in classifier files (cloud, water, land, ...) use Resampling.nearest.

Resampling target¤

The resampling is not done by providing a new target resolution like 10m/pixel. Instead a reference GeoTIFF is used to provide all necessary informtion. The reference has to have the same spatial extends (not pixel extends). After resampling the result will have the same pixel extends and the same georeference. Each pixel represents exactly the same postion on the reference coordinate system. Additionally the scaling factor and offset are equalized to reflect the same values as the reference.

Parameters¤

Name Type Description
input_dir str Input directory containing GeoTIFF files. Can contain subfolders.
output_dir str Output directory. If same as input then the original files are overwritten. Keeps subfolders.
resampling_method Resampling Resampling method from rasterio.warp.Resampling
reference_path str Path to a valid GeoTIFF file used as template.
regex str A regex pattern to filter the files to be resampled. Default is *. The pattern can include wildcards:

* matches any sequence of characters (including an empty sequence).
? matches any single character.
[seq] matches any character in seq.
[!seq] matches any character not in seq.
include bool Whether to include or exclude files matching the regex pattern. Default is True.
num_processes int Process multiple files in parallel using multi-processing. Default is 1.

Example¤

Python
from sipt.processing import resample
from rasterio.warp import Resampling

reference_path = "./processed/20240511T000000.tif"
num_processes = 4

resample("./src", "./processed", Resampling.nearest, reference_path, 4)