Skip to content

Commit 4fd8701

Browse files
authored
Make preprocessors mask_above/below_threshold, mask_inside/outside_range lazy (#2169)
1 parent d518743 commit 4fd8701

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

.zenodo.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@
181181
{
182182
"affiliation": "DLR, Germany",
183183
"name": "Bauer, Julian"
184+
},
185+
{
186+
"affiliation": "Forschungszentrum Juelich, Germany",
187+
"name": "Benke, Joerg"
184188
}
185189
],
186190
"description": "ESMValCore: A community tool for pre-processing data from Earth system models in CMIP and running analysis scripts.",

CITATION.cff

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ authors:
190190
affiliation: "DLR, Germany"
191191
family-names: Bauer
192192
given-names: Julian
193+
-
194+
affiliation: "Forschungszentrum Juelich (FZJ), Germany"
195+
family-names: Benke
196+
given-names: Joerg
193197

194198
cff-version: 1.2.0
195199
date-released: 2023-07-04

esmvalcore/preprocessor/_mask.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ def _mask_with_shp(cube, shapefilename, region_indices=None):
281281
if region_indices:
282282
regions = [regions[idx] for idx in region_indices]
283283

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

287287
# Create a set of x,y points from the cube
288288
# 1D regular grids
@@ -400,7 +400,8 @@ def mask_above_threshold(cube, threshold):
400400
iris.cube.Cube
401401
thresholded cube.
402402
"""
403-
cube.data = np.ma.masked_where(cube.data > threshold, cube.data)
403+
cube.data = (da.ma.masked_where(cube.core_data() > threshold,
404+
cube.core_data()))
404405
return cube
405406

406407

@@ -422,7 +423,8 @@ def mask_below_threshold(cube, threshold):
422423
iris.cube.Cube
423424
thresholded cube.
424425
"""
425-
cube.data = np.ma.masked_where(cube.data < threshold, cube.data)
426+
cube.data = (da.ma.masked_where(cube.core_data() < threshold,
427+
cube.core_data()))
426428
return cube
427429

428430

@@ -446,7 +448,7 @@ def mask_inside_range(cube, minimum, maximum):
446448
iris.cube.Cube
447449
thresholded cube.
448450
"""
449-
cube.data = np.ma.masked_inside(cube.data, minimum, maximum)
451+
cube.data = da.ma.masked_inside(cube.core_data(), minimum, maximum)
450452
return cube
451453

452454

@@ -470,7 +472,7 @@ def mask_outside_range(cube, minimum, maximum):
470472
iris.cube.Cube
471473
thresholded cube.
472474
"""
473-
cube.data = np.ma.masked_outside(cube.data, minimum, maximum)
475+
cube.data = da.ma.masked_outside(cube.core_data(), minimum, maximum)
474476
return cube
475477

476478

0 commit comments

Comments
 (0)