wradlib.util.UtilMethods.crop

Contents

wradlib.util.UtilMethods.crop#

UtilMethods.crop(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 with x and y coordinates.

  • trg (xarray.DataArray) – Target data providing the spatial extent via its x and y coordinates.

  • 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 of src that 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.