From ae5c59c072e4e5815f7e9da024ec847a490e4fb2 Mon Sep 17 00:00:00 2001 From: Carles Tena Date: Mon, 16 Dec 2019 18:22:08 +0100 Subject: [PATCH 1/7] Defining rotated nested domain --- conf/hermes.conf | 12 ++++++++++-- hermesv3_bu/config/config.py | 22 +++++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/conf/hermes.conf b/conf/hermes.conf index ad9ea14..179e9ef 100755 --- a/conf/hermes.conf +++ b/conf/hermes.conf @@ -16,8 +16,8 @@ erase_auxiliary_files = 0 [DOMAIN] -# domain_type=[lcc, rotated, mercator, regular] -domain_type = lcc +# domain_type=[lcc, rotated, mercator, regular, rotated_nested] +domain_type = roated_nested # output_type=[MONARCH, CMAQ, WRF_CHEM, DEFAULT] output_model = DEFAULT output_attributes = /writing/global_attributes_WRF-Chem.csv @@ -39,6 +39,14 @@ vertical_description = /profiles/vertical/MONARCH_Global_48layers_ver # inc_rlat = 0.4 # inc_rlon = 0.4 +# if domain_type == rotated_nested: + parent_grid_path = /scratch/Earth/ctena/temporal_coords.nc + parent_ratio = 4 + i_parent_start = 266 + j_parent_start = 164 + n_rlat = 212 + n_rlon = 196 + # if domain_type == lcc: # CALIOPE diff --git a/hermesv3_bu/config/config.py b/hermesv3_bu/config/config.py index f99e3e4..4852a63 100755 --- a/hermesv3_bu/config/config.py +++ b/hermesv3_bu/config/config.py @@ -74,12 +74,13 @@ class Config(ArgParser): p.add_argument('--output_attributes', required=False, help='Path to the file that contains the global attributes.') - p.add_argument('--domain_type', required=True, help='Type of domain to simulate.', - choices=['lcc', 'rotated', 'mercator', 'regular']) - p.add_argument('--vertical_description', required=True, help='Path to the file that contains the vertical description of the desired output.') + p.add_argument('--domain_type', required=True, help='Type of domain to simulate.', + choices=['lcc', 'rotated', 'mercator', 'regular', 'rotated_nested']) + + # Rotated options p.add_argument('--centre_lat', required=False, type=float, help='Central geographic latitude of grid (non-rotated degrees). Corresponds to the TPH0D ' + @@ -100,6 +101,21 @@ class Config(ArgParser): help='Longitudinal grid resolution (rotated degrees). Corresponds to the DLMD parameter ' + 'in NMMB-MONARCH.') + # Rotated_nested options + p.add_argument('--parent_grid_path', required=False, type=str, + help='Path to the netCDF that contains the grid definition.') + p.add_argument('--parent_ratio', required=False, type=int, + help='Ratio between the parent and the nested domain.') + p.add_argument('--i_parent_start', required=False, type=int, + help='Location of the I to start the nested.') + p.add_argument('--j_parent_start', required=False, type=int, + help='Location of the J to start the nested.') + p.add_argument('--n_rlat', required=False, type=int, + help='Number of rotated latitude points.') + p.add_argument('--n_rlon', required=False, type=int, + help='Number of rotated longitude points.') + + # Lambert conformal conic options p.add_argument('--lat_1', required=False, type=float, help='Standard parallel 1 (in deg). Corresponds to the P_ALP parameter of the GRIDDESC file.') -- GitLab From b3c92a11d010d451fe472fc89b24952fd273ca15 Mon Sep 17 00:00:00 2001 From: Carles Tena Date: Wed, 15 Jan 2020 18:48:11 +0100 Subject: [PATCH 2/7] Adding Rotated nested grid --- conf/hermes.conf | 4 +- hermesv3_bu/config/config.py | 5 +- hermesv3_bu/grids/grid.py | 6 + hermesv3_bu/grids/grid_rotated.py | 2 +- hermesv3_bu/grids/grid_rotated_nested.py | 194 +++++++++++++++++++++++ 5 files changed, 206 insertions(+), 5 deletions(-) create mode 100755 hermesv3_bu/grids/grid_rotated_nested.py diff --git a/conf/hermes.conf b/conf/hermes.conf index 179e9ef..d14ae8f 100755 --- a/conf/hermes.conf +++ b/conf/hermes.conf @@ -9,7 +9,7 @@ start_date = 2016/11/29 00:00:00 # ----- end_date = start_date [DEFAULT] ----- # end_date = 2010/01/01 00:00:00 output_timestep_num = 24 -auxiliary_files_path = /scratch/Earth/HERMESv3_BU_aux/__test +auxiliary_files_path = /scratch/Earth/ctena/HERMESv3_BU_aux/__test first_time = 0 erase_auxiliary_files = 0 @@ -17,7 +17,7 @@ erase_auxiliary_files = 0 [DOMAIN] # domain_type=[lcc, rotated, mercator, regular, rotated_nested] -domain_type = roated_nested +domain_type = rotated_nested # output_type=[MONARCH, CMAQ, WRF_CHEM, DEFAULT] output_model = DEFAULT output_attributes = /writing/global_attributes_WRF-Chem.csv diff --git a/hermesv3_bu/config/config.py b/hermesv3_bu/config/config.py index 4852a63..4def471 100755 --- a/hermesv3_bu/config/config.py +++ b/hermesv3_bu/config/config.py @@ -80,7 +80,6 @@ class Config(ArgParser): p.add_argument('--domain_type', required=True, help='Type of domain to simulate.', choices=['lcc', 'rotated', 'mercator', 'regular', 'rotated_nested']) - # Rotated options p.add_argument('--centre_lat', required=False, type=float, help='Central geographic latitude of grid (non-rotated degrees). Corresponds to the TPH0D ' + @@ -115,7 +114,6 @@ class Config(ArgParser): p.add_argument('--n_rlon', required=False, type=int, help='Number of rotated longitude points.') - # Lambert conformal conic options p.add_argument('--lat_1', required=False, type=float, help='Standard parallel 1 (in deg). Corresponds to the P_ALP parameter of the GRIDDESC file.') @@ -702,6 +700,9 @@ class Config(ArgParser): elif arguments.domain_type == 'rotated': arguments.__dict__[item] = arguments.__dict__[item].replace('', '{1}_{2}'.format( item, arguments.inc_rlat, arguments.inc_rlon)) + elif arguments.domain_type == 'rotated_nested': + arguments.__dict__[item] = arguments.__dict__[item].replace('', '{1}_{2}'.format( + item, arguments.n_rlat, arguments.n_rlon)) elif arguments.domain_type == 'lcc' or arguments.domain_type == 'mercator': arguments.__dict__[item] = arguments.__dict__[item].replace('', '{1}_{2}'.format( item, arguments.inc_x, arguments.inc_y)) diff --git a/hermesv3_bu/grids/grid.py b/hermesv3_bu/grids/grid.py index 6dea082..6803fe4 100755 --- a/hermesv3_bu/grids/grid.py +++ b/hermesv3_bu/grids/grid.py @@ -45,6 +45,12 @@ def select_grid(comm, logger, arguments): logger, arguments.auxiliary_files_path, arguments.output_timestep_num, arguments.vertical_description, arguments.centre_lat, arguments.centre_lon, arguments.west_boundary, arguments.south_boundary, arguments.inc_rlat, arguments.inc_rlon) + elif arguments.domain_type == 'rotated_nested': + from hermesv3_bu.grids.grid_rotated_nested import RotatedNestedGrid + grid = RotatedNestedGrid( + logger, arguments.auxiliary_files_path, arguments.output_timestep_num, + arguments.vertical_description, arguments.parent_grid_path, arguments.parent_ratio, + arguments.i_parent_start, arguments.j_parent_start, arguments.n_rlat, arguments.n_rlon) elif arguments.domain_type == 'mercator': from hermesv3_bu.grids.grid_mercator import MercatorGrid diff --git a/hermesv3_bu/grids/grid_rotated.py b/hermesv3_bu/grids/grid_rotated.py index 2195707..5d1fbec 100755 --- a/hermesv3_bu/grids/grid_rotated.py +++ b/hermesv3_bu/grids/grid_rotated.py @@ -172,7 +172,7 @@ class RotatedGrid(Grid): boundary_latitudes=self.boundary_latitudes, boundary_longitudes=self.boundary_longitudes, rotated=True, rotated_lats=self.rlat, rotated_lons=self.rlon, - north_pole_lat=90 - self.attributes['new_pole_latitude_degrees'], + north_pole_lat=self.attributes['new_pole_latitude_degrees'], north_pole_lon=self.attributes['new_pole_longitude_degrees']) self.logger.write_log("\tGrid created at '{0}'".format(self.netcdf_path), 3) self.logger.write_time_log('RotatedGrid', 'write_netcdf', timeit.default_timer() - spent_time, 3) diff --git a/hermesv3_bu/grids/grid_rotated_nested.py b/hermesv3_bu/grids/grid_rotated_nested.py new file mode 100755 index 0000000..90dd3df --- /dev/null +++ b/hermesv3_bu/grids/grid_rotated_nested.py @@ -0,0 +1,194 @@ +#!/usr/bin/env python + +import os +import timeit +from hermesv3_bu.grids.grid import Grid +import numpy as np +import math + +from hermesv3_bu.logger.log import Log + + +class RotatedNestedGrid(Grid): + def __init__(self, logger, auxiliary_path, tstep_num, vertical_description_path, parent_grid_path, parent_ratio, + i_parent_start, j_parent_start, n_rlat, n_rlon): + """ + + :param logger: Logger. + :type logger: Log + + :param auxiliary_path: + :param tstep_num: + :param vertical_description_path: + + """ + spent_time = timeit.default_timer() + + self.rlat = None + self.rlon = None + + logger.write_log('Rotated Nested grid selected.') + self.grid_type = 'Rotated_nested' + + attributes = {'parent_grid_path': parent_grid_path, 'parent_ratio': parent_ratio, + 'i_parent_start': i_parent_start, 'j_parent_start': j_parent_start, + 'n_rlat': n_rlat, 'n_rlon': n_rlon, 'crs': {'init': 'epsg:4326'}} + attributes = self.get_parent_attributes(attributes) + + # Initialises with parent class + super(RotatedNestedGrid, self).__init__(logger, attributes, auxiliary_path, vertical_description_path) + + self.shape = (tstep_num, len(self.vertical_desctiption), attributes['n_rlat'], attributes['n_rlon']) + self.logger.write_time_log('RotatedNestedGrid', '__init__', timeit.default_timer() - spent_time, 3) + + @staticmethod + def get_parent_attributes(attributes): + from netCDF4 import Dataset + + netcdf = Dataset(attributes['parent_grid_path'], mode='r') + + rlat = netcdf.variables['rlat'][:] + attributes['inc_rlat'] = (rlat[1] - rlat[0]) / attributes['parent_ratio'] + attributes['1st_rlat'] = rlat[int(attributes['j_parent_start'])] + + rlon = netcdf.variables['rlon'][:] + attributes['inc_rlon'] = (rlon[1] - rlon[0]) / attributes['parent_ratio'] + attributes['1st_rlon'] = rlon[attributes['i_parent_start']] + + rotated_pole = netcdf.variables['rotated_pole'] + attributes['parent'] = {'new_pole_longitude_degrees': rotated_pole.grid_north_pole_longitude, + 'new_pole_latitude_degrees': 90 - rotated_pole.grid_north_pole_latitude} + + return attributes + + def create_regular_rotated(self): + """ + Create a regular grid on the rotated domain. + + :return: center_latitudes, center_longitudes, corner_latitudes, corner_longitudes + :rtype: tuple + """ + spent_time = timeit.default_timer() + + center_latitudes = np.linspace(self.attributes['1st_rlat'], self.attributes['1st_rlat'] + + (self.attributes['inc_rlat'] * (self.attributes['n_rlat'] - 1)), + self.attributes['n_rlat'], dtype=np.float) + center_longitudes = np.linspace(self.attributes['1st_rlon'], self.attributes['1st_rlon'] + + (self.attributes['inc_rlon'] * (self.attributes['n_rlon'] - 1)), + self.attributes['n_rlon'], dtype=np.float) + + corner_latitudes = self.create_bounds(center_latitudes, self.attributes['inc_rlat'], number_vertices=4, + inverse=True) + corner_longitudes = self.create_bounds(center_longitudes, self.attributes['inc_rlon'], number_vertices=4) + + self.logger.write_time_log('RotatedNestedGrid', 'create_regular_rotated', timeit.default_timer() - spent_time, 3) + return center_latitudes, center_longitudes, corner_latitudes, corner_longitudes + + def create_coords(self): + """ + Create the coordinates for a rotated domain. + """ + spent_time = timeit.default_timer() + # Create rotated coordinates + (self.rlat, self.rlon, br_lats_single, br_lons_single) = self.create_regular_rotated() + + # 1D to 2D + c_lats = np.array([self.rlat] * len(self.rlon)).T + c_lons = np.array([self.rlon] * len(self.rlat)) + + # Create rotated boundary coordinates + b_lats = super(RotatedNestedGrid, self).create_bounds(c_lats, self.attributes['inc_rlat'], number_vertices=4, + inverse=True) + b_lons = super(RotatedNestedGrid, self).create_bounds(c_lons, self.attributes['inc_rlon'], number_vertices=4) + + # Rotated to Lat-Lon + self.boundary_longitudes, self.boundary_latitudes = self.rotated2latlon(b_lons, b_lats) + self.center_longitudes, self.center_latitudes = self.rotated2latlon(c_lons, c_lats) + + self.logger.write_time_log('RotatedNestedGrid', 'create_coords', timeit.default_timer() - spent_time, 3) + return True + + def rotated2latlon(self, lon_deg, lat_deg, lon_min=-180): + """ + Calculate the unrotated coordinates using the rotated ones. + + :param lon_deg: Rotated longitude coordinate. + :type lon_deg: numpy.array + + :param lat_deg: Rotated latitude coordinate. + :type lat_deg: numpy.array + + :param lon_min: Minimum value for the longitudes: -180 (-180 to 180) or 0 (0 to 360) + :type lon_min: float + + :return: Unrotated coordinates. Longitudes, Latitudes + :rtype: tuple(numpy.array, numpy.array) + """ + spent_time = timeit.default_timer() + degrees_to_radians = math.pi / 180. + # radians_to_degrees = 180. / math.pi + + # Positive east to negative east + # self.new_pole_longitude_degrees -= 180 + + tph0 = self.attributes['parent']['new_pole_latitude_degrees'] * degrees_to_radians + tlm = lon_deg * degrees_to_radians + tph = lat_deg * degrees_to_radians + tlm0d = self.attributes['parent']['new_pole_longitude_degrees'] + ctph0 = np.cos(tph0) + stph0 = np.sin(tph0) + + stlm = np.sin(tlm) + ctlm = np.cos(tlm) + stph = np.sin(tph) + ctph = np.cos(tph) + + # Latitude + sph = (ctph0 * stph) + (stph0 * ctph * ctlm) + # if sph > 1.: + # sph = 1. + # if sph < -1.: + # sph = -1. + sph[sph > 1.] = 1. + sph[sph < -1.] = -1. + + aph = np.arcsin(sph) + aphd = aph / degrees_to_radians + + # Longitude + anum = ctph * stlm + denom = (ctlm * ctph - stph0 * sph) / ctph0 + relm = np.arctan2(anum, denom) - math.pi + almd = relm / degrees_to_radians + tlm0d + + # if almd < min_lon: + # almd += 360 + # elif almd > max_lon: + # almd -= 360 + almd[almd > (lon_min + 360)] -= 360 + almd[almd < lon_min] += 360 + + self.logger.write_time_log('RotatedNestedGrid', 'rotated2latlon', timeit.default_timer() - spent_time, 3) + + return almd, aphd + + def write_netcdf(self): + """ + Write a rotated grid NetCDF with empty data + """ + from hermesv3_bu.io_server.io_netcdf import write_coords_netcdf + spent_time = timeit.default_timer() + if not os.path.exists(self.netcdf_path): + if not os.path.exists(os.path.dirname(self.netcdf_path)): + os.makedirs(os.path.dirname(self.netcdf_path)) + # Writes an auxiliary empty NetCDF only with the coordinates and an empty variable. + write_coords_netcdf(self.netcdf_path, self.center_latitudes, self.center_longitudes, + [{'name': 'var_aux', 'units': '', 'data': 0}], + boundary_latitudes=self.boundary_latitudes, + boundary_longitudes=self.boundary_longitudes, + rotated=True, rotated_lats=self.rlat, rotated_lons=self.rlon, + north_pole_lat=90 - self.attributes['parent']['new_pole_latitude_degrees'], + north_pole_lon=self.attributes['parent']['new_pole_longitude_degrees']) + self.logger.write_log("\tGrid created at '{0}'".format(self.netcdf_path), 3) + self.logger.write_time_log('RotatedNestedGrid', 'write_netcdf', timeit.default_timer() - spent_time, 3) + return True -- GitLab From 7d020381bf2b83eea9658303b3fa3f2e00c34fcd Mon Sep 17 00:00:00 2001 From: Carles Tena Date: Mon, 20 Jan 2020 17:56:21 +0100 Subject: [PATCH 3/7] Adding Rotated nested grid --- conf/hermes.conf | 10 ++++++---- hermesv3_bu/grids/grid_rotated_nested.py | 15 +++++++++------ hermesv3_bu/writer/default_writer.py | 8 ++++---- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/conf/hermes.conf b/conf/hermes.conf index d14ae8f..364be0d 100755 --- a/conf/hermes.conf +++ b/conf/hermes.conf @@ -42,10 +42,12 @@ vertical_description = /profiles/vertical/MONARCH_Global_48layers_ver # if domain_type == rotated_nested: parent_grid_path = /scratch/Earth/ctena/temporal_coords.nc parent_ratio = 4 - i_parent_start = 266 - j_parent_start = 164 - n_rlat = 212 - n_rlon = 196 + # i -> lon + i_parent_start = 200 + # j -> lat + j_parent_start = 100 + n_rlat = 400 + n_rlon = 400 # if domain_type == lcc: diff --git a/hermesv3_bu/grids/grid_rotated_nested.py b/hermesv3_bu/grids/grid_rotated_nested.py index 90dd3df..13cf552 100755 --- a/hermesv3_bu/grids/grid_rotated_nested.py +++ b/hermesv3_bu/grids/grid_rotated_nested.py @@ -47,6 +47,7 @@ class RotatedNestedGrid(Grid): netcdf = Dataset(attributes['parent_grid_path'], mode='r') + # TODO check if the i_parent start, j_parent_start begin in 0 or in 1 rlat = netcdf.variables['rlat'][:] attributes['inc_rlat'] = (rlat[1] - rlat[0]) / attributes['parent_ratio'] attributes['1st_rlat'] = rlat[int(attributes['j_parent_start'])] @@ -56,8 +57,10 @@ class RotatedNestedGrid(Grid): attributes['1st_rlon'] = rlon[attributes['i_parent_start']] rotated_pole = netcdf.variables['rotated_pole'] - attributes['parent'] = {'new_pole_longitude_degrees': rotated_pole.grid_north_pole_longitude, - 'new_pole_latitude_degrees': 90 - rotated_pole.grid_north_pole_latitude} + attributes['new_pole_longitude_degrees'] = rotated_pole.grid_north_pole_longitude + attributes['new_pole_latitude_degrees'] = 90 - rotated_pole.grid_north_pole_latitude + + netcdf.close() return attributes @@ -131,10 +134,10 @@ class RotatedNestedGrid(Grid): # Positive east to negative east # self.new_pole_longitude_degrees -= 180 - tph0 = self.attributes['parent']['new_pole_latitude_degrees'] * degrees_to_radians + tph0 = self.attributes['new_pole_latitude_degrees'] * degrees_to_radians tlm = lon_deg * degrees_to_radians tph = lat_deg * degrees_to_radians - tlm0d = self.attributes['parent']['new_pole_longitude_degrees'] + tlm0d = self.attributes['new_pole_longitude_degrees'] ctph0 = np.cos(tph0) stph0 = np.sin(tph0) @@ -187,8 +190,8 @@ class RotatedNestedGrid(Grid): boundary_latitudes=self.boundary_latitudes, boundary_longitudes=self.boundary_longitudes, rotated=True, rotated_lats=self.rlat, rotated_lons=self.rlon, - north_pole_lat=90 - self.attributes['parent']['new_pole_latitude_degrees'], - north_pole_lon=self.attributes['parent']['new_pole_longitude_degrees']) + north_pole_lat=90 - self.attributes['new_pole_latitude_degrees'], + north_pole_lon=self.attributes['new_pole_longitude_degrees']) self.logger.write_log("\tGrid created at '{0}'".format(self.netcdf_path), 3) self.logger.write_time_log('RotatedNestedGrid', 'write_netcdf', timeit.default_timer() - spent_time, 3) return True diff --git a/hermesv3_bu/writer/default_writer.py b/hermesv3_bu/writer/default_writer.py index 5bde50b..1f2546f 100755 --- a/hermesv3_bu/writer/default_writer.py +++ b/hermesv3_bu/writer/default_writer.py @@ -110,7 +110,7 @@ class DefaultWriter(Writer): var_dim = ('y', 'x',) lat_dim = lon_dim = var_dim - elif self.grid.grid_type == 'Rotated': + elif self.grid.grid_type in ['Rotated', 'Rotated_nested']: netcdf.createDimension('rlat', len(self.grid.rlat)) netcdf.createDimension('rlon', len(self.grid.rlon)) var_dim = ('rlat', 'rlon') @@ -177,7 +177,7 @@ class DefaultWriter(Writer): y_var.standard_name = "projection_y_coordinate" y_var[:] = self.grid.y - elif self.grid.grid_type == 'Rotated': + elif self.grid.grid_type in ['Rotated', 'Rotated_nested']: self.logger.write_log('\t\tCreating rlat variable', message_level=3) rlat = netcdf.createVariable('rlat', np.float64, ('rlat',)) rlat.long_name = "latitude in rotated pole grid" @@ -224,7 +224,7 @@ class DefaultWriter(Writer): var.grid_mapping = 'Latitude_Longitude' elif self.grid.grid_type == 'Lambert Conformal Conic': var.grid_mapping = 'Lambert_Conformal' - elif self.grid.grid_type == 'Rotated': + elif self.grid.grid_type in ['Rotated', 'Rotated_nested']: var.grid_mapping = 'rotated_pole' elif self.grid.grid_type == 'Mercator': var.grid_mapping = 'mercator' @@ -247,7 +247,7 @@ class DefaultWriter(Writer): mapping.longitude_of_central_meridian = self.grid.attributes['lon_0'] mapping.latitude_of_projection_origin = self.grid.attributes['lat_0'] - elif self.grid.grid_type == 'Rotated': + elif self.grid.grid_type in ['Rotated', 'Rotated_nested']: mapping = netcdf.createVariable('rotated_pole', 'c') mapping.grid_mapping_name = 'rotated_latitude_longitude' mapping.grid_north_pole_latitude = 90 - self.grid.attributes['new_pole_latitude_degrees'] -- GitLab From ecda0f044a8f74169e8234d3541b052397da9a2b Mon Sep 17 00:00:00 2001 From: Carles Tena Date: Wed, 12 Feb 2020 12:05:46 +0100 Subject: [PATCH 4/7] Added rotated-nested on monarch writer --- hermesv3_bu/writer/monarch_writer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hermesv3_bu/writer/monarch_writer.py b/hermesv3_bu/writer/monarch_writer.py index 3e43f0d..3975620 100755 --- a/hermesv3_bu/writer/monarch_writer.py +++ b/hermesv3_bu/writer/monarch_writer.py @@ -62,8 +62,8 @@ class MonarchWriter(Writer): super(MonarchWriter, self).__init__(comm_world, comm_write, logger, netcdf_path, grid, date_array, pollutant_info, rank_distribution, emission_summary) - if self.grid.grid_type not in ['Rotated']: - error_exit("ERROR: Only Rotated grid is implemented for MONARCH. " + + if self.grid.grid_type not in ['Rotated', 'Rotated_nested']: + error_exit("ERROR: Only Rotated or Rotated-nested grid is implemented for MONARCH. " + "The current grid type is '{0}'".format(self.grid.grid_type)) for i, (pollutant, variable) in enumerate(self.pollutant_info.iterrows()): -- GitLab From 1a61f0d344d9697d1444099e0b9ffa83fd464f3c Mon Sep 17 00:00:00 2001 From: Carles Tena Date: Wed, 12 Feb 2020 13:49:06 +0100 Subject: [PATCH 5/7] PEP8 corrections --- hermesv3_bu/grids/grid_rotated_nested.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hermesv3_bu/grids/grid_rotated_nested.py b/hermesv3_bu/grids/grid_rotated_nested.py index 13cf552..2630173 100755 --- a/hermesv3_bu/grids/grid_rotated_nested.py +++ b/hermesv3_bu/grids/grid_rotated_nested.py @@ -84,7 +84,8 @@ class RotatedNestedGrid(Grid): inverse=True) corner_longitudes = self.create_bounds(center_longitudes, self.attributes['inc_rlon'], number_vertices=4) - self.logger.write_time_log('RotatedNestedGrid', 'create_regular_rotated', timeit.default_timer() - spent_time, 3) + self.logger.write_time_log('RotatedNestedGrid', 'create_regular_rotated', + timeit.default_timer() - spent_time, 3) return center_latitudes, center_longitudes, corner_latitudes, corner_longitudes def create_coords(self): @@ -101,7 +102,7 @@ class RotatedNestedGrid(Grid): # Create rotated boundary coordinates b_lats = super(RotatedNestedGrid, self).create_bounds(c_lats, self.attributes['inc_rlat'], number_vertices=4, - inverse=True) + inverse=True) b_lons = super(RotatedNestedGrid, self).create_bounds(c_lons, self.attributes['inc_rlon'], number_vertices=4) # Rotated to Lat-Lon -- GitLab From 5d088b77618daa8513c8bdf35b00312d3dbe32e5 Mon Sep 17 00:00:00 2001 From: Carles Tena Date: Thu, 13 Feb 2020 10:45:49 +0100 Subject: [PATCH 6/7] Substracting 1 to the i_parent and j_parent start --- hermesv3_bu/grids/grid_rotated_nested.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hermesv3_bu/grids/grid_rotated_nested.py b/hermesv3_bu/grids/grid_rotated_nested.py index 2630173..9b5ed39 100755 --- a/hermesv3_bu/grids/grid_rotated_nested.py +++ b/hermesv3_bu/grids/grid_rotated_nested.py @@ -47,14 +47,15 @@ class RotatedNestedGrid(Grid): netcdf = Dataset(attributes['parent_grid_path'], mode='r') - # TODO check if the i_parent start, j_parent_start begin in 0 or in 1 rlat = netcdf.variables['rlat'][:] attributes['inc_rlat'] = (rlat[1] - rlat[0]) / attributes['parent_ratio'] - attributes['1st_rlat'] = rlat[int(attributes['j_parent_start'])] + # j_parent_start start the index at 1 so we must - 1 + attributes['1st_rlat'] = rlat[int(attributes['j_parent_start']) - 1] rlon = netcdf.variables['rlon'][:] attributes['inc_rlon'] = (rlon[1] - rlon[0]) / attributes['parent_ratio'] - attributes['1st_rlon'] = rlon[attributes['i_parent_start']] + # i_parent_start start the index at 1 so we must - 1 + attributes['1st_rlon'] = rlon[attributes['i_parent_start'] - 1] rotated_pole = netcdf.variables['rotated_pole'] attributes['new_pole_longitude_degrees'] = rotated_pole.grid_north_pole_longitude -- GitLab From 55f4ee99cffc87496b7b072a5fdbe87acb142cb9 Mon Sep 17 00:00:00 2001 From: Carles Tena Date: Thu, 13 Feb 2020 14:37:02 +0100 Subject: [PATCH 7/7] Increased the buffer size --- hermesv3_bu/writer/writer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hermesv3_bu/writer/writer.py b/hermesv3_bu/writer/writer.py index 0a92322..f7ca833 100755 --- a/hermesv3_bu/writer/writer.py +++ b/hermesv3_bu/writer/writer.py @@ -14,6 +14,8 @@ CHUNKING = True BALANCED = False MPI_TAG_CONSTANT = 10**6 +BUFFER_SIZE = 2**28 + def select_writer(logger, comm_world, arguments, grid, date_array): """ @@ -328,7 +330,7 @@ class Writer(object): for i_rank in range(self.comm_world.Get_size()): self.logger.write_log( '\tFrom {0} to {1}'.format(i_rank, self.comm_world.Get_rank()), message_level=3) - req = self.comm_world.irecv(2**27, source=i_rank, tag=i_rank) + req = self.comm_world.irecv(BUFFER_SIZE, source=i_rank, tag=i_rank) dataframe = req.wait() data_list.append(dataframe.reset_index()) -- GitLab