Skip to content

Commit a898641

Browse files
kthyngdcherian
andauthored
Change coord criteria to {cf_name: criteria} (#233)
Co-authored-by: Deepak Cherian <[email protected]>
1 parent e11cf07 commit a898641

File tree

3 files changed

+67
-54
lines changed

3 files changed

+67
-54
lines changed

cf_xarray/accessor.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,13 @@ def _get_axis_coord(var: Union[DataArray, Dataset], key: str) -> List[str]:
220220

221221
results: Set = set()
222222
for coord in search_in:
223-
for criterion, valid_values in coordinate_criteria.items():
224-
if key in valid_values:
225-
expected = valid_values[key]
223+
if key in coordinate_criteria:
224+
for criterion, expected in coordinate_criteria[key].items():
226225
if (
227226
coord in var.coords
228227
and var.coords[coord].attrs.get(criterion, None) in expected
229228
):
230229
results.update((coord,))
231-
232230
return list(results)
233231

234232

cf_xarray/criteria.py

Lines changed: 64 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,36 @@
55
"""
66

77

8-
import copy
98
import re
109
from typing import MutableMapping, Tuple
1110

1211
coordinate_criteria: MutableMapping[str, MutableMapping[str, Tuple]] = {
13-
"standard_name": {
14-
"X": ("projection_x_coordinate",),
15-
"Y": ("projection_y_coordinate",),
16-
"T": ("time",),
17-
"time": ("time",),
18-
"vertical": (
19-
"air_pressure",
20-
"height",
21-
"depth",
22-
"geopotential_height",
23-
# computed dimensional coordinate name
24-
"altitude",
25-
"height_above_geopotential_datum",
26-
"height_above_reference_ellipsoid",
27-
"height_above_mean_sea_level",
12+
"latitude": {
13+
"standard_name": ("latitude",),
14+
"units": (
15+
"degree_north",
16+
"degree_N",
17+
"degreeN",
18+
"degrees_north",
19+
"degrees_N",
20+
"degreesN",
2821
),
29-
"Z": (
22+
"_CoordinateAxisType": ("Lat",),
23+
},
24+
"longitude": {
25+
"standard_name": ("longitude",),
26+
"units": (
27+
"degree_east",
28+
"degree_E",
29+
"degreeE",
30+
"degrees_east",
31+
"degrees_E",
32+
"degreesE",
33+
),
34+
"_CoordinateAxisType": ("Lon",),
35+
},
36+
"Z": {
37+
"standard_name": (
3038
"model_level_number",
3139
"atmosphere_ln_pressure_coordinate",
3240
"atmosphere_sigma_coordinate",
@@ -40,44 +48,51 @@
4048
"ocean_sigma_z_coordinate",
4149
"ocean_double_sigma_coordinate",
4250
),
43-
"latitude": ("latitude",),
44-
"longitude": ("longitude",),
45-
},
46-
"_CoordinateAxisType": {
47-
"T": ("Time",),
48-
"Z": ("GeoZ", "Height", "Pressure"),
49-
"Y": ("GeoY",),
50-
"latitude": ("Lat",),
51-
"X": ("GeoX",),
52-
"longitude": ("Lon",),
53-
},
54-
"axis": {"T": ("T",), "Z": ("Z",), "Y": ("Y",), "X": ("X",)},
55-
"cartesian_axis": {"T": ("T",), "Z": ("Z",), "Y": ("Y",), "X": ("X",)},
56-
"positive": {"vertical": ("up", "down")},
57-
"units": {
58-
"latitude": (
59-
"degree_north",
60-
"degree_N",
61-
"degreeN",
62-
"degrees_north",
63-
"degrees_N",
64-
"degreesN",
51+
"_CoordinateAxisType": (
52+
"GeoZ",
53+
"Height",
54+
"Pressure",
6555
),
66-
"longitude": (
67-
"degree_east",
68-
"degree_E",
69-
"degreeE",
70-
"degrees_east",
71-
"degrees_E",
72-
"degreesE",
56+
"axis": ("Z",),
57+
},
58+
"vertical": {
59+
"standard_name": (
60+
"air_pressure",
61+
"height",
62+
"depth",
63+
"geopotential_height",
64+
# computed dimensional coordinate name
65+
"altitude",
66+
"height_above_geopotential_datum",
67+
"height_above_reference_ellipsoid",
68+
"height_above_mean_sea_level",
7369
),
70+
"positive": ("up", "down"),
71+
},
72+
"X": {
73+
"standard_name": ("projection_x_coordinate",),
74+
"_CoordinateAxisType": ("GeoX",),
75+
"axis": ("X",),
76+
},
77+
"Y": {
78+
"standard_name": ("projection_y_coordinate",),
79+
"_CoordinateAxisType": ("GeoY",),
80+
"axis": ("Y",),
81+
},
82+
"T": {"standard_name": ("time",), "_CoordinateAxisType": ("Time",), "axis": ("T",)},
83+
"time": {
84+
"standard_name": ("time",),
7485
},
7586
}
7687

7788
# "long_name" and "standard_name" criteria are the same. For convenience.
78-
coordinate_criteria["long_name"] = copy.deepcopy(coordinate_criteria["standard_name"])
79-
coordinate_criteria["long_name"]["X"] += ("cell index along first dimension",)
80-
coordinate_criteria["long_name"]["Y"] += ("cell index along second dimension",)
89+
for coord, attrs in coordinate_criteria.items():
90+
coordinate_criteria[coord]["long_name"] = coordinate_criteria[coord][
91+
"standard_name"
92+
]
93+
coordinate_criteria["X"]["long_name"] += ("cell index along first dimension",)
94+
coordinate_criteria["Y"]["long_name"] += ("cell index along second dimension",)
95+
8196

8297
#: regular expressions for guess_coord_axis
8398
regex = {

cf_xarray/scripts/make_doc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def make_criteria_csv():
3737

3838
# Axes and coordinates
3939
for keys, name in zip([_AXIS_NAMES, _COORD_NAMES], ["axes", "coords"]):
40-
subdf = df.loc[sorted(keys)].dropna(1, how="all")
40+
subdf = df[sorted(keys)].dropna(1, how="all")
4141
subdf = subdf.dropna(1, how="all").transpose()
4242
subdf.to_csv(os.path.join(csv_dir, f"{name}_criteria.csv"))
4343

0 commit comments

Comments
 (0)