@@ -475,11 +475,11 @@ def load_NWP(input_nc_path_decomp, input_path_velocities, start_time, n_timestep
475475 ncf_decomp = netCDF4 .Dataset (input_nc_path_decomp , "r" , format = "NETCDF4" )
476476 velocities = np .load (input_path_velocities )
477477
478- # Initialise the decomposition dictionary
479- decomp_dict = dict ()
480- decomp_dict [ "domain" ] = ncf_decomp .domain
481- decomp_dict [ "normalized" ] = bool (ncf_decomp .normalized )
482- decomp_dict [ "compact_output" ] = bool ( ncf_decomp . compact_output )
478+ decomp_dict = {
479+ "domain" : ncf_decomp . domain ,
480+ "normalized" : bool ( ncf_decomp .normalized ),
481+ "compact_output" : bool (ncf_decomp .compact_output ),
482+ }
483483
484484 # Convert the start time and the timestep to datetime64 and timedelta64 type
485485 zero_time = np .datetime64 ("1970-01-01T00:00:00" , "ns" )
@@ -515,23 +515,18 @@ def load_NWP(input_nc_path_decomp, input_path_velocities, start_time, n_timestep
515515 # Initialise the list of dictionaries which will serve as the output (cf: the STEPS function)
516516 R_d = list ()
517517
518- for i in range (start_i , end_i ):
519- decomp_dict_ = decomp_dict .copy ()
518+ pr_decomposed = ncf_decomp .variables ["pr_decomposed" ][start_i :end_i , :, :, :]
519+ means = ncf_decomp .variables ["means" ][start_i :end_i , :]
520+ stds = ncf_decomp .variables ["stds" ][start_i :end_i , :]
520521
521- # Obtain the decomposed cascades for time step i
522- cascade_levels = ncf_decomp .variables ["pr_decomposed" ][i , :, :, :]
523- # Obtain the mean values
524- means = ncf_decomp .variables ["means" ][i , :]
525- # Obtain de standard deviations
526- stds = ncf_decomp .variables ["stds" ][i , :]
527-
528- # Save the values in the dictionary as normal arrays with the filled method
529- decomp_dict_ ["cascade_levels" ] = np .ma .filled (cascade_levels , fill_value = np .nan )
530- decomp_dict_ ["means" ] = np .ma .filled (means , fill_value = np .nan )
531- decomp_dict_ ["stds" ] = np .ma .filled (stds , fill_value = np .nan )
522+ for i in range (n_timesteps + 1 ):
523+ decomp_dict ["cascade_levels" ] = np .ma .filled (
524+ pr_decomposed [i ], fill_value = np .nan
525+ )
526+ decomp_dict ["means" ] = np .ma .filled (means [i ], fill_value = np .nan )
527+ decomp_dict ["stds" ] = np .ma .filled (stds [i ], fill_value = np .nan )
532528
533- # Append the output list
534- R_d .append (decomp_dict_ )
529+ R_d .append (decomp_dict .copy ())
535530
536531 ncf_decomp .close ()
537532 return R_d , uv
0 commit comments