Commit e2b6b9ac authored by Javier Vegas-Regidor's avatar Javier Vegas-Regidor
Browse files

Use dask in regmean

parent af349fa3
...@@ -205,7 +205,7 @@ class RegionMean(Diagnostic): ...@@ -205,7 +205,7 @@ class RegionMean(Diagnostic):
def _mean_2d_var(self, data, mesh, masks): def _mean_2d_var(self, data, mesh, masks):
areacello = mesh.get_areacello(cell_point=self.grid_point) 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) self._save_result_2d("mean", mean, data)
def _meand_3d_variable(self, data, mesh, masks): def _meand_3d_variable(self, data, mesh, masks):
...@@ -213,20 +213,20 @@ class RegionMean(Diagnostic): ...@@ -213,20 +213,20 @@ class RegionMean(Diagnostic):
e3 = self._try_load_cube(3) e3 = self._try_load_cube(3)
e3 = self._rename_depth(e3) e3 = self._rename_depth(e3)
e3.coord("depth").bounds = data.coord("depth").bounds 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_constraint = iris.Constraint(
depth=lambda c: self.box.min_depth <= c <= self.box.max_depth depth=lambda c: self.box.min_depth <= c <= self.box.max_depth
) )
e3 = e3.extract(depth_constraint) e3 = e3.extract(depth_constraint)
data = data.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 self.box.min_depth = 0
depth_constraint = iris.Constraint( depth_constraint = iris.Constraint(
depth=lambda c: self.box.min_depth <= c <= self.box.max_depth depth=lambda c: self.box.min_depth <= c <= self.box.max_depth
) )
e3 = e3.extract(depth_constraint) e3 = e3.extract(depth_constraint)
data = data.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 self.box.max_depth = 6000
depth_constraint = iris.Constraint( depth_constraint = iris.Constraint(
depth=lambda c: self.box.min_depth <= c <= self.box.max_depth depth=lambda c: self.box.min_depth <= c <= self.box.max_depth
...@@ -234,10 +234,12 @@ class RegionMean(Diagnostic): ...@@ -234,10 +234,12 @@ class RegionMean(Diagnostic):
e3 = e3.extract(depth_constraint) e3 = e3.extract(depth_constraint)
data = data.extract(depth_constraint) data = data.extract(depth_constraint)
volcello = areacello * e3.data.astype(np.float32) 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) self._save_result_2d("mean", mean, data)
if self.save3d: 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) self._save_result_3d("mean", mean3d, data)
def _try_load_cube(self, number): def _try_load_cube(self, number):
...@@ -270,26 +272,6 @@ class RegionMean(Diagnostic): ...@@ -270,26 +272,6 @@ class RegionMean(Diagnostic):
return cube return cube
def _load_data(self): 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) data = iris.load_cube(self.variable_file.local_file)
return self._rename_depth(data) return self._rename_depth(data)
......
...@@ -229,7 +229,7 @@ class RegionSum(Diagnostic): ...@@ -229,7 +229,7 @@ class RegionSum(Diagnostic):
e3 = self._try_load_cube(3) e3 = self._try_load_cube(3)
e3 = self._rename_depth(e3) e3 = self._rename_depth(e3)
e3.coord("depth").bounds = data.coord("depth").bounds 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_constraint = iris.Constraint(
depth=lambda c: self.box.min_depth <= c <= self.box.max_depth depth=lambda c: self.box.min_depth <= c <= self.box.max_depth
) )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment