Skip to content

Commit a91056f

Browse files
committed
Avoid deprecated use of dataset.dims
1 parent d8b79ee commit a91056f

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

examples/tutorial/blob2d.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
"outputs": [],
199199
"source": [
200200
"# dz is a scalar, so gets stored in 'metadata'\n",
201-
"dz = xr.DataArray(ds.metadata['dz']).expand_dims({'z': ds.dims['z']})\n",
201+
"dz = xr.DataArray(ds.metadata['dz']).expand_dims({'z': ds.sizes['z']})\n",
202202
"z = dz.cumsum(dim='z')\n",
203203
"ds = ds.assign_coords({'z': z})\n",
204204
"\n",

xbout/geometries.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def apply_geometry(ds, geometry_name, *, coordinates=None, grid=None):
144144
# 'dx' may not be consistent between different regions (e.g. core and PFR).
145145
# For some geometries xcoord may have already been created by
146146
# add_geometry_coords, in which case we do not need this.
147-
nx = updated_ds.dims[xcoord]
147+
nx = updated_ds.sizes[xcoord]
148148

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

186186
# In BOUT++ v5, dz is either a Field2D or Field3D.
187187
# We can use it as a 1D coordinate if it's a Field3D, _or_ if nz == 1

xbout/load.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,10 +810,10 @@ def get_nonnegative_scalar(ds, key, default=1, info=True):
810810
mxg = get_nonnegative_scalar(ds, "MXG", default=2, info=info)
811811
myg = get_nonnegative_scalar(ds, "MYG", default=0, info=info)
812812
mxsub = get_nonnegative_scalar(
813-
ds, "MXSUB", default=ds.dims["x"] - 2 * mxg, info=info
813+
ds, "MXSUB", default=ds.sizes["x"] - 2 * mxg, info=info
814814
)
815815
mysub = get_nonnegative_scalar(
816-
ds, "MYSUB", default=ds.dims["y"] - 2 * myg, info=info
816+
ds, "MYSUB", default=ds.sizes["y"] - 2 * myg, info=info
817817
)
818818

819819
# Check whether this is a single file squashed from the multiple output files of a
@@ -828,8 +828,8 @@ def get_nonnegative_scalar(ds, key, default=1, info=True):
828828
else:
829829
# Workaround for older data files
830830
ny = ds["MYSUB"].values * ds["NYPE"].values
831-
nx_file = ds.dims["x"]
832-
ny_file = ds.dims["y"]
831+
nx_file = ds.sizes["x"]
832+
ny_file = ds.sizes["y"]
833833
is_squashed_doublenull = False
834834
if nxpe > 1 or nype > 1:
835835
# if nxpe = nype = 1, was only one process anyway, so no need to check for

0 commit comments

Comments
 (0)