From b68f4fb22892b6dac0296267bb9975ab87717ebf Mon Sep 17 00:00:00 2001 From: Carles Tena Date: Thu, 21 May 2020 17:04:40 +0200 Subject: [PATCH] Added capability to try 'lat' instead of 'latitude' while reading a NetCDF. Same for 'lon' and 'longitude' --- hermesv3_bu/io_server/io_netcdf.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hermesv3_bu/io_server/io_netcdf.py b/hermesv3_bu/io_server/io_netcdf.py index 56f57e8..caa9558 100755 --- a/hermesv3_bu/io_server/io_netcdf.py +++ b/hermesv3_bu/io_server/io_netcdf.py @@ -49,7 +49,11 @@ class IoNetcdf(IoServer): lat_o = nc.variables['latitude'][:] lon_o = nc.variables['longitude'][:] except KeyError as e: - error_exit("{0} variable not found in {1} file.".format(str(e), netcdf_path)) + try: + lat_o = nc.variables['lat'][:] + lon_o = nc.variables['lon'][:] + except KeyError as e: + error_exit("{0} variable not found in {1} file.".format(str(e), netcdf_path)) if date_type == 'daily': try: @@ -125,7 +129,13 @@ class IoNetcdf(IoServer): n_lat = len(lat_o) time = nc.variables['time'] except KeyError as e: - error_exit("{0} variable not found in {1} file.".format(str(e), path)) + try: + lat_o = nc.variables['lat'][:] + lon_o = nc.variables['lon'][:] + n_lat = len(lat_o) + time = nc.variables['time'] + except KeyError as e: + error_exit("{0} variable not found in {1} file.".format(str(e), path)) # From time array to list of dates. time_array = num2date(time[:], time.units, CALENDAR_STANDARD) i_time = np.where(time_array == date_array[0])[0][0] -- GitLab