Skip to content

Commit 0761754

Browse files
authored
Merge pull request #303 from boutproject/xarray-2024-07
Update to xarray 2023.1.0
2 parents d113e0e + 609c784 commit 0761754

File tree

12 files changed

+273
-295
lines changed

12 files changed

+273
-295
lines changed

.github/workflows/master.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
if: always()
2121
strategy:
2222
matrix:
23-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.x"]
23+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
2424
fail-fast: false
2525

2626
steps:
@@ -61,7 +61,7 @@ jobs:
6161
run: |
6262
sudo apt-get update && sudo apt-get install libhdf5-dev libnetcdf-dev
6363
python -m pip install --upgrade pip
64-
pip install xarray~=0.18.0 pandas~=1.4.0
64+
pip install xarray~=2023.1.0 pandas~=1.4.0
6565
- name: Install package
6666
run: |
6767
pip install -e .[tests]

.github/workflows/pythonpackage.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ jobs:
3131
python-version: ${{ matrix.python-version }}
3232
- name: Install dependencies
3333
run: |
34-
sudo apt-get update && sudo apt-get install libhdf5-dev libnetcdf-dev
3534
python -m pip install --upgrade pip
3635
- name: Install package
3736
run: |
@@ -59,9 +58,8 @@ jobs:
5958
python-version: ${{ matrix.python-version }}
6059
- name: Install dependencies
6160
run: |
62-
sudo apt-get update && sudo apt-get install libhdf5-dev libnetcdf-dev
6361
python -m pip install --upgrade pip
64-
pip install xarray~=0.18.0 pandas~=1.4.0
62+
pip install xarray~=2023.1.0 pandas~=1.4.0
6563
- name: Install package
6664
run: |
6765
pip install -e .[tests]

