Skip to content

Commit

Permalink
Fix Regression: "ERA5 is not working because "time" variable.."
Browse files Browse the repository at this point in the history
  • Loading branch information
lassebje committed Nov 1, 2024
1 parent e03f84d commit 3aa24eb
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions metocean_api/ts/internal/ec/ec_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def import_data(self, ts: TimeSeries, save_csv=True, save_nc=False, use_cache=Fa

for filename in filenames:
with xr.open_mfdataset(filename) as ds:
# Rename the dimensions and variables to match the required format
ds = ds.rename_dims({"valid_time": "time"}).rename_vars({"valid_time": "time"})
lon_near=ds.longitude.values[0]
lat_near=ds.latitude.values[0]
ds = ds.drop_vars(['longitude','latitude'], errors="ignore")
Expand Down Expand Up @@ -83,9 +85,9 @@ def import_data(self, ts: TimeSeries, save_csv=True, save_nc=False, use_cache=Fa
lat_near = ds.latitude.values[0]
top_header = f'#{ts.product};LONGITUDE:{lon_near:0.4f};LATITUDE:{lat_near:0.4f}\n'
header = [top_header, '#Variable_name;standard_name;long_name;units\n'] + variable_info
with open(ts.datafile, 'w', encoding="utf8") as f:
with open(ts.datafile, "w", encoding="utf8", newline="") as f:
f.writelines(header)
df_res.to_csv(f, index_label='time')
df.to_csv(f, header=False, encoding=f.encoding, index_label="time")

if save_nc:
ds_res.to_netcdf(ts.datafile.replace('csv','nc'))
Expand Down Expand Up @@ -243,6 +245,5 @@ def __download_gtsm_from_cds(self,start_time, end_time, variable, folder='cache
filename_list.append(filename)
return filename_list


def download_temporary_files(self, ts: TimeSeries, use_cache: bool = False) -> Tuple[List[str], float, float]:
raise NotImplementedError(f"Not implemented for {self.name}")

0 comments on commit 3aa24eb

Please sign in to comment.