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
WIP: add xarray dataarray_accessor #197
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #197 +/- ##
==========================================
- Coverage 89.73% 89.24% -0.50%
==========================================
Files 4 5 +1
Lines 653 688 +35
Branches 143 146 +3
==========================================
+ Hits 586 614 +28
- Misses 36 41 +5
- Partials 31 33 +2
Continue to review full report at Codecov.
|
Oh neat! I have definitely worked with many grid objects before, so I think this might be worth thinking about more. But perhaps there could be some input checks that would help sort out the “right” grid object (We discusses this in an earlier release...but the new github app has no autocomplete 😭) |
That's what the function |
I see. I think this is really cool (but have to check it out in practice more). |
Just linking #225 here, since it seems relevant to connect the discussions. |
This pull request has been marked 'stale' due to lack of recent activity. If there is no further activity, the pull request will be closed in another 30 days. Thank you for your contribution! |
Let's keep this alive! Not stale! |
Just wanted to say this is an awesome project and having a Maybe And to handle multiple grids, maybe the accessor could be optionally indexed (e.g. |
This is something we have discussed for a while. Today I realized it was pretty simple to implement. (Famous last words.) So I had to give it a try.
Several people (e.g. @JiaweiZhuang) have commented that they would like to be able to use xgcm with an accessor. The challenge is figuring out which Grid object to use with any given xarray.DataArray.
What I did here was copy Dask's mechanism for finding a Client object to use for computation. I used weakref to create a global set of Grid objects. When you access the
.grid
property of a DataArray, the accessor searches for a Grid that can align with the DataArray. The first one it finds is used forda.grid.interp
andda.grid.diff
methods.Here's a simple example:
There are many ways this could go wrong, particularly if there are multiple Grid objects in existence. However, in my workflows I tend to only ever have one at a time. So perhaps it's a easy, simple solution that will improve our API.