From a599a3d06564c8bbedc44c91c65680fa108f4093 Mon Sep 17 00:00:00 2001 From: Lars Bonnefoy Date: Wed, 18 Nov 2026 14:49:56 +0100 Subject: [PATCH 1/6] Reverted conditional to hardcoded value True as False would lead to exploding rainfall values outside of radar domain. See issue #579 --- pysteps/blending/steps.py | 7 +- pysteps/tests/test_blending_steps.py | 128 +++++++++++++++------------ 2 files changed, 77 insertions(+), 58 deletions(-) diff --git a/pysteps/blending/steps.py b/pysteps/blending/steps.py index 6c0d8372d..1e7313e5f 100644 --- a/pysteps/blending/steps.py +++ b/pysteps/blending/steps.py @@ -1456,6 +1456,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, @@ -1465,7 +1470,7 @@ def __initialize_noise(self): self.__params.perturbation_generator, self.__params.noise_generator, 20, - conditional=self.__config.conditional, + conditional=True, num_workers=self.__config.num_workers, seed=self.__config.seed, ) diff --git a/pysteps/tests/test_blending_steps.py b/pysteps/tests/test_blending_steps.py index 940568748..67bb25063 100644 --- a/pysteps/tests/test_blending_steps.py +++ b/pysteps/tests/test_blending_steps.py @@ -12,73 +12,77 @@ # fmt:off steps_arg_values = [ - (1, 3, 4, 8, 'steps', None, None, False, "spn", True, 4, False, False, 0, False, None, None, None), - (1, 3, 4, 8,'steps', "obs", None, False, "spn", True, 4, False, False, 0, False, None, None, None), - (1, 3, 4, 8,'steps', "incremental", None, False, "spn", True, 4, False, False, 0, False, None, None, None), - (1, 3, 4, 8,'steps', None, "mean", False, "spn", True, 4, False, False, 0, False, None, None, None), - (1, 3, 4, 8,'steps', None, "mean", False, "spn", True, 4, False, False, 0, True, None, None, None), - (1, 3, 4, 8,'steps', None, "cdf", False, "spn", True, 4, False, False, 0, False, None, None, None), - (1, [1, 2, 3], 4, 8,'steps', None, "cdf", False, "spn", True, 4, False, False, 0, False, None, None, None), + (1, 3, 4, 8, 'steps', None, None, False, "spn", True, 4, False, False, 0, False, None, None, None, False), + (1, 3, 4, 8,'steps', "obs", None, False, "spn", True, 4, False, False, 0, False, None, None, None, False), + (1, 3, 4, 8,'steps', "incremental", None, False, "spn", True, 4, False, False, 0, False, None, None, None, False), + (1, 3, 4, 8,'steps', None, "mean", False, "spn", True, 4, False, False, 0, False, None, None, None, False), + (1, 3, 4, 8,'steps', None, "mean", False, "spn", True, 4, False, False, 0, True, None, None, None, False), + (1, 3, 4, 8,'steps', None, "cdf", False, "spn", True, 4, False, False, 0, False, None, None, None, False), + (1, [1, 2, 3], 4, 8,'steps', None, "cdf", False, "spn", True, 4, False, False, 0, False, None, None, None, False), # Regression test for a gap in the timesteps list (e.g. [1, 3] skips 2): this used to raise # "TypeError: 'NoneType' object is not iterable" because the bin for the skipped step never # got a value written to final_blended_forecast_all_members_one_timestep. - (1, [1, 3], 4, 8,'steps', None, "cdf", False, "spn", True, 4, False, False, 0, False, None, None, None), - (1, 3, 4, 8,'steps', "incremental", "cdf", False, "spn", True, 4, False, False, 0, False, None, None, None), - (1, 3, 4, 6,'steps', "incremental", "cdf", False, "bps", True, 4, False, False, 0, False, None, None, None), - (1, 3, 4, 6,'steps', "incremental", "cdf", False, "bps", False, 4, False, False, 0, False, None, None, None), - (1, 3, 4, 6,'steps', "incremental", "cdf", False, "bps", False, 4, False, False, 0, True, None, None, None), - (1, 3, 4, 9,'steps', "incremental", "cdf", False, "spn", True, 4, False, False, 0, False, None, None, None), - (2, 3, 10, 8,'steps', "incremental", "cdf", False, "spn", True, 10, False, False, 0, False, None, None, None), - (5, 3, 5, 8,'steps', "incremental", "cdf", False, "spn", True, 5, False, False, 0, False, None, None, None), - (1, 10, 1, 8,'steps', "incremental", "cdf", False, "spn", True, 1, False, False, 0, False, None, None, None), - (2, 3, 2, 8,'steps', "incremental", "cdf", True, "spn", True, 2, False, False, 0, False, None, None, None), - (1, 3, 6, 8,'steps', None, None, False, "spn", True, 6, False, False, 0, False, None, None, None), - (1, 3, 6, 8,'steps', None, None, False, "spn", True, 6, False, False, 0, False, "bps", None, None), + (1, [1, 3], 4, 8,'steps', None, "cdf", False, "spn", True, 4, False, False, 0, False, None, None, None, False), + (1, 3, 4, 8,'steps', "incremental", "cdf", False, "spn", True, 4, False, False, 0, False, None, None, None, False), + (1, 3, 4, 6,'steps', "incremental", "cdf", False, "bps", True, 4, False, False, 0, False, None, None, None, False), + (1, 3, 4, 6,'steps', "incremental", "cdf", False, "bps", False, 4, False, False, 0, False, None, None, None, False), + (1, 3, 4, 6,'steps', "incremental", "cdf", False, "bps", False, 4, False, False, 0, True, None, None, None, False), + (1, 3, 4, 9,'steps', "incremental", "cdf", False, "spn", True, 4, False, False, 0, False, None, None, None, False), + (2, 3, 10, 8,'steps', "incremental", "cdf", False, "spn", True, 10, False, False, 0, False, None, None, None, False), + (5, 3, 5, 8,'steps', "incremental", "cdf", False, "spn", True, 5, False, False, 0, False, None, None, None, False), + (1, 10, 1, 8,'steps', "incremental", "cdf", False, "spn", True, 1, False, False, 0, False, None, None, None, False), + (2, 3, 2, 8,'steps', "incremental", "cdf", True, "spn", True, 2, False, False, 0, False, None, None, None, False), + (1, 3, 6, 8,'steps', None, None, False, "spn", True, 6, False, False, 0, False, None, None, None, False), + (1, 3, 6, 8,'steps', None, None, False, "spn", True, 6, False, False, 0, False, "bps", None, None, False), # Test the case where the radar image contains no rain. - (1, 3, 6, 8,'steps', None, None, False, "spn", True, 6, True, False, 0, False, None, None, None), - (5, 3, 5, 6,'steps', "incremental", "cdf", False, "spn", False, 5, True, False, 0, False, None, None, None), - (5, 3, 5, 6,'steps', "incremental", "cdf", False, "spn", False, 5, True, False, 0, True, None, None, None), + (1, 3, 6, 8,'steps', None, None, False, "spn", True, 6, True, False, 0, False, None, None, None, False), + (5, 3, 5, 6,'steps', "incremental", "cdf", False, "spn", False, 5, True, False, 0, False, None, None, None, False), + (5, 3, 5, 6,'steps', "incremental", "cdf", False, "spn", False, 5, True, False, 0, True, None, None, None, False), # Test the case where the NWP fields contain no rain. - (1, 3, 6, 8,'steps', None, None, False, "spn", True, 6, False, True, 0, False, None, None, None), - (5, 3, 5, 6,'steps', "incremental", "cdf", False, "spn", False, 5, False, True, 0, True, None, None, None), + (1, 3, 6, 8,'steps', None, None, False, "spn", True, 6, False, True, 0, False, None, None, None, False), + (5, 3, 5, 6,'steps', "incremental", "cdf", False, "spn", False, 5, False, True, 0, True, None, None, None, False), # Test the case where both the radar image and the NWP fields contain no rain. - (1, 3, 6, 8,'steps', None, None, False, "spn", True, 6, True, True, 0, False, None, None, None), - (5, 3, 5, 6,'steps', "incremental", "cdf", False, "spn", False, 5, True, True, 0, False, None, None, None), - (5, 3, 5, 6,'steps', "obs", "mean", True, "spn", True, 5, True, True, 0, False, None, None, None), + (1, 3, 6, 8,'steps', None, None, False, "spn", True, 6, True, True, 0, False, None, None, None, False), + (5, 3, 5, 6,'steps', "incremental", "cdf", False, "spn", False, 5, True, True, 0, False, None, None, None, False), + (5, 3, 5, 6,'steps', "obs", "mean", True, "spn", True, 5, True, True, 0, False, None, None, None, False), # Test cases where we apply timestep_start_full_nwp_weight - (1, 10, 2, 6,'steps', "incremental", "cdf", False, "bps", False, 2, False, False, 0, True, None, None, 5), - (1, 10, 2, 6,'steps', "incremental", "cdf", False, "spn", False, 2, False, False, 0, False, None, None, 5), + (1, 10, 2, 6,'steps', "incremental", "cdf", False, "bps", False, 2, False, False, 0, True, None, None, 5, False), + (1, 10, 2, 6,'steps', "incremental", "cdf", False, "spn", False, 2, False, False, 0, False, None, None, 5, False), # Test for smooth radar mask - (1, 3, 6, 8,'steps', None, None, False, "spn", True, 6, False, False, 80, False, None, None, None), - (5, 3, 5, 6,'steps', "incremental", "cdf", False, "spn", False, 5, False, False, 80, False, None, None, None), - (5, 3, 5, 6,'steps', "obs", "mean", False, "spn", False, 5, False, False, 80, False, None, None, None), - (1, 3, 6, 8,'steps', None, None, False, "spn", True, 6, False, True, 80, False, None, None, None), - (5, 3, 5, 6,'steps', "incremental", "cdf", False, "spn", False, 5, True, False, 80, True, None, None, None), - (5, 3, 5, 6,'steps', "obs", "mean", False, "spn", False, 5, True, True, 80, False, None, None, None), - (5, [1, 2, 3], 5, 6,'steps', "obs", "mean", False, "spn", False, 5, True, True, 80, False, None, None, None), - (5, [1, 3], 5, 6,'steps', "obs", "mean", False, "spn", False, 5, True, True, 80, False, None, None, None), + (1, 3, 6, 8,'steps', None, None, False, "spn", True, 6, False, False, 80, False, None, None, None, False), + (5, 3, 5, 6,'steps', "incremental", "cdf", False, "spn", False, 5, False, False, 80, False, None, None, None, False), + (5, 3, 5, 6,'steps', "obs", "mean", False, "spn", False, 5, False, False, 80, False, None, None, None, False), + (1, 3, 6, 8,'steps', None, None, False, "spn", True, 6, False, True, 80, False, None, None, None, False), + (5, 3, 5, 6,'steps', "incremental", "cdf", False, "spn", False, 5, True, False, 80, True, None, None, None, False), + (5, 3, 5, 6,'steps', "obs", "mean", False, "spn", False, 5, True, True, 80, False, None, None, None, False), + (5, [1, 2, 3], 5, 6,'steps', "obs", "mean", False, "spn", False, 5, True, True, 80, False, None, None, None, False), + (5, [1, 3], 5, 6,'steps', "obs", "mean", False, "spn", False, 5, True, True, 80, False, None, None, None, False), # Test the usage of a max_mask_rim in the mask_kwargs - (1, 3, 6, 8,'steps', None, None, False, "bps", True, 6, False, False, 80, False, None, 40, None), - (5, 3, 5, 6,'steps', "obs", "mean", False, "bps", False, 5, False, False, 80, False, None, 40, None), - (5, 3, 5, 6,'steps', "incremental", "cdf", False, "bps", False, 5, False, False, 80, False, None, 25, None), - (5, 3, 5, 6,'steps', "incremental", "cdf", False, "bps", False, 5, False, False, 80, False, None, 40, None), - (5, 3, 5, 6,'steps', "incremental", "cdf", False, "bps", False, 5, False, False, 80, False, None, 60, None), + (1, 3, 6, 8,'steps', None, None, False, "bps", True, 6, False, False, 80, False, None, 40, None, False), + (5, 3, 5, 6,'steps', "obs", "mean", False, "bps", False, 5, False, False, 80, False, None, 40, None, False), + (5, 3, 5, 6,'steps', "incremental", "cdf", False, "bps", False, 5, False, False, 80, False, None, 25, None, False), + (5, 3, 5, 6,'steps', "incremental", "cdf", False, "bps", False, 5, False, False, 80, False, None, 40, None, False), + (5, 3, 5, 6,'steps', "incremental", "cdf", False, "bps", False, 5, False, False, 80, False, None, 60, None, False), #Test the externally provided nowcast - (1, 10, 1, 8,'external_nowcast_det', None, None, False, "spn", True, 1, False, False, 0, False, None, None, None), - (1, 10, 1, 8,'external_nowcast_det', "incremental", None, False, "bps", True, 1, False, False, 0, False, None, None, None), - (1, 10, 1, 8,'external_nowcast_det', "incremental", None, False, "spn", True, 1, False, False, 80, False, None, None, None), - (1, 10, 1, 8,'external_nowcast_det', "incremental", None, False, "bps", True, 1, True, False, 0, False, None, None, None), - (1, 10, 1, 8,'external_nowcast_det', "incremental", None, False, "spn", True, 1, False, True, 0, False, None, None, None), - (1, 10, 1, 8,'external_nowcast_det', "incremental", None, False, "bps", True, 1, True, True, 0, False, None, None, None), - (1, 10, 1, 8,'external_nowcast_det', "incremental", "cdf", False, "spn", True, 1, False, False, 0, True, None, None, None), - (1, 10, 1, 8,'external_nowcast_det', "incremental", "obs", False, "bps", True, 1, False, False, 0, False, None, None, None), - (1, 10, 1, 8,'external_nowcast_det', "incremental", None, False, "bps", True, 1, False, False, 0, False, None, None, 5), - (5, 10, 5, 8,'external_nowcast_ens', "incremental", None, False, "spn", True, 5, False, False, 0, False, None, None, None), - (5, 10, 5, 8,'external_nowcast_ens', "incremental", None, False, "spn", True, 5, False, False, 0, False, None, None, None), - (1, 10, 5, 8,'external_nowcast_ens', "incremental", None, False, "spn", True, 5, False, False, 0, False, None, None, None), - (1, 10, 1, 8,'external_nowcast_ens', "incremental", "cdf", False, "bps", True, 5, False, False, 0, False, None, None, None), - (5, 10, 1, 8,'external_nowcast_ens', "incremental", "obs", False, "spn", True, 5, False, False, 0, False, None, None, None), - (1, 10, 5, 8,'external_nowcast_ens', "incremental", "cdf", False, "bps", True, 5, False, False, 0, False, None, None, 5) + (1, 10, 1, 8,'external_nowcast_det', None, None, False, "spn", True, 1, False, False, 0, False, None, None, None, False), + (1, 10, 1, 8,'external_nowcast_det', "incremental", None, False, "bps", True, 1, False, False, 0, False, None, None, None, False), + (1, 10, 1, 8,'external_nowcast_det', "incremental", None, False, "spn", True, 1, False, False, 80, False, None, None, None, False), + (1, 10, 1, 8,'external_nowcast_det', "incremental", None, False, "bps", True, 1, True, False, 0, False, None, None, None, False), + (1, 10, 1, 8,'external_nowcast_det', "incremental", None, False, "spn", True, 1, False, True, 0, False, None, None, None, False), + (1, 10, 1, 8,'external_nowcast_det', "incremental", None, False, "bps", True, 1, True, True, 0, False, None, None, None, False), + (1, 10, 1, 8,'external_nowcast_det', "incremental", "cdf", False, "spn", True, 1, False, False, 0, True, None, None, None, False), + (1, 10, 1, 8,'external_nowcast_det', "incremental", "obs", False, "bps", True, 1, False, False, 0, False, None, None, None, False), + (1, 10, 1, 8,'external_nowcast_det', "incremental", None, False, "bps", True, 1, False, False, 0, False, None, None, 5, False), + (5, 10, 5, 8,'external_nowcast_ens', "incremental", None, False, "spn", True, 5, False, False, 0, False, None, None, None, False), + (5, 10, 5, 8,'external_nowcast_ens', "incremental", None, False, "spn", True, 5, False, False, 0, False, None, None, None, False), + (1, 10, 5, 8,'external_nowcast_ens', "incremental", None, False, "spn", True, 5, False, False, 0, False, None, None, None, False), + (1, 10, 1, 8,'external_nowcast_ens', "incremental", "cdf", False, "bps", True, 5, False, False, 0, False, None, None, None, False), + (5, 10, 1, 8,'external_nowcast_ens', "incremental", "obs", False, "spn", True, 5, False, False, 0, False, None, None, None, False), + (1, 10, 5, 8,'external_nowcast_ens', "incremental", "cdf", False, "bps", True, 5, False, False, 0, False, None, None, 5, False), + # Regression test for #579: with conditional=False and a low fraction of rainy pixels, + # the noise adjustment coefficients exploded and so did the forecast values. + (1, 3, 4, 8,'steps', None, None, False, "spn", True, 4, False, False, 0, False, None, None, None, True), + (1, 3, 4, 8,'steps', "incremental", None, False, "bps", True, 4, False, False, 0, False, None, None, None, True) ] # fmt:on @@ -119,6 +123,9 @@ def run_and_assert_forecast( assert precip_forecast.shape[1] == n_timesteps, ( "Wrong amount of output time steps in converted forecast output" ) + assert np.nanmax(precip_forecast) < 1000.0, ( + "Forecast precipitation values exploded (see #579)" + ) steps_arg_names = ( @@ -140,6 +147,7 @@ def run_and_assert_forecast( "vel_pert_method", "max_mask_rim", "timestep_start_full_nwp_weight", + "low_rain_fraction", ) @@ -163,6 +171,7 @@ def test_steps_blending( vel_pert_method, max_mask_rim, timestep_start_full_nwp_weight, + low_rain_fraction, ): pytest.importorskip("cv2") @@ -225,6 +234,11 @@ def test_steps_blending( radar_precip[2, 30:155, 40 + 1 * 3] = 0.5 radar_precip[2, 30:155, 41 + 1 * 3] = 0.1 + if low_rain_fraction: + # Keep only a thin strip of the rain band: ~0.15% of the domain is rainy + radar_precip[:, :100, :] = 0.0 + radar_precip[:, 105:, :] = 0.0 + precip_nowcast = np.zeros((n_ens_members, last_timestep + 1, 200, 200)) if nowcasting_method == "external_nowcast_ens": From 77c6b07dd928900d969a2205afc694b18e123c2d Mon Sep 17 00:00:00 2001 From: Lars Bonnefoy Date: Wed, 18 Nov 2026 15:39:58 +0100 Subject: [PATCH 2/6] Run only the high precip tests for specific tests --- pysteps/tests/test_blending_steps.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pysteps/tests/test_blending_steps.py b/pysteps/tests/test_blending_steps.py index 67bb25063..f335aa29e 100644 --- a/pysteps/tests/test_blending_steps.py +++ b/pysteps/tests/test_blending_steps.py @@ -95,8 +95,12 @@ def run_and_assert_forecast( n_timesteps, converter, metadata, + max_precip=None, ): - """Run a blended nowcast and assert the output has the expected shape.""" + """Run a blended nowcast and assert the output has the expected shape. + + If max_precip is given, also assert that the forecast (in mm/h) stays below it. + """ precip_forecast_dataset = blending.steps.forecast(radar_dataset, **forecast_kwargs) precip_var_forecast = precip_forecast_dataset.attrs["precip_var"] precip_forecast = precip_forecast_dataset[precip_var_forecast].values @@ -123,9 +127,10 @@ def run_and_assert_forecast( assert precip_forecast.shape[1] == n_timesteps, ( "Wrong amount of output time steps in converted forecast output" ) - assert np.nanmax(precip_forecast) < 1000.0, ( - "Forecast precipitation values exploded (see #579)" - ) + if max_precip is not None: + assert np.nanmax(precip_forecast) < max_precip, ( + "Forecast precipitation values exploded (see #579)" + ) steps_arg_names = ( @@ -454,6 +459,7 @@ def test_steps_blending( n_timesteps, converter, metadata, + max_precip=1000.0 if low_rain_fraction else None, ) From 9411aba406bce1f33892ebd0ffdf424697ec1fc5 Mon Sep 17 00:00:00 2001 From: Lesley De Cruz Date: Tue, 24 Nov 2026 14:31:26 +0100 Subject: [PATCH 3/6] Revert conditional=True also for pure steps nowcast. Make comments clearer for both cases. This was the behaviour before the 2024 refactor. --- pysteps/blending/steps.py | 8 ++++++-- pysteps/nowcasts/steps.py | 15 +++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pysteps/blending/steps.py b/pysteps/blending/steps.py index 1e7313e5f..76d3c693e 100644 --- a/pysteps/blending/steps.py +++ b/pysteps/blending/steps.py @@ -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 @@ -3626,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 diff --git a/pysteps/nowcasts/steps.py b/pysteps/nowcasts/steps.py index aa3238471..9b5669d16 100644 --- a/pysteps/nowcasts/steps.py +++ b/pysteps/nowcasts/steps.py @@ -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. @@ -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, :, :], @@ -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, num_workers=self.__config.num_workers, seed=self.__config.seed, ) @@ -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. From be6cf68ba6dc6d44989a026f21a6c2fd1acc83fa Mon Sep 17 00:00:00 2001 From: Lesley De Cruz Date: Tue, 24 Nov 2026 15:39:05 +0100 Subject: [PATCH 4/6] Add sanity check for hi rainfall values in steps nowcast and fix seed --- pysteps/tests/test_blending_steps.py | 2 +- pysteps/tests/test_nowcasts_steps.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pysteps/tests/test_blending_steps.py b/pysteps/tests/test_blending_steps.py index f335aa29e..46981c8b7 100644 --- a/pysteps/tests/test_blending_steps.py +++ b/pysteps/tests/test_blending_steps.py @@ -434,7 +434,7 @@ def test_steps_blending( smooth_radar_mask_range=smooth_radar_mask_range, callback=None, return_output=True, - seed=None, + seed=42, num_workers=1, fft_method="numpy", domain="spatial", diff --git a/pysteps/tests/test_nowcasts_steps.py b/pysteps/tests/test_nowcasts_steps.py index 8f8bb454a..30ecdb4e6 100644 --- a/pysteps/tests/test_nowcasts_steps.py +++ b/pysteps/tests/test_nowcasts_steps.py @@ -249,6 +249,7 @@ def run_and_assert_forecast( assert precip_forecast.shape[1] == n_timesteps, ( "Wrong amount of output time steps in converted forecast output" ) + return precip_forecast @pytest.mark.parametrize(steps_arg_names, steps_arg_values) @@ -385,7 +386,7 @@ def test_steps_nowcast( mask_method=mask_method, callback=None, return_output=True, - seed=None, + seed=42, num_workers=1, fft_method="numpy", domain=domain, @@ -469,7 +470,7 @@ def test_steps_nowcast_partial_zero_radar(ar_order): oflow_method = motion.get_method("lucaskanade") dataset_w_motion = oflow_method(dataset_input) - run_and_assert_forecast( + precip_forecast = run_and_assert_forecast( dataset_w_motion, dict( timesteps=n_timesteps, @@ -504,3 +505,7 @@ def test_steps_nowcast_partial_zero_radar(ar_order): n_timesteps=n_timesteps, converter=converter, ) + # Regression test for #579 + assert np.nanmax(precip_forecast) < 1000.0, ( + f"Forecast precipitation values exploded: max value = {np.nanmax(precip_forecast)}" + ) From 400bd1ab9baf55c2956a7e813474d0d615680955 Mon Sep 17 00:00:00 2001 From: Lesley De Cruz Date: Wed, 25 Nov 2026 11:22:53 +0100 Subject: [PATCH 5/6] Fix bug with NaN in noise_stddev_adj. Set adjustment to 1.0 in case of NaNs (e.g. single wet pixel). --- pysteps/noise/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pysteps/noise/utils.py b/pysteps/noise/utils.py index aaae82f9b..e5c658308 100644 --- a/pysteps/noise/utils.py +++ b/pysteps/noise/utils.py @@ -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 ---------- @@ -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) From 8b437b1accac1e39f9575e01ccae96f4f9f77d70 Mon Sep 17 00:00:00 2001 From: Lesley De Cruz Date: Wed, 25 Nov 2026 16:22:37 +0100 Subject: [PATCH 6/6] Check for unphysically high precip values in steps nowcast --- pysteps/tests/test_nowcasts_steps.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pysteps/tests/test_nowcasts_steps.py b/pysteps/tests/test_nowcasts_steps.py index 30ecdb4e6..5f67792ad 100644 --- a/pysteps/tests/test_nowcasts_steps.py +++ b/pysteps/tests/test_nowcasts_steps.py @@ -249,6 +249,10 @@ def run_and_assert_forecast( assert precip_forecast.shape[1] == n_timesteps, ( "Wrong amount of output time steps in converted forecast output" ) + assert np.nanmax(precip_forecast) < 1000.0, ( + f"Forecast precipitation values exploded: max value = {np.nanmax(precip_forecast)}" + ) + return precip_forecast @@ -470,7 +474,7 @@ def test_steps_nowcast_partial_zero_radar(ar_order): oflow_method = motion.get_method("lucaskanade") dataset_w_motion = oflow_method(dataset_input) - precip_forecast = run_and_assert_forecast( + run_and_assert_forecast( dataset_w_motion, dict( timesteps=n_timesteps, @@ -505,7 +509,3 @@ def test_steps_nowcast_partial_zero_radar(ar_order): n_timesteps=n_timesteps, converter=converter, ) - # Regression test for #579 - assert np.nanmax(precip_forecast) < 1000.0, ( - f"Forecast precipitation values exploded: max value = {np.nanmax(precip_forecast)}" - )