99 DimensionMapper ,
1010)
1111
12- TEMPORAL_LABEL_CELL_METHODS_MAPPER = CellMethodsSubStringMapper (
12+ TEMPORAL_LABEL_CELL_METHODS_INITIAL_TESTS_MAPPER = CellMethodsSubStringMapper (
1313 sub_string_map = {
1414 "time: max" : "tmax" ,
1515 "time: min" : "tmin" ,
1818)
1919"""
2020Mapper from sub-strings of cell methods to the temporal label
21+
22+ These are for the 'initial tests'
23+ i.e. the cell methods which are checked first.
24+ There is a coupling with dimensions in the logic in
25+ [get_temporal_label][(m).], be careful!
2126"""
2227
2328TEMPORAL_LABEL_DIMENSIONS_MAPPER = DimensionMapper (
3237Mapper from dimensions to the temporal label
3338"""
3439
40+ TEMPORAL_LABEL_CELL_METHODS_TIME4_TESTS_MAPPER = CellMethodsSubStringMapper (
41+ sub_string_map = {
42+ "time: max" : "tmaxavg" ,
43+ "time: min" : "tminavg" ,
44+ }
45+ )
46+ """
47+ Mapper from sub-strings of cell methods to the temporal label for "time4" data
3548
36- def get_temporal_label (
49+ I.e. for data which has "time4" as a dimension
50+ """
51+
52+
53+ def get_temporal_label ( # noqa: PLR0913
3754 cell_methods : str | None ,
3855 dimensions : tuple [str , ...],
39- cell_methods_mapper : CellMethodsSubStringMapper = (
40- TEMPORAL_LABEL_CELL_METHODS_MAPPER
56+ cell_methods_initial_mapper : CellMethodsSubStringMapper = (
57+ TEMPORAL_LABEL_CELL_METHODS_INITIAL_TESTS_MAPPER
4158 ),
59+ cell_methods_initial_required_dimension : str = "time" ,
4260 dimensions_mapper : DimensionMapper = TEMPORAL_LABEL_DIMENSIONS_MAPPER ,
61+ cell_methods_time4_mapper : CellMethodsSubStringMapper = (
62+ TEMPORAL_LABEL_CELL_METHODS_TIME4_TESTS_MAPPER
63+ ),
4364 fallback : str = "ti" ,
4465) -> str :
4566 """
@@ -59,12 +80,29 @@ def get_temporal_label(
5980 dimensions
6081 Dimensions of the variable
6182
62- cell_methods_mapper
83+ cell_methods_initial_mapper
6384 Mapper to use to get values based on cell methods
6485
86+ This is for the 'initial' tests
87+ i.e. checks of cell methods which are performed
88+ before any other checks.
89+
90+ cell_methods_initial_required_dimension
91+ Dimension required for the result of using `cell_methods_initial_mapper`
92+ to be returned.
93+
94+ If this dimension is not found, then the other mapping checks are performed.
95+
6596 dimensions_mapper
6697 Mapper to use to get values based on dimensions
6798
99+ If you include "time4" as a mapping here,
100+ you can make a mess as you will effectively
101+ disable any use of `cell_methods_time4_mapper`.
102+
103+ cell_methods_time4_mapper
104+ Mapper to use to get values based on cell methods if "time4" is in dimensions
105+
68106 fallback
69107 Value to return if no other conditions are matched
70108
@@ -75,10 +113,18 @@ def get_temporal_label(
75113 """
76114 if cell_methods is not None :
77115 # Check cell methods first
78- if (match := cell_methods_mapper .get_value (cell_methods )) is not None :
79- return match
116+ if (match := cell_methods_initial_mapper .get_value (cell_methods )) is not None :
117+ if cell_methods_initial_required_dimension in dimensions :
118+ return match
119+
120+ # We matched cell methods but not the required dimension,
121+ # fall through to other tests
80122
81123 if (match := dimensions_mapper .get_value (dimensions )) is not None :
82124 return match
83125
126+ if cell_methods is not None and "time4" in dimensions :
127+ if (match := cell_methods_time4_mapper .get_value (cell_methods )) is not None :
128+ return match
129+
84130 return fallback
0 commit comments