Skip to content

Commit

Permalink
Import DataTree from xarray (#218)
Browse files Browse the repository at this point in the history
* use datatree from xarray
* fix docstrings
* fix tests
* fix notebooks
* add history.md entry
---------
Co-authored-by: aladinor <[email protected]>
  • Loading branch information
kmuehlbauer authored Oct 28, 2024
1 parent bbac0d6 commit 617bd34
Show file tree
Hide file tree
Showing 37 changed files with 293 additions and 796 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: xarray-nightly
fetch-depth: 0
- name: Install micromamba environment
uses: mamba-org/setup-micromamba@v1
Expand Down Expand Up @@ -173,19 +172,19 @@ jobs:
xmltodict
numpy=${{matrix.numpy-version}}
conda
- name: Install xradar
run: |
python -m pip install --no-deps .
- name: Install xarray
run: |
python -m pip install --no-deps --ignore-installed --no-cache-dir -vvv \
git+https://github.com/pydata/xarray.git@main
- name: Install xradar
run: |
python -m pip install --no-deps .
- name: Version Info
run: |
python -c "import xradar; print(xradar.version.version)"
- name: Test with pytest
run: |
pytest -n auto --dist loadfile --verbose --durations=15 --pyargs tests
pytest -n auto --dist loadscope --verbose --durations=15 --pyargs tests
test_build_distribution_testpypi:
name: test build distribution for testpypi
Expand Down
3 changes: 1 addition & 2 deletions ci/notebooktests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ dependencies:
- pytest-xdist
- scipy
- setuptools
- xarray<=2024.9.0
- xarray-datatree>=0.0.10
- xarray>=2024.10.0
- xmltodict
- boto3
- arm_pyart
Expand Down
3 changes: 1 addition & 2 deletions ci/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ dependencies:
- pytest-xdist
- scipy
- setuptools
- xarray<=2024.9.0
- xarray-datatree>=0.0.10
- xarray>=2024.10.0
- xmltodict
6 changes: 6 additions & 0 deletions docs/history.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# History

## 0.8.0 (2024-10-28)

This is the first version which uses datatree directly from xarray. Thus, xarray is pinned to version >= 2024.10.0.

* Use DataTree from xarray and add xarray nightly run ({pull}`213`, {pull}`214`, {pull}`215`, {pull}`218`) by [@kmuehlbauer](https://github.com/kmuehlbauer).

## 0.7.0 (2024-10-26)

This is the last version which uses datatree from xarray-contrib/datatree. Thus, xarray is pinned to version 2024.9.0.
Expand Down
5 changes: 2 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- conda-forge
- nodefaults
dependencies:
- python >=3.9,<3.12
- python >=3.10,<3.13
- pydata-sphinx-theme
- pip
- myst-parser
Expand All @@ -18,8 +18,7 @@ dependencies:
- netCDF4
- open-radar-data>=0.1.0
- pyproj
- xarray<=2024.9.0
- xarray-datatree>=0.0.10
- xarray>=2024.10.0
- xmltodict
- cartopy
- cmweather
Expand Down
9 changes: 5 additions & 4 deletions examples/notebooks/CfRadial1_Export.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"outputs": [],
"source": [
"import cmweather # noqa\n",
"import datatree as xt\n",
"import xarray as xr\n",
"from open_radar_data import DATASETS\n",
"\n",
"import xradar as xd"
Expand Down Expand Up @@ -138,7 +138,8 @@
"outputs": [],
"source": [
"def ref_filter(dtree, sweep=\"sweep_0\", field=\"DBZ\"):\n",
" ds = dtree[sweep].where((dtree[sweep][field] >= -10) & (dtree[sweep][field] <= 70))\n",
" ds = dtree[sweep].ds\n",
" ds = ds.where((ds[field] >= -10) & (ds[field] <= 70))\n",
" red_patch = ds.where(\n",
" (\n",
" (ds[field] >= ds[field].max().values - 0.5)\n",
Expand Down Expand Up @@ -189,13 +190,13 @@
"outputs": [],
"source": [
"# Initialize an empty DataTree\n",
"result_tree = xt.DataTree()\n",
"result_tree = xr.DataTree()\n",
"\n",
"for sweep in radar.sweep_group_name.values:\n",
" corrected_data = ref_filter(radar, sweep, field=\"DBZ\")\n",
"\n",
" # Convert the xarray Dataset to a DataTree and add it to the result_tree\n",
" data_tree = xt.DataTree.from_dict(corrected_data.to_dict())\n",
" data_tree = xr.DataTree.from_dict(corrected_data.to_dict())\n",
"\n",
" # Copy the contents of data_tree into result_tree\n",
" for key, value in data_tree.items():\n",
Expand Down
5 changes: 2 additions & 3 deletions examples/notebooks/CfRadial1_Model_Transformation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"source": [
"import os\n",
"\n",
"import datatree as xt\n",
"import xarray as xr\n",
"from open_radar_data import DATASETS\n",
"\n",
Expand Down Expand Up @@ -474,7 +473,7 @@
"metadata": {},
"outputs": [],
"source": [
"dtree2 = xt.open_datatree(outfile)\n",
"dtree2 = xr.open_datatree(outfile)\n",
"with xr.set_options(display_expand_data_vars=True, display_expand_attrs=True):\n",
" display(dtree2)"
]
Expand Down Expand Up @@ -539,7 +538,7 @@
"metadata": {},
"outputs": [],
"source": [
"dtree4 = xt.open_datatree(\"test_cfradial2.nc\")\n",
"dtree4 = xr.open_datatree(\"test_cfradial2.nc\")\n",
"with xr.set_options(display_expand_data_vars=True, display_expand_attrs=True):\n",
" display(dtree4)"
]
Expand Down
2 changes: 1 addition & 1 deletion examples/notebooks/HaloPhotonics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"source": [
"fig, ax = plt.subplots(3, 3, figsize=(12, 10))\n",
"for sweep in range(9):\n",
" sweep_ds = xd.georeference.get_x_y_z(ds[\"sweep_%d\" % sweep])\n",
" sweep_ds = xd.georeference.get_x_y_z(ds[\"sweep_%d\" % sweep].ds)\n",
" sweep_ds = sweep_ds.set_coords([\"x\", \"y\", \"z\", \"time\", \"range\"])\n",
" sweep_ds[\"mean_doppler_velocity\"].plot(\n",
" x=\"x\", y=\"y\", ax=ax[int(sweep / 3), sweep % 3]\n",
Expand Down
Loading

0 comments on commit 617bd34

Please sign in to comment.