.github/workflows/ruff.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ jobs:
55
dependency-review:
66
runs-on: ubuntu-latest
77
steps:
8-
- uses: actions/checkout@v3
9-
- uses: actions/setup-python@v4
8+
- uses: actions/checkout@v4
9+
- uses: actions/setup-python@v5
1010
with:
1111
python-version: '3.x'
1212
- name: Install ruff
1313
run: pip install ruff
1414
- name: Run ruff
15-
run: ruff xbout
15+
run: ruff check xbout

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ classifiers = [
3333
]
3434
requires-python = ">=3.8"
3535
dependencies = [
36-
"xarray>=0.18.0,<2022.9.0",
36+
"xarray>=2023.01.0",
3737
"boutdata>=0.1.4",
3838
"dask[array]>=2.10.0",
3939
"gelidum>=0.5.3",
@@ -82,5 +82,5 @@ write_to = "xbout/_version.py"
8282
[tool.setuptools]
8383
packages = ["xbout"]
8484

85-
[tool.ruff]
85+
[tool.ruff.lint]
8686
ignore = ["E501"]

xbout/boutdataset.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -597,12 +597,12 @@ def interpolate_to_cartesian(
597597
n_toroidal = ds.sizes[zdim]
598598

599599
# Create Cartesian grid to interpolate to
600-
Xmin = ds["X_cartesian"].min()
601-
Xmax = ds["X_cartesian"].max()
602-
Ymin = ds["Y_cartesian"].min()
603-
Ymax = ds["Y_cartesian"].max()
604-
Zmin = ds["Z_cartesian"].min()
605-
Zmax = ds["Z_cartesian"].max()
600+
Xmin = ds["X_cartesian"].min().data[()]
601+
Xmax = ds["X_cartesian"].max().data[()]
602+
Ymin = ds["Y_cartesian"].min().data[()]
603+
Ymax = ds["Y_cartesian"].max().data[()]
604+
Zmin = ds["Z_cartesian"].min().data[()]
605+
Zmax = ds["Z_cartesian"].max().data[()]
606606
newX_1d = xr.DataArray(np.linspace(Xmin, Xmax, nX), dims="X")
607607
newX = newX_1d.expand_dims({"Y": nY, "Z": nZ}, axis=[1, 2])
608608
newY_1d = xr.DataArray(np.linspace(Ymin, Ymax, nY), dims="Y")

xbout/geometries.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
_set_attrs_on_all_vars,
1111
_set_as_coord,
1212
_1d_coord_from_spacing,
13+
_maybe_rename_dimension,
1314
)
1415

1516
REGISTERED_GEOMETRIES = {}
@@ -144,7 +145,7 @@ def apply_geometry(ds, geometry_name, *, coordinates=None, grid=None):
144145
# 'dx' may not be consistent between different regions (e.g. core and PFR).
145146
# For some geometries xcoord may have already been created by
146147
# add_geometry_coords, in which case we do not need this.
147-
nx = updated_ds.dims[xcoord]
148+
nx = updated_ds.sizes[xcoord]
148149

149150
# can't use commented out version, uncommented one works around xarray bug
150151
# removing attrs
@@ -181,7 +182,7 @@ def apply_geometry(ds, geometry_name, *, coordinates=None, grid=None):
181182
if zcoord in updated_ds.dims and zcoord not in updated_ds.coords:
182183
# Generates a coordinate whose value is 0 on the first grid point, not dz/2, to
183184
# match how BOUT++ generates fields from input file expressions.
184-
nz = updated_ds.dims[zcoord]
185+
nz = updated_ds.sizes[zcoord]
185186

186187
# In BOUT++ v5, dz is either a Field2D or Field3D.
187188
# We can use it as a 1D coordinate if it's a Field3D, _or_ if nz == 1
@@ -213,7 +214,7 @@ def apply_geometry(ds, geometry_name, *, coordinates=None, grid=None):
213214
dz = updated_ds["dz"]
214215

215216
z0 = 2 * np.pi * updated_ds.metadata["ZMIN"]
216-
z1 = z0 + nz * dz
217+
z1 = z0 + nz * dz.data[()]
217218
if not np.all(
218219
np.isclose(
219220
z1,
@@ -392,12 +393,12 @@ def add_toroidal_geometry_coords(ds, *, coordinates=None, grid=None):
392393
],
393394
)
394395

395-
if "t" in ds.dims:
396+
if coordinates["t"] != "t":
396397
# Rename 't' if user requested it
397-
ds = ds.rename(t=coordinates["t"])
398+
ds = _maybe_rename_dimension(ds, "t", coordinates["t"])
398399

399400
# Change names of dimensions to Orthogonal Toroidal ones
400-
ds = ds.rename(y=coordinates["y"])
401+
ds = _maybe_rename_dimension(ds, "y", coordinates["y"])
401402

402403
# TODO automatically make this coordinate 1D in simplified cases?
403404
ds = ds.rename(psixy=coordinates["x"])
@@ -413,7 +414,7 @@ def add_toroidal_geometry_coords(ds, *, coordinates=None, grid=None):
413414

414415
# If full data (not just grid file) then toroidal dim will be present
415416
if "z" in ds.dims:
416-
ds = ds.rename(z=coordinates["z"])
417+
ds = _maybe_rename_dimension(ds, "z", coordinates["z"])
417418

418419
# Record which dimension 'z' was renamed to.
419420
ds.metadata["bout_zdim"] = coordinates["z"]
@@ -505,7 +506,7 @@ def add_s_alpha_geometry_coords(ds, *, coordinates=None, grid=None):
505506
ds["r"] = ds["hthe"].isel({ycoord: 0}).squeeze(drop=True)
506507
ds["r"].attrs["units"] = "m"
507508
ds = ds.set_coords("r")
508-
ds = ds.rename(x="r")
509+
ds = ds.swap_dims(x="r")
509510
ds.metadata["bout_xdim"] = "r"
510511

511512
if hthe_from_grid:

0 commit comments

Comments
 (0)