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

Update to xarray 2024.7.0 #303

Merged
merged 27 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a39b729
Use .values to convert DataArray to scalar before storing in Region
johnomotani Jan 20, 2023
8422b9b
Fix warnings about not creating indexes when using .rename()
johnomotani Jan 20, 2023
089000a
Fix updating of indexes when adding guard cells in region.py
johnomotani Jan 20, 2023
e91fec0
Set minimum xarray version to 2024.07.0
bendudson Oct 29, 2024
2d11a6f
Fix Dataset.dims FutureWarning
bendudson Oct 29, 2024
f925dba
Simplify and speed up open_mfdataset
bendudson Oct 29, 2024
1697ded
Use xarray.open_mfdataset with better options
bendudson Oct 29, 2024
c0977d2
Minor fixes
bendudson Oct 29, 2024
94b4545
flake8 fixes
bendudson Oct 29, 2024
730ca6b
Work on tests
bendudson Oct 29, 2024
04fe5d1
test_load: remove test_trim_timing_info
bendudson Oct 29, 2024
1b9608a
test_animate: Skip test_animate_list_1d_multiline
bendudson Oct 29, 2024
b98d4fa
black formatting
bendudson Oct 29, 2024
b6c11d3
Merge branch 'master' into xarray-2024-07
bendudson Oct 30, 2024
b2c5eb8
geometries: Fix FutureWarning
bendudson Oct 30, 2024
4a422fd
Github Actions: Drop testing python 3.8
bendudson Oct 30, 2024
658cd4f
Apply black formatting
bendudson Oct 30, 2024
4cae8ea
Restore support for python 3.8
bendudson Oct 30, 2024
b5398ad
Remove test_load::test_trim_timing_info
bendudson Oct 30, 2024
bbeb492
Apply black formatting
bendudson Oct 30, 2024
54f8375
github actions update xarray version
bendudson Oct 30, 2024
0615058
Ensure arguments to `np.linspace` are simple floats
ZedThree Oct 30, 2024
9da499f
CI: Run on 3.12 and not 3.13 due to bug in `TestSave`
ZedThree Oct 30, 2024
8a2f8df
CI: Fix ruff check
ZedThree Oct 30, 2024
1abb17f
Fix some ruff warnings
ZedThree Oct 30, 2024
febb3a2
test_animate: Remove unneeded comment
bendudson Oct 30, 2024
609c784
CI: Don't install packages from apt
ZedThree Nov 7, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
if: always()
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.x"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
fail-fast: false

steps:
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
run: |
sudo apt-get update && sudo apt-get install libhdf5-dev libnetcdf-dev
python -m pip install --upgrade pip
pip install xarray~=0.18.0 pandas~=1.4.0
pip install xarray~=2023.1.0 pandas~=1.4.0
- name: Install package
run: |
pip install -e .[tests]
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get install libhdf5-dev libnetcdf-dev
python -m pip install --upgrade pip
- name: Install package
run: |
Expand Down Expand Up @@ -59,9 +58,8 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get install libhdf5-dev libnetcdf-dev
python -m pip install --upgrade pip
pip install xarray~=0.18.0 pandas~=1.4.0
pip install xarray~=2023.1.0 pandas~=1.4.0
- name: Install package
run: |
pip install -e .[tests]
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ruff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install ruff
run: pip install ruff
- name: Run ruff
run: ruff xbout
run: ruff check xbout
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ classifiers = [
]
requires-python = ">=3.8"
dependencies = [
"xarray>=0.18.0,<2022.9.0",
"xarray>=2023.01.0",
"boutdata>=0.1.4",
"dask[array]>=2.10.0",
"gelidum>=0.5.3",
Expand Down Expand Up @@ -79,5 +79,5 @@ write_to = "xbout/_version.py"
[tool.setuptools]
packages = ["xbout"]

[tool.ruff]
[tool.ruff.lint]
ignore = ["E501"]
12 changes: 6 additions & 6 deletions xbout/boutdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,12 +597,12 @@ def interpolate_to_cartesian(
n_toroidal = ds.sizes[zdim]

# Create Cartesian grid to interpolate to
Xmin = ds["X_cartesian"].min()
Xmax = ds["X_cartesian"].max()
Ymin = ds["Y_cartesian"].min()
Ymax = ds["Y_cartesian"].max()
Zmin = ds["Z_cartesian"].min()
Zmax = ds["Z_cartesian"].max()
Xmin = ds["X_cartesian"].min().data[()]
Xmax = ds["X_cartesian"].max().data[()]
Ymin = ds["Y_cartesian"].min().data[()]
Ymax = ds["Y_cartesian"].max().data[()]
Zmin = ds["Z_cartesian"].min().data[()]
Zmax = ds["Z_cartesian"].max().data[()]
newX_1d = xr.DataArray(np.linspace(Xmin, Xmax, nX), dims="X")
newX = newX_1d.expand_dims({"Y": nY, "Z": nZ}, axis=[1, 2])
newY_1d = xr.DataArray(np.linspace(Ymin, Ymax, nY), dims="Y")
Expand Down
17 changes: 9 additions & 8 deletions xbout/geometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
_set_attrs_on_all_vars,
_set_as_coord,
_1d_coord_from_spacing,
_maybe_rename_dimension,
)

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

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

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

z0 = 2 * np.pi * updated_ds.metadata["ZMIN"]
z1 = z0 + nz * dz
z1 = z0 + nz * dz.data[()]
if not np.all(
np.isclose(
z1,
Expand Down Expand Up @@ -392,12 +393,12 @@ def add_toroidal_geometry_coords(ds, *, coordinates=None, grid=None):
],
)

if "t" in ds.dims:
if coordinates["t"] != "t":
# Rename 't' if user requested it
ds = ds.rename(t=coordinates["t"])
ds = _maybe_rename_dimension(ds, "t", coordinates["t"])

# Change names of dimensions to Orthogonal Toroidal ones
ds = ds.rename(y=coordinates["y"])
ds = _maybe_rename_dimension(ds, "y", coordinates["y"])

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

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

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

if hthe_from_grid:
Expand Down
Loading
Loading