16
16
17
17
_AXIS_NAMES = ("X" , "Y" , "Z" , "T" )
18
18
_COORD_NAMES = ("longitude" , "latitude" , "vertical" , "time" )
19
- _COORD_AXIS_MAPPING = dict (zip (_COORD_NAMES , _AXIS_NAMES ))
20
19
_CELL_MEASURES = ("area" , "volume" )
21
20
22
21
# Define the criteria for coordinate matches
23
22
# Copied from metpy
24
23
# Internally we only use X, Y, Z, T
25
- # TODO: Metpy adds latitude and longitude separately so we may revert to doing that too
26
- coordinate_criteria = {
24
+ coordinate_criteria : dict = {
27
25
"standard_name" : {
28
26
"T" : ("time" ,),
27
+ "time" : ("time" ,),
29
28
"Z" : (
30
29
"air_pressure" ,
31
30
"height" ,
41
40
"height_above_reference_ellipsoid" ,
42
41
"height_above_mean_sea_level" ,
43
42
),
44
- "Y " : ("latitude" ,),
45
- "X " : ("longitude" ,),
43
+ "latitude " : ("latitude" ,),
44
+ "longitude " : ("longitude" ,),
46
45
},
47
- "long_name" : {"T" : ("time" ,)},
48
46
"_CoordinateAxisType" : {
49
47
"T" : ("Time" ,),
50
48
"Z" : ("GeoZ" , "Height" , "Pressure" ),
51
- "Y" : ("GeoY" , "Lat" ),
52
- "X" : ("GeoX" , "Lon" ),
49
+ "Y" : ("GeoY" ,),
50
+ "latitude" : ("Lat" ,),
51
+ "X" : ("GeoX" ,),
52
+ "longitude" : ("Lon" ,),
53
53
},
54
54
"axis" : {"T" : ("T" ,), "Z" : ("Z" ,), "Y" : ("Y" ,), "X" : ("X" ,)},
55
- "positive" : {"Z" : ("up" , "down" )},
55
+ "positive" : {"Z" : ("up" , "down" ), "vertical" : ( "up" , "down" ) },
56
56
"units" : {
57
- "Y " : (
57
+ "latitude " : (
58
58
"degree_north" ,
59
59
"degree_N" ,
60
60
"degreeN" ,
61
61
"degrees_north" ,
62
62
"degrees_N" ,
63
63
"degreesN" ,
64
64
),
65
- "X " : (
65
+ "longitude " : (
66
66
"degree_east" ,
67
67
"degree_E" ,
68
68
"degreeE" ,
84
84
# },
85
85
}
86
86
87
+ coordinate_criteria ["standard_name" ]["vertical" ] = coordinate_criteria ["standard_name" ][
88
+ "Z"
89
+ ]
90
+ coordinate_criteria ["long_name" ] = coordinate_criteria ["standard_name" ]
91
+
87
92
88
93
def _get_axis_coord_single (var , key , * args ):
89
94
""" Helper method for when we really want only one result per key. """
@@ -134,22 +139,12 @@ def _get_axis_coord(
134
139
MetPy's parse_cf
135
140
"""
136
141
137
- axis = None
138
- if key in _COORD_NAMES :
139
- coord = key
140
- axis = _COORD_AXIS_MAPPING [key ]
141
- elif key in _AXIS_NAMES :
142
- coord = ""
143
- axis = key
144
- else :
142
+ if key not in _COORD_NAMES and key not in _AXIS_NAMES :
145
143
if error :
146
144
raise KeyError (f"Did not understand { key } " )
147
145
else :
148
146
return [default ]
149
147
150
- if axis is None :
151
- raise AssertionError ("Should be unreachable" )
152
-
153
148
if "coordinates" in var .encoding :
154
149
search_in = var .encoding ["coordinates" ].split (" " )
155
150
elif "coordinates" in var .attrs :
@@ -160,8 +155,8 @@ def _get_axis_coord(
160
155
results : Set = set ()
161
156
for coord in search_in :
162
157
for criterion , valid_values in coordinate_criteria .items ():
163
- if axis in valid_values : # type: ignore
164
- expected = valid_values [axis ] # type: ignore
158
+ if key in valid_values : # type: ignore
159
+ expected = valid_values [key ] # type: ignore
165
160
if var .coords [coord ].attrs .get (criterion , None ) in expected :
166
161
results .update ((coord ,))
167
162
0 commit comments