@@ -39,7 +39,7 @@ def download_GTSM_from_cds(start_time, end_time, folder="dnora_wlv_temp") -> str
3939
4040 c = cdsapi .Client ()
4141
42- filename = f"{ folder } /EC_GTSM_ERA5.tar.gz "
42+ filename = f"{ folder } /EC_GTSM_ERA5.zip "
4343 # cds_command_test = {
4444 # 'product_type': 'reanalysis',
4545 # 'format': 'netcdf',
@@ -75,12 +75,12 @@ def download_GTSM_from_cds(start_time, end_time, folder="dnora_wlv_temp") -> str
7575 months = months [0 ]
7676
7777 cds_command = {
78- "data_format" : "tgz" ,
7978 "variable" : ["total_water_level" ],
8079 "experiment" : "reanalysis" ,
8180 "temporal_aggregation" : "hourly" ,
8281 "year" : years , # 1979-2018
8382 "month" : months ,
83+ "version" : ["v3" ]
8484 }
8585
8686 c .retrieve ("sis-water-level-change-timeseries-cmip6" , cds_command , filename )
@@ -120,26 +120,23 @@ def __call__(
120120 out_file = download_GTSM_from_cds (start_time , end_time , folder = temp_folder )
121121
122122 temppath = os .path .dirname (out_file )
123- # first unpack the tar.gz file.
124- nc_file = (
125- subprocess .run (["tar" , "-ztf" , out_file ], stdout = subprocess .PIPE )
126- .stdout .decode ("utf-8" )
127- .split ("\n " )[0 :- 1 ]
128- )
129- nc_file = sorted ([ff .strip ("\r " ) for ff in nc_file ])
130- # print(nc_file)
131- subprocess .run (
132- ["tar" , "-xzvf" , out_file , "--directory" , temppath ], stdout = subprocess .PIPE
133- ) # Extract tar file
134-
123+
124+ import zipfile
125+ with zipfile .ZipFile (out_file , "r" ) as zip_ref :
126+ nc_files = zip_ref .namelist ()
127+
128+ # Extract all files to the specified directory
129+ zip_ref .extractall (temppath )
130+
131+
135132 lon_local = np .arange (lon [0 ], lon [1 ], 0.1 )
136133 lat_local = np .arange (lat [0 ], lat [1 ], 0.1 )
137134 grid_x , grid_y = np .meshgrid (lon_local , lat_local , indexing = "xy" )
138135
139- print (nc_file )
136+ print (nc_files )
140137 grid_tot = []
141138 time_tot = []
142- for ncfile in nc_file :
139+ for ncfile in nc_files :
143140 # print(os.path.join(temppath,nc_file))
144141 waterlevel = xr .open_dataset (
145142 os .path .join (temppath , ncfile ), engine = "netcdf4"
@@ -190,7 +187,8 @@ def __call__(
190187 # )
191188
192189 # print(waterlevel_gridded)
193- coord_dict = {"lon" : lon_local , "lat" : lat_local , "time" : time }
190+
191+ coord_dict = {"lon" : lon_local , "lat" : lat_local , "time" : time_tot }
194192 data_dict = {"eta" : grid_tot }
195193 meta_dict = {"description" : "Waterlevel from GTSM/ERA5" }
196194
0 commit comments