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

Identify 'lv_' variables as vertical coordinates. #1225

Merged
merged 2 commits into from
Oct 30, 2019

Conversation

ahijevyc
Copy link
Contributor

ncl_convert2nc starts its vertical coordinate variables with the
string "lv_". Added this to the set of regular expressions to match
in metpy.xarray.coordinate_criteria.

For example, when you download NARR grib files from https://nomads.ncdc.noaa.gov/data/narr/
and convert them from grib to netCDF, the 10-m zonal wind is stored in a variable called U_GRD_221_HTGL with a vertical coordinate lv_HTGL5.

Here are its attributes:
int lv_HTGL5(lv_HTGL5) ;
lv_HTGL5:long_name = "fixed height above ground" ;
lv_HTGL5:units = "m" ;

Unfortunately, because lv_HTGL5 doesn't have units of pressure, nor the "positive" attribute indicating positive is "up". metpy.parse_cf() doesn't recognize this as a vertical coordinate. It would be nice if ncl_convert2nc did this for you, but I think its development is over.

Could we have metpy.parse_cf() recognize this prefix? i.e. "lv_"

Otherwise you get an Attribute error
AttributeError: vertical attribute is not available.

p.s. sorry about empty line in line 194. not needed. Couldn't figure out an easy way to remove.

Description Of Changes

Checklist

  • Closes #xxxx
  • Tests added
  • Fully documented

ncl_convert2nc starts its vertical coordinate variables with the
string "lv_". Added this to the set of regular expressions to match
in metpy.xarray.coordinate_criteria.

For example, when NARR grib files are converted from grib to netCDF
the 10-m zonal wind is stored in a variable called U_GRD_221_HTGL
with a vertical coordinate lv_HTGL5.
    long_name:    fixed height above ground
    units:        m

Let metpy.parse_cf() recognize this.

Otherwise you get an Attribute error
AttributeError: vertical attribute is not available.
@CLAassistant
Copy link

CLAassistant commented Oct 30, 2019

CLA assistant check
All committers have signed the CLA.

@jthielen
Copy link
Collaborator

Good catch! Would you be able to add a test for this by adding an entry like ('lv_HTGL5', 'vertical'), to the regex_matches list in the test file? See

MetPy/tests/test_xarray.py

Lines 372 to 410 in 82e5258

regex_matches = [
('time', 'time'),
('time1', 'time'),
('time42', 'time'),
('Time', 'time'),
('TIME', 'time'),
('bottom_top', 'vertical'),
('sigma', 'vertical'),
('HGHT', 'vertical'),
('height', 'vertical'),
('Altitude', 'vertical'),
('depth', 'vertical'),
('isobaric', 'vertical'),
('isobaric1', 'vertical'),
('isobaric42', 'vertical'),
('PRES', 'vertical'),
('pressure', 'vertical'),
('pressure_difference_layer', 'vertical'),
('isothermal', 'vertical'),
('y', 'y'),
('Y', 'y'),
('lat', 'lat'),
('latitude', 'lat'),
('Latitude', 'lat'),
('XLAT', 'lat'),
('x', 'x'),
('X', 'x'),
('lon', 'lon'),
('longitude', 'lon'),
('Longitude', 'lon'),
('XLONG', 'lon')
]
@pytest.mark.parametrize('test_tuple', regex_matches)
def test_check_axis_regular_expression_match(test_ds_generic, test_tuple):
"""Test the variety of possibilities for check_axis in the regular expression match."""
data = test_ds_generic.rename({'e': test_tuple[0]})
assert check_axis(data[test_tuple[0]], test_tuple[1])

@ahijevyc
Copy link
Contributor Author

Yes, I will add a test for this in the test_xarray.py file, as suggested!

Restored whitespace to match master.
Copy link
Contributor

@zbruick zbruick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

@dopplershift dopplershift added this to the 0.12 milestone Oct 30, 2019
@dopplershift dopplershift added Area: Xarray Pertains to xarray integration Type: Enhancement Enhancement to existing functionality labels Oct 30, 2019
Copy link
Member

@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My preference would also be to fix NCL to be CF-compliant, but alas. I think this is a reasonable way to make things more useful. Thanks for the PR!

@dopplershift dopplershift merged commit fe8a511 into Unidata:master Oct 30, 2019
@ahijevyc ahijevyc deleted the lv_vertical branch October 31, 2019 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Xarray Pertains to xarray integration Type: Enhancement Enhancement to existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants