Skip to content

KeyError: "no index found for coordinate 'layer'" #515

@vincentpost

Description

@vincentpost

When running nlmod.to_model_ds(...) the following error occurs when xarray version 2025.4.0 is installed: KeyError: "no index found for coordinate 'layer'" The error does not occur with xarray version 2024.6.0. The error is thrown by the remove_inactive_layers method

ds = ds.sel(layer=(idomain > 0).any(idomain.dims[1:]))

but the cause lies somewhere else. I traced it down to the interp method used here:

ds_out = ds_in.interp(

Somewhere between xarray versions 2024.6.0 and 2025.4.0 the behaviour of this method must have changed: In the newer xarray version 'layer' is dropped from the DataSet's indexes attribute (causing the KeyError later down the track in remove_inactive_layers), in the older version it remains preserved.

Has anyone seen this before? Not sure what the best solution is (other than using an older xarray version).

Thanks,
Vincent

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions