Skip to content

Commit

Permalink
Make preprocessors mask_above/below_threshold, mask_inside/outside_ra…
Browse files Browse the repository at this point in the history
…nge lazy (#2169)
  • Loading branch information
joergbenke authored Aug 21, 2023
1 parent d518743 commit 4fd8701
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@
{
"affiliation": "DLR, Germany",
"name": "Bauer, Julian"
},
{
"affiliation": "Forschungszentrum Juelich, Germany",
"name": "Benke, Joerg"
}
],
"description": "ESMValCore: A community tool for pre-processing data from Earth system models in CMIP and running analysis scripts.",
Expand Down
4 changes: 4 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ authors:
affiliation: "DLR, Germany"
family-names: Bauer
given-names: Julian
-
affiliation: "Forschungszentrum Juelich (FZJ), Germany"
family-names: Benke
given-names: Joerg

cff-version: 1.2.0
date-released: 2023-07-04
Expand Down
14 changes: 8 additions & 6 deletions esmvalcore/preprocessor/_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ def _mask_with_shp(cube, shapefilename, region_indices=None):
if region_indices:
regions = [regions[idx] for idx in region_indices]

# Create a mask for the data
mask = np.zeros(cube.shape, dtype=bool)
# Create a mask for the data (np->da)
mask = da.zeros(cube.shape, dtype=bool)

# Create a set of x,y points from the cube
# 1D regular grids
Expand Down Expand Up @@ -400,7 +400,8 @@ def mask_above_threshold(cube, threshold):
iris.cube.Cube
thresholded cube.
"""
cube.data = np.ma.masked_where(cube.data > threshold, cube.data)
cube.data = (da.ma.masked_where(cube.core_data() > threshold,
cube.core_data()))
return cube


Expand All @@ -422,7 +423,8 @@ def mask_below_threshold(cube, threshold):
iris.cube.Cube
thresholded cube.
"""
cube.data = np.ma.masked_where(cube.data < threshold, cube.data)
cube.data = (da.ma.masked_where(cube.core_data() < threshold,
cube.core_data()))
return cube


Expand All @@ -446,7 +448,7 @@ def mask_inside_range(cube, minimum, maximum):
iris.cube.Cube
thresholded cube.
"""
cube.data = np.ma.masked_inside(cube.data, minimum, maximum)
cube.data = da.ma.masked_inside(cube.core_data(), minimum, maximum)
return cube


Expand All @@ -470,7 +472,7 @@ def mask_outside_range(cube, minimum, maximum):
iris.cube.Cube
thresholded cube.
"""
cube.data = np.ma.masked_outside(cube.data, minimum, maximum)
cube.data = da.ma.masked_outside(cube.core_data(), minimum, maximum)
return cube


Expand Down

0 comments on commit 4fd8701

Please sign in to comment.