Skip to content

Commit

Permalink
Merge pull request #310 from roocs/open-xarray-pin
Browse files Browse the repository at this point in the history
Pin xarray for xesmf-based regridding
  • Loading branch information
Zeitsperre authored Nov 30, 2023
2 parents 0b94f66 + b90f69c commit 08555fe
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
8 changes: 8 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Version History
===============

v0.12.1 (2023-11-30)
--------------------

Other Changes
^^^^^^^^^^^^^
* Warnings are now emitted if the user attempts to run the regridding utilities with a version of `xarray` that is not compatible with `cf-xarray`. (#310).
* Dependency pins now constrain the `xarray` version when installing with `$ pip install ".[extra]"`. (#310).

v0.12.0 (2023-11-23)
--------------------

Expand Down
2 changes: 2 additions & 0 deletions clisops/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Core functionality for clisops."""

from .subset import (
create_mask,
subset_bbox,
Expand Down
11 changes: 11 additions & 0 deletions clisops/core/regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import xarray as xr
from packaging.version import Version
from roocs_utils.exceptions import InvalidParameterValue
from xarray import __version__ as __xarray_version__

import clisops.utils.dataset_utils as clidu
from clisops import CONFIG
Expand All @@ -35,6 +36,16 @@
except (ModuleNotFoundError, ValueError):
xe = None

# FIXME: Remove this when xarray addresses https://github.com/pydata/xarray/issues/7794
XARRAY_INCOMPATIBLE_VERSION = "2023.03.0"
if Version(__xarray_version__) >= Version(XARRAY_INCOMPATIBLE_VERSION):
warnings.warn(
f"xarray version >= {XARRAY_INCOMPATIBLE_VERSION} "
f"is not supported for regridding operations with cf-time indexed arrays. "
f"Please use xarray version < {XARRAY_INCOMPATIBLE_VERSION}. "
"For more information, see: https://github.com/pydata/xarray/issues/7794."
)


# Read coordinate variable precision from the clisops configuration (roocs.ini)
# All horizontal coordinate variables will be rounded to this precision
Expand Down
4 changes: 3 additions & 1 deletion clisops/ops/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .average import average
"""Operations module for clisops."""

from .average import average_over_dims, average_time
from .regrid import regrid
from .subset import subset
13 changes: 0 additions & 13 deletions clisops/ops/regrid.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import warnings
from datetime import datetime as dt
from pathlib import Path
from typing import List, Optional, Union

import xarray as xr
from loguru import logger
from packaging.version import Version
from roocs_utils.exceptions import InvalidParameterValue
from xarray import __version__ as __xarray_version__

from clisops.core import Grid, Weights
from clisops.core import regrid as core_regrid
from clisops.ops.base_operation import Operation
from clisops.utils.file_namers import get_file_namer

# from clisops.utils.output_utils import get_output, get_time_slices

__all__ = [
"regrid",
]
Expand Down Expand Up @@ -213,14 +208,6 @@ def regrid(
| split_method: "time:auto"
| file_namer: "standard"
| keep_attrs: True
"""
if Version(__xarray_version__) >= Version("23.3.0"):
warnings.warn(
"xarray version >= 23.3.0 is not supported for regridding operations "
"with cf-time indexed arrays. Please use xarray version < 23.3.0. "
"For more information, see: https://github.com/pydata/xarray/issues/7794."
)

op = Regrid(**locals())
return op.process()
9 changes: 2 additions & 7 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies:
- python >=3.8,<3.12
- flit
- bottleneck >=1.3.1
- cf_xarray >=0.8.5
- cf_xarray >=0.8.6
- cftime >=1.4.1
- dask >=2.6.0
- gdal >=3.0
Expand All @@ -22,7 +22,7 @@ dependencies:
- roocs-grids >=0.1.2
- roocs-utils >=0.6.4,<0.7
- shapely >=1.9
- xarray >=0.21 # https://github.com/pydata/xarray/issues/7794
- xarray >=0.21,<2023.03.0 # See: https://github.com/pydata/xarray/issues/7794
- xesmf >=0.8.2
# Dev tools and testing
- black >=23.10.1
Expand All @@ -48,8 +48,3 @@ dependencies:
- pandoc
- sphinx
- sphinx-rtd-theme >=1.0
# Upstream
# - pip
# - pip:
# - cf-xarray @ git+https://github.com/xarray-contrib/cf-xarray/@main#egg=cf-xarray
# - roocs-utils @ git+https://github.com/roocs/roocs-utils.git@master#egg=roocs-utils
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ dependencies = [
"roocs_grids>=0.1.2",
"roocs-utils>=0.6.4,<0.7",
"shapely>=1.9",
# https://github.com/pydata/xarray/issues/7794
"xarray>=0.21"
]

Expand Down Expand Up @@ -98,7 +97,11 @@ docs = [
"sphinx",
"sphinx-rtd-theme>=1.0"
]
extra = ["xesmf>=0.8.2"]
extra = [
"xesmf>=0.8.2",
# See: https://github.com/pydata/xarray/issues/7794
"xarray>=0.21.0,<2023.03.0"
]

[project.urls]
"Homepage" = "https://clisops.readthedocs.io/"
Expand Down

0 comments on commit 08555fe

Please sign in to comment.