Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update coord criteria regex so that X prefixes or _ infixes don't break it #2347

Merged
merged 1 commit into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .codespellignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'vertical': (r'(lv_|bottom_top|sigma|h(ei)?ght|altitude|depth|isobaric|pres|'
r'^(z|lv_|bottom_top|sigma|h(ei)?ght|altitude|depth|isobaric|pres|isotherm)'
| ``(thta, u, v, dx, dy, dim_order='yx')`` |
Changed signature from ``(thta, u, v, dx, dy, dim_order='yx')``
dpres = gempak.PRES.values
Expand Down
21 changes: 11 additions & 10 deletions src/metpy/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@
},
},
'regular_expression': {
'time': r'time[0-9]*',
'vertical': (r'(lv_|bottom_top|sigma|h(ei)?ght|altitude|depth|isobaric|pres|'
r'isotherm)[a-z_]*[0-9]*'),
'y': r'y',
'latitude': r'x?lat[a-z0-9]*',
'x': r'x',
'longitude': r'x?lon[a-z0-9]*'
'time': re.compile(r'^(x?)time(s?)[0-9]*$'),
'vertical': re.compile(
r'^(z|lv_|bottom_top|sigma|h(ei)?ght|altitude|depth|isobaric|pres|isotherm)'
r'[a-z_]*[0-9]*$'
),
'y': re.compile(r'^y(_?)[a-z0-9]*$'),
'latitude': re.compile(r'^(x?)lat[a-z0-9_]*$'),
'x': re.compile(r'^x(?!lon|lat|time).*(_?)[a-z0-9]*$'),
'longitude': re.compile(r'^(x?)lon[a-z0-9_]*$')
}
}

Expand Down Expand Up @@ -505,8 +507,7 @@ def find_axis_number(self, axis):
# vertical dim recognition
if axis in ('vertical', 'y', 'x'):
for i, dim in enumerate(self._data_array.dims):
if re.match(coordinate_criteria['regular_expression'][axis],
dim.lower()):
if coordinate_criteria['regular_expression'][axis].match(dim.lower()):
return i
raise exc
except ValueError:
Expand Down Expand Up @@ -1067,7 +1068,7 @@ def check_axis(var, *axes):
return True

# Check if name matches regular expression (non-CF failsafe)
if re.match(coordinate_criteria['regular_expression'][axis], var.name.lower()):
if coordinate_criteria['regular_expression'][axis].match(var.name.lower()):
return True

# If no match has been made, return False (rather than None)
Expand Down
13 changes: 12 additions & 1 deletion tests/test_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,10 @@ def test_check_axis_unit_match(test_ds_generic, test_tuple):
('time42', 'time'),
('Time', 'time'),
('TIME', 'time'),
('XTIME', 'time'),
('Times', 'time'),
('bottom_top', 'vertical'),
('bottom_top_stag', 'vertical'),
('sigma', 'vertical'),
('HGHT', 'vertical'),
('height', 'vertical'),
Expand All @@ -512,18 +515,26 @@ def test_check_axis_unit_match(test_ds_generic, test_tuple):
('pressure', 'vertical'),
('pressure_difference_layer', 'vertical'),
('isothermal', 'vertical'),
('z', 'vertical'),
('z_stag', 'vertical'),
('y', 'y'),
('Y', 'y'),
('y_stag', 'y'),
('yc', 'y'),
('lat', 'latitude'),
('latitude', 'latitude'),
('Latitude', 'latitude'),
('XLAT', 'latitude'),
('XLAT_U', 'latitude'),
('x', 'x'),
('X', 'x'),
('x_stag', 'x'),
('xc', 'x'),
('lon', 'longitude'),
('longitude', 'longitude'),
('Longitude', 'longitude'),
('XLONG', 'longitude')
('XLONG', 'longitude'),
('XLONG_V', 'longitude')
]


Expand Down