wradlib.util.crop#
- wradlib.util.crop(src, trg, pad=0)[source]#
Crop a 2D DataArray to the spatial extent of another DataArray, optionally extending the crop by a given number of grid cells.
The crop bounds are derived from the minimum and maximum values of the target coordinates. Coordinate axes that are sorted in descending order are handled correctly.
- Parameters:
src (
xarray.DataArray) – Source data withxandycoordinates.trg (
xarray.DataArray) – Target data providing the spatial extent via itsxandycoordinates.pad (
int, optional) – Number of additional grid cells to include beyond the target extent in each direction. The padding is applied in coordinate units using the source grid spacing. Default is 0.
- Returns:
xarray.DataArray– Cropped view ofsrcthat covers the target domain plus the optional padding.
Notes
Padding is applied symmetrically in both directions along each axis. This is particularly useful when preparing data for higher-order interpolation methods (e.g., linear or cubic splines) that require neighboring grid cells near the domain boundaries.