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

Conversation

guziy
Copy link
Contributor

@guziy guziy commented Oct 21, 2020

Change summary

  • Fix projection of domain corner for cyl projections.
  • Remove reference to matplotlib.image.imread as it is not able to open URLs anymore.
  • Add a test to make sure arcgisimage method works.

Objective

This PR makes the following code not fail and show a map:

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt

m = Basemap(projection='cyl',llcrnrlon=-90,llcrnrlat=30,urcrnrlon=-60,urcrnrlat=60, epsg="4326")
m.arcgisimage(verbose=True)
plt.show()

Current behavior

The code above produces the exception below with current basemap:

---------------------------------------------------------------------------
UnsupportedOperation                      Traceback (most recent call last)
<ipython-input-1-18c43d1bdc96> in <module>
      8 m = Basemap(projection='cyl',llcrnrlon=-90,llcrnrlat=30,urcrnrlon=-60,urcrnrlat=60, epsg="4326")
      9 
---> 10 m.arcgisimage(verbose=True)
     11 

~/Python/anaconda3/envs/py373/lib/python3.7/site-packages/mpl_toolkits/basemap/__init__.py in arcgisimage(self, server, service, xpixels, ypixels, dpi, verbose, **kwargs)
   4271         if verbose: print(basemap_url)
   4272         # return AxesImage instance.
-> 4273         return self.imshow(imread(urlopen(basemap_url)),ax=ax,
   4274                            origin='upper')
   4275 

~/Python/anaconda3/envs/py373/lib/python3.7/site-packages/matplotlib/image.py in imread(fname, format)
   1474             with urllib.request.urlopen(fname) as response:
   1475                 return imread(response, format=ext)
-> 1476     with img_open(fname) as image:
   1477         return (_pil_png_to_float_array(image)
   1478                 if isinstance(image, PIL.PngImagePlugin.PngImageFile) else

~/Python/anaconda3/envs/py373/lib/python3.7/site-packages/PIL/ImageFile.py in __init__(self, fp, filename)
    115         try:
    116             try:
--> 117                 self._open()
    118             except (
    119                 IndexError,  # end of data

~/Python/anaconda3/envs/py373/lib/python3.7/site-packages/PIL/PngImagePlugin.py in _open(self)
    651             # get next chunk
    652 
--> 653             cid, pos, length = self.png.read()
    654 
    655             try:

~/Python/anaconda3/envs/py373/lib/python3.7/site-packages/PIL/PngImagePlugin.py in read(self)
    126             s = self.fp.read(8)
    127             cid = s[4:]
--> 128             pos = self.fp.tell()
    129             length = i32(s)
    130 

UnsupportedOperation: seek

@molinav molinav merged commit b9c161b into matplotlib:master Dec 23, 2020
@molinav
Copy link
Member

molinav commented Dec 23, 2020

Thanks @guziy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants