From 253315e50a5daf85899537be03c846df6bf28375 Mon Sep 17 00:00:00 2001 From: Carles Tena Date: Thu, 11 Jul 2019 16:41:31 +0200 Subject: [PATCH 1/5] Added decimals --- conf/hermes.conf | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/conf/hermes.conf b/conf/hermes.conf index 06efd97..2679fcd 100755 --- a/conf/hermes.conf +++ b/conf/hermes.conf @@ -30,12 +30,12 @@ vertical_description = /data/profiles/vertical/Benchmark_15layers_ver auxiliar_files_path = /data/auxiliar_files/_ # if domain_type == global: - #inc_lat = 1. + #inc_lat = 1.0 #inc_lon = 1.40625 # if domain_type == regular: - lat_orig = 30. - lon_orig = -30. + lat_orig = 30.0 + lon_orig = -30.0 inc_lat = 0.05 inc_lon = 0.1 n_lat = 840 @@ -43,18 +43,18 @@ auxiliar_files_path = /data/auxiliar_files/_ # if domain_type == rotated: - #centre_lat = 35 - #centre_lon = 20 + #centre_lat = 35.0 + #centre_lon = 20.0 #west_boundary = -51 #south_boundary = -35 #inc_rlat = 0.1 #inc_rlon = 0.1 # if domain_type == lcc: - #lat_1 = 37 - #lat_2 = 43 - #lon_0 = -3 - #lat_0 = 40 + #lat_1 = 37.0 + #lat_2 = 43.0 + #lon_0 = -3.0 + #lat_0 = 40.0 #nx = 478 #ny = 398 #inc_x = 12000 @@ -64,13 +64,13 @@ auxiliar_files_path = /data/auxiliar_files/_ # if domain_type == mercator: #lat_ts = -1.5 - #lon_0 = -18 + #lon_0 = -18.0 #nx = 210 #ny = 236 #inc_x = 50000 #inc_y = 50000 #x_0 = -126017.5 - #y_0 = -5407460 + #y_0 = -5407460.0 [EMISSION_INVENTORY_CONFIGURATION] -- GitLab From 5554bc5fc85b77eb2514a2d3b4de89aa8baf2fd5 Mon Sep 17 00:00:00 2001 From: Carles Tena Date: Fri, 19 Jul 2019 14:50:49 +0200 Subject: [PATCH 2/5] Corrected bug on creating 1d coordinates arrays --- conf/hermes.conf | 16 ++-- hermesv3_gr/modules/grids/grid.py | 7 +- hermesv3_gr/modules/grids/grid_latlon.py | 9 ++- hermesv3_gr/modules/grids/grid_lcc.py | 5 +- hermesv3_gr/modules/grids/grid_mercator.py | 4 +- hermesv3_gr/tools/coordinates_tools.py | 86 +--------------------- 6 files changed, 26 insertions(+), 101 deletions(-) diff --git a/conf/hermes.conf b/conf/hermes.conf index 06efd97..7092653 100755 --- a/conf/hermes.conf +++ b/conf/hermes.conf @@ -30,16 +30,16 @@ vertical_description = /data/profiles/vertical/Benchmark_15layers_ver auxiliar_files_path = /data/auxiliar_files/_ # if domain_type == global: - #inc_lat = 1. - #inc_lon = 1.40625 + inc_lat = 1. + inc_lon = 1.40625 # if domain_type == regular: - lat_orig = 30. - lon_orig = -30. - inc_lat = 0.05 - inc_lon = 0.1 - n_lat = 840 - n_lon = 900 + #lat_orig = 30. + #lon_orig = -30. + #inc_lat = 0.05 + #inc_lon = 0.1 + #n_lat = 840 + #n_lon = 900 # if domain_type == rotated: diff --git a/hermesv3_gr/modules/grids/grid.py b/hermesv3_gr/modules/grids/grid.py index 81c4dfd..7ade19f 100755 --- a/hermesv3_gr/modules/grids/grid.py +++ b/hermesv3_gr/modules/grids/grid.py @@ -312,13 +312,18 @@ class Grid(object): """ st_time = timeit.default_timer() + print center + print inc + print boundary # Calculate first center point. origin = center - abs(boundary) + print origin # Calculate the quantity of cells. n = (abs(boundary) / inc) * 2 # Calculate all the values - values = np.arange(origin + inc, origin + (n * inc) - inc + inc / 2, inc, dtype=np.float) + # values_old = np.arange(origin + inc, origin + (n * inc) - inc + inc / 2, inc, dtype=np.float) + values = np.linspace(origin + inc, origin + ((n - 1) * inc), n - 1, dtype=np.float) settings.write_time('Grid', 'create_regular_grid_1d_array', timeit.default_timer() - st_time, level=3) diff --git a/hermesv3_gr/modules/grids/grid_latlon.py b/hermesv3_gr/modules/grids/grid_latlon.py index 21b28ab..f66f80e 100755 --- a/hermesv3_gr/modules/grids/grid_latlon.py +++ b/hermesv3_gr/modules/grids/grid_latlon.py @@ -117,19 +117,20 @@ class LatLonGrid(Grid): lat_c_orig = self.lat_orig + (self.inc_lat / 2) lon_c_orig = self.lon_orig + (self.inc_lon / 2) - self.center_latitudes = np.arange(lat_c_orig, lat_c_orig + self.inc_lat * self.n_lat, self.inc_lat, - dtype=np.float) + self.center_latitudes = np.linspace(lat_c_orig, lat_c_orig + (self.inc_lat * (self.n_lat - 1)), self.n_lat, + dtype=np.float) boundary_latitudes = self.create_bounds(self.center_latitudes, self.inc_lat) # ===== Longitudes ===== - self.center_longitudes = np.arange(lon_c_orig, lon_c_orig + self.inc_lon * self.n_lon, self.inc_lon, - dtype=np.float) + self.center_longitudes = np.linspace(lon_c_orig, lon_c_orig + (self.inc_lon * (self.n_lon - 1)), self.n_lon, + dtype=np.float) if len(self.center_longitudes)//2 < settings.size: settings.write_log('ERROR: Check the .err file to get more info.') if settings.rank == 0: raise AttributeError("ERROR: Maximum number of processors exceeded. " + "It has to be less or equal than {0}.".format(len(self.center_longitudes)//2)) sys.exit(1) + boundary_longitudes = self.create_bounds(self.center_longitudes, self.inc_lon) self.boundary_latitudes = boundary_latitudes.reshape((1,) + boundary_latitudes.shape) diff --git a/hermesv3_gr/modules/grids/grid_lcc.py b/hermesv3_gr/modules/grids/grid_lcc.py index 321aebd..c0b4d4e 100755 --- a/hermesv3_gr/modules/grids/grid_lcc.py +++ b/hermesv3_gr/modules/grids/grid_lcc.py @@ -175,14 +175,15 @@ class LccGrid(Grid): settings.write_log('\t\tCreating lcc coordinates', level=3) # Create a regular grid in metres (Two 1D arrays) - self.x = np.arange(self.x_0, self.x_0 + self.inc_x * self.nx, self.inc_x, dtype=np.float) + self.x = np.linspace(self.x_0, self.x_0 + (self.inc_x * (self.nx - 1)), self.nx, dtype=np.float) if len(self.x)//2 < settings.size: settings.write_log('ERROR: Check the .err file to get more info.') if settings.rank == 0: raise AttributeError("ERROR: Maximum number of processors exceeded. " + "It has to be less or equal than {0}.".format(len(self.x)//2)) sys.exit(1) - self.y = np.arange(self.y_0, self.y_0 + self.inc_y * self.ny, self.inc_y, dtype=np.float) + + self.y = np.linspace(self.y_0, self.y_0 + (self.inc_y * (self.ny - 1)), self.ny, dtype=np.float) # 1D to 2D x = np.array([self.x] * len(self.y)) diff --git a/hermesv3_gr/modules/grids/grid_mercator.py b/hermesv3_gr/modules/grids/grid_mercator.py index 6a0f651..c715b8e 100755 --- a/hermesv3_gr/modules/grids/grid_mercator.py +++ b/hermesv3_gr/modules/grids/grid_mercator.py @@ -164,14 +164,14 @@ class MercatorGrid(Grid): st_time = timeit.default_timer() # Create a regular grid in metres (Two 1D arrays) - self.x = np.arange(self.x_0, self.x_0 + self.inc_x * self.nx, self.inc_x, dtype=np.float) + self.x = np.linspace(self.x_0, self.x_0 + (self.inc_x * (self.nx - 1)), self.nx, dtype=np.float) if len(self.x)//2 < settings.size: settings.write_log('ERROR: Check the .err file to get more info.') if settings.rank == 0: raise AttributeError("ERROR: Maximum number of processors exceeded. " + "It has to be less or equal than {0}.".format(len(self.x)//2)) sys.exit(1) - self.y = np.arange(self.y_0, self.y_0 + self.inc_y * self.ny, self.inc_y, dtype=np.float) + self.y = np.linspace(self.y_0, self.y_0 + (self.inc_y * (self.ny - 1)), self.ny, dtype=np.float) # 1D to 2D x = np.array([self.x] * len(self.y)) diff --git a/hermesv3_gr/tools/coordinates_tools.py b/hermesv3_gr/tools/coordinates_tools.py index 8dbc7cd..56d929a 100755 --- a/hermesv3_gr/tools/coordinates_tools.py +++ b/hermesv3_gr/tools/coordinates_tools.py @@ -283,8 +283,8 @@ def create_regular_rotated(lat_origin, lon_origin, lat_inc, lon_inc, n_lat, n_lo """ import numpy as np - center_latitudes = np.arange(lat_origin, lat_origin + (n_lat*lat_inc), lat_inc, dtype=np.float) - center_longitudes = np.arange(lon_origin, lon_origin + (n_lon*lon_inc), lon_inc, dtype=np.float) + center_latitudes = np.linspace(lat_origin, lat_origin + (n_lat * (lat_inc - 1)), n_lat, dtype=np.float) + center_longitudes = np.linspace(lon_origin, lon_origin + (n_lon * (lon_inc - 1)), n_lon, dtype=np.float) corner_latitudes = create_bounds_esmpy(center_latitudes) corner_longitudes = create_bounds_esmpy(center_longitudes) @@ -292,88 +292,6 @@ def create_regular_rotated(lat_origin, lon_origin, lat_inc, lon_inc, n_lat, n_lo return center_latitudes, center_longitudes, corner_latitudes, corner_longitudes -def create_regular_old(lat_origin, lon_origin, lat_inc, lon_inc, n_lat, n_lon): - # TODO Documentation - import numpy as np - - center_latitudes = np.arange(lat_origin, lat_origin + (n_lat*lat_inc), lat_inc, dtype=np.float) - center_longitudes = np.arange(lon_origin, lon_origin + (n_lon*lon_inc), lon_inc, dtype=np.float) - - corner_latitudes = create_bounds(center_latitudes) - corner_longitudes = create_bounds(center_longitudes) - - return center_latitudes, center_longitudes, corner_latitudes, corner_longitudes - - -def create_regular_grid(center_lat, center_lon, west_boundary, south_boundary, inc_lat, inc_lon): - """ - Create a custom grid with the given parameters. The grid is divided in 4 arrays: - - Center Latitudes - - Center Longitudes - - Boundary Latitudes (# latitudes +1) - - Boundary Longitudes (# longitudes +1) - - :param center_lat: Latitude of the center of the grid (degrees). - :type center_lat: float - - :param center_lon: Longitude of the center of the grid (degrees). - :type center_lon: float - - :param west_boundary: Distance from de center to the western boundary (degrees) - (not to the center of the first cell) - :type west_boundary: float - - :param south_boundary: Distance from de center to the southern boundary (degrees) - (not to the center of the first cell) - :type south_boundary: float - - :param inc_lat: Vertical resolution of each cell (degrees). - :type inc_lat: float - - :param inc_lon: Horizontal resolution of each cell (degrees) - :type inc_lon: float - - :return: Arrays with the Center Latitudes, Center Longitudes, Boundary Latitudes, Boundary Longitudes. - :rtype: tuple (numpy.array, numpy.array, numpy.array, numpy.array) - """ - import numpy as np - - lat_origin = center_lat - abs(south_boundary) # + (inc_lat/2) - lon_origin = center_lon - abs(west_boundary) # + (inc_lon/2) - n_lat = (abs(south_boundary)/inc_lat)*2 - n_lon = (abs(west_boundary)/inc_lon)*2 - - center_latitudes = np.arange(lat_origin + inc_lat, lat_origin + (n_lat*inc_lat) - inc_lat + inc_lat / 2, inc_lat, - dtype=np.float) - center_longitudes = np.arange(lon_origin + inc_lon, lon_origin + (n_lon*inc_lon) - inc_lon + inc_lon / 2, inc_lon, - dtype=np.float) - - corner_latitudes = create_bounds(center_latitudes) - corner_longitudes = create_bounds(center_longitudes) - - center_latitudes = np.concatenate([ - [lat_origin + inc_lat / 2 - inc_lat / 4], - center_latitudes, - [lat_origin + (n_lat * inc_lat) - inc_lat / 2 + inc_lat / 4]]) - - center_longitudes = np.concatenate([ - [lon_origin + inc_lon / 2 - inc_lon / 4], - center_longitudes, - [lon_origin + (n_lon * inc_lon) - inc_lon / 2 + inc_lon / 4]]) - - corner_latitudes = np.concatenate([ - [[[lat_origin, lat_origin + inc_lat / 2]]], - corner_latitudes, - [[[lat_origin + (n_lat * inc_lat) - inc_lat / 2, lat_origin + (n_lat * inc_lat)]]]], axis=1) - - corner_longitudes = np.concatenate([ - [[[lon_origin, lon_origin + inc_lon / 2]]], - corner_longitudes, - [[[lon_origin + (n_lon * inc_lon) - inc_lon / 2, lon_origin + (n_lon * inc_lon)]]]], axis=1) - - return center_latitudes, center_longitudes, corner_latitudes, corner_longitudes - - if __name__ == '__main__': import numpy as np new_pole_lon_d = 20.0 # lonpole tlm0d -- GitLab From c0b2ab08b9a35dd5c9285d7e2bb51458b9613c1e Mon Sep 17 00:00:00 2001 From: Carles Tena Date: Fri, 19 Jul 2019 15:34:16 +0200 Subject: [PATCH 3/5] drop some prints --- hermesv3_gr/modules/grids/grid.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/hermesv3_gr/modules/grids/grid.py b/hermesv3_gr/modules/grids/grid.py index 7ade19f..e8f636c 100755 --- a/hermesv3_gr/modules/grids/grid.py +++ b/hermesv3_gr/modules/grids/grid.py @@ -312,13 +312,9 @@ class Grid(object): """ st_time = timeit.default_timer() - print center - print inc - print boundary # Calculate first center point. origin = center - abs(boundary) - print origin # Calculate the quantity of cells. n = (abs(boundary) / inc) * 2 # Calculate all the values @@ -455,7 +451,6 @@ class Grid(object): x_aux[:, :, 3] = x[np.newaxis, :, 0] x = x_aux - # print x del x_aux # y_aux = np.empty((x.shape[0], y.shape[0], 4)) @@ -470,7 +465,6 @@ class Grid(object): y_aux[:, :, 2] = y[:, np.newaxis, 1] y_aux[:, :, 3] = y[:, np.newaxis, 1] - # print y_aux y = y_aux del y_aux -- GitLab From c0b59911648c8ceba47a629af6146e1b774b17ae Mon Sep 17 00:00:00 2001 From: Carles Tena Date: Fri, 19 Jul 2019 16:27:24 +0200 Subject: [PATCH 4/5] drop old function --- hermesv3_gr/modules/grids/grid.py | 1 - 1 file changed, 1 deletion(-) diff --git a/hermesv3_gr/modules/grids/grid.py b/hermesv3_gr/modules/grids/grid.py index e8f636c..ce1133b 100755 --- a/hermesv3_gr/modules/grids/grid.py +++ b/hermesv3_gr/modules/grids/grid.py @@ -318,7 +318,6 @@ class Grid(object): # Calculate the quantity of cells. n = (abs(boundary) / inc) * 2 # Calculate all the values - # values_old = np.arange(origin + inc, origin + (n * inc) - inc + inc / 2, inc, dtype=np.float) values = np.linspace(origin + inc, origin + ((n - 1) * inc), n - 1, dtype=np.float) settings.write_time('Grid', 'create_regular_grid_1d_array', timeit.default_timer() - st_time, level=3) -- GitLab From 9c790ac00896eef2affe39ed4e9842def46bdb54 Mon Sep 17 00:00:00 2001 From: Carles Tena Date: Fri, 19 Jul 2019 18:05:10 +0200 Subject: [PATCH 5/5] MOdified version and changelog --- CHANGELOG | 4 +++- hermesv3_gr/__init__.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 918d3d0..7d4bbaf 100755 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ 1.0.4 - XXXX/XX/XX + 2019/07/19 - Specified version on timezonefinder to be less than 4.0.0 (not further support to python 2.7.X) + - Solved bug on some grid creation that makes one cell more sometimes issue #23 + 1.0.3 2019/06/07 - Solved bug on WRF-Chem unit change diff --git a/hermesv3_gr/__init__.py b/hermesv3_gr/__init__.py index 976498a..92192ee 100755 --- a/hermesv3_gr/__init__.py +++ b/hermesv3_gr/__init__.py @@ -1 +1 @@ -__version__ = "1.0.3" +__version__ = "1.0.4" -- GitLab