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

Model level constraint operator #272

Merged
merged 20 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
6d3ce6a
extendign constraints operator with constraining by model level and a…
Sylviabohnenstengel Nov 20, 2023
822d2b6
Update src/CSET/operators/constraints.py
Sylviabohnenstengel Nov 21, 2023
4611ebe
Update src/CSET/operators/constraints.py
Sylviabohnenstengel Nov 21, 2023
ccbb6fe
Update src/CSET/operators/constraints.py
Sylviabohnenstengel Nov 21, 2023
7b160e2
Update src/CSET/operators/constraints.py
Sylviabohnenstengel Nov 21, 2023
4322c40
Update src/CSET/operators/constraints.py
Sylviabohnenstengel Nov 21, 2023
83cf52f
addressing review suggestions.
Sylviabohnenstengel Nov 21, 2023
ef7aac6
Merge branch '271-extent-cset-operator-constraint-model-level' of git…
Sylviabohnenstengel Nov 21, 2023
6cfc64e
Update tests/operators/test_constraints.py
Sylviabohnenstengel Nov 21, 2023
d640abe
Update src/CSET/recipes/extract_instant_model_level_air_temp.yaml
Sylviabohnenstengel Nov 21, 2023
ec4b7de
Update tests/operators/test_constraints.py
Sylviabohnenstengel Nov 21, 2023
3e791f2
Update src/CSET/recipes/extract_instant_model_level_air_temp.yaml
Sylviabohnenstengel Nov 21, 2023
c247007
adding review changes.
Sylviabohnenstengel Nov 21, 2023
fb3151c
Merge branch '271-extent-cset-operator-constraint-model-level' of git…
Sylviabohnenstengel Nov 21, 2023
863a507
renaming recipe file
Sylviabohnenstengel Nov 21, 2023
b935f48
deleting redundant yaml file
Sylviabohnenstengel Nov 21, 2023
a89c313
correcting bug in recipe.
Sylviabohnenstengel Nov 21, 2023
e6f803f
Update tests/operators/test_constraints.py
Sylviabohnenstengel Nov 21, 2023
3969426
Update src/CSET/operators/constraints.py
jfrost-mo Nov 23, 2023
24dba3b
Use old union syntax
jfrost-mo Nov 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/CSET/operators/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ def generate_var_constraint(varname: str, **kwargs) -> iris.Constraint:
return varname_constraint


def generate_model_level_constraint(model_level_name: str, **kwargs) -> iris.Constraint:
Sylviabohnenstengel marked this conversation as resolved.
Show resolved Hide resolved
"""Generate constraint from variable name.
Sylviabohnenstengel marked this conversation as resolved.
Show resolved Hide resolved

Operator that takes a CF compliant model_level_number string, and uses iris to
generate a constraint to be passed into the read operator to minimize the
CubeList the read operator loads and speed up loading.
Sylviabohnenstengel marked this conversation as resolved.
Show resolved Hide resolved

Arguments
---------
model_level_name: str
Sylviabohnenstengel marked this conversation as resolved.
Show resolved Hide resolved
CF compliant model level name of variable. Needed later for LFRic.
Sylviabohnenstengel marked this conversation as resolved.
Show resolved Hide resolved

Returns
-------
model_level_number_constraint: iris.Constraint
"""
Sylviabohnenstengel marked this conversation as resolved.
Show resolved Hide resolved
model_level_number_constraint = iris.Constraint(model_level_number=model_level_name)
return model_level_number_constraint


def generate_cell_methods_constraint(cell_methods: list, **kwargs) -> iris.Constraint:
"""Generate constraint from cell methods.

Expand Down
36 changes: 36 additions & 0 deletions src/CSET/recipes/extract_instant_model_level_air_temp.yaml
Sylviabohnenstengel marked this conversation as resolved.
Show resolved Hide resolved
jfrost-mo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
title: Extract Meaned Model level Air Temperature
Sylviabohnenstengel marked this conversation as resolved.
Show resolved Hide resolved
description: |
Extracts out the instantaneous model level air temperature from a file and writes it
to a new one.
section: Grid Stat
major_cat: Major Category 1
minor_cat: Minor Category 1
Sylviabohnenstengel marked this conversation as resolved.
Show resolved Hide resolved

steps:
- operator: read.read_cubes
constraint:
operator: constraints.generate_var_constraint
varname: air_temperature

- operator: filters.filter_cubes
constraint:
operator: constraints.combine_constraints
varname_constraint:
operator: constraints.generate_var_constraint
varname: air_temperature
model_level_number_constraint:
operator: constraints.generate_model_level_constraint
model_level_name: 2
Sylviabohnenstengel marked this conversation as resolved.
Show resolved Hide resolved
cell_methods_constraint:
operator: constraints.generate_cell_methods_constraint
cell_methods: []

- operator: collapse.collapse
coordinate: time
method: MEAN

- operator: plot.spatial_contour_plot
file_path: CSET_OUTPUT_PATH

- operator: write.write_cube_to_nc
file_path: CSET_OUTPUT_PATH
9 changes: 9 additions & 0 deletions tests/operators/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ def test_generate_var_constraint():
assert repr(var_constraint) == expected_var_constraint


def test_generate_model_level_constraint():
"""Generate iris cube constraint for str variable name."""
Sylviabohnenstengel marked this conversation as resolved.
Show resolved Hide resolved
var_constraint = constraints.generate_model_level_constraint("2")
expected_model_level_constraint = (
"Constraint(coord_values={'model_level_number': 2})"
Sylviabohnenstengel marked this conversation as resolved.
Show resolved Hide resolved
)
assert repr(var_constraint) == expected_model_level_constraint


def test_generate_cell_methods_constraint():
"""Generate iris cube constraint for cell methods."""
cell_methods_constraint = constraints.generate_cell_methods_constraint([])
Expand Down
Loading