Support for mixed precip/noprecip input and AR order 1#544
Support for mixed precip/noprecip input and AR order 1#544
Conversation
Reduce overall number of tests and refactor code Add dedicated AR order parameterization
2e24248 to
5170768
Compare
- similar to the tests in test_blending_steps.py
…meters inherited from blending test
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #544 +/- ##
==========================================
+ Coverage 83.89% 84.20% +0.31%
==========================================
Files 168 170 +2
Lines 14678 14974 +296
==========================================
+ Hits 12314 12609 +295
- Misses 2364 2365 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
We consider these fixes important enough to merge them into the master branch. They can have a direct positive impact on the operation of pysteps, as they |
|
The implemented solution prevents pysteps from crashing when the radar input data contains both precip and noprecip time steps. |
pysteps/blending/steps.py
Outdated
| ) | ||
|
|
||
| # Check all time steps for zero-precip (constant field, minimum==maximum) | ||
| zero_precip = [np.nanmin(obs) == np.nanmax(obs) for obs in precip] |
There was a problem hiding this comment.
Why do you not use the check_norain method here?
There was a problem hiding this comment.
The output differs. While check_norain returns a Boolean value for the entire array, the check here is performed for each individual timestep and returns a list of length ar_order+1. This is a simple technical check to verify whether the input array is constant for the respective timestep, which must be avoided in order to calculate the spatial correlation coefficient.
Note that check_norain is still used later in steps.py to apply the specified thresholds.
There was a problem hiding this comment.
If you prefer, we could call this const_precip or so to avoid confusion?
|
We have been having these issues as well in our processing, so I hope this PR finally fixes it. To me it looks good, I just had a couple of questions. If they can be answered I can approve it. |
There was a problem hiding this comment.
I have tried to answer @mats-knmi's questions. Final approval for the updates of the blending and autoregression functions is still pending, most of it to enable AR-1 runs.
|
Thanks for picking this up, great work! I will go through the changes and leave my review as well. Regarding AR_order = 1, indeed this was not yet supported (also mentioned in the code by the way: "The order of the autoregressive model to use. Must be >= 1."). I am glad to see that we are fixing this now, too. :) |
pysteps/utils/check_norain.py
Outdated
| ) | ||
|
|
||
| # Check all time steps for zero-precip/constant field (constant field, minimum==maximum) | ||
| const_precip = [np.nanmin(obs) == np.nanmax(obs) for obs in precip] |
There was a problem hiding this comment.
A lot of 'no_rain' cases consist of a couple of cells containing clutter. Our experience is that the autoregressive model and/or determining the correlation coefficients then also fail. So, ideally we check for that, too.
In the check_norain function, we have built in a norain_thr, which is the minimum fraction of rainy pixels, and a threshold (precip_thr). I can imagine that it would be good, and consistent, to use that here, too. If so, the function becomes more similar to the check_norain function, so we could even see if an integration of the two functions makes more sense at that point (no preference on my side).
There was a problem hiding this comment.
Ah, gotcha! That makes sense, now I understand why the check_norain method is for flexible than just checking the min and max.
As mentioned, it was a technical test here to avoid const arrays as they cause errors in the correlation coefficients.
I will modify the function to use the thresholds and check for a constant field.
There was a problem hiding this comment.
Also in check_norain we now also have support for a window function. I am not sure how it works in this case, but we have had instances where there was precipitation outside the window function, so it passed a no_rain check, but after the window function was applied it was still a constant field so we got an error.
I am not sure if that is the case here, but imo just using the check_norain method here is slightly more robust and it should also cover the case of a constant field that you are checking for.
Do you have a specific reason why using check_norain here would be worse than what you are doing now?
There was a problem hiding this comment.
I mean, I guess we can assume that a constant field exists if all precip is zero only. It woudl be very unlikely to have the same non-zero value at every pixel ;)
Since I need a list of length ar_order+1 as output, I can simply do const_precip = [check_norain(obs) for obs in precip] that should work and address @RubenImhoff 's comment, too.
| "precip_thr": precip_thr, | ||
| "norain_thr": norain_thr, | ||
| # Set default window function to "tukey" to match the default in check_inputs() below | ||
| "win_fun": "tukey" if noise_kwargs is None else noise_kwargs["win_fun"], |
There was a problem hiding this comment.
I was not totally sure whether this check should be for the entire domain or for the window function that is used in later noise generation.
Here I set it to match this window function ("tukey" by default).
If you think it is better to check the full domain at this point of the code, we simply delete lines 3665/3666.
| "precip_thr": precip_thr, | ||
| "norain_thr": norain_thr, | ||
| # Set default window function to "tukey" to match the default in check_inputs() below | ||
| "win_fun": "tukey" if noise_kwargs is None else noise_kwargs["win_fun"], |
There was a problem hiding this comment.
Same as in blending.steps.py.
If we want to check the entire domain here, we can delete lines 1515/1516.
Fix several issues in case of intermittent rainfall in the radar images:
Works towards fixing issue #543.