From ff212b839767f90481c0177460fa98d93e5e8ab7 Mon Sep 17 00:00:00 2001 From: Knut-Frode Dagestad Date: Thu, 27 Jun 2024 07:31:05 +0200 Subject: [PATCH] Hack in generic reader since ECMWF contains winds at several levels. A new format for reader-lists is needed. --- opendrift/readers/reader_netCDF_CF_generic.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/opendrift/readers/reader_netCDF_CF_generic.py b/opendrift/readers/reader_netCDF_CF_generic.py index fbb3bb6e6..e52bffd92 100644 --- a/opendrift/readers/reader_netCDF_CF_generic.py +++ b/opendrift/readers/reader_netCDF_CF_generic.py @@ -335,6 +335,16 @@ def __init__(self, filename=None, zarr_storage_options=None, name=None, proj4=No self.variable_mapping[standard_name] = str(var_name) else: skipvars.append(var_name) + # Necessary hack for ECMWF with winds at several levels + # TODO: must provide variable mapping along with URLs to create readers + if self.variable_mapping.get('x_wind') is not None: + if 'x_wind_200m' in self.Dataset.variables and 'x_wind_10m' in self.Dataset.variables: + logger.warning('Shifting variable names of ECMWF data, to get winds at 10m') + self.variable_mapping['x_wind'] = 'x_wind_10m' + self.variable_mapping['y_wind'] = 'y_wind_10m' + if self.dimensions.get('y') == 'latitude1' and 'latitude' in self.Dataset.variables: + self.dimensions['x'] = 'longitude' + self.dimensions['y'] = 'latitude' if len(skipvars) > 0: logger.debug('Skipped variables without standard_name: %s' % skipvars)