Skip to content

Commit 836ba17

Browse files
authored
Merge pull request #346 from boutproject/remove-t_array
Remove t_array to prevent duplicate times in dataset
2 parents 8cfdf2d + 051d189 commit 836ba17

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

xbout/geometries.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,15 @@ def apply_geometry(ds, geometry_name, *, coordinates=None, grid=None):
127127
ycoord = updated_ds.metadata["bout_ydim"]
128128
zcoord = updated_ds.metadata["bout_zdim"]
129129

130-
if (tcoord not in updated_ds.coords) and (tcoord in updated_ds.dims):
130+
if "t_array" in updated_ds:
131+
# Always use t_array as the ground truth for the time coordinate
132+
131133
# Create the time coordinate from t_array
132134
# Slightly odd looking way to create coordinate ensures 'index variable' is
133135
# created, which using set_coords() does not (possible xarray bug?
134136
# https://github.com/pydata/xarray/issues/4417
135-
updated_ds[tcoord] = updated_ds["t_array"]
137+
if tcoord in updated_ds.dims:
138+
updated_ds[tcoord] = updated_ds["t_array"]
136139
updated_ds = updated_ds.drop_vars("t_array")
137140

138141
if xcoord not in updated_ds.coords:

xbout/lazyload.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,5 @@ def lazy_open_boutdataset(
360360
f"Variable '{name}' has only one of x/y dimensions and will be skipped"
361361
)
362362

363-
coords = {}
364-
if "t_array" in ds:
365-
coords["t"] = ds["t_array"].values
366-
367363
# Create a global dataset
368-
return xr.Dataset(data_vars, coords=coords, attrs={"metadata": metadata})
364+
return xr.Dataset(data_vars, attrs={"metadata": metadata})

0 commit comments

Comments
 (0)