From 8845b53dcd4b3e2ad056fdbf3d59f1f49b3a9a68 Mon Sep 17 00:00:00 2001 From: daflack Date: Thu, 12 Dec 2024 12:07:19 +0000 Subject: [PATCH] applies review comments --- src/CSET/operators/filters.py | 13 ++++++------ ...ml => example_combined_mask_addition.yaml} | 0 ...example_combined_mask_multiplication.yaml} | 0 ...ple_mask.yaml => example_simple_mask.yaml} | 0 .../recipes/example_spatial_plot_of_mask.yaml | 21 +++++++++++++++++++ 5 files changed, 28 insertions(+), 6 deletions(-) rename src/CSET/recipes/{combined_mask_addition.yaml => example_combined_mask_addition.yaml} (100%) rename src/CSET/recipes/{combined_mask_multiplication.yaml => example_combined_mask_multiplication.yaml} (100%) rename src/CSET/recipes/{simple_mask.yaml => example_simple_mask.yaml} (100%) create mode 100644 src/CSET/recipes/example_spatial_plot_of_mask.yaml diff --git a/src/CSET/operators/filters.py b/src/CSET/operators/filters.py index 496365ed9..cae102cae 100644 --- a/src/CSET/operators/filters.py +++ b/src/CSET/operators/filters.py @@ -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 ------- @@ -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 @@ -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: diff --git a/src/CSET/recipes/combined_mask_addition.yaml b/src/CSET/recipes/example_combined_mask_addition.yaml similarity index 100% rename from src/CSET/recipes/combined_mask_addition.yaml rename to src/CSET/recipes/example_combined_mask_addition.yaml diff --git a/src/CSET/recipes/combined_mask_multiplication.yaml b/src/CSET/recipes/example_combined_mask_multiplication.yaml similarity index 100% rename from src/CSET/recipes/combined_mask_multiplication.yaml rename to src/CSET/recipes/example_combined_mask_multiplication.yaml diff --git a/src/CSET/recipes/simple_mask.yaml b/src/CSET/recipes/example_simple_mask.yaml similarity index 100% rename from src/CSET/recipes/simple_mask.yaml rename to src/CSET/recipes/example_simple_mask.yaml diff --git a/src/CSET/recipes/example_spatial_plot_of_mask.yaml b/src/CSET/recipes/example_spatial_plot_of_mask.yaml new file mode 100644 index 000000000..c2e7b8883 --- /dev/null +++ b/src/CSET/recipes/example_spatial_plot_of_mask.yaml @@ -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