Add test and fix conservative interpolation algorithm #635
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey folks, I was just messing around with an example how to transform some tracer (e.g. temperature) from one depth bin layout to another in a way to make sure that the vertical integral is conserved.
This should be easy in theory by doing something like this:
and this should then preserve the vertical integral of the tracer!
I just found out it does NOT if there are nans in the input data (which is pretty common 😝).
What happened was that in this line, any nan value in the input would result in the output bin being nan.
The simple test I added maybe shows this better:
The current code returns nan for this, whereas the fix implemented here returns 3. To me that seems like the desired behavior.
Would love to hear from @rabernat @dcherian @TomNicholas if that all seems right to you?
I also changes another behavior here, and we should discuss if this is desired at all, and if so, if I should factor it out to another PR.
The fixed behavior basically will set every output bin to zero if none of the input cells have any data (e.g. when both the input and output depths cells are below the sea floor. This seems problematic to me since we now have lost any indication/separation between a cell that happens to have a value of zero, vs a cell that does not have any data at all.
I changed this behavior to set cells to nan if there was never any input data that matched them. It is worth noting that the current behavior does 'mask out' cells with all nan input (but also masks out others!), so in a sense combining these changes would not really change the way the output is presented to the user, it just fixes the above bug.
Let me know if you can think of any issues arising from this.
pre-commit run --all-files
whats-new.rst
api.rst