@@ -90,8 +90,11 @@ def download_copernicus(
9090 dataset_id_curr = "med-cmcc-cur-rean-h"
9191 dataset_id_temp = "med-cmcc-tem-rean-d"
9292 output_name = output_name .format ("reanalysis" )
93-
9493 files = []
94+
95+ # Normalized date to be sure to get enough time slices of dataset
96+ start_time = start_time .normalize ()
97+
9598 for dataset in [dataset_id_curr , dataset_id_temp ]:
9699
97100 if "cur" in dataset :
@@ -111,10 +114,10 @@ def download_copernicus(
111114 )
112115 # Add depth dimension (0 m) to 2D dataset
113116 ds = xr .open_dataset (f"{ output_path } curr.nc" )
114- ds = ds .expand_dims (depth = [0 ])
117+ ds = ds .expand_dims (depth = [0 , 10 , 30 , 120 ])
115118 ds .to_netcdf (f"{ output_path } curr.nc" )
116-
117119 files .append (output_path + "curr.nc" )
120+
118121 else :
119122 copernicusmarine .subset (
120123 dataset_id = dataset_id_temp ,
@@ -132,7 +135,12 @@ def download_copernicus(
132135 username = user ,
133136 password = password ,
134137 )
135-
138+ ds_temp = xr .open_dataset (f"{ output_path } temp.nc" )
139+ ds_temp = ds_temp .sel (depth = [0 , 10 , 30 , 120 ], method = "nearest" )
140+ ds_temp ["depth" ] = [0 , 10 , 30 , 120 ]
141+ ds_temp = ds_temp .resample (time = '1H' ).ffill ()
142+ ds_temp = ds_temp .load () # Load the dataset into memory to release the file handle
143+ ds_temp .to_netcdf (f"{ output_path } temp.nc" )
136144 files .append (output_path + "temp.nc" )
137145
138146 # Transform to medslik standards
@@ -141,12 +149,6 @@ def download_copernicus(
141149 # Rename variables only if they exist in the dataset
142150 ds = Utils .rename_netcdf_variables_mdk3 (ds )
143151
144- # Selecting only 4 layers
145- ds = ds .sel (depth = [0 , 10 , 30 , 120 ], method = "nearest" )
146-
147- # Modifying labels to simplfy drop in temperature columns
148- ds ["depth" ] = [0 , 10 , 30 , 120 ]
149-
150152 # Selecting only the relavent variables
151153 ds = ds [["uo" , "vo" , "thetao" ]]
152154
@@ -164,7 +166,8 @@ def download_copernicus(
164166 dataset_id_curr = "cmems_mod_med_phy-cur_anfc_4.2km-2D_PT1H-m"
165167 dataset_id_temp = "cmems_mod_med_phy-tem_anfc_4.2km-2D_PT1H-m"
166168 output_name = output_name .format ("analysis" )
167-
169+ # Normalized date to be sure to get enough time slices of dataset
170+ start_time = start_time .normalize ()
168171 files = []
169172 for dataset in [dataset_id_curr , dataset_id_temp ]:
170173
@@ -228,7 +231,8 @@ def download_copernicus(
228231 dataset_id_curr = "cmems_mod_med_phy-cur_anfc_4.2km-3D_PT1H-m"
229232 dataset_id_temp = "cmems_mod_med_phy-tem_anfc_4.2km-3D_PT1H-m"
230233 output_name = output_name .format ("analysis" )
231-
234+ # Normalized date to be sure to get enough time slices of dataset
235+ start_time = start_time .normalize ()
232236 files = []
233237 for dataset in [dataset_id_curr , dataset_id_temp ]:
234238
0 commit comments