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

Error specifying center long for Mercator projection and extents on Python 3.6 #1097

Closed
acrosby opened this issue Jul 27, 2018 · 4 comments
Closed

Comments

@acrosby
Copy link
Contributor

acrosby commented Jul 27, 2018

Description

The following code works in Python 2 but fails in Python 3. The commented lines appear to work OK however, so it is really only a minor problem.

Code to reproduce

import cartopy.crs as ccrs
import cartopy
import matplotlib.pyplot as plt

cm_lon=51.15
maplimits = [-26., 128.3, -73.3, -31.1]

ax = plt.axes(projection=ccrs.Mercator(central_longitude=cm_lon))
#ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=cm_lon))
#ax = plt.axes(projection=ccrs.Mercator())
ax.set_extent([maplimits[0], maplimits[1], maplimits[2], maplimits[3]])
plt.show()

Traceback

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/miniconda2/envs/xesmf/lib/python3.6/site-packages/cartopy/mpl/geoaxes.py in set_extent(self, extents, crs)
    686             # the projection extents, so try and give a better error message.
--> 687             x1, y1, x2, y2 = projected.bounds
    688         except ValueError:

ValueError: not enough values to unpack (expected 4, got 0)

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-1-47cd62a8a14f> in <module>()
     12 ax.add_feature(cartopy.feature.LAND, color='gray')
     13 ax.coastlines(resolution='10m', linewidth=0.25)
---> 14 ax.set_extent([maplimits[0], maplimits[1], maplimits[2], maplimits[3]])
     15 plt.show()

~/miniconda2/envs/xesmf/lib/python3.6/site-packages/cartopy/mpl/geoaxes.py in set_extent(self, extents, crs)
    692                    'y_limits=[{ylim[0]}, {ylim[1]}]).')
    693             raise ValueError(msg.format(xlim=self.projection.x_limits,
--> 694                                         ylim=self.projection.y_limits))
    695         self.set_xlim([x1, x2])
    696         self.set_ylim([y1, y2])

ValueError: Failed to determine the required bounds in projection coordinates. Check that the values provided are within the valid range (x_limits=[-20037508.342789244, -20037508.34278924], y_limits=[-15496570.739723722, 18764656.23138057]).

@dopplershift
Copy link
Contributor

dopplershift commented Aug 10, 2018

What version of CartoPy are you using? Linux? I can't reproduce here on Python 3.6.5 and CartoPy 0.16.0 from conda-forge on MacOS. Instead (if I add ax.coastlines()), I get the following image:

map

@acrosby
Copy link
Contributor Author

acrosby commented Aug 10, 2018

I have Python 3.6.6 miniconda running under Ubuntu 18.04 with the following (subset) of packages:

# Name                    Version                   Build  Channel
cartopy                   0.16.0           py36hfa13621_0 
proj4                     5.0.1                h14c3975_0
pyepsg                    0.3.2                    py36_0  
pyproj                    1.9.5.1          py36h7b21b82_1
shapely                   1.6.4            py36h7ef4460_0  
six                       1.11.0                   py36_1  

It sounds like there is some kind of issue with the non- conda-forge repository. I think we have been using conda install -c scitools cartopy, but I see in the documentation that this is no longer recommended/mentioned. Simply running conda install -c conda-forge cartopy does in fact solve the problem...

@ajdawson
Copy link
Member

I can reproduce this problem now, it is due to using version 5 of proj (proj4 5.0.1). If you install cartopy from conda defaults you get a version built against proj4 5.0.1, but on conda-forge you get a cartopy built with proj4 4.9.3. You should pin proj4 to a version less than 5 when installing, for a new environment from defaults:

conda create -n my_env_name cartopy "proj4<5"

or to modify an existing install from defaults:

conda install "proj4<5"

Other proj4 5 problems are reported in #1071 and #1045.

@acrosby
Copy link
Contributor Author

acrosby commented Aug 10, 2018

Oh interesting, I'll have to double check that we are indeed having an issue on the Win install that seems to have a lower proj4 major version of 4.

EDIT: Yes it seems the windows installation is OK in this regard, had a different problem unrelated to Cartopy that impacted the test above.

Chilipp added a commit to psyplot/psy-maps that referenced this issue Aug 31, 2018
@QuLogic QuLogic added this to the 0.17 milestone Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants