Skip to content

Arcgisimage fails #242

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

Closed
bjacotg opened this issue Dec 14, 2015 · 19 comments
Closed

Arcgisimage fails #242

bjacotg opened this issue Dec 14, 2015 · 19 comments

Comments

@bjacotg
Copy link

bjacotg commented Dec 14, 2015

I tried a simple map and add some arcgisimage, but it failed.

Here is the code:

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

And the error:

Traceback (most recent call last):
  File "/home/bastien/PycharmProjects/untitled/rider_analysis.py", line 55, in <module>
    m.arcgisimage(verbose=True)
  File "/usr/lib/python3.5/site-packages/mpl_toolkits/basemap/__init__.py", line 4270, in arcgisimage
    return self.imshow(imread(urllib.request.urlopen(basemap_url)),origin='upper')
  File "/usr/lib/python3.5/site-packages/matplotlib/image.py", line 1326, in imread
    return handler(fname)
SystemError: <built-in function read_png> returned NULL without setting an error

Process finished with exit code 1

After debugging around, I found that imread does not like http.request.HttpResponse, but works fine with file path.

Regards,

Bastien

@WeatherGod
Copy link
Member

Which version of matplotlib are you using? I am pretty sure this is fixed
in matplotlib 1.5.x.

On Mon, Dec 14, 2015 at 1:02 PM, Bastien Jacot-Guillarmod <
notifications@github.com> wrote:

I tried a simple map and add some arcgisimage, but it failed.

Here is the code:

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

And the error:

Traceback (most recent call last):
File "/home/bastien/PycharmProjects/untitled/rider_analysis.py", line 55, in
m.arcgisimage(verbose=True)
File "/usr/lib/python3.5/site-packages/mpl_toolkits/basemap/init.py", line 4270, in arcgisimage
return self.imshow(imread(urllib.request.urlopen(basemap_url)),origin='upper')
File "/usr/lib/python3.5/site-packages/matplotlib/image.py", line 1326, in imread
return handler(fname)
SystemError: returned NULL without setting an error

Process finished with exit code 1

After debugging around, I found that imread does not like
http.request.HttpResponse, but works fine with file path.

Regards,

Bastien


Reply to this email directly or view it on GitHub
#242.

@bjacotg
Copy link
Author

bjacotg commented Dec 14, 2015

I use matplotlib 1.5.0 (arch linux)
I also have libpng 1.6.19

@WeatherGod
Copy link
Member

Ah, I think I know what it is... do you have Pillow installed?

On Mon, Dec 14, 2015 at 1:11 PM, Bastien Jacot-Guillarmod <
notifications@github.com> wrote:

I use matplotlib 1.5.0 (arch linux)
I also have libpng 1.6.19


Reply to this email directly or view it on GitHub
#242 (comment).

@bjacotg
Copy link
Author

bjacotg commented Dec 14, 2015

Yes, I do. Version 3.0.0

@bjacotg
Copy link
Author

bjacotg commented Dec 14, 2015

I uninstalled it and retry. The error remains though.

@micahcochran
Copy link
Contributor

Does example/testarcgis.py work for you?

@guziy
Copy link
Contributor

guziy commented Dec 14, 2015

Here is what worked for me:

https://github.com/guziy/PyNotebooks/blob/master/basemap_issue_%23242.ipynb

Cheers

2015-12-14 13:30 GMT-05:00 Micah Cochran notifications@github.com:

Does example/testarcgis.py work for you?


Reply to this email directly or view it on GitHub
#242 (comment).

Sasha

@bjacotg
Copy link
Author

bjacotg commented Dec 14, 2015

testarcgist.py fails with the same error it seems.

http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer/export?bbox=-90.0,29.999999999999996,-59.99999999999999,59.99999999999999&bboxSR=4326&imageSR=4326&size=400,400&dpi=96&format=png32&f=image
Traceback (most recent call last):
  File "test.py", line 11, in <module>
    m.arcgisimage(verbose=True)
  File "/usr/lib/python3.5/site-packages/mpl_toolkits/basemap/__init__.py", line 4270, in arcgisimage
    return self.imshow(imread(urllib.request.urlopen(basemap_url)),origin='upper')
  File "/usr/lib/python3.5/site-packages/matplotlib/image.py", line 1326, in imread
    return handler(fname)
