Skip to content

Commit

Permalink
Merge pull request #11 from alaurent101/master
Browse files Browse the repository at this point in the history
Added code to deal with extra "expver" dimension in ERA5T files
  • Loading branch information
trondkr authored Mar 30, 2023
2 parents f8ce8da + c9de2ca commit 5bf4863
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 13 additions & 3 deletions ECMWF_convert_to_ROMS.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ def __init__(self):

def convert_to_ROMS_units_standards(self, out_filename: str, metadata, parameter: str, config_ecmwf: ECMWF_query):
dset = netCDF4.Dataset(out_filename, 'r+')

da = dset.variables[metadata['short_name']][:]

# ERA5 CDS requests can return a mixture of ERA5 and ERA5T data
# in this case there is an extra dimension and we need to reduce that dimension
# https://confluence.ecmwf.int/pages/viewpage.action?pageId=173385064
if 'expver' in dset.variables.keys():
dimid = dset.variables[metadata['short_name']].dimensions.index("expver")
da = np.mean(dset.variables[metadata['short_name']][:],axis=dimid)
else:
da = dset.variables[metadata['short_name']][:]
masked_array = np.ma.masked_where(da == dset.variables[metadata['short_name']].missing_value, da)
logging.debug("[ECMWF_convert_to_ROMS] Will convert for parameter: {}".format(parameter))
if parameter in ['mean_surface_net_short_wave_radiation_flux',
Expand Down Expand Up @@ -124,9 +131,12 @@ def write_to_ROMS_netcdf_file(self, config_ecmwf: ECMWF_query, data_array, var_u

f1 = netCDF4.Dataset(netcdf_roms_filename, 'w')
f1.title = "{} ECMWF model forcing for parameter {}".format(config_ecmwf.dataset.upper(), parameter)
note = ""
if 'expver' in ds.variables.keys():
note = "Note: Includes ERA5T (near real time) preliminary data. "
f1.description = "Created by Trond Kristiansen (at) niva.no." \
"Atmospheric data on original grid but converted to ROMS units and parameter names." \
"Files created using the ECMWF_tools toolbox:" \
f"{note}Files created using the ECMWF_tools toolbox:" \
"https://github.com/trondkr/ERA5-ROMS"
f1.history = f"Created {datetime.now()}"
f1.link = "https://github.com/trondkr/"
Expand Down
4 changes: 2 additions & 2 deletions ECMWF_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def submit_request(self, req):
"variable": [parameter],
"format": "netcdf",
"area": self.config_ecmwf.area,
"verbose": self.config_ecmwf.debug,
# "verbose": self.config_ecmwf.debug,
}

# Add more specific options for variables on pressure surfaces
Expand Down Expand Up @@ -197,4 +197,4 @@ def update(*a):
pool = multiprocessing.Pool(processes=4)
pool.map(tool.submit_request, requests)
pool.close()
pool.join()
pool.join()

0 comments on commit 5bf4863

Please sign in to comment.