Coverage for src/CSET/loaders/timeseries.py: 38%
27 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 timeseries 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 # Surface timeseries
28 if conf.TIMESERIES_SURFACE_FIELD: 28 ↛ 29line 28 didn't jump to line 29 because the condition on line 28 was never true
29 for field in conf.SURFACE_FIELDS:
30 yield RawRecipe(
31 recipe="generic_surface_domain_mean_time_series.yaml",
32 variables={
33 "VARNAME": field,
34 "MODEL_NAME": [model["name"] for model in models],
35 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None,
36 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT
37 if conf.SELECT_SUBAREA
38 else None,
39 },
40 model_ids=[model["id"] for model in models],
41 aggregation=False,
42 )
44 # Pressure level fields.
45 if conf.TIMESERIES_PLEVEL_FIELD: 45 ↛ 46line 45 didn't jump to line 46 because the condition on line 45 was never true
46 for field, plevel in itertools.product(
47 conf.PRESSURE_LEVEL_FIELDS, conf.PRESSURE_LEVELS
48 ):
49 yield RawRecipe(
50 recipe="generic_level_domain_mean_time_series.yaml",
51 variables={
52 "VARNAME": field,
53 "LEVELTYPE": "pressure",
54 "LEVEL": plevel,
55 "MODEL_NAME": [model["name"] for model in models],
56 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None,
57 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT
58 if conf.SELECT_SUBAREA
59 else None,
60 },
61 model_ids=[model["id"] for model in models],
62 aggregation=False,
63 )
65 # Model level fields
66 if conf.TIMESERIES_MLEVEL_FIELD: 66 ↛ 67line 66 didn't jump to line 67 because the condition on line 66 was never true
67 for field, mlevel in itertools.product(
68 conf.MODEL_LEVEL_FIELDS, conf.MODEL_LEVELS
69 ):
70 yield RawRecipe(
71 recipe="generic_level_domain_mean_time_series.yaml",
72 variables={
73 "VARNAME": field,
74 "LEVELTYPE": "model_level_number",
75 "LEVEL": mlevel,
76 "MODEL_NAME": [model["name"] for model in models],
77 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None,
78 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT
79 if conf.SELECT_SUBAREA
80 else None,
81 },
82 model_ids=[model["id"] for model in models],
83 aggregation=False,
84 )
86 # Rain presence
87 if conf.RAIN_PRESENCE_DOMAIN_MEAN_TIMESERIES: 87 ↛ 88line 87 didn't jump to line 88 because the condition on line 87 was never true
88 yield RawRecipe(
89 recipe="rain_presence_domain_mean_time_series.yaml",
90 variables={
91 "MODEL_NAME": [model["name"] for model in models],
92 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None,
93 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT if conf.SELECT_SUBAREA else None,
94 },
95 model_ids=[model["id"] for model in models],
96 aggregation=False,
97 )
99 # Surface winds on Beaufort Scale
100 if conf.SFC_WIND_BEAUFORT_SCALE_DOMAIN_MEAN_TIMESERIES: 100 ↛ 101line 100 didn't jump to line 101 because the condition on line 100 was never true
101 yield RawRecipe(
102 recipe="surface_wind_speed_on_beaufort_scale_domain_mean_time_series.yaml",
103 variables={
104 "MODEL_NAME": [model["name"] for model in models],
105 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None,
106 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT if conf.SELECT_SUBAREA else None,
107 },
108 model_ids=[model["id"] for model in models],
109 aggregation=False,
110 )
112 # Create a list of case aggregation types.
113 AGGREGATION_TYPES = ["lead_time", "hour_of_day", "validity_time", "all"]
115 # Surface (2D) fields.
116 for atype, field in itertools.product(AGGREGATION_TYPES, conf.SURFACE_FIELDS): 116 ↛ 117line 116 didn't jump to line 117 because the loop on line 116 never started
117 if conf.TIMESERIES_SURFACE_FIELD_AGGREGATION[AGGREGATION_TYPES.index(atype)]:
118 yield RawRecipe(
119 recipe=f"generic_surface_domain_mean_time_series_case_aggregation_{atype}.yaml",
120 variables={
121 "VARNAME": field,
122 "MODEL_NAME": [model["name"] for model in models],
123 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None,
124 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT
125 if conf.SELECT_SUBAREA
126 else None,
127 },
128 model_ids=[model["id"] for model in models],
129 aggregation=True,
130 )
132 # Pressure level fields.
133 for atype, field, plevel in itertools.product( 133 ↛ 136line 133 didn't jump to line 136 because the loop on line 133 never started
134 AGGREGATION_TYPES, conf.PRESSURE_LEVEL_FIELDS, conf.PRESSURE_LEVELS
135 ):
136 if conf.TIMESERIES_PLEVEL_FIELD_AGGREGATION[AGGREGATION_TYPES.index(atype)]:
137 yield RawRecipe(
138 recipe=f"generic_level_domain_mean_time_series_case_aggregation_{atype}.yaml",
139 variables={
140 "VARNAME": field,
141 "LEVELTYPE": "pressure",
142 "LEVEL": plevel,
143 "MODEL_NAME": [model["name"] for model in models],
144 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None,
145 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT
146 if conf.SELECT_SUBAREA
147 else None,
148 },
149 model_ids=[model["id"] for model in models],
150 aggregation=True,
151 )
153 # Model level fields.
154 for atype, field, mlevel in itertools.product( 154 ↛ 157line 154 didn't jump to line 157 because the loop on line 154 never started
155 AGGREGATION_TYPES, conf.MODEL_LEVEL_FIELDS, conf.MODEL_LEVELS
156 ):
157 if conf.TIMESERIES_MLEVEL_FIELD_AGGREGATION[AGGREGATION_TYPES.index(atype)]:
158 yield RawRecipe(
159 recipe=f"generic_level_domain_mean_time_series_case_aggregation_{atype}.yaml",
160 variables={
161 "VARNAME": field,
162 "LEVELTYPE": "model_level_number",
163 "LEVEL": mlevel,
164 "MODEL_NAME": [model["name"] for model in models],
165 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None,
166 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT
167 if conf.SELECT_SUBAREA
168 else None,
169 },
170 model_ids=[model["id"] for model in models],
171 aggregation=True,
172 )