Skip to content
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

Merged
merged 8 commits into from
Jul 1, 2021

Conversation

lbunting
Copy link
Contributor

@lbunting lbunting commented Jun 18, 2021

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.

@CLAassistant
Copy link

CLAassistant commented Jun 18, 2021

CLA assistant check
All committers have signed the CLA.


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'
Copy link
Member

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'

Copy link
Member

@dopplershift dopplershift left a 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']}

Copy link
Member

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.

Copy link
Member

@dopplershift dopplershift left a 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.

tests/plots/test_mapping.py Outdated Show resolved Hide resolved
Copy link
Member

@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

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

Looks great!

@dopplershift dopplershift linked an issue Jul 1, 2021 that may be closed by this pull request
@dopplershift dopplershift added Area: Projections Pertains to projecting coordinates between coordinate systems Type: Bug Something is not working like it should labels Jul 1, 2021
@dopplershift dopplershift added this to the 1.1.0 milestone Jul 1, 2021
@dopplershift dopplershift merged commit 15d0c80 into Unidata:main Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Projections Pertains to projecting coordinates between coordinate systems Type: Bug Something is not working like it should
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pyproj output not acceptd by metpy
3 participants