-
Notifications
You must be signed in to change notification settings - Fork 178
fix noise tapering and error handling #460
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
Changes from 3 commits
6ab76a7
76539bb
f71b2db
ee9a787
e42d5d0
c9ba211
4d4bef7
5d7f59d
3656d8f
f2cddf8
a01eae4
c4e6cac
a684836
8be4327
d7b193f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import numpy as np | ||
|
||
from pysteps import utils | ||
|
||
|
||
def check_norain(precip_arr, precip_thr=None, norain_thr=0.0, win_fun="tukey"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest to leave There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, yes but in the fftgenerators the default method is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed, but in principle There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason I set the tapering method to Ofcourse the I think that if we call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the best approach is to do what I typed in the last paragraph of my previous message, so I will implement that today. |
||
""" | ||
|
||
Parameters | ||
---------- | ||
precip_arr: array-like | ||
An at least 2 dimensional array containing the input precipitation field | ||
precip_thr: float, optional | ||
Specifies the threshold value for minimum observable precipitation intensity. If None, the | ||
minimum value over the domain is taken. | ||
norain_thr: float, optional | ||
Specifies the threshold value for the fraction of rainy pixels in precip_arr below which we consider there to be | ||
no rain. Standard set to 0.0 | ||
win_fun: {'hann', 'tukey', None} | ||
Optional tapering function to be applied to the input field, generated with | ||
:py:func:`pysteps.utils.tapering.compute_window_function` | ||
(default 'tukey'). | ||
This parameter needs to match the window function you use in later noise generation, | ||
or else this method will say that there is rain, while after the tapering function is | ||
applied there is no rain left, so you will run into a ValueError. | ||
Returns | ||
------- | ||
norain: bool | ||
Returns whether the fraction of rainy pixels is below the norain_thr threshold. | ||
|
||
""" | ||
|
||
if win_fun is not None: | ||
tapering = utils.tapering.compute_window_function( | ||
precip_arr.shape[-2], precip_arr.shape[-1], win_fun | ||
) | ||
else: | ||
tapering = np.ones((precip_arr.shape[-2], precip_arr.shape[-1])) | ||
|
||
tapering_mask = tapering == 0.0 | ||
masked_precip = precip_arr.copy() | ||
masked_precip[..., tapering_mask] = np.nanmin(precip_arr) | ||
|
||
if precip_thr is None: | ||
precip_thr = np.nanmin(masked_precip) | ||
rain_pixels = masked_precip[masked_precip > precip_thr] | ||
norain = rain_pixels.size / masked_precip.size <= norain_thr | ||
print( | ||
f"Rain fraction is: {str(rain_pixels.size / masked_precip.size)}, while minimum fraction is {str(norain_thr)}" | ||
) | ||
return norain |
Uh oh!
There was an error while loading. Please reload this page.