From 2b563b6e2266e88ada5ea25e7e97c1bf7c9b87c8 Mon Sep 17 00:00:00 2001 From: Carles Tena Date: Fri, 3 May 2019 16:50:26 +0200 Subject: [PATCH] Selected gridded coordinates names depending on the grid_type --- CHANGELOG | 5 ++++ hermesv3_gr/modules/temporal/temporal.py | 32 ++++++++++++++++++------ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ed2436d..cbebe53 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +1.0.X + XXXX/XX/XX + + - Solved issue #16 + 1.0.2 2019/04/30 diff --git a/hermesv3_gr/modules/temporal/temporal.py b/hermesv3_gr/modules/temporal/temporal.py index 9ebb759..e46374a 100644 --- a/hermesv3_gr/modules/temporal/temporal.py +++ b/hermesv3_gr/modules/temporal/temporal.py @@ -198,13 +198,31 @@ class TemporalDistribution(object): def get_gridded_temporal_profile(self, profile_value, profile_path): from netCDF4 import Dataset nc_in = Dataset(profile_path, mode='r') - if nc_in.dimensions['latitude'].size * nc_in.dimensions['longitude'].size != self.grid.full_shape[-2] * \ - self.grid.full_shape[-1]: - settings.write_log('ERROR: Check the .err file to get more info.') - if settings.rank == 0: - raise IOError('ERROR: The temporal gridded profile {0} '.format(profile_path) + - 'is not in the destiny resolution like {1}.'.format(self.grid.coords_netcdf_file)) - sys.exit(1) + if self.grid.grid_type == 'rotated': + lat_name = 'rlat' + lon_name = 'rlon' + elif self.grid.grid_type.isin(['mercator', 'lcc']): + lat_name = 'x' + lon_name = 'y' + else: + lat_name = 'lat' + lon_name = 'lon' + try: + if nc_in.dimensions[lat_name].size * nc_in.dimensions[lon_name].size != self.grid.full_shape[-2] * \ + self.grid.full_shape[-1]: + settings.write_log('ERROR: Check the .err file to get more info.') + if settings.rank == 0: + raise IOError('ERROR: The temporal gridded profile {0} '.format(profile_path) + + 'is not in the destiny resolution like {1}.'.format(self.grid.coords_netcdf_file)) + sys.exit(1) + + except KeyError: + if nc_in.dimensions['latitude'].size * nc_in.dimensions['longitude'].size != self.grid.full_shape[-2] * \ + self.grid.full_shape[-1]: + settings.write_log('ERROR: Check the .err file to get more info.') + if settings.rank == 0: + raise IOError('ERROR: The temporal gridded profile {0} '.format(profile_path) + + 'is not in the destiny resolution like {1}.'.format(self.grid.coords_netcdf_file)) try: var = nc_in.variables[profile_value][:, self.grid.x_lower_bound:self.grid.x_upper_bound, -- GitLab