Skip to content
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
15 changes: 15 additions & 0 deletions src/metpy/plots/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class CFProjection(object):
"""Handle parsing CF projection metadata."""

# mapping from Cartopy to CF vocabulary
_default_attr_mapping = [('false_easting', 'false_easting'),
('false_northing', 'false_northing'),
('central_latitude', 'latitude_of_projection_origin'),
Expand Down Expand Up @@ -124,6 +125,20 @@ def make_lcc(attrs_dict, globe):
return ccrs.LambertConformal(globe=globe, **kwargs)


@CFProjection.register('albers_conical_equal_area')
def make_aea(attrs_dict, globe):
"""Handle Albers Equal Area."""
attr_mapping = [('central_longitude', 'longitude_of_central_meridian'),
('standard_parallels', 'standard_parallel')]
kwargs = CFProjection.build_projection_kwargs(attrs_dict, attr_mapping)
if 'standard_parallels' in kwargs:
try:
len(kwargs['standard_parallels'])
except TypeError:
kwargs['standard_parallels'] = [kwargs['standard_parallels']]
return ccrs.AlbersEqualArea(globe=globe, **kwargs)


@CFProjection.register('latitude_longitude')
def make_latlon(attrs_dict, globe):
"""Handle plain latitude/longitude mapping."""
Expand Down
28 changes: 28 additions & 0 deletions tests/plots/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,34 @@ def test_globe_spheroid():
assert globe_params['a'] == 6367000
assert globe_params['b'] == 6360000


def test_aea():
"""Test handling albers equal area projection."""
attrs = {'grid_mapping_name': 'albers_conical_equal_area', 'earth_radius': 6367000,
'standard_parallel': [20, 50]}
proj = CFProjection(attrs)

crs = proj.to_cartopy()
assert isinstance(crs, ccrs.AlbersEqualArea)
assert crs.proj4_params['lat_1'] == 20
assert crs.proj4_params['lat_2'] == 50
assert crs.globe.to_proj4_params()['ellps'] == 'sphere'


def test_aea_minimal():
"""Test handling albers equal area projection with minimal attributes."""
attrs = {'grid_mapping_name': 'albers_conical_equal_area'}
crs = CFProjection(attrs).to_cartopy()
assert isinstance(crs, ccrs.AlbersEqualArea)


def test_aea_single_std_parallel():
"""Test albers equal area with one standard parallel."""
attrs = {'grid_mapping_name': 'albers_conical_equal_area', 'standard_parallel': 25}
crs = CFProjection(attrs).to_cartopy()
assert isinstance(crs, ccrs.AlbersEqualArea)
assert crs.proj4_params['lat_1'] == 20
Copy link
Collaborator

Choose a reason for hiding this comment

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

This does not seem to match with the attrs that was set (attrs says 25, this says 20), which is causing test suite to now fail after the fixes I'm working on in #1325. @dopplershift Can I update it there to get tests passing?

Copy link
Member

Choose a reason for hiding this comment

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

sigh Yes. This is why we need CI working, because I suck at code review.



def test_lcc():
"""Test handling lambert conformal conic projection."""
Expand Down