Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
27 changes: 21 additions & 6 deletions src/CSET/operators/constraints.py
Comment thread
mo-sro marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,28 @@ def generate_var_constraint(varname: str, **kwargs) -> iris.Constraint:

Returns
-------
varname_constraint: iris.Constraint
An Iris constraint for either:
- a single UM STASH code
- a single variable name
- a list of variable names (Cardington multi-input case)
Comment thread
mo-sro marked this conversation as resolved.
Outdated
"""
if re.match(r"m[0-9]{2}s[0-9]{2}i[0-9]{3}$", varname):
varname_constraint = iris.AttributeConstraint(STASH=varname)
else:
varname_constraint = iris.Constraint(name=varname)
return varname_constraint
_STASH_RE = re.compile(r"m\d{2}s\d{2}i\d{3}$")
# ---- CASE 1: list of variable names (e.g. Cardington multi-variable) ----
if isinstance(varname, (list, tuple)):
return iris.Constraint(
cube_func=lambda cube: (
cube.var_name in varname
Comment thread
mo-sro marked this conversation as resolved.
Outdated
or cube.standard_name in varname
or cube.name() in varname
Comment thread
mo-sro marked this conversation as resolved.
Outdated
)
)

# ---- CASE 2: single UM STASH code ----
if _STASH_RE.match(varname):
return iris.AttributeConstraint(STASH=varname)

# ---- CASE 3: single variable name ----
return iris.Constraint(name=varname)


def generate_level_constraint(
Expand Down