@@ -18,6 +18,9 @@ class LSASAFDownloader(URLDownloader):
1818
1919 single_temp_folder = False
2020
21+ retries = 3
22+ retry_delay = 10 # seconds
23+
2124 default_options = {
2225 "ts_per_year" : 365 ,
2326 "variables" : None , # all variables
@@ -115,24 +118,41 @@ def _get_data_ts(self,
115118 tmp_path : str ) -> Generator [tuple [xr .DataArray , dict ], None , None ]:
116119
117120
121+ credentials = self .get_credentials ()
118122 tmp_file_nc = f'temp_{ self .product } { timestep .start :%Y%m%d} .nc'
119123
120124 # check if the file is not already downloaded in the tmp_path
121125 tmp_destination = os .path .join (tmp_path , tmp_file_nc )
122126 this_filename = self .filename .format (time = timestep .start )
123- self .download (tmp_destination , min_size = 2000 , missing_action = 'warning' ,
124- time = timestep .start , product_name = self .product_name , satellite = self .satellite , filename = this_filename )
125-
126- # open the file
127- raw_data = xr .open_dataset (tmp_destination , engine = 'netcdf4' )
128- for var , varopts in self .variables .items ():
129- vardata = raw_data [var ].isel (time = 0 , drop = True ) # remove the time dimension if present
130-
131- # crop to the bounding box
132- vardata = crop_to_bb (vardata , space_bounds )
133-
134- # set the metadata
135- vardata = vardata .rio .write_crs ('EPSG:4326' )
136- vardata = vardata .rio .set_spatial_dims (x_dim = 'lon' , y_dim = 'lat' )
137127
138- yield vardata , {'variable' : var }
128+ success = False
129+ while not success and self .retries > 0 :
130+
131+ success = self .download (tmp_destination , min_size = 2000 , missing_action = 'warning' , auth = tuple (credentials .split (':' )),
132+ time = timestep .start , product_name = self .product_name , satellite = self .satellite , filename = this_filename )
133+
134+ if not success :
135+ self .retries -= 1
136+ if self .retries > 0 :
137+ print (f'Retrying download in { self .retry_delay } seconds... ({ self .retries } retries left)' )
138+ import time
139+ time .sleep (self .retry_delay )
140+ continue
141+ else :
142+ print ('Max retries reached. Giving up.' )
143+ break
144+
145+ # open the file
146+ raw_data = xr .open_dataset (tmp_destination , engine = 'netcdf4' )
147+ raw_data .close ()
148+ for var , varopts in self .variables .items ():
149+ vardata = raw_data [var ].isel (time = 0 , drop = True ) # remove the time dimension if present
150+
151+ # crop to the bounding box
152+ vardata = crop_to_bb (vardata , space_bounds )
153+
154+ # set the metadata
155+ vardata = vardata .rio .write_crs ('EPSG:4326' )
156+ vardata = vardata .rio .set_spatial_dims (x_dim = 'lon' , y_dim = 'lat' )
157+
158+ yield vardata , {'variable' : var }
0 commit comments