Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make preprocessors mask_above/below_threshold, mask_inside/outside_range lazy #2169

Merged
merged 10 commits into from
Aug 21, 2023
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