Skip to content

Commit

Permalink
use xarray's version of DataTree (#81)
Browse files Browse the repository at this point in the history
* stop depending on `xarray-datatree`

* don't install datatree in ci

* require at least `xarray>=2024.10.0`

* don't link to `datatree`'s documentation

* use `xarray`'s version of `DataTree`

* don't install `datatree` in the dev environment, either

* nor in the docs

* remove it from the docs

* allow using the upstream-dev install script locally
  • Loading branch information
keewis authored Oct 30, 2024
1 parent 33be447 commit 09d9437
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# xarray-ceos-alos2

Read ALOS2 CEOS files into `datatree` objects.
Read ALOS2 CEOS files into `xarray.DataTree` objects.

## Installation

Expand Down
8 changes: 3 additions & 5 deletions ceos_alos2/tests/test_xarray.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import datatree
import datatree.testing
import numpy as np
import pytest
import xarray as xr
Expand Down Expand Up @@ -168,7 +166,7 @@ def test_to_dataset(group, chunks, expected):
},
attrs={"coordinates": ["d"]},
),
datatree.DataTree.from_dict(
xr.DataTree.from_dict(
{
"/": xr.Dataset(
{"c": ("x", [1, 2, 3], {"a": 1})},
Expand All @@ -193,7 +191,7 @@ def test_to_dataset(group, chunks, expected):
},
attrs={},
),
datatree.DataTree.from_dict(
xr.DataTree.from_dict(
{
"/": xr.Dataset({"c": ("x", [1, 2, 3], {"a": 1})}),
"d": xr.Dataset({"e": (["x", "y"], np.arange(12).reshape(3, 4), {"b": "abc"})}),
Expand All @@ -206,4 +204,4 @@ def test_to_dataset(group, chunks, expected):
def test_to_datatree(group, chunks, expected):
actual = xarray.to_datatree(group, chunks=chunks)

datatree.testing.assert_identical(actual, expected)
xr.testing.assert_identical(actual, expected)
5 changes: 2 additions & 3 deletions ceos_alos2/xarray.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import datatree
import numpy as np
import numpy.typing
import xarray as xr
Expand Down Expand Up @@ -76,7 +75,7 @@ def to_datatree(group, chunks=None):
mapping = {"/": to_dataset(group, chunks=chunks)} | {
path: to_dataset(subgroup, chunks=chunks) for path, subgroup in group.subtree
}
return datatree.DataTree.from_dict(mapping)
return xr.DataTree.from_dict(mapping)


def open_alos2(path, chunks=None, backend_options={}):
Expand Down Expand Up @@ -107,7 +106,7 @@ def open_alos2(path, chunks=None, backend_options={}):
Returns
-------
tree : datatree.DataTree
tree : xarray.DataTree
The newly created datatree.
"""
root = io.open(path, **backend_options)
Expand Down
10 changes: 8 additions & 2 deletions ci/install-upstream-dev.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/usr/bin/env bash

conda remove -y --force cytoolz numpy xarray construct toolz xarray-datatree fsspec python-dateutil pandas
if command -v micromamba >/dev/null; then
conda=micromamba
elif command -v mamba >/dev/null; then
conda=mamba
else
conda=conda
fi
conda remove -y --force cytoolz numpy xarray construct toolz fsspec python-dateutil pandas
python -m pip install \
-i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple \
--no-deps \
Expand All @@ -12,6 +19,5 @@ python -m pip install \
python -m pip install --upgrade \
git+https://github.com/construct/construct \
git+https://github.com/pytoolz/toolz \
git+https://github.com/xarray-contrib/datatree \
git+https://github.com/fsspec/filesystem_spec \
git+https://github.com/dateutil/dateutil
3 changes: 1 addition & 2 deletions ci/requirements/environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ dependencies:
- python-dateutil
- construct
- fsspec
- xarray
- xarray-datatree
- xarray>=2024.10.0
- dask
- distributed
- aiohttp
Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
"python": ("https://docs.python.org/3/", None),
"sphinx": ("https://www.sphinx-doc.org/en/stable/", None),
"xarray": ("https://docs.xarray.dev/en/latest/", None),
"datatree": ("https://xarray-datatree.readthedocs.io/en/latest/", None),
}


Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# xarray-ceos-alos2

`xarray-ceos-alos2` allows reading CEOS ALOS2 datasets (for now, level 1.1, 1.5, and 3.1 only) into [datatree](https://github.com/xarray-contrib/datatree) objects.
`xarray-ceos-alos2` allows reading CEOS ALOS2 datasets (for now, level 1.1, 1.5, and 3.1 only) into {py:class}`xarray.DataTree` objects.

**Contents**:

Expand Down
3 changes: 1 addition & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ cytoolz
python-dateutil
construct
fsspec
xarray
xarray-datatree
xarray>=2024.10.0
platformdirs
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ readme = "README.md"
dependencies = [
"toolz",
"python-dateutil",
"xarray",
"xarray-datatree",
"xarray>=2024.10.0",
"numpy",
"construct>=2.10",
"fsspec",
Expand Down

0 comments on commit 09d9437

Please sign in to comment.