-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor methods to module. Fix conservative nan bug. (#19)
* Refactor methods to module. Fix conservative nan bug. * Fix linting and typing issues
- Loading branch information
1 parent
56b60fa
commit 7937260
Showing
6 changed files
with
115 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
from xarray_regrid import methods | ||
from xarray_regrid.regrid import Regridder | ||
from xarray_regrid.utils import Grid, create_regridding_dataset | ||
|
||
__all__ = [ | ||
"Grid", | ||
"Regridder", | ||
"create_regridding_dataset", | ||
"methods", | ||
] | ||
|
||
__version__ = "0.2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Methods based on xr.interp.""" | ||
from typing import Literal, overload | ||
|
||
import xarray as xr | ||
|
||
|
||
@overload | ||
def interp_regrid( | ||
data: xr.DataArray, | ||
target_ds: xr.Dataset, | ||
method: Literal["linear", "nearest", "cubic"], | ||
) -> xr.DataArray: | ||
... | ||
|
||
|
||
@overload | ||
def interp_regrid( | ||
data: xr.Dataset, | ||
target_ds: xr.Dataset, | ||
method: Literal["linear", "nearest", "cubic"], | ||
) -> xr.Dataset: | ||
... | ||
|
||
|
||
def interp_regrid( | ||
data: xr.DataArray | xr.Dataset, | ||
target_ds: xr.Dataset, | ||
method: Literal["linear", "nearest", "cubic"], | ||
) -> xr.DataArray | xr.Dataset: | ||
"""Refine a dataset using xarray's interp method. | ||
Args: | ||
data: Input dataset. | ||
target_ds: Dataset which coordinates the input dataset should be regrid to. | ||
method: Which interpolation method to use (e.g. 'linear', 'nearest'). | ||
Returns: | ||
Regridded input dataset | ||
""" | ||
coord_names = set(target_ds.coords).intersection(set(data.coords)) | ||
coords = {name: target_ds[name] for name in coord_names} | ||
|
||
return data.interp( | ||
coords=coords, | ||
method=method, | ||
) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters