Skip to content

Lazy load time coordinate bug #344

Description

@mikekryjak

The new lazy loader assigns a time coordinate:

xBOUT/xbout/lazyload.py

Lines 363 to 365 in e4f23d5

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

This is not needed unless you have to use the lazy loaded dataset independently from everyone else, because the time coordinate is set up in apply_geometry:

xBOUT/xbout/geometries.py

Lines 130 to 136 in e4f23d5

if (tcoord not in updated_ds.coords) and (tcoord in updated_ds.dims):
# 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"]
updated_ds = updated_ds.drop_vars("t_array")

Unfortunately, the way it's been assigned links the t_array data and the t coordinate, so changing one means the other is also changed (I know, setting it to .values makes it seem like this shouldn't happen, but... Xarray). Now, xHermes unnormalises both t_array as a data variable and t as a coordinate:
https://github.com/boutproject/xhermes/blob/5588fbd0ceb2ec98344cd1752f2acf69c25055e6/xhermes/accessors.py#L42-L48

Since the assignment in the lazy loader makes them linked, t gets unnormalised twice and the time coordinate is all wrong, which causes the drift-wave test to fail: boutproject/hermes-3#546

@bendudson do you need that time coordinate assignment there or can I remove it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions