diff --git a/src/metpy/plots/mapping.py b/src/metpy/plots/mapping.py index d959ce291a8..14756c01d0d 100644 --- a/src/metpy/plots/mapping.py +++ b/src/metpy/plots/mapping.py @@ -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'), @@ -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.""" diff --git a/tests/plots/test_mapping.py b/tests/plots/test_mapping.py index fee0261a8c0..1294a54d638 100644 --- a/tests/plots/test_mapping.py +++ b/tests/plots/test_mapping.py @@ -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 + def test_lcc(): """Test handling lambert conformal conic projection."""