Coverage for src/CSET/loaders/profiles.py: 39%
17 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-05 21:08 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-05 21:08 +0000
1# © Crown copyright, Met Office (2022-2025) and CSET contributors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
15"""Load profile recipes."""
17import itertools
19from CSET.recipes import Config, RawRecipe, get_models
22def load(conf: Config):
23 """Yield recipes from the given workflow configuration."""
24 # Load a list of model detail dictionaries.
25 models = get_models(conf.asdict())
27 # Pressure level fields.
28 if conf.PROFILE_PLEVEL: 28 ↛ 29line 28 didn't jump to line 29 because the condition on line 28 was never true
29 for field, method in itertools.product(
30 conf.PRESSURE_LEVEL_FIELDS,
31 conf.SPATIAL_PLEVEL_FIELD_METHOD,
32 ):
33 yield RawRecipe(
34 recipe="generic_level_domain_mean_vertical_profile_series.yaml",
35 variables={
36 "VARNAME": field,
37 "LEVELTYPE": "pressure",
38 "MODEL_NAME": [model["name"] for model in models],
39 "METHOD": method,
40 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None,
41 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT
42 if conf.SELECT_SUBAREA
43 else None,
44 },
45 model_ids=[model["id"] for model in models],
46 aggregation=False,
47 )
49 # Model level fields
50 if conf.PROFILE_MLEVEL: 50 ↛ 51line 50 didn't jump to line 51 because the condition on line 50 was never true
51 for field, method in itertools.product(
52 conf.MODEL_LEVEL_FIELDS,
53 conf.SPATIAL_MLEVEL_FIELD_METHOD,
54 ):
55 yield RawRecipe(
56 recipe="generic_level_domain_mean_vertical_profile_series.yaml",
57 variables={
58 "VARNAME": field,
59 "LEVELTYPE": "model_level_number",
60 "MODEL_NAME": [model["name"] for model in models],
61 "METHOD": method,
62 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None,
63 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT
64 if conf.SELECT_SUBAREA
65 else None,
66 },
67 model_ids=[model["id"] for model in models],
68 aggregation=False,
69 )
71 # Create a list of case aggregation types.
72 AGGREGATION_TYPES = ["lead_time", "hour_of_day", "validity_time", "all"]
74 # Pressure level fields.
75 for atype, field in itertools.product( 75 ↛ 78line 75 didn't jump to line 78 because the loop on line 75 never started
76 AGGREGATION_TYPES, conf.PRESSURE_LEVEL_FIELDS
77 ):
78 if conf.PROFILE_PLEVEL_AGGREGATION[AGGREGATION_TYPES.index(atype)]:
79 yield RawRecipe(
80 recipe=f"generic_level_domain_mean_vertical_profile_series_case_aggregation_{atype}.yaml",
81 variables={
82 "VARNAME": field,
83 "LEVELTYPE": "pressure",
84 "MODEL_NAME": [model["name"] for model in models],
85 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None,
86 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT
87 if conf.SELECT_SUBAREA
88 else None,
89 },
90 model_ids=[model["id"] for model in models],
91 aggregation=True,
92 )
94 # Model level fields.
95 for atype, field in itertools.product(AGGREGATION_TYPES, conf.MODEL_LEVEL_FIELDS): 95 ↛ 96line 95 didn't jump to line 96 because the loop on line 95 never started
96 if conf.PROFILE_MLEVEL_AGGREGATION[AGGREGATION_TYPES.index(atype)]:
97 yield RawRecipe(
98 recipe=f"generic_level_domain_mean_vertical_profile_series_case_aggregation_{atype}.yaml",
99 variables={
100 "VARNAME": field,
101 "LEVELTYPE": "model_level_number",
102 "MODEL_NAME": [model["name"] for model in models],
103 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None,
104 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT
105 if conf.SELECT_SUBAREA
106 else None,
107 },
108 model_ids=[model["id"] for model in models],
109 aggregation=True,
110 )