Skip to content

Can't exchange UGRID data between Iris and xarray #259

Description

@pp-mo

In the past, with xarray < v2026.02.0, the way that ncdata exchanges data with xarray was permitting us to freely pass UGRID data from iris to xarray, and get it back again.
Unfortunately this no longer works : cf failures with more recent versions of xarray (and Iris)

For the sake of quickly resolving the CI tests, I chose to simply exclude unstructured testfiles from the iris-xarray-iris roundtrip tests.

However, if this is an important problem for some users, then we should aim to fix it.

Status for now:

We will not fix this, unless users indicate that this usage is needed + wanted

Points to note:

  • the problem emerges when trying to load data from xarray into Iris
  • it was never possible to load UGRID data with xarray and pass it to Iris (with successful creation of a mesh),
    but previously it was possible to pass Iris mesh data out to xarray and back again
  • the mechanism by which this works used to be that,
    when an xarray dataset is created with ncdata.xarray._XarrayNcDataStore.load ...
    .. the iris-style masked integer arrays in connectivity variables, are "smuggled" into xarray (which wouldn't normally contain masked arrays) by direct copying into the xarray objects, and likewise retrieved directly when converted back to Iris.
    it's worth saying that this was always rather questionable -- since xarray does not expect to contain masked data.
    the fact that this 'stopped working' is not a huge surprise, but it does account for the new difficulty.

How might we fix this, if required ?

  • probably simplest : allow Iris to accept non-integer data in connectivities, and/or convert it "automatically"
  • -or- there may still be a way to "smuggle" masked arrays into xarray loading, but it's not known if this is possible : At any rate, I have tried simply adding mask_and_scale=False, and that does not fix the problem.
  • -or- make specific allowance in ncdata to transform nan-data to masked, specifically when translating xarray to iris (or possibly ncdata to iris).
    But this is awkward as the translation would ideally only be applied to connectivity data-arrays, and recognising that context is rather wildly out-of-scope for ncdata
  • -and/or- add a ncdata-specific data marking mechanism, akin to the xarray ".encoding" properties, so that ncdata can automatically adjust round-tripped data (specifically) back to an 'original' array form

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions