Skip to content

Commit 28053ba

Browse files
authored
remove cdms2 (#8441)
* remove `cdms2` from all environments * remove any code related to `cdms2` * remove the `mypy` override for `cdms2` * remove the special environment files for python 3.11 * whats-new * more info on the replacement * remove the `cdms2` methods from the api docs * remove all mentions of UV-CDAT / cdms2 from the faq * also change the binder environment
1 parent 49bd63a commit 28053ba

15 files changed

+8
-359
lines changed

.binder/environment.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ dependencies:
66
- boto3
77
- bottleneck
88
- cartopy
9-
- cdms2
109
- cfgrib
1110
- cftime
1211
- coveralls
@@ -38,5 +37,4 @@ dependencies:
3837
- toolz
3938
- xarray
4039
- zarr
41-
- pip:
42-
- numbagg
40+
- numbagg

.github/workflows/ci.yaml

+1-7
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,7 @@ jobs:
6767
run: |
6868
echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
6969
70-
if [[ "${{matrix.python-version}}" == "3.11" ]]; then
71-
if [[ ${{matrix.os}} == windows* ]]; then
72-
echo "CONDA_ENV_FILE=ci/requirements/environment-windows-py311.yml" >> $GITHUB_ENV
73-
else
74-
echo "CONDA_ENV_FILE=ci/requirements/environment-py311.yml" >> $GITHUB_ENV
75-
fi
76-
elif [[ ${{ matrix.os }} == windows* ]] ;
70+
if [[ ${{ matrix.os }} == windows* ]] ;
7771
then
7872
echo "CONDA_ENV_FILE=ci/requirements/environment-windows.yml" >> $GITHUB_ENV
7973
elif [[ "${{ matrix.env }}" != "" ]] ;

ci/requirements/all-but-dask.yml

-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ channels:
33
- conda-forge
44
- nodefaults
55
dependencies:
6-
- python=3.10
76
- black
87
- aiobotocore
98
- boto3
109
- bottleneck
1110
- cartopy
12-
- cdms2
1311
- cftime
1412
- coveralls
1513
- flox

ci/requirements/environment-py311.yml

-47
This file was deleted.

ci/requirements/environment-windows-py311.yml

-43
This file was deleted.

ci/requirements/environment-windows.yml

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ dependencies:
55
- boto3
66
- bottleneck
77
- cartopy
8-
# - cdms2 # Not available on Windows
98
- cftime
109
- dask-core
1110
- distributed

ci/requirements/environment.yml

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ dependencies:
77
- boto3
88
- bottleneck
99
- cartopy
10-
- cdms2
1110
- cftime
1211
- dask-core
1312
- distributed

ci/requirements/min-all-deps.yml

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ dependencies:
1111
- boto3=1.24
1212
- bottleneck=1.3
1313
- cartopy=0.20
14-
- cdms2=3.1
1514
- cftime=1.6
1615
- coveralls
1716
- dask-core=2022.7

doc/api.rst

-2
Original file line numberDiff line numberDiff line change
@@ -628,11 +628,9 @@ DataArray methods
628628
load_dataarray
629629
open_dataarray
630630
DataArray.as_numpy
631-
DataArray.from_cdms2
632631
DataArray.from_dict
633632
DataArray.from_iris
634633
DataArray.from_series
635-
DataArray.to_cdms2
636634
DataArray.to_dask_dataframe
637635
DataArray.to_dataframe
638636
DataArray.to_dataset

doc/getting-started-guide/faq.rst

+3-10
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,11 @@ integration with Cartopy_.
168168
.. _Iris: https://scitools-iris.readthedocs.io/en/stable/
169169
.. _Cartopy: https://scitools.org.uk/cartopy/docs/latest/
170170

171-
`UV-CDAT`__ is another Python library that implements in-memory netCDF-like
172-
variables and `tools for working with climate data`__.
173-
174-
__ https://uvcdat.llnl.gov/
175-
__ https://drclimate.wordpress.com/2014/01/02/a-beginners-guide-to-scripting-with-uv-cdat/
176-
177171
We think the design decisions we have made for xarray (namely, basing it on
178172
pandas) make it a faster and more flexible data analysis tool. That said, Iris
179-
and CDAT have some great domain specific functionality, and xarray includes
180-
methods for converting back and forth between xarray and these libraries. See
181-
:py:meth:`~xarray.DataArray.to_iris` and :py:meth:`~xarray.DataArray.to_cdms2`
182-
for more details.
173+
has some great domain specific functionality, and xarray includes
174+
methods for converting back and forth between xarray and Iris. See
175+
:py:meth:`~xarray.DataArray.to_iris` for more details.
183176

184177
What other projects leverage xarray?
185178
------------------------------------

doc/whats-new.rst

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ New Features
2929

3030
Breaking changes
3131
~~~~~~~~~~~~~~~~
32+
- drop support for `cdms2 <https://github.com/CDAT/cdms>`_. Please use
33+
`xcdat <https://github.com/xCDAT/xcdat>`_ instead (:pull:`8441`).
34+
By `Justus Magin <https://github.com/keewis`_.
3235

3336
- Bump minimum tested pint version to ``>=0.22``. By `Deepak Cherian <https://github.com/dcherian>`_.
3437

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ module = [
8888
"affine.*",
8989
"bottleneck.*",
9090
"cartopy.*",
91-
"cdms2.*",
9291
"cf_units.*",
9392
"cfgrib.*",
9493
"cftime.*",

xarray/convert.py

-88
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from collections import Counter
44

55
import numpy as np
6-
import pandas as pd
76

87
from xarray.coding.times import CFDatetimeCoder, CFTimedeltaCoder
98
from xarray.conventions import decode_cf
@@ -12,7 +11,6 @@
1211
from xarray.core.dtypes import get_fill_value
1312
from xarray.core.pycompat import array_type
1413

15-
cdms2_ignored_attrs = {"name", "tileIndex"}
1614
iris_forbidden_keys = {
1715
"standard_name",
1816
"long_name",
@@ -60,92 +58,6 @@ def _filter_attrs(attrs, ignored_attrs):
6058
return {k: v for k, v in attrs.items() if k not in ignored_attrs}
6159

6260

63-
def from_cdms2(variable):
64-
"""Convert a cdms2 variable into an DataArray"""
65-
values = np.asarray(variable)
66-
name = variable.id
67-
dims = variable.getAxisIds()
68-
coords = {}
69-
for axis in variable.getAxisList():
70-
coords[axis.id] = DataArray(
71-
np.asarray(axis),
72-
dims=[axis.id],
73-
attrs=_filter_attrs(axis.attributes, cdms2_ignored_attrs),
74-
)
75-
grid = variable.getGrid()
76-
if grid is not None:
77-
ids = [a.id for a in grid.getAxisList()]
78-
for axis in grid.getLongitude(), grid.getLatitude():
79-
if axis.id not in variable.getAxisIds():
80-
coords[axis.id] = DataArray(
81-
np.asarray(axis[:]),
82-
dims=ids,
83-
attrs=_filter_attrs(axis.attributes, cdms2_ignored_attrs),
84-
)
85-
attrs = _filter_attrs(variable.attributes, cdms2_ignored_attrs)
86-
dataarray = DataArray(values, dims=dims, coords=coords, name=name, attrs=attrs)
87-
return decode_cf(dataarray.to_dataset())[dataarray.name]
88-
89-
90-
def to_cdms2(dataarray, copy=True):
91-
"""Convert a DataArray into a cdms2 variable"""
92-
# we don't want cdms2 to be a hard dependency
93-
import cdms2
94-
95-
def set_cdms2_attrs(var, attrs):
96-
for k, v in attrs.items():
97-
setattr(var, k, v)
98-
99-
# 1D axes
100-
axes = []
101-
for dim in dataarray.dims:
102-
coord = encode(dataarray.coords[dim])
103-
axis = cdms2.createAxis(coord.values, id=dim)
104-
set_cdms2_attrs(axis, coord.attrs)
105-
axes.append(axis)
106-
107-
# Data
108-
var = encode(dataarray)
109-
cdms2_var = cdms2.createVariable(
110-
var.values, axes=axes, id=dataarray.name, mask=pd.isnull(var.values), copy=copy
111-
)
112-
113-
# Attributes
114-
set_cdms2_attrs(cdms2_var, var.attrs)
115-
116-
# Curvilinear and unstructured grids
117-
if dataarray.name not in dataarray.coords:
118-
cdms2_axes = {}
119-
for coord_name in set(dataarray.coords.keys()) - set(dataarray.dims):
120-
coord_array = dataarray.coords[coord_name].to_cdms2()
121-
122-
cdms2_axis_cls = (
123-
cdms2.coord.TransientAxis2D
124-
if coord_array.ndim
125-
else cdms2.auxcoord.TransientAuxAxis1D
126-
)
127-
cdms2_axis = cdms2_axis_cls(coord_array)
128-
if cdms2_axis.isLongitude():
129-
cdms2_axes["lon"] = cdms2_axis
130-
elif cdms2_axis.isLatitude():
131-
cdms2_axes["lat"] = cdms2_axis
132-
133-
if "lon" in cdms2_axes and "lat" in cdms2_axes:
134-
if len(cdms2_axes["lon"].shape) == 2:
135-
cdms2_grid = cdms2.hgrid.TransientCurveGrid(
136-
cdms2_axes["lat"], cdms2_axes["lon"]
137-
)
138-
else:
139-
cdms2_grid = cdms2.gengrid.AbstractGenericGrid(
140-
cdms2_axes["lat"], cdms2_axes["lon"]
141-
)
142-
for axis in cdms2_grid.getAxisList():
143-
cdms2_var.setAxis(cdms2_var.getAxisIds().index(axis.id), axis)
144-
cdms2_var.setGrid(cdms2_grid)
145-
146-
return cdms2_var
147-
148-
14961
def _pick_attrs(attrs, keys):
15062
"""Return attrs with keys in keys list"""
15163
return {k: v for k, v in attrs.items() if k in keys}

xarray/core/dataarray.py

-46
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
ReprObject,
5757
_default,
5858
either_dict_or_kwargs,
59-
emit_user_level_warning,
6059
)
6160
from xarray.core.variable import (
6261
IndexVariable,
@@ -81,10 +80,6 @@
8180
from dask.delayed import Delayed
8281
except ImportError:
8382
Delayed = None # type: ignore
84-
try:
85-
from cdms2 import Variable as cdms2_Variable
86-
except ImportError:
87-
cdms2_Variable = None
8883
try:
8984
from iris.cube import Cube as iris_Cube
9085
except ImportError:
@@ -4402,47 +4397,6 @@ def from_series(cls, series: pd.Series, sparse: bool = False) -> DataArray:
44024397
result.name = series.name
44034398
return result
44044399

4405-
def to_cdms2(self) -> cdms2_Variable:
4406-
"""Convert this array into a cdms2.Variable
4407-
4408-
.. deprecated:: 2023.06.0
4409-
The `cdms2`_ library has been deprecated. Please consider using the
4410-
`xcdat`_ library instead.
4411-
4412-
.. _cdms2: https://github.com/CDAT/cdms
4413-
.. _xcdat: https://github.com/xCDAT/xcdat
4414-
"""
4415-
from xarray.convert import to_cdms2
4416-
4417-
emit_user_level_warning(
4418-
"The cdms2 library has been deprecated."
4419-
" Please consider using the xcdat library instead.",
4420-
DeprecationWarning,
4421-
)
4422-
4423-
return to_cdms2(self)
4424-
4425-
@classmethod
4426-
def from_cdms2(cls, variable: cdms2_Variable) -> Self:
4427-
"""Convert a cdms2.Variable into an xarray.DataArray
4428-
4429-
.. deprecated:: 2023.06.0
4430-
The `cdms2`_ library has been deprecated. Please consider using the
4431-
`xcdat`_ library instead.
4432-
4433-
.. _cdms2: https://github.com/CDAT/cdms
4434-
.. _xcdat: https://github.com/xCDAT/xcdat
4435-
"""
4436-
from xarray.convert import from_cdms2
4437-
4438-
emit_user_level_warning(
4439-
"The cdms2 library has been deprecated."
4440-
" Please consider using the xcdat library instead.",
4441-
DeprecationWarning,
4442-
)
4443-
4444-
return from_cdms2(variable)
4445-
44464400
def to_iris(self) -> iris_Cube:
44474401
"""Convert this array into a iris.cube.Cube"""
44484402
from xarray.convert import to_iris

0 commit comments

Comments
 (0)