Skip to content
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

Fix support for timesteps list in case model has rain but radar does not #411

Merged
merged 4 commits into from
Jul 25, 2024
Merged
Changes from 1 commit
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
35 changes: 12 additions & 23 deletions pysteps/blending/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,10 @@
from scipy.linalg import inv
from scipy.ndimage import binary_dilation, generate_binary_structure, iterate_structure

from pysteps import cascade
from pysteps import extrapolation
from pysteps import noise
from pysteps import utils
from pysteps import blending, cascade, extrapolation, noise, utils
from pysteps.nowcasts import utils as nowcast_utils
from pysteps.postprocessing import probmatching
from pysteps.timeseries import autoregression, correlation
from pysteps import blending

try:
import dask
Expand Down Expand Up @@ -578,6 +574,14 @@
precip_models_pm, precip_thr, norain_thr
)

if isinstance(timesteps, int):
timesteps = list(range(timesteps + 1))
timestep_type = "int"
else:
original_timesteps = [0] + list(timesteps)
timesteps = nowcast_utils.binned_timesteps(original_timesteps)
timestep_type = "list"

Check warning on line 583 in pysteps/blending/steps.py

View check run for this annotation

Codecov / codecov/patch

pysteps/blending/steps.py#L581-L583

Added lines #L581 - L583 were not covered by tests

# 2.3.1 If precip is below the norain threshold and precip_models_pm is zero,
# we consider it as no rain in the domain.
# The forecast will directly return an array filled with the minimum
Expand All @@ -591,14 +595,6 @@
# Create the output list
R_f = [[] for j in range(n_ens_members)]

if isinstance(timesteps, int):
timesteps = range(timesteps + 1)
timestep_type = "int"
else:
original_timesteps = [0] + list(timesteps)
timesteps = nowcast_utils.binned_timesteps(original_timesteps)
timestep_type = "list"

# Save per time step to ensure the array does not become too large if
# no return_output is requested and callback is not None.
for t, subtimestep_idx in enumerate(timesteps):
Expand Down Expand Up @@ -680,7 +676,8 @@
precip_models_pm, precip_thr, precip_models_pm.shape[0], timesteps
)
# Make sure precip_noise_input is three dimensional
precip_noise_input = precip_noise_input[np.newaxis, :, :]
if len(precip_noise_input.shape) != 3:
precip_noise_input = precip_noise_input[np.newaxis, :, :]
else:
precip_noise_input = precip.copy()

Expand Down Expand Up @@ -782,14 +779,6 @@
if measure_time:
starttime_mainloop = time.time()

if isinstance(timesteps, int):
timesteps = range(timesteps + 1)
timestep_type = "int"
else:
original_timesteps = [0] + list(timesteps)
timesteps = nowcast_utils.binned_timesteps(original_timesteps)
timestep_type = "list"

extrap_kwargs["return_displacement"] = True
forecast_prev = precip_cascade
noise_prev = noise_cascade
Expand Down Expand Up @@ -2498,7 +2487,7 @@
max_rain_pixels_j = -1
max_rain_pixels_t = -1
for j in range(n_models):
for t in range(timesteps):
for t in timesteps:
rain_pixels = precip_models_pm[j][t][
precip_models_pm[j][t] > precip_thr
].size
Expand Down