Skip to content

Commit

Permalink
Nan threshold for conservative regridding (continuation of #39) (#41)
Browse files Browse the repository at this point in the history
* add nan_threshold option

* track nan frac across dims, use xr.dot, consolidate ds/da paths, tests

* fixes and cleanup plus initial notebook cell

* speed up by only tracking the max of nonnull points over non_regrid_dims

* fix tests for newer dependency versions

* Improve typing of call_on_dataset

* Fix typing in updated conservative routines

* Apply code formatting

* Ensure hashable is a valid input for coordinate identifier

* Make tests & typing pass

* Make `create_regridding_dataset` a method of `Grid` #38

* Update notebooks and dependencies

* Allow xesmf test to run if it's available

* Add @slevang to the contributors list

* Update changelog

* Ignore linter in test

* Update readme with badges and "why use..." text

---------

Co-authored-by: Sam Levang <slevang@salientpredictions.com>
  • Loading branch information
BSchilperoort and slevang authored Sep 4, 2024
1 parent 970d07d commit 524c1c8
Show file tree
Hide file tree
Showing 15 changed files with 628 additions and 301 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

## Unreleased

New contributors:
- @slevang

Fixed:
- conservative regridding now can be constructed fully lazily [#39](https://github.com/EXCITED-CO2/xarray-regrid/pull/39).

Added:
- Documentation for the package, including readthedocs integration ([#40](https://github.com/EXCITED-CO2/xarray-regrid/pull/40)).
- documentation for the package, including readthedocs integration ([#40](https://github.com/EXCITED-CO2/xarray-regrid/pull/40)).
- better handling of NaNs to the conservative regridding routine, with a `nan_threshold` keyword argument. For more information see the notebooks on the documentation [#39](https://github.com/EXCITED-CO2/xarray-regrid/pull/39) \& [#41](https://github.com/EXCITED-CO2/xarray-regrid/pull/41).
- `create_regridding_dataset` as a method of the `xarray_regrid.Grid` dataclass [#41](https://github.com/EXCITED-CO2/xarray-regrid/pull/41).

## v0.2.3 (2024-02-29)

Expand Down
7 changes: 4 additions & 3 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ authors:
family-names: Doore
orcid: 'https://orcid.org/0000-0001-5035-4016'
affiliation: United States Geological Survey

- given-names: Sam
family-names: Levang
affiliation: Salient Predictions

repository-code: 'https://github.com/EXCITED-CO2/xarray-regrid'
keywords:
- xarray
- geospatial
- regridding
- conservative regridding
license: Apache-2.0
version: 0.2.3
date-released: '2023-11-24'
abstract: >
xarray-regrid can regrid (geospatial) data to a new
coordinate system.
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<img align="right" width="100" alt="Logo" src="./docs/assets/logo.png">


With xarray-regrid it is possible to regrid between two rectilinear grids. The following methods are supported:
- Linear
- Nearest-neighbor
Expand All @@ -11,7 +12,13 @@ With xarray-regrid it is possible to regrid between two rectilinear grids. The f

Note that "Most common value" is designed to regrid categorical data to a coarse resolution. For regridding categorical data to a finer resolution, please use "nearest-neighbor" regridder.

[![PyPI](https://img.shields.io/pypi/v/xarray-regrid.svg?style=flat)](https://pypi.python.org/pypi/xarray-regrid/)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.10203304.svg)](https://doi.org/10.5281/zenodo.10203304)
[![Docs](https://readthedocs.org/projects/xarray-regrid/badge/?version=latest&style=flat)](https://xarray-regrid.readthedocs.org/)

## Why xarray-regrid?

Regridding is a common operation in earth science and other fields. While xarray does have some interpolation methods available, these are not always straightforward to use. Additionally, methods such as conservative regridding, or taking the most common value, are not available in xarray.

## Installation

Expand Down
41 changes: 15 additions & 26 deletions docs/notebooks/benchmarks/benchmarking_bilinear.ipynb

Large diffs are not rendered by default.

141 changes: 82 additions & 59 deletions docs/notebooks/benchmarks/benchmarking_conservative.ipynb

Large diffs are not rendered by default.

63 changes: 21 additions & 42 deletions docs/notebooks/benchmarks/benchmarking_nearest.ipynb

Large diffs are not rendered by default.

Binary file modified docs/notebooks/benchmarks/data/cdo_conservative_64b.nc
Binary file not shown.
176 changes: 176 additions & 0 deletions docs/notebooks/demos/demo_conservative_nan_threshold.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/notebooks/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ Most notebooks compare the methods implemented in xarray-regrid against more sta
:caption: Demos

demos/demo_most_common.ipynb
demos/demo_conservative_nan_threshold.ipynb
7 changes: 5 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ name: xarray-regrid
channels:
- conda-forge
dependencies:
- python==3.10
- python==3.12
- xESMF
- cdo
- pip:
- "xarray-regrid"
- "xarray-regrid"
- "cftime"
- "matplotlib"
- "dask[distributed]"
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ Source = "https://github.com/EXCITED-CO2/xarray-regrid"
benchmarking = [
"dask[distributed]",
"matplotlib",
"zarr",
"requests",
"aiohttp",
]
dev = [
"hatch",
Expand All @@ -51,6 +54,7 @@ dev = [
"pytest-cov",
"cftime", # required for decode time of test netCDF files
"pandas-stubs", # Adds typing for pandas.
"cftime",
]
docs = [ # Required for ReadTheDocs
"myst_parser",
Expand Down Expand Up @@ -102,7 +106,6 @@ select = [
"E",
"EM",
"F",
"FBT",
"I",
"ICN",
"ISC",
Expand All @@ -123,8 +126,6 @@ select = [
ignore = [
# Allow non-abstract empty methods in abstract base classes
"B027",
# Allow boolean positional values in function calls, like `dict.get(... True)`
"FBT003",
# Ignore checks for possible passwords
"S105", "S106", "S107",
# Ignore complexity
Expand Down
Loading

0 comments on commit 524c1c8

Please sign in to comment.