-
Notifications
You must be signed in to change notification settings - Fork 39
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
anomalies function modifying original cube in-place #2223
Comments
@schlunma this was the thing I was dreading and was on about just an hour ago during the review of your PR - you got a lot more experience with actually running these preprocessors - could you help here please? 🍺 |
@valeriupredoi if you had to guess whether this was due to using iris version 3.7.0 (instead of 3.6.1) or to updates to ESMValCore, what would you guess? If the latter, any chance you could tell me which commit you used when you made the environment for me so I can go back to it while this is being sorted? |
Update: I downgraded my iris and the problem persists, so I do believe it is on the ESMValCore side @schlunma |
@rebeccaherman1 - have a look at this 4baa8aa#diff-ec2da1a859c8d6359e23421a3de9d444e455ed3008152eaa67bbdd01f4cadfb8 - you can downgrade to esmvalcore=2.8 and see if you still hit the issue |
@valeriupredoi does esmvalcore=2.8 have the patch you made for me for the iris problem? anyway another UPDATE: If it seems like a reasonable solution to the problem, then perhaps it's time for me to learn how to do a pull request Though it seems from your first comment that maybe you have reason to believe this is a larger issue than just this one function? |
actually a further update (sorry for writing before I've investigated much): |
TBF I've not dug deep enough yet to identify it as a real issue - so prob best for you to use your patch locally (well done btw) and then if you got time to open a PR, then we can spend time to investigate if it's a real bug, and if so, what's the best fix 👍 |
This should be fixed with PR #2191, so hopefully in time for v2.10: |
@schlunma that's an exciting update! My full patch for consideration in the meantime: #prevents modifying cube in-place
cube = copy.deepcopy(cube)
#allows repeated applications of climate statistics functions
if 'time_weights' in [c.name() for c in cube.aux_coords]:
cube.remove_coord('time_weights') I have been using the preprocessor functions in a notebook and do occasionally apply anomalies again after further analysis; I'm not sure that's even possible in the official ESMValTool preprocessor. Nevertheless I think it should be possible in a python script. |
@schlunma cheers! If it's allowed and (scientifically relevant) to call anomalies after other anomalies have been created beforehand, we should probably include the info in the preprocessor's API docs - I didn't think it'd make much sense to call them twice, but that's why I am not a climate scientist 😁 |
@valeriupredoi calling anomalies twice in a row is theoretically not harmful but entirely unnecessary, as the second call would make no change. However I think what I did in my notebook was call anomalies, then do further processing (like finding the max and min over an area) and then I wanted to call anomalies again on the resulting data. This second call to anomalies has different logic than the first, and thus is still scientifically-relevant. I could imagine doing such a thing in pre-processing if I overrode the default order and was allowed to use a function more than once. |
Description
The preprocessor functions generally do not modify the cubes in-place, and instead return the new cube. But in the most up-to-date development version of ESMValCore, calling
anomalies
on a cube adds atime_weights
coordinate to the original cube, preventing future applications of anomalies to that cube by causing aduplicate coordinate
error.@valeriupredoi this discovered while trying to run my old code with my new environment. I'm not sure if the source of the change is ESMValCore or Iris.
Traceback
Minimum Reproducible Code
C
-- there will be noAuxiliary coordinate
calledtime_weights
C
again; there will now be anAuxiliary coordinate
calledtime_weights
pp.anomalies(C, period='full')
againThe text was updated successfully, but these errors were encountered: