-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Extend xarray with custom "coordinate wrappers" #1961
Comments
As an example, in >>> ds = ds_original.xgcm.generate(...)
>>> ds.xgcm.interp(‘var’, axis=‘X’) instead of >>> ds = xgcm.generate_grid_ds(ds_original, ...)
>>> grid = xgcm.Grid(ds)
>>> grid.interp(ds.var, axis=‘X’) The advantage in the first example is that the information on the grid’s physical axes is bound to a @rabernat I don't have much experience with I guess we could just use Dataset attributes and/or private instance attributes in the Dataset accessor class for that, but
|
This has some similarity to what we would need for a What would the proposed interface be here? |
I guess the common pattern for "coordinate wrappers"/"indexes" looks like:
Possible future features for coordinate wrappers:
I'm open to other names, but my inclination would be to still call all of these |
I don't have a full idea yet of what would be the interface, but taking the
Like Like 3rd-party coordinate wrappers thus make sense only if there is accessors to handle them. If we add an I use More generally, on the xarray side we would need
|
Agreed with all your points @shoyer.
Except here where, instead of a flat collection of coordinate wrappers, I was rather thinking about a 1-level nested collection that separates them depending on what they implement. Indexes would represent one of these sub-collections. |
This seems messier to me. I would rather stick with adding a single OrderedDict to the data model for Would it be that confusing to see an xgcm grid or xarray-simlab clock listed as in the repr as an "Index"? Letting third-party libraries add their own repr categories seems like possibly going too far. |
Yes you're probably right. I can imagine in the example above that It is just that the name "Index" feels a bit wrong to me in this case, and also that |
That said, as real indexes cover most of the use cases, I'd by fine if we keep calling these |
In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity If this issue remains relevant, please comment here or remove the |
I think we can close this issue. The flexible index refactor now provides a nice framework for the suggestions made here. |
Recent and ongoing developments in xarray turn DataArray and Dataset more and more into data wrappers that are extensible at (almost) every level:
DataStore
interfaceRegarding the latter, I’m thinking about the idea of extending xarray at an even more abstract level, i.e., the possibility of adding / registering "coordinate wrappers" to
DataArray
orDataset
objects. Basically, it would correspond to adding any object that allows to do some operation based on one or several coordinates(I haven’t found any better name than "coordinate agent" to describe that).EDIT: "coordinate agents" may not be quite right here, I changed that to "coordinate wrappers")
Indexes are a specific case of coordinate wrappers that serve the purpose of indexing. This is built in xarray.
While indexing is enough in 80% of cases, I see a couple of use cases where other coordinate wrappers (built outside of xarray) would be nice to have:
In those examples we usually rely on coordinate attributes and/or classes that encapsulate xarray objects to implement the specific features that we need. While it works, it has limitations and I think it can be improved.
Custom coordinate wrappers would be a way of extending xarray that is very consistent with other current (or considered) extension mechanisms.
This is still a very vague idea and I’m sure that there are lots of details that can be discussed (serialization, etc.).
But before going further, I’d like to know your thoughts @pydata/xarray. Do you think it is a silly idea? Do you have in mind other use cases where custom coordinate wrappers would be useful?
The text was updated successfully, but these errors were encountered: