Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions xbout/geometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,15 @@ def apply_geometry(ds, geometry_name, *, coordinates=None, grid=None):
ycoord = updated_ds.metadata["bout_ydim"]
zcoord = updated_ds.metadata["bout_zdim"]

if (tcoord not in updated_ds.coords) and (tcoord in updated_ds.dims):
if "t_array" in updated_ds:
# Always use t_array as the ground truth for the time coordinate

# Create the time coordinate from t_array
# Slightly odd looking way to create coordinate ensures 'index variable' is
# created, which using set_coords() does not (possible xarray bug?
# https://github.com/pydata/xarray/issues/4417
updated_ds[tcoord] = updated_ds["t_array"]
if tcoord in updated_ds.dims:
updated_ds[tcoord] = updated_ds["t_array"]
updated_ds = updated_ds.drop_vars("t_array")

if xcoord not in updated_ds.coords:
Expand Down
6 changes: 1 addition & 5 deletions xbout/lazyload.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,5 @@ def lazy_open_boutdataset(
f"Variable '{name}' has only one of x/y dimensions and will be skipped"
)

coords = {}
if "t_array" in ds:
coords["t"] = ds["t_array"].values

# Create a global dataset
return xr.Dataset(data_vars, coords=coords, attrs={"metadata": metadata})
return xr.Dataset(data_vars, attrs={"metadata": metadata})
Loading