Skip to content

Commit

Permalink
added reader for era data and adjusted the transformation of lons acc…
Browse files Browse the repository at this point in the history
…ordingly
  • Loading branch information
bohlinger committed Oct 31, 2024
1 parent f251609 commit aaea899
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
5 changes: 4 additions & 1 deletion wavy/model_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,10 @@ def _enforce_longitude_format(self):
attrs['valid_max'] = 180
attrs['valid_min'] = -180
attrs['comments'] = 'forced to range: -180 to 180'
new.vars.lons.values = ((new.vars.lons.values + 180) % 360) - 180
try:
new.vars.lons.values = ((new.vars.lons.values + 180) % 360) - 180
except Exception as e:
new.vars.assign_coords({"lons": ((new.vars.lons.values + 180) % 360) - 180})
return new

def _enforce_meteorologic_convention(self):
Expand Down
34 changes: 34 additions & 0 deletions wavy/model_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,37 @@ def read_ww3_unstructured_to_grid(**kwargs):
from wavy.grid_readers import read_ww3_unstructured_to_grid
ds = read_ww3_unstructured_to_grid(**kwargs)
return ds


def read_era(**kwargs):
pathlst = kwargs.get('pathlst')
nID = kwargs.get('nID')
fc_dates = kwargs.get('fc_dates')
varname = kwargs.get('varname')
ds_lst = []
# retrieve sliced data
for i in range(len(fc_dates)):
d = parse_date(fc_dates[i])
p = pathlst[i]
ds = xr.open_dataset(p)
ds_sliced = ds.sel({model_dict[nID]['vardef']['time']: d})
ds_sliced = ds_sliced[[varname,
model_dict[nID]['vardef']['lons'],
model_dict[nID]['vardef']['lats']]]

ds_lst.append(ds_sliced)

print(" Concatenate ...")
combined = xr.concat(ds_lst, model_dict[nID]['vardef']['time'],
coords='minimal',
data_vars='minimal',
compat='override',
combine_attrs='override',
join='override')
print(" ... done concatenating")

print(' Build dataset')
print(' dataset ready!')

return combined

0 comments on commit aaea899

Please sign in to comment.