SystemError: <built-in function read_png> returned NULL without setting an error
                                                                                                                                                                                                                    ```

@WeatherGod
Copy link
Member

Ah, I have been looking at this wrong... Just noticed that you are using
ArchLinux, so that likely means that you are on the development branch of
1.5.x rather than the release of 1.5.0. There might be a subtle change to
the underlying read code that might have broken this use-case.

@mdboom, could the recent error-checking changes we made to _png.h in
matplotlib have made things too finicky for file-like objects?

On Mon, Dec 14, 2015 at 1:33 PM, Huziy Oleksandr (Sasha) <
notifications@github.com> wrote:

Here is what worked for me:

https://github.com/guziy/PyNotebooks/blob/master/basemap_issue_%23242.ipynb

Cheers

2015-12-14 13:30 GMT-05:00 Micah Cochran notifications@github.com:

Does example/testarcgis.py work for you?


Reply to this email directly or view it on GitHub
<#242 (comment)
.

Sasha


Reply to this email directly or view it on GitHub
#242 (comment).

@guziy
Copy link
Contributor

guziy commented Dec 14, 2015

I think plt.imread is a problem here, for some reason it does not accept
the object that has seek, tell and read..

Cheers

2015-12-14 13:40 GMT-05:00 Benjamin Root notifications@github.com:

Ah, I have been looking at this wrong... Just noticed that you are using
ArchLinux, so that likely means that you are on the development branch of
1.5.x rather than the release of 1.5.0. There might be a subtle change to
the underlying read code that might have broken this use-case.

@mdboom, could the recent error-checking changes we made to _png.h in
matplotlib have made things too finicky for file-like objects?

On Mon, Dec 14, 2015 at 1:33 PM, Huziy Oleksandr (Sasha) <
notifications@github.com> wrote:

Here is what worked for me:

https://github.com/guziy/PyNotebooks/blob/master/basemap_issue_%23242.ipynb

Cheers

2015-12-14 13:30 GMT-05:00 Micah Cochran notifications@github.com:

Does example/testarcgis.py work for you?


Reply to this email directly or view it on GitHub
<
#242 (comment)
.

Sasha


Reply to this email directly or view it on GitHub
<#242 (comment)
.


Reply to this email directly or view it on GitHub
#242 (comment).

Sasha

@WeatherGod
Copy link
Member

btw, a possible fix in our code might be to do something similar to that in
wmsimage():

        return
self.imshow(imread(io.BytesIO(urllib2.urlopen(img.url).read()),
                           format=format),origin='upper')

On Mon, Dec 14, 2015 at 1:40 PM, Benjamin Root ben.v.root@gmail.com wrote:

Ah, I have been looking at this wrong... Just noticed that you are using
ArchLinux, so that likely means that you are on the development branch of
1.5.x rather than the release of 1.5.0. There might be a subtle change to
the underlying read code that might have broken this use-case.

@mdboom, could the recent error-checking changes we made to _png.h in
matplotlib have made things too finicky for file-like objects?

On Mon, Dec 14, 2015 at 1:33 PM, Huziy Oleksandr (Sasha) <
notifications@github.com> wrote:

Here is what worked for me:

https://github.com/guziy/PyNotebooks/blob/master/basemap_issue_%23242.ipynb

Cheers

2015-12-14 13:30 GMT-05:00 Micah Cochran notifications@github.com:

Does example/testarcgis.py work for you?


Reply to this email directly or view it on GitHub
<
https://github.com/matplotlib/basemap/issues/242#issuecomment-164518939>.

Sasha


Reply to this email directly or view it on GitHub
#242 (comment)
.

@WeatherGod
Copy link
Member

@guzly, plt.imread() accepts file-like objects. This hasn't changed. There is some very nifty code in matplotlib that can take a python file-like object and turn it into something kinda like a C FILE pointer, which can be used by the C png reader.

What has changed is that @mdboom (and I, to a much lesser extent) made some tiny fixes to the PNG reading code to add error checking in case that was the cause of some random, spurious issues with Travis in matplotlib. It is entirely possible that this error-checking is too tight and is triggering when it shouldn't be.

@guziy
Copy link
Contributor

guziy commented Dec 14, 2015

2015-12-14 13:45 GMT-05:00 Benjamin Root notifications@github.com:

btw, a possible fix in our code might be to do something similar to that in
wmsimage():

return
self.imshow(imread(io.BytesIO(urllib2.urlopen(img.url).read()),
format=format),origin='upper')

I am not sure if it won't cause memory problems, but from the other side I
do not know how imread or imshow are implemented, if they anyways put the
whole image in memory, then my comment does not matter))

Cheers

Sasha

@bjacotg
Copy link
Author

bjacotg commented Dec 15, 2015

@guziy Thanks for the gist! I was able to make it work!

@WeatherGod
Copy link
Member

This is potentially fixed by matplotlib/matplotlib#5910

@WeatherGod
Copy link
Member

Fixed in master. Seeing if it needs to be backported to 1.5.x.

@WeatherGod
Copy link
Member

This has been backported to v1.5.x as well.

@einarbmag
Copy link

I've updated my matplotlib from 1.5.0 to 1.5.1 today using pip (Python 3), and I still have this problem. Do I need to install matplotlib from github to get the fix?

@WeatherGod
Copy link
Member

The fix will be in the upcoming v1.5.2, and in the upcoming v2.0 releases.
You could also install matplotlib from github source as well.

On Sun, Feb 14, 2016 at 4:40 AM, einarbmag notifications@github.com wrote:

I've updated my matplotlib from 1.5.0 to 1.5.1 today using pip (Python 3),
and I still have this problem. Do I need to install matplotlib from github
to get the fix?


Reply to this email directly or view it on GitHub
#242 (comment).

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

No branches or pull requests

5 participants