Skip to content

Commit

Permalink
performance fix and black complaince
Browse files Browse the repository at this point in the history
  • Loading branch information
gjm174 committed Jul 29, 2024
1 parent d58c144 commit ff03ea1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
20 changes: 10 additions & 10 deletions pysteps/blending/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
from pysteps.timeseries import autoregression, correlation
from pysteps import blending

from copy import deepcopy

try:
import dask

Expand Down Expand Up @@ -694,15 +696,11 @@ def forecast(
# 5. Repeat precip_cascade for n ensemble members
# First, discard all except the p-1 last cascades because they are not needed
# for the AR(p) model
precip_cascade = [
precip_cascade[i][-ar_order:] for i in range(n_cascade_levels)
]

precip_cascade = [
[precip_cascade[j].copy() for j in range(n_cascade_levels)]
for i in range(n_ens_members)
]
precip_cascade = np.stack(precip_cascade)
precip_cascade = np.stack(
[[precip_cascade[i][-ar_order:].copy() for i in range(n_cascade_levels)]]
* n_ens_members
)

# 6. Initialize all the random generators and prepare for the forecast loop
randgen_prec, vps, generate_vel_noise = _init_random_generators(
Expand Down Expand Up @@ -773,8 +771,10 @@ def forecast(
timestep_type = "list"

extrap_kwargs["return_displacement"] = True
forecast_prev = precip_cascade
noise_prev = noise_cascade

forecast_prev = deepcopy(precip_cascade)
noise_prev = deepcopy(noise_cascade)

t_prev = [0.0 for j in range(n_ens_members)]
t_total = [0.0 for j in range(n_ens_members)]

Expand Down
6 changes: 4 additions & 2 deletions pysteps/blending/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def load_NWP(input_nc_path_decomp, input_path_velocities, start_time, n_timestep
decomp_dict = {
"domain": ncf_decomp.domain,
"normalized": bool(ncf_decomp.normalized),
"compact_output": bool(ncf_decomp.compact_output)
"compact_output": bool(ncf_decomp.compact_output),
}

# Convert the start time and the timestep to datetime64 and timedelta64 type
Expand Down Expand Up @@ -512,7 +512,9 @@ def load_NWP(input_nc_path_decomp, input_path_velocities, start_time, n_timestep
stds = ncf_decomp.variables["stds"][start_i:end_i, :]

for i in range(n_timesteps + 1):
decomp_dict["cascade_levels"] = np.ma.filled(pr_decomposed[i], fill_value=np.nan)
decomp_dict["cascade_levels"] = np.ma.filled(
pr_decomposed[i], fill_value=np.nan
)
decomp_dict["means"] = np.ma.filled(means[i], fill_value=np.nan)
decomp_dict["stds"] = np.ma.filled(stds[i], fill_value=np.nan)

Expand Down
2 changes: 1 addition & 1 deletion pysteps/extrapolation/semilagrangian.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def extrapolate(

if xy_coords is None:
x_values, y_values = np.meshgrid(
np.arange(velocity.shape[2]), np.arange(velocity.shape[1])
np.arange(velocity.shape[2]), np.arange(velocity.shape[1]), copy=False
)

xy_coords = np.stack([x_values, y_values])
Expand Down

0 comments on commit ff03ea1

Please sign in to comment.