Coverage for src/CSET/loaders/spatial_field.py: 34%

29 statements  

« 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. 

14 

15"""Load spatial field recipes.""" 

16 

17import itertools 

18 

19from CSET.recipes import Config, RawRecipe, get_models 

20 

21 

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()) 

26 

27 # Surface (2D) fields. 

28 if conf.SPATIAL_SURFACE_FIELD: 28 ↛ 29line 28 didn't jump to line 29 because the condition on line 28 was never true

29 for model, field, method in itertools.product( 

30 models, conf.SURFACE_FIELDS, conf.SPATIAL_SURFACE_FIELD_METHOD 

31 ): 

32 yield RawRecipe( 

33 recipe="generic_surface_spatial_plot_sequence.yaml", 

34 model_ids=model["id"], 

35 variables={ 

36 "VARNAME": field, 

37 "MODEL_NAME": model["name"], 

38 "METHOD": method, 

39 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None, 

40 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT 

41 if conf.SELECT_SUBAREA 

42 else None, 

43 }, 

44 aggregation=False, 

45 ) 

46 

47 # Pressure level fields. 

48 if conf.SPATIAL_PLEVEL_FIELD: 48 ↛ 49line 48 didn't jump to line 49 because the condition on line 48 was never true

49 for model, field, plevel, method in itertools.product( 

50 models, 

51 conf.PRESSURE_LEVEL_FIELDS, 

52 conf.PRESSURE_LEVELS, 

53 conf.SPATIAL_PLEVEL_FIELD_METHOD, 

54 ): 

55 yield RawRecipe( 

56 recipe="generic_level_spatial_plot_sequence.yaml", 

57 variables={ 

58 "VARNAME": field, 

59 "LEVELTYPE": "pressure", 

60 "LEVEL": plevel, 

61 "MODEL_NAME": model["name"], 

62 "METHOD": method, 

63 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None, 

64 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT 

65 if conf.SELECT_SUBAREA 

66 else None, 

67 }, 

68 model_ids=model["id"], 

69 aggregation=False, 

70 ) 

71 

72 # Model level fields 

73 if conf.SPATIAL_MLEVEL_FIELD: 73 ↛ 74line 73 didn't jump to line 74 because the condition on line 73 was never true

74 for model, field, mlevel, method in itertools.product( 

75 models, 

76 conf.MODEL_LEVEL_FIELDS, 

77 conf.MODEL_LEVELS, 

78 conf.SPATIAL_MLEVEL_FIELD_METHOD, 

79 ): 

80 yield RawRecipe( 

81 recipe="generic_level_spatial_plot_sequence.yaml", 

82 variables={ 

83 "VARNAME": field, 

84 "LEVELTYPE": "model_level_number", 

85 "LEVEL": mlevel, 

86 "MODEL_NAME": model["name"], 

87 "METHOD": method, 

88 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None, 

89 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT 

90 if conf.SELECT_SUBAREA 

91 else None, 

92 }, 

93 model_ids=model["id"], 

94 aggregation=False, 

95 ) 

96 

97 # Rain presence 

98 if conf.RAIN_PRESENCE_SPATIAL_PLOT: 98 ↛ 99line 98 didn't jump to line 99 because the condition on line 98 was never true

99 for model in models: 

100 yield RawRecipe( 

101 recipe="rain_presence_spatial_plot.yaml", 

102 model_ids=model["id"], 

103 variables={ 

104 "MODEL_NAME": model["name"], 

105 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None, 

106 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT 

107 if conf.SELECT_SUBAREA 

108 else None, 

109 }, 

110 aggregation=False, 

111 ) 

112 

113 # Surface winds on Beaufort Scale 

114 if conf.SFC_WIND_BEAUFORT_SCALE_SPATIAL: 114 ↛ 115line 114 didn't jump to line 115 because the condition on line 114 was never true

115 for model in models: 

116 yield RawRecipe( 

117 recipe="surface_wind_speed_on_beaufort_scale_spatial_plot.yaml", 

118 model_ids=model["id"], 

119 variables={ 

120 "MODEL_NAME": model["name"], 

121 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None, 

122 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT 

123 if conf.SELECT_SUBAREA 

124 else None, 

125 }, 

126 aggregation=False, 

127 ) 

128 

129 # Create a list of case aggregation types. 

130 AGGREGATION_TYPES = ["lead_time", "hour_of_day", "validity_time", "all"] 

131 

132 # Surface (2D) fields. 

133 for model, atype, field in itertools.product( 133 ↛ 136line 133 didn't jump to line 136 because the loop on line 133 never started

134 models, AGGREGATION_TYPES, conf.SURFACE_FIELDS 

135 ): 

136 if conf.SPATIAL_SURFACE_FIELD_AGGREGATION[AGGREGATION_TYPES.index(atype)]: 

137 yield RawRecipe( 

138 recipe=f"generic_surface_spatial_plot_sequence_case_aggregation_mean_{atype}.yaml", 

139 variables={ 

140 "VARNAME": field, 

141 "MODEL_NAME": model["name"], 

142 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None, 

143 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT 

144 if conf.SELECT_SUBAREA 

145 else None, 

146 }, 

147 model_ids=model["id"], 

148 aggregation=True, 

149 ) 

150 

151 # Pressure level fields. 

152 for model, atype, field, plevel in itertools.product( 152 ↛ 155line 152 didn't jump to line 155 because the loop on line 152 never started

153 models, AGGREGATION_TYPES, conf.PRESSURE_LEVEL_FIELDS, conf.PRESSURE_LEVELS 

154 ): 

155 if conf.SPATIAL_PLEVEL_FIELD_AGGREGATION[AGGREGATION_TYPES.index(atype)]: 

156 yield RawRecipe( 

157 recipe=f"generic_level_spatial_plot_sequence_case_aggregation_mean_{atype}.yaml", 

158 variables={ 

159 "VARNAME": field, 

160 "LEVELTYPE": "pressure", 

161 "LEVEL": plevel, 

162 "MODEL_NAME": model["name"], 

163 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None, 

164 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT 

165 if conf.SELECT_SUBAREA 

166 else None, 

167 }, 

168 model_ids=model["id"], 

169 aggregation=True, 

170 ) 

171 

172 # Model level fields. 

173 for model, atype, field, mlevel in itertools.product( 173 ↛ 176line 173 didn't jump to line 176 because the loop on line 173 never started

174 models, AGGREGATION_TYPES, conf.MODEL_LEVEL_FIELDS, conf.MODEL_LEVELS 

175 ): 

176 if conf.SPATIAL_MLEVEL_FIELD_AGGREGATION[AGGREGATION_TYPES.index(atype)]: 

177 yield RawRecipe( 

178 recipe=f"generic_level_spatial_plot_sequence_case_aggregation_mean_{atype}.yaml", 

179 variables={ 

180 "VARNAME": field, 

181 "LEVELTYPE": "model_level_number", 

182 "LEVEL": mlevel, 

183 "MODEL_NAME": model["name"], 

184 "SUBAREA_TYPE": conf.SUBAREA_TYPE if conf.SELECT_SUBAREA else None, 

185 "SUBAREA_EXTENT": conf.SUBAREA_EXTENT 

186 if conf.SELECT_SUBAREA 

187 else None, 

188 }, 

189 model_ids=model["id"], 

190 aggregation=True, 

191 )