19
19
20
20
21
21
class Mixin__formulae_tests (Mixin__nc_load_actions ):
22
- def _make_testcase_cdl (self , formula_root_name = None , term_names = None ):
22
+ def _make_testcase_cdl (
23
+ self , formula_root_name = None , term_names = None , extra_formula_type = None
24
+ ):
23
25
"""Construct a testcase CDL for data with hybrid vertical coords."""
24
26
if formula_root_name is None :
25
27
formula_root_name = "atmosphere_hybrid_height_coordinate"
@@ -29,22 +31,54 @@ def _make_testcase_cdl(self, formula_root_name=None, term_names=None):
29
31
# unsupported type : just make something up
30
32
term_names = ["term1" ]
31
33
32
- terms_string = ""
33
- phenom_coord_names = ["vert" ] # always include the root variable
34
+ # Arrange to create additional term variables for an 'extra' hybrid
35
+ # formula, if requested.
36
+ if extra_formula_type is None :
37
+ term_names_extra = []
38
+ phenom_coord_names = ["vert" ] # always include the root variable
39
+ else :
40
+ phenom_coord_names = ["vert" , "vert_2" ] # two formula coords
41
+ term_names_extra = hh .CF_COORD_VERTICAL .get (extra_formula_type )
42
+
43
+ # Build strings to define term variables.
34
44
formula_term_strings = []
35
- for term_name in term_names :
45
+ extra_formula_term_strings = []
46
+ terms_string = ""
47
+ for term_name in term_names + term_names_extra :
36
48
term_varname = "v_" + term_name
49
+ # Include in the phenom coordinates list.
37
50
phenom_coord_names .append (term_varname )
38
- formula_term_strings .append (f"{ term_name } : { term_varname } " )
51
+ term_string = f"{ term_name } : { term_varname } "
52
+ if term_name in term_names :
53
+ # Include in the 'main' terms list.
54
+ formula_term_strings .append (term_string )
55
+ else :
56
+ # Include in the 'extra' terms list.
57
+ extra_formula_term_strings .append (term_string )
39
58
terms_string += f"""
40
59
double { term_varname } (h) ;
41
60
{ term_varname } :long_name = "{ term_name } _long_name" ;
42
61
{ term_varname } :units = "m" ;
43
62
"""
44
63
45
- # remove the extra initial space from the formula terms string
64
+ # Construct the reference strings.
46
65
phenom_coords_string = " " .join (phenom_coord_names )
47
66
formula_terms_string = " " .join (formula_term_strings )
67
+ extra_formula_terms_string = " " .join (extra_formula_term_strings )
68
+
69
+ # Construct the 'extra' hybrid coord if requested.
70
+ if extra_formula_type is None :
71
+ extra_formula_string = ""
72
+ else :
73
+ # Create the lines to add an 'extra' formula.
74
+ # For now, put this on the same dim : makes no difference.
75
+ extra_formula_string = f"""
76
+ double vert_2(h) ;
77
+ vert_2:standard_name = "{ extra_formula_type } " ;
78
+ vert_2:units = "m" ;
79
+ vert_2:formula_terms = "{ extra_formula_terms_string } " ;
80
+ """
81
+
48
82
# Create the main result string.
49
83
cdl_str = f"""
50
84
netcdf test {{
@@ -61,6 +95,7 @@ def _make_testcase_cdl(self, formula_root_name=None, term_names=None):
61
95
vert:units = "m" ;
62
96
vert:formula_terms = "{ formula_terms_string } " ;
63
97
{ terms_string }
98
+ { extra_formula_string }
64
99
}}
65
100
"""
66
101
return cdl_str
@@ -171,6 +206,31 @@ def test_unrecognised_verticaltype(self):
171
206
# which is simply discarded.
172
207
self .check_result (result , factory_type = None , formula_terms = ["a" , "b" ])
173
208
209
+ def test_two_formulae (self ):
210
+ # Construct an example with TWO hybrid coords.
211
+ # This is not errored, but we don't correctly support it.
212
+ #
213
+ # NOTE: the original Pyke implementation does not detect this problem
214
+ # By design, the new mechanism does + will raise a warning.
215
+ warning = (
216
+ "Omitting factories for some hybrid coordinates.*"
217
+ "multiple hybrid coordinates.* not supported"
218
+ )
219
+
220
+ extra_type = "ocean_sigma_coordinate"
221
+ result = self .run_testcase (
222
+ extra_formula_type = extra_type , warning = warning
223
+ )
224
+ # NOTE: FOR NOW, check expected behaviour : only one factory will be
225
+ # built, but there are coordinates (terms) for both types.
226
+ # TODO: this is a bug and needs fixing : translation should handle
227
+ # multiple hybrid coordinates in a sensible way.
228
+ self .check_result (
229
+ result ,
230
+ factory_type = extra_type ,
231
+ formula_terms = ["a" , "b" , "depth" , "eta" , "orog" , "sigma" ],
232
+ )
233
+
174
234
175
235
# Add in tests methods to exercise each (supported) vertical coordinate type
176
236
# individually.
0 commit comments