-
Notifications
You must be signed in to change notification settings - Fork 27
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
Important Maintenance: improve gather_dimensions #715
Comments
All the improvements sound good.
|
Regarding 2. Currently before calling weights_dims = None
if weights is not None:
weights_dims = weights.dims I agree with Rob that instead of repeating this logic everywhere, it should just be implemented once within Note that most metrics aren't even using the |
Regarding (2), I disagree that it should just be in gather_dimensions, but of course I'm open to discussing the pros and cons. This code isn't user-facing code, so the focus should be on testatibility and repeatability. It is substantially easier to write well-targetted unit tests if the weights_dims are passed in separately rather than being extracted from the xarray. This is because the tests for the actual weights logic can then be written using strings and simple objects that are easy to construct, without any risk of side-effects. While it's slightly longer calling code as a result, it's not user-facing calling code so I think it's reasonable to put the responsibility inside the score rather than in gather_dimensions. The code in the score could possible be simplified further to a shorter pattern. I could look into it, but I don't think it's so hard to have that code appear. One approach could be to write a simple function called extract_weights_dim containing the if statement, then all the calling code could pass extract_weights_dim(xarray) saving two lines of code. |
Again not familiar with the code, so someone else may answer this - the question is: Does the code need to retain the information that If it's the former, branching is unavoidable since that is by design of the type - otherwise don't use an optional at all. If its the latter then all metrics should use The question isn't about if the checks should be in |
A number of improvements requested:
gather_dimensions
docstring needs updating. Current arguments are iterables, but the docstring indicates they are xarray objects.weights
argument. At the moment ifweights=None
then we cannot pass onweights.dims
togather_dimensions
. So we need to use the following logic prior to everygather_dimensions
call: if weights is not None then pass onweights.dims
else pass onNone
. It would be good if this logic was handled bygather_dimensions
itself. Probably the easiest solution is to allowgather_dimensions
to accept either iterables or xarray objects as inputs (at least forweights
if not forfcst
orobs
).gather_dimensions
has a kwargscore_specific_fcst_dims
. It would be good to have an analogous kwargscore_specific_obs_dims
. I have at least one use case for it in a new metric I am writing. I don't think this concept needs to be expanded beyond fcsts and obs.gather_dimensions
early as part of arg checks. It would be good to fix this up so that good coding is modelled well for new metrics. This issue has already been noted: Ensure gather_dimensions occurs early in score calculation APIs #299@tennlee , @nicholasloveday
The text was updated successfully, but these errors were encountered: