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

Fix arcgisimage for cylindrical coordinates, remove imread #505

Merged
merged 3 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions lib/mpl_toolkits/basemap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4228,6 +4228,21 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\

returns a matplotlib.image.AxesImage instance.
"""


# fix PIL import on some versions of OSX and scipy
try:
from PIL import Image
except ImportError:
try:
import Image
except ImportError:
msg = ('arcgisimage method requires PIL '
'(http://pillow.readthedocs.io)')
raise ImportError(msg)



if not hasattr(self,'epsg'):
msg = dedent("""
Basemap instance must be creating using an EPSG code
Expand All @@ -4247,7 +4262,7 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\
arcgisimage cannot handle images that cross
the dateline for cylindrical projections.""")
raise ValueError(msg)
if self.projection == 'cyl':
if self.projection != 'cyl':
xmin = (180./np.pi)*xmin; xmax = (180./np.pi)*xmax
ymin = (180./np.pi)*ymin; ymax = (180./np.pi)*ymax
# ypixels not given, find by scaling xpixels by the map aspect ratio.
Expand All @@ -4268,8 +4283,8 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\
# print URL?
if verbose: print(basemap_url)
# return AxesImage instance.
return self.imshow(imread(urlopen(basemap_url)),ax=ax,
origin='upper')
img = Image.open(urlopen(basemap_url))
return self.imshow(img, ax=ax, origin='upper')

def wmsimage(self,server,\
xpixels=400,ypixels=None,\
Expand Down
12 changes: 11 additions & 1 deletion lib/mpl_toolkits/basemap/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,21 @@ def test_optional_casting(self):

class TestOrthoProjPolygons(TestCase):
def test_basemapcreation_should_not_fail(self):
# different resolutions should work
# different resolutions should work
for r in ['c', 'l', 'i', 'h', 'f']:
m = Basemap(projection='ortho',resolution=r,lat_1=45.,lat_2=55,lat_0=50,lon_0=-107.)
pass

@skipIf(not PY3, "Test skipped for Python 2.x as it requires PIL installed")
class TestArcgisimage(TestCase):
def test_cyl_proj_should_not_fail(self):
m = Basemap(projection='cyl',
llcrnrlon=-90,llcrnrlat=30,
urcrnrlon=-60,urcrnrlat=60)
m.arcgisimage(verbose=True)



def test():
"""
Run some tests.
Expand Down