Skip to content

Commit

Permalink
Merge pull request #163 from vincelhx/develop
Browse files Browse the repository at this point in the history
raster modif cause ecmwf format change
  • Loading branch information
agrouaze authored Jun 1, 2023
2 parents 25db1e9 + 5f7e68b commit 131485b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/xsar/raster_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ def ecmwf_0100_1h(fname, **kwargs):
"""
ecmwf_ds = xr.open_dataset(fname, chunks={'Longitude': 1000, 'Latitude': 1000}).isel(time=0)
ecmwf_ds.attrs['time'] = datetime.datetime.fromtimestamp(ecmwf_ds.time.item() // 1000000000)
ecmwf_ds = ecmwf_ds.drop_vars('time').rename(
if 'time' in ecmwf_ds:
ecmwf_ds = ecmwf_ds.drop("time")
ecmwf_ds = ecmwf_ds[["Longitude","Latitude","10U","10V"]].rename(
{
'Longitude': 'x',
'Latitude': 'y',
Expand Down Expand Up @@ -127,7 +129,7 @@ def ecmwf_0125_1h(fname, **kwargs):
return ecmwf_ds


def hwrf_0015_3h(fname, **kwargs):
def hwrf_0015_3h(fname,**kwargs):
"""
hwrf 0.015 deg 3h reader ()
Expand All @@ -143,15 +145,16 @@ def hwrf_0015_3h(fname, **kwargs):
xarray.Dataset
"""
hwrf_ds = xr.open_dataset(fname)
try:
hwrf_ds = hwrf_ds.sel(t=kwargs['date'])[['U', 'V', 'LON', 'LAT']]
except Exception as e:
try :
hwrf_ds = hwrf_ds[['U','V','LON','LAT']]
hwrf_ds = hwrf_ds.squeeze('t', drop=True)

except Exception as e:
raise ValueError("date '%s' can't be find in %s " % (kwargs['date'], fname))

time_datetime = datetime.datetime.utcfromtimestamp(hwrf_ds.t.values.astype(int) * 1e-9)
hwrf_ds.attrs['time'] = (time_datetime.strftime("%Y/%m/%d %H:%M:%S"))
hwrf_ds.attrs['time'] = datetime.datetime.strftime(kwargs['date'],'%Y-%m-%d %H:%M:%S')

hwrf_ds = hwrf_ds.assign_coords({"x":hwrf_ds.LON.values[0,:],"y":hwrf_ds.LAT.values[:,0]}).drop_vars(['t','LON','LAT']).rename(
hwrf_ds = hwrf_ds.assign_coords({"x":hwrf_ds.LON.values[0,:],"y":hwrf_ds.LAT.values[:,0]}).drop_vars(['LON','LAT']).rename(
{
'U': 'U10',
'V': 'V10'
Expand Down

0 comments on commit 131485b

Please sign in to comment.