-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add average module with average_shape #109
Conversation
Hi @aulemahal, thanks for putting the PR together. I think that our requirements for I think that our (C3S) requirements could be summed up by implementing something like:
What do think? If it is really that easy for us create the functionality we need for C3S work then the real issue here is making sure that we structure the code so that the various layers work together properly. |
Hi Ag, Let's say a use case is to compute the tropical average (averaged over both lon and lat, between lat=[-23, 23]).
I think what we are proposing (not in this PR but in general), is to have a In other words, I think trying to pack everything in one |
@huard, @aulemahal: I agree that your general approach of matching |
@huard and @aulemahal: Thinking in more detail, there is one part of the function signature to
But we also want to allow the user to say:
Do you have a proposal for a function interface that allows all these options? I am struggling to come up with something elegant that copes with the two different approaches. |
Thought about the same thing yesterday. |
@huard: I think the problem is that we have a single argument for |
@agstephens Agreed. I must confess that I'm a bit confused by the fact that |
I think I share the perspective of @huard : We could have the computational side of things in To be completely coherent with that idea, functions in Thus I am suggesting here to have things in |
This PR is consistent with this vision. So if @agstephens agrees, I suggest we go with this and defer the refactoring of core processes to another PR. |
@aulemahal and @huard: Yes, I agree. Let's go ahead with this approach. |
Cool! Now this leaves another issue I raised above : the use of xESMF is powerful for "exact" shape-averaging, but it has 1 more restriction then the previous "contains" (as in If, however, this is a problem, we could write a |
@aulemahal: From the perspective of what we are required to do for the C3S service:
So, I think that we can implement that quickly, and it leaves space for Ouranos to add in a range of more sophisticated averaging functions within I propose that we will propagate the functionality through to our WPS, with:
Tagging @ellesmith88 |
Co-authored-by: David Huard <huard.david@ouranos.ca>
Hi! So this last push:
|
Update doc and new method: I think this is ready for review! |
Co-authored-by: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com>
I had a chat with @aulemahal. We will await the release of xesmf:0.5.2 on conda-forge before merging this PR. |
Added a comment on the non-installability of xESMF on windows + fixed a conflict in history. And woups I just realized that all patch version are noted in the HISTORY, should I not have run bumpversion? |
Hi @agstephens , is there a (tentative) schedule for the release of clisops 0.6 (or 0.5.2) ? |
@aulemahal: @ellesmith88 will be in touch to discuss a new release :-) |
Hi @aulemahal We plan to release v0.6.0 when the averaging work is all merged in, so within the next few weeks hopefully. We've been working on I've opened our average as a separate PR to be reviewed (#125) - once we're happy that the 2 average PRs line up I'll go about merging and releasing. I couldn't do the PR to your branch as its on a fork so it's to master but we can merge them so that you are able to resolve any conflicts how you would like. Let me know what you think of this plan. |
Sounds good to me! Thanks. |
EDIT: With comments from @tlogan2000, I just realized this is missing a relatively important option to skip, or not, missing values in the sum. |
I was wrong, xESMF's SpatialAverager is broken with the usual NaN-skipping solution (passing a mask). I'll leave this improvement for a future release. pangeo-data/xESMF#77 must be fixed before. Even if the functionality of |
This all looks good. 👍 |
Pull Request Checklist:
bumpversion minor
has been called on this branchAUTHORS.md
Adds
clisops/core/average.py
with a first methodaverage_shape
that uses the power of xESMF to perform averages over polygons. As discussed in the slack channel, I might have had a different idea of what the average submodule was supposed to be, this is why I only implemented the method I needed and only the computational pare (not theclisops.ops.average
part).My understanding at first was that most methods in
average
would be no more than a call to the relatedsubset_*
followed by a mean over the appropriate dimensions. The use of xESMF for polygon averaging adds complexity but also precision as it considers partial overlaps, grid cell sizes and holes, whilesubset_shape
does not (it is a simple "contains" test).On the other hand, it restricts the inputs:
Because of that, we could also choose to
a. not implement a xESMF-backed shape-averaging method, but this would break our relatively clean "clisops->finch" pipeline.
b. implement
average_shape_simple
and/oraverage_shape_exact
(or other name alternatives). The "simple" version would be something likesubet_shape(ds, shape).mean(['lat', 'lon'])
.c. implement a switch in the function itself, either with a keyword or a try..except. I do not like this alternative, because I feel like that is the job of the
clisops.ops.average
version.This is a draft PR. I plan to add documentation, fix all requirements and maybe implement a
create_weight_masks
helper, that returns the weight mask for each polygon in a given GeoDataFrame, giving more control on the average to the user, similar tosubset.create_mask
.If my understanding for the base average method (subset + mean on dims) is correct, I could also add them here.
This will add a new dependency : xESMF (and thus ESMF), which is not light and makes pip installs difficult.