Skip to content

Commit

Permalink
Store grid mapping on metpy_crs coord rather than DataArray attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
jthielen committed Aug 30, 2021
1 parent e6786f8 commit 260e541
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/metpy/io/gempak.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
specific_humidity_from_dewpoint, thickness_hydrostatic,
virtual_temperature)
from ..package_tools import Exporter
from ..plots.mapping import CFProjection
from ..units import units

exporter = Exporter(globals())
Expand Down Expand Up @@ -1270,12 +1271,12 @@ def gdxarray(self, parameter=None, date_time=None, coordinate=None,
gvcord: [col_head.GLV1],
'x': self.x,
'y': self.y,
'metpy_crs': CFProjection(self.crs.to_cf())
},
dims=['time', gvcord, 'y', 'x'],
name=var,
attrs={
**self.crs.to_cf(),
'grid_type': ftype,
'gempak_grid_type': ftype,
}
)
grids.append(xrda)
Expand Down
25 changes: 25 additions & 0 deletions tests/io/test_gempak.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,28 @@ def test_coordinates_creation(proj_type):

assert_allclose(decode_lat, true_lat, rtol=1e-6, atol=1e-2)
assert_allclose(decode_lon, true_lon, rtol=1e-6, atol=1e-2)


@pytest.mark.parametrize('proj_type, proj_attrs', [
('conical', {
'grid_mapping_name': 'lambert_conformal_conic',
'standard_parallel': (25.0, 25.0),
'latitude_of_projection_origin': 0.0,
'longitude_of_central_meridian': -95.0,
'semi_major_axis': 6371200.,
'semi_minor_axis': 6371200.,
}),
('azimuthal', {
'grid_mapping_name': 'polar_stereographic',
'latitude_of_projection_origin': 90.0,
'straight_vertical_longitude_from_pole': -105.0,
'scale_factor_at_projection_origin': 1.0,
'semi_major_axis': 6371200.,
'semi_minor_axis': 6371200.,
})
])
def test_metpy_crs_creation(proj_type, proj_attrs):
grid = GempakGrid(get_test_data(f'gem_{proj_type}.grd'))
metpy_crs = grid.gdxarray()[0].metpy.crs
for k, v in proj_attrs.items():
assert metpy_crs[k] == v

0 comments on commit 260e541

Please sign in to comment.