Field Preprocessing
The wrangler.preproc.field module provides functionality for preprocessing satellite image fields through a series of customizable operations. This document describes the available preprocessing steps, their parameters, and usage.
Main Preprocessing Function
- main(field, mask, **kwargs)
Preprocesses an input field image with a series of optional steps.
- Parameters:
field (numpy.ndarray) – Input field array
mask (numpy.ndarray) – Data mask (True = masked values)
kwargs – Optional preprocessing parameters
- Returns:
Tuple of (preprocessed_field, metadata_dict)
- Return type:
Preprocessing Steps
The preprocessing steps are applied in the following order if enabled through parameters:
Inpainting
Fill masked regions using a biharmonic inpainting algorithm.
- param inpaint:
Enable inpainting
- type inpaint:
bool
- param only_inpaint:
Return after inpainting
- type only_inpaint:
bool
Resizing
Resize the field to a specified size.
- param resize:
Enable resizing
- type resize:
bool
- param field_size:
Target size for the field
- type field_size:
int
Noise Addition
Add Gaussian noise to the field.
- param noise:
Standard deviation of noise to add
- type noise:
float
Median Filtering
Apply a median filter to reduce noise while preserving edges.
- param median:
Enable median filtering
- type median:
bool
- param med_size:
Size of the median filter window (tuple)
- type med_size:
tuple
Downscaling
Reduce the field size by local mean downscaling.
- param downscale:
Enable downscaling
- type downscale:
bool
- param dscale_size:
Downscaling factors (tuple)
- type dscale_size:
tuple
Mean Removal
Normalize the field by removing the mean value.
- param de_mean:
Enable mean removal
- type de_mean:
bool
- param min_mean:
Minimum required mean value
- type min_mean:
float
Sigmoid Transformation
Apply error function (erf) transformation to field values.
- param sigmoid:
Enable sigmoid transformation
- type sigmoid:
bool
Scaling
Apply a multiplicative scaling factor to field values.
- param scale:
Scaling factor
- type scale:
float
Exponentiation
Raise field values to a power, preserving sign.
- param expon:
Exponent value
- type expon:
float
Gradient Enhancement
Apply a Sobel filter to enhance edges and gradients.
- param gradient:
Enable gradient enhancement
- type gradient:
bool
Logarithmic Scaling
Apply logarithmic scaling to gradient values.
- param log_scale:
Enable logarithmic scaling
- type log_scale:
bool
Metadata
The function returns a metadata dictionary containing statistics about the field:
Tmax: Maximum temperature valueTmin: Minimum temperature valueT10: 10th percentile temperatureT90: 90th percentile temperaturemu: Mean field value
If gradient enhancement is enabled, additional metadata is included:
G10: 10th percentile gradient valueG90: 90th percentile gradient valueGmax: Maximum gradient value
Usage Examples
Basic Inpainting
from wrangler.preproc.field import main as process_field
# Load field and mask data
# ...
# Just inpaint the field
inpainted_field, _ = process_field(field, mask, inpaint=True, only_inpaint=True)
Multiple Preprocessing Steps
# Apply several preprocessing steps
processed_field, metadata = process_field(
field,
mask,
inpaint=True,
median=True,
med_size=(3, 1),
downscale=True,
dscale_size=(2, 2),
de_mean=True,
scale=0.1
)
print(f"Mean value: {metadata['mu']}")
print(f"Temperature range: {metadata['Tmin']} to {metadata['Tmax']}")
Gradient Enhancement Pipeline
# Create a gradient-enhanced version
gradient_field, metadata = process_field(
field,
mask,
inpaint=True,
de_mean=True,
gradient=True,
log_scale=True
)
print(f"Gradient range: {metadata['G10']} to {metadata['G90']}")
Important Notes
Not all combinations of parameters are valid. For example,
log_scale=Truerequiresgradient=True.The function will return
None, Noneif any of these conditions occur: - Inpainting fails - The field contains NaN values after processing - The mean is below themin_meanthresholdFor resizing, the field is resized to match the specified
field_sizeWhen using
expon, the sign of values is preserved (negative values remain negative)