Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pin xarray for xesmf-based regridding #310

Merged
merged 7 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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