-
Notifications
You must be signed in to change notification settings - Fork 416
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
Interpret inverse_flattening = 0 as spherical datum in mapping.py #1920
Conversation
src/metpy/plots/mapping.py
Outdated
|
||
if kwargs.get('inverse_flattening', None) == 0: | ||
kwargs['ellipse'] = 'sphere' | ||
kwargs.pop('inverse_flattening', None) | ||
# WGS84 with semi_major==semi_minor is NOT the same as spherical Earth | ||
# Also need to handle the case where we're not given any spheroid | ||
kwargs['ellipse'] = None if kwargs else 'sphere' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this is the source of the current test failure. You should move this line (and it's comment) up to line 63 (in the else
) to have it say:
# Override CartoPy's default ellipse setting depending on whether we have any metadata to map about the
# spheroid.
kwargs['ellipse'] = None if kwargs else 'sphere'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code changes generally look in good shape. Can you add a test that validates that we're doing what we want? We have this right now for testing the globe:
def test_globe():
"""Test handling building a cartopy globe."""
attrs = {'grid_mapping_name': 'lambert_conformal_conic', 'earth_radius': 6367000,
'standard_parallel': 25}
proj = CFProjection(attrs)
crs = proj.to_cartopy()
globe_params = crs.globe.to_proj4_params()
assert globe_params['ellps'] == 'sphere'
assert globe_params['a'] == 6367000
assert globe_params['b'] == 6367000
It would be good to write a new test function in test_mapping.py
that sets inverse_flattening
to 0 and verifies that we can do what was failing in the original issue.
@@ -49,16 +49,23 @@ def cartopy_globe(self): | |||
if 'earth_radius' in self._attrs: | |||
kwargs = {'ellipse': 'sphere', 'semimajor_axis': self._attrs['earth_radius'], | |||
'semiminor_axis': self._attrs['earth_radius']} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a stray change crept in here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there. I think we need a slight tweak to the test so that it's actually executing the new code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Currently, pyproj CF output is not accepted by metpy.assign_crs(). The relevant logic in in /metpy/plot/mapping.py, property cartopy_globe. The error is occuring because the conversion from PyProj to CF produces a value of 0 for inverse_flattening.
This PR updates mapping.py to not pass on a value of 0 for inverse_flattening by interpreting it as a spherical datum. Currently, it passes all tests except for test_globe_spheroid() in test_mapping.py.