From bcd2301ba97234a8e93cd301dd187d035cc3acc6 Mon Sep 17 00:00:00 2001 From: ctena Date: Tue, 7 Mar 2023 10:42:43 +0100 Subject: [PATCH 1/4] Cell measures: Corrected bug on serial write --- nes/nc_projections/default_nes.py | 12 ++++++++---- tests/2.4-test_cell_area.py | 4 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/nes/nc_projections/default_nes.py b/nes/nc_projections/default_nes.py index a5cdb8a..da83b2b 100644 --- a/nes/nc_projections/default_nes.py +++ b/nes/nc_projections/default_nes.py @@ -342,7 +342,7 @@ class Nes(object): """ d = self.__dict__ - state = {k: d[k] for k in d if k not in ['comm', 'variables', 'netcdf']} + state = {k: d[k] for k in d if k not in ['comm', 'variables', 'netcdf', 'cell_measures']} return state @@ -380,8 +380,10 @@ class Nes(object): nessy.netcdf = None if copy_vars: nessy.variables = nessy._get_lazy_variables() + nessy.cell_measures = deepcopy(self.cell_measures) else: nessy.variables = {} + nessy.cell_measures = {} return nessy @@ -2388,11 +2390,13 @@ class Nes(object): else: # if serial: if serial and self.size > 1: - data = self._gather_data() + data = self._gather_data(self.variables) + c_measures = self._gather_data(self.cell_measures) if self.master: new_nc = self.copy(copy_vars=False) new_nc.set_communicator(MPI.COMM_SELF) new_nc.variables = data + new_nc.cell_measures = c_measures if type == 'NES': new_nc.__to_netcdf_py(path) elif type == 'CAMS_RA': @@ -2924,7 +2928,7 @@ class Nes(object): return data_list - def _gather_data(self): + def _gather_data(self, data_to_gather): """ Gather all the variable data into the MPI rank 0 to perform a serial write. @@ -2934,7 +2938,7 @@ class Nes(object): Variables dictionary with all the data from all the ranks. """ - data_list = deepcopy(self.variables) + data_list = deepcopy(data_to_gather) for var_name in data_list.keys(): if self.info and self.master: print("Gathering {0}".format(var_name)) diff --git a/tests/2.4-test_cell_area.py b/tests/2.4-test_cell_area.py index 4c9b152..bd4fb39 100644 --- a/tests/2.4-test_cell_area.py +++ b/tests/2.4-test_cell_area.py @@ -54,7 +54,8 @@ print('Rank {0:03d}: Calculate grid cell area: {1}'.format(rank, nessy.cell_meas # WRITE st_time = timeit.default_timer() -nessy.to_netcdf(test_name.replace(' ', '_') + "_{0:03d}.nc".format(size)) +nessy.to_netcdf(test_name.replace(' ', '_') + "_{0:03d}.nc".format(size), serial=True) +print("SERIE "*20) comm.Barrier() result.loc['write', test_name] = timeit.default_timer() - st_time @@ -192,3 +193,4 @@ del nessy if rank == 0: result.to_csv(result_path) + -- GitLab From 5d86c03d1c997c36a24ecf02df027e0d57624301 Mon Sep 17 00:00:00 2001 From: ctena Date: Tue, 7 Mar 2023 10:48:08 +0100 Subject: [PATCH 2/4] Cell measures: Corrected bug on serial write (CHANGELOG update) --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5017be6..6bcc27c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # NES CHANGELOG +### 1.1.1 +* Release date: ??? +* Changes and new features: + * Bugs fixing: + * Bug on `cell_methods` serial write ([#53](https://earth.bsc.es/gitlab/es/NES/-/issues/53)) + ### 1.1.0 * Release date: 2023/03/02 * Changes and new features: -- GitLab From 80a5ff0ad95d5a9639c57f258e4c40d0305e9886 Mon Sep 17 00:00:00 2001 From: ctena Date: Tue, 7 Mar 2023 10:49:47 +0100 Subject: [PATCH 3/4] Cell measures: Corrected bug on serial write (CHANGELOG update) --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bcc27c..663be2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * Release date: 2023/03/02 * Changes and new features: * Improve Lat-Lon to Cartesian coordinates method (used in Providentia). + * Horizontal interpolation: Conservative * Function to_shapefile() to create shapefiles from a NES object without losing data from the original grid and being able to select the time and level. * Function from_shapefile() to create a new grid with data from a shapefile after doing a spatial join. * Function create_shapefile() can now be used in parallel. -- GitLab From e9999299a339511d47076a3234626f2889f93f36 Mon Sep 17 00:00:00 2001 From: Alba Vilanova Date: Tue, 7 Mar 2023 15:18:22 +0100 Subject: [PATCH 4/4] Remove serial=True and print --- tests/2.4-test_cell_area.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/2.4-test_cell_area.py b/tests/2.4-test_cell_area.py index bd4fb39..fde0b56 100644 --- a/tests/2.4-test_cell_area.py +++ b/tests/2.4-test_cell_area.py @@ -54,8 +54,7 @@ print('Rank {0:03d}: Calculate grid cell area: {1}'.format(rank, nessy.cell_meas # WRITE st_time = timeit.default_timer() -nessy.to_netcdf(test_name.replace(' ', '_') + "_{0:03d}.nc".format(size), serial=True) -print("SERIE "*20) +nessy.to_netcdf(test_name.replace(' ', '_') + "_{0:03d}.nc".format(size)) comm.Barrier() result.loc['write', test_name] = timeit.default_timer() - st_time -- GitLab