Skip to content

Commit

Permalink
applies review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
daflack committed Dec 12, 2024
1 parent 33a7ad0 commit 8845b53
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/CSET/operators/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ def apply_mask(
Parameters
----------
original_field: iris.cube.Cube | iris.cube.CubeList
The field to be masked.
The field(s) to be masked.
masks: iris.cube.Cube | iris.cube.CubeList
The mask being applied to the original field.
The mask being applied to the original field. Masks should
be the same length type as the original_field. The masks are applied
to each individual Cube in a CubeList in the order they are provided.
Returns
-------
Expand Down Expand Up @@ -64,14 +66,14 @@ def apply_mask(
if len(mask_list) == 1:
masked_field = original_field.copy()
masked_field.data *= mask_list[0].data
masked_field.rename(f"mask_of_{original_field.name()}")
masked_field.attributes["mask"] = f"mask_of_{original_field.name()}"
return masked_field
else:
mask_field_list = iris.cube.CubeList()
for data, mask in zip(original_field, mask_list, strict=True):
mask_field_data = data.copy()
mask_field_data.data *= mask.data
mask_field_data.rename(f"mask_of_{data.name()}")
mask_field_data.attributes["mask"] = f"mask_of_{original_field.name()}"
mask_field_list.append(mask_field_data)
return mask_field_list

Expand Down Expand Up @@ -216,8 +218,7 @@ def generate_mask(
else:
raise ValueError("""Unexpected value for condition. Expected ==, !=,
>, >=, <, <=""")
masks.rename(f"mask_for_{cube.name()}_{condition}_{value}")
masks.attributes.pop("STASH", None)
masks.attributes["mask"] = f"mask_for_{cube.name()}_{condition}_{value}"

mask_list.append(masks)
if len(mask_list) == 1:
Expand Down
File renamed without changes.
21 changes: 21 additions & 0 deletions src/CSET/recipes/example_spatial_plot_of_mask.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
category: Surface Spatial Plot
title: Example plot of a mask
description: |
Generates a mask and then provides a spatial map of the mask.
steps:
- operator: read.read_cubes

- operator: filters.generate_mask
mask_field:
operator: filters.filter_cubes
constraint:
operator: constraints.generate_var_constraint
varname: surface_altitude
condition: '>='
value: 500

- operator: plot.spatial_pcolormesh_plot

- operator: write.write_cube_to_nc
overwrite: True

0 comments on commit 8845b53

Please sign in to comment.