diff --git a/xbout/geometries.py b/xbout/geometries.py index 35c541ea..9493fde8 100644 --- a/xbout/geometries.py +++ b/xbout/geometries.py @@ -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: diff --git a/xbout/lazyload.py b/xbout/lazyload.py index aeb59940..e4c53630 100644 --- a/xbout/lazyload.py +++ b/xbout/lazyload.py @@ -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})