-
Notifications
You must be signed in to change notification settings - Fork 10
Xarray's explicit indexes #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
More notes: These explicit indexes are currently insufficiently mature (e.g. tries to convert to PandasIndex now when accessing via
Without changes to the explicit indexes:
The largest benefit is that it's a good deal simpler. No need to juggle between xarray <-> xugrid types. No need to forward calls, which still feels a bit haphazard to me as it currently stands. Also no custom type which trip up checks in other packages that do understand xarray objects. |
Alternatively, maybe a topology and its data should be grouped together in a completely different way, see: https://xarray-datatree.readthedocs.io/en/latest/ This also has a similar drawback, which is that the API looks quite different when working with unstructured viz a viz structured data, which I'd really like to avoid. |
I think you can handle this in
The same problem exists with handling CF style bounds arrays and |
Yes, I think so too now. That would be a very comfortable solution.
Ah, right -- that's good news! Ideally, the same index could be associated with all three dimensions somehow (... I think). I think that's the only exceptional part of the UGRID topology versus the other uses of the explicit indexes. I'm itching to find out what this entails, hopefully I can free up some time to investigate. |
This is already possible with Datasets today. In https://github.com/dcherian/xindexes/blob/main/crsindex.ipynb, CRSIndex is associated with the |
For examples, see:
https://github.com/martinfleis/xvec
https://github.com/dcherian/crsindex/blob/main/crsindex.ipynb
They can be set with:
https://docs.xarray.dev/en/stable/generated/xarray.DataArray.set_xindex.html
One issue is that in the UGRID conventions, the connectivity arrays are 2D. So the first dimension matches whatever's going on in the data (node, edge, face), but the second doesn't. This can be avoided with a trick using numpy structured arrays:
This feels like a hack, and doesn't seem like a serious option.
An alternative approach is perhaps using a Pandas ExtensionArray. This seems like a lot of work: https://stackoverflow.com/questions/68893521/simple-example-of-pandas-extensionarray
Next, we can define a UgridIndex:
This seems to do the trick:
Now we could start adding methods to the Ugrid2dIndex and make it possible to select values with
sel
. Or alternatively provide other operations via a.ugrid
accessor.However, it doesn't solve all problems that we encounter with UGRID topologies (?):
.ugrid.sel
and.ugrid.isel
instead.)I think the fundamental question is whether a UgridDataset is properly considered as an xarray Dataset: I don't think so, as it breaks a premise of fully separated, orthogonal dimensions. From that perspective, it may be better to accept this, and special case the UGRID topology dimensions.
The text was updated successfully, but these errors were encountered: