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

parse_cf() mercator projection - no central_latitude #1101

Closed
ahuang11 opened this issue Jul 18, 2019 · 7 comments · Fixed by #1102
Closed

parse_cf() mercator projection - no central_latitude #1101

ahuang11 opened this issue Jul 18, 2019 · 7 comments · Fixed by #1102
Labels
Area: Projections Pertains to projecting coordinates between coordinate systems Area: Xarray Pertains to xarray integration Type: Bug Something is not working like it should
Milestone

Comments

@ahuang11
Copy link
Contributor

ahuang11 commented Jul 18, 2019

~/anaconda3/lib/python3.7/site-packages/metpy/plots/mapping.py in make_mercator(attrs_dict, globe)
    146         kwargs.pop('false_northing', None)
    147 
--> 148     return ccrs.Mercator(globe=globe, **kwargs)
    149 
    150 

TypeError: __init__() got an unexpected keyword argument 'central_latitude'

I think similar to

    # CartoPy can't handle central latitude for Geostationary (nor should it)
    # Just remove it if it's 0.
    if not kwargs.get('central_latitude'):
        kwargs.pop('central_latitude', None)
@dopplershift
Copy link
Member

Can you point me to a file somewhere with this attribute? I'd like to use it validate putting in a patch to CartoPy.

zbruick added a commit to zbruick/MetPy that referenced this issue Jul 18, 2019
ahuang11 pushed a commit to ahuang11/MetPy that referenced this issue Aug 30, 2019
@dopplershift dopplershift added Area: Projections Pertains to projecting coordinates between coordinate systems Area: Xarray Pertains to xarray integration Type: Bug Something is not working like it should labels Sep 27, 2019
@dopplershift dopplershift added this to the 0.11 milestone Sep 27, 2019
@ahuang11
Copy link
Contributor Author

ahuang11 commented Dec 3, 2019

I think I'm still getting this issue.

I don't think the logic is correct:

    if not kwargs.get('central_latitude'):
        kwargs.pop('central_latitude', None)

With this minimal example:

kwargs = {'central_latitude': 90}
if not kwargs.get('central_latitude'):
    kwargs.pop('central_latitude', None)
print(kwargs)

You can see central_latitude still exists.

I think if you remove the if statement, it works and thus can be simplified to:

kwargs = {'central_latitude': 90}
kwargs.pop('central_latitude', None)
print(kwargs)

@dopplershift
Copy link
Member

If you drop a central_latitude of 90, any already projected coordinates won't work. Can you point me to a file with this metadata so I can do a more exhaustive test?

@ahuang11
Copy link
Contributor Author

ahuang11 commented Dec 4, 2019 via email

@dopplershift
Copy link
Member

The code that's in right now, only drops central_latitude if it's "falsey", meaning that bool(kwargs['central_latitude']) == False--so None or 0 essentially. Those can be dropped without impacting the projection math. If central_latitude is 90, that results in entirely different projected value than 0, unless I'm missing something about Mercator?

@ahuang11
Copy link
Contributor Author

ahuang11 commented Dec 4, 2019

I see.

I think the issue is that cartopy's Mercator projection has no central_latitude kwd: e.g. ccrs.Mercator(central_latitude=90) will error out.

@dopplershift
Copy link
Member

@ahuang11 I'm not sure that it makes sense to ever specify a central latitude (or origin latitude) for Mercator. The CF Conventions documentation on Mercator don't list it as a metadata parameter. Also, the PROJ docs on Mercator only show lon_0 as an option, not lat_0

Testing with PyProj, it looks like lat_0 is silently ignored:

from pyproj import Proj

proj1 = Proj({'proj':'merc', 'lon_0':'-100', 'lat_0':'90'})
proj2 = Proj({'proj':'merc', 'lon_0':'-100', 'lat_0':'0'})

proj1(-100, 50) == proj2(-100, 50)

prints True.

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 Area: Xarray Pertains to xarray integration Type: Bug Something is not working like it should
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants