From dc2da816840829fd87f98db47421616cd5b669d6 Mon Sep 17 00:00:00 2001 From: Javier Vegas-Regidor Date: Tue, 8 Jun 2021 12:05:25 +0200 Subject: [PATCH 1/2] Use dask in regmean --- earthdiagnostics/ocean/regionmean.py | 32 ++++++---------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/earthdiagnostics/ocean/regionmean.py b/earthdiagnostics/ocean/regionmean.py index e01b5a0a..1b18093f 100644 --- a/earthdiagnostics/ocean/regionmean.py +++ b/earthdiagnostics/ocean/regionmean.py @@ -205,7 +205,7 @@ class RegionMean(Diagnostic): def _mean_2d_var(self, data, mesh, masks): areacello = mesh.get_areacello(cell_point=self.grid_point) - mean = regmean.compute_regmean_2d(data.data, masks, areacello) + mean = regmean.compute_regmean_2d(data.core_data(), masks, areacello) self._save_result_2d("mean", mean, data) def _meand_3d_variable(self, data, mesh, masks): @@ -213,20 +213,20 @@ class RegionMean(Diagnostic): e3 = self._try_load_cube(3) e3 = self._rename_depth(e3) e3.coord("depth").bounds = data.coord("depth").bounds - if self.box.min_depth is not -1 and self.box.max_depth is not -1: + if self.box.min_depth != -1 and self.box.max_depth != -1: depth_constraint = iris.Constraint( depth=lambda c: self.box.min_depth <= c <= self.box.max_depth ) e3 = e3.extract(depth_constraint) data = data.extract(depth_constraint) - if self.box.min_depth is -1 and self.box.max_depth is not -1: + if self.box.min_depth == -1 and self.box.max_depth != -1: self.box.min_depth = 0 depth_constraint = iris.Constraint( depth=lambda c: self.box.min_depth <= c <= self.box.max_depth ) e3 = e3.extract(depth_constraint) data = data.extract(depth_constraint) - if self.box.min_depth is not -1 and self.box.max_depth is -1: + if self.box.min_depth != -1 and self.box.max_depth == -1: self.box.max_depth = 6000 depth_constraint = iris.Constraint( depth=lambda c: self.box.min_depth <= c <= self.box.max_depth @@ -234,10 +234,10 @@ class RegionMean(Diagnostic): e3 = e3.extract(depth_constraint) data = data.extract(depth_constraint) volcello = areacello * e3.data.astype(np.float32) - mean = regmean.compute_regmean_3d(data.data, masks, volcello) + mean = regmean.compute_regmean_3d(data.core_data(), masks, volcello) self._save_result_2d("mean", mean, data) if self.save3d: - mean3d = regmean.compute_regmean_levels(data.data, masks, volcello) + mean3d = regmean.compute_regmean_levels(data.core_data(), masks, volcello) self._save_result_3d("mean", mean3d, data) def _try_load_cube(self, number): @@ -270,26 +270,6 @@ class RegionMean(Diagnostic): return cube def _load_data(self): - # handler = Utils.open_cdf(self.variable_file.local_file) - # coords = set(handler.variables[self.variable].coordinates.split(' ')) - # for variable in handler.variables: - # if variable in ( - # "time", - # "lev", - # "lat", - # "lon", - # "latitude", - # "longitude", - # "leadtime", - # "time_centered", - # ): - # coords.add(variable) - # if variable == "time_centered": - # handler.variables[variable].standard_name = "" - - # handler.variables[self.variable].coordinates = " ".join(coords) - # handler.close() - data = iris.load_cube(self.variable_file.local_file) return self._rename_depth(data) -- GitLab From 235ae852bb709954e6200f946f9475f867c17a65 Mon Sep 17 00:00:00 2001 From: Javier Vegas-Regidor Date: Tue, 8 Jun 2021 13:16:38 +0200 Subject: [PATCH 2/2] Fix flake8 --- earthdiagnostics/ocean/regionmean.py | 4 +++- earthdiagnostics/ocean/regionsum.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/earthdiagnostics/ocean/regionmean.py b/earthdiagnostics/ocean/regionmean.py index 1b18093f..e2d2db10 100644 --- a/earthdiagnostics/ocean/regionmean.py +++ b/earthdiagnostics/ocean/regionmean.py @@ -237,7 +237,9 @@ class RegionMean(Diagnostic): mean = regmean.compute_regmean_3d(data.core_data(), masks, volcello) self._save_result_2d("mean", mean, data) if self.save3d: - mean3d = regmean.compute_regmean_levels(data.core_data(), masks, volcello) + mean3d = regmean.compute_regmean_levels( + data.core_data(), masks, volcello + ) self._save_result_3d("mean", mean3d, data) def _try_load_cube(self, number): diff --git a/earthdiagnostics/ocean/regionsum.py b/earthdiagnostics/ocean/regionsum.py index ded849f6..b89cc195 100644 --- a/earthdiagnostics/ocean/regionsum.py +++ b/earthdiagnostics/ocean/regionsum.py @@ -229,7 +229,7 @@ class RegionSum(Diagnostic): e3 = self._try_load_cube(3) e3 = self._rename_depth(e3) e3.coord("depth").bounds = data.coord("depth").bounds - if self.box.min_depth is not -1 and self.box.max_depth is not -1: + if self.box.min_depth != -1 and self.box.max_depth != -1: depth_constraint = iris.Constraint( depth=lambda c: self.box.min_depth <= c <= self.box.max_depth ) -- GitLab