Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
Add option to specify input grid (#114)
Browse files Browse the repository at this point in the history
## Purpose

Allow the caller to override the src grid definition for the input field. Useful if the regrid needs to be chained as the RegularGrid.from_field method is limited to the rotated latlon CRS.

## Code changes

- `idpi.operators.regrid.regrid` takes `src` as an optional parameter.
  • Loading branch information
cfkanesan authored Feb 23, 2024
1 parent 5f6d822 commit 0993234
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/idpi/operators/regrid.py
Original file line number Diff line number Diff line change
@@ -215,7 +215,12 @@ def _get_metadata(grid: RegularGrid):
}


def regrid(field: xr.DataArray, dst: RegularGrid, resampling: Resampling):
def regrid(
field: xr.DataArray,
dst: RegularGrid,
resampling: Resampling,
src: RegularGrid | None = None,
):
"""Regrid a field.
Parameters
@@ -226,6 +231,8 @@ def regrid(field: xr.DataArray, dst: RegularGrid, resampling: Resampling):
Destination grid onto which to project the field.
resampling : Resampling
Resampling method, alias of rasterio.warp.Resampling.
src : RegularGrid, optional
Definition of the input field grid
Raises
------
@@ -239,7 +246,8 @@ def regrid(field: xr.DataArray, dst: RegularGrid, resampling: Resampling):
Field regridded in the destination grid.
"""
src = RegularGrid.from_field(field)
if src is None:
src = RegularGrid.from_field(field)

def reproject_layer(field):
output = np.zeros((dst.ny, dst.nx))

0 comments on commit 0993234

Please sign in to comment.