Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions pysteps/blending/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ class StepsBlendingConfig:
conditional: bool, optional
If set to True, compute the statistics of the precipitation field
conditionally by excluding pixels where the values are below the threshold
precip_thr.
precip_thr. This setting does not affect the noise standard deviation
adjustment (noise_stddev_adj='auto'), which always uses conditional
statistics (see #579).
probmatching_method: {'cdf','mean',None}, optional
Method for matching the statistics of the forecast field with those of
the most recently observed one. 'cdf'=map the forecast CDF to the observed
Expand Down Expand Up @@ -1456,6 +1458,11 @@ def __initialize_noise(self):
starttime = time.time()

precip_forecast_min = np.min(self.__state.precip_noise_input)

# Conditonal = False leads to issue with blending. See #579
# Conditional=True is hardcoded currently and bypasses the user provided values
# will always require user to provide a threshold as it is needed to compute the precipitation mask

self.__params.noise_std_coeffs = noise.utils.compute_noise_stddev_adjs(
self.__state.precip_noise_input[-1, :, :],
self.__params.precip_threshold,
Expand All @@ -1465,7 +1472,7 @@ def __initialize_noise(self):
self.__params.perturbation_generator,
self.__params.noise_generator,
20,
conditional=self.__config.conditional,
conditional=True,
Comment thread
ladc marked this conversation as resolved.
Resolved
num_workers=self.__config.num_workers,
seed=self.__config.seed,
)
Expand Down Expand Up @@ -3621,7 +3628,9 @@ def forecast(
conditional: bool, optional
If set to True, compute the statistics of the precipitation field
conditionally by excluding pixels where the values are below the threshold
precip_thr.
precip_thr. This setting does not affect the noise standard deviation
adjustment (noise_stddev_adj='auto'), which always uses conditional
statistics (see #579).
probmatching_method: {'cdf','mean',None}, optional
Method for matching the statistics of the forecast field with those of
the most recently observed one. 'cdf'=map the forecast CDF to the observed
Expand Down
7 changes: 5 additions & 2 deletions pysteps/noise/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def compute_noise_stddev_adjs(
The calculations are done for n realizations of the noise field, and the
correction factors are calculated from the average values of the standard
deviations.
If an adjustment factor is undefined (e.g. single wet pixel), it is set to 1.0,
i.e. no adjustment.

Parameters
----------
Expand Down Expand Up @@ -131,5 +133,6 @@ def worker(k):

# for each cascade level, compare the standard deviations between the
# observed field and the masked noise field, which gives the correction
# factors
return decomp_R["stds"] / np.mean(np.vstack(N_stds), axis=0)
# factors. Undefined factors (e.g. 0/0 for a single-pixel mask) are set to 1.
adjs = decomp_R["stds"] / np.mean(np.vstack(N_stds), axis=0)
return np.where(np.isfinite(adjs), adjs, 1.0)
15 changes: 11 additions & 4 deletions pysteps/nowcasts/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ class StepsNowcasterConfig:
conditional: bool, optional
If set to True, compute the statistics of the precipitation field
conditionally by excluding pixels where the values are below the
threshold precip_thr.
threshold precip_thr. This setting does not affect the noise standard
deviation adjustment (noise_stddev_adj='auto'), which always uses
conditional statistics (see #579).
mask_method: {'obs','sprog','incremental',None}, optional
The method to use for masking no precipitation areas in the forecast
field. The masked pixels are set to the minimum value of the observations.
Expand Down Expand Up @@ -773,7 +775,10 @@ def __apply_noise_and_ar_model(self):
if self.__config.measure_time:
starttime = time.time()

# Compute noise adjustment coefficients
# Compute noise adjustment coefficients.
# conditional=True is hardcoded and bypasses the user-provided value:
# with conditional=False the coefficients explode when only a small
# fraction of the domain is rainy. See #579.
self.__params.noise_std_coefficients = (
noise.utils.compute_noise_stddev_adjs(
self.__state.precip[-1, :, :],
Expand All @@ -784,7 +789,7 @@ def __apply_noise_and_ar_model(self):
self.__params.perturbation_generator,
self.__params.noise_generator,
20,
conditional=self.__config.conditional,
conditional=True,
Comment thread
ladc marked this conversation as resolved.
Resolved
num_workers=self.__config.num_workers,
seed=self.__config.seed,
)
Expand Down Expand Up @@ -1370,7 +1375,9 @@ def forecast(
conditional: bool, optional
If set to True, compute the statistics of the precipitation field
conditionally by excluding pixels where the values are below the
threshold precip_thr.
threshold precip_thr. This setting does not affect the noise standard
deviation adjustment (noise_stddev_adj='auto'), which always uses
conditional statistics (see #579).
mask_method: {'obs','sprog','incremental',None}, optional
The method to use for masking no precipitation areas in the forecast
field. The masked pixels are set to the minimum value of the observations.
Expand Down
Loading
Loading