Skip to content

Commit

Permalink
Add rotated latitude longitude projection to mapping.py (#3123)
Browse files Browse the repository at this point in the history
* initial attempt to add rotated_latitude_longitude

#3099

* added test for rotated lat/lon mapping

* changed to single quotes because of flake

* fixed rotated latlon test assertion
  • Loading branch information
blaylockbk committed Jul 24, 2023
1 parent 3e70b98 commit d49d6b3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/metpy/plots/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,14 @@ def make_polar_stereo(attrs_dict, globe):
kwargs = CFProjection.build_projection_kwargs(attrs_dict, attr_mapping)

return ccrs.Stereographic(globe=globe, **kwargs)


@CFProjection.register('rotated_latitude_longitude')
def make_rotated_latlon(attrs_dict, globe):
"""Handle rotated latitude/longitude projection."""
attr_mapping = [('pole_longitude', 'grid_north_pole_longitude'),
('pole_latitude', 'grid_north_pole_latitude'),
('central_rotated_longitude', 'north_pole_grid_longitude')]
kwargs = CFProjection.build_projection_kwargs(attrs_dict, attr_mapping)

return ccrs.RotatedPole(globe=globe, **kwargs)
16 changes: 16 additions & 0 deletions tests/plots/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,22 @@ def test_polar_stereographic_std_parallel():
assert crs.proj4_params['lat_ts'] == 60


def test_rotated_latitude_longitude():
"""Test handling a rotated latitude longitude projection."""
attrs = {
'grid_mapping_name': 'rotated_latitude_longitude',
'grid_north_pole_latitude': 36,
'grid_north_pole_longitude': 65,
'north_pole_grid_longitude': 0.0,
}
crs = CFProjection(attrs).to_cartopy()

assert isinstance(crs, ccrs.RotatedPole)
assert crs.proj4_params['o_lon_p'] == 0
assert crs.proj4_params['o_lat_p'] == 36
assert crs.proj4_params['lon_0'] == 180 + 65


def test_lat_lon():
"""Test handling basic lat/lon projection."""
attrs = {'grid_mapping_name': 'latitude_longitude'}
Expand Down

0 comments on commit d49d6b3

Please sign in to comment.