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

arcgisimage() fails with io.UnsupportedOperation: seek #499

Closed
ReagentX opened this issue Sep 5, 2020 · 14 comments
Closed

arcgisimage() fails with io.UnsupportedOperation: seek #499

ReagentX opened this issue Sep 5, 2020 · 14 comments

Comments

@ReagentX
Copy link

ReagentX commented Sep 5, 2020

repo/venv/lib/python3.8/site-packages/pyproj-3.0.dev1-py3.8-macosx-10.15-x86_64.egg/pyproj/crs/crs.py:53: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6
  return _prepare_from_string(" ".join(pjargs))
repo/venv/lib/python3.8/site-packages/pyproj-3.0.dev1-py3.8-macosx-10.15-x86_64.egg/pyproj/crs/crs.py:294: FutureWarning: '+init=<authority>:<code>' syntax is deprecated. '<authority>:<code>' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6
  projstring = _prepare_from_string(" ".join((projstring, projkwargs)))
http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer/export?bbox=6408577.827624549,1513410.7748487424,6817761.036725002,2005424.6213916629&bboxSR=3498&imageSR=3498&size=2000,2404&dpi=96&format=png32&transparent=true&f=image
Traceback (most recent call last):
  File "repo/scripts/plot_city.py", line 26, in <module>
    m.arcgisimage(xpixels=2000, verbose=True)
  File "/Users/chris/Downloads/basemap-1.2.2rel/lib/mpl_toolkits/basemap/__init__.py", line 4271, in arcgisimage
    return self.imshow(imread(urlopen(basemap_url)),ax=ax,
  File "repo/venv/lib/python3.8/site-packages/matplotlib/image.py", line 1486, in imread
    with img_open(fname) as image:
  File "repo/venv/lib/python3.8/site-packages/PIL/ImageFile.py", line 106, in __init__
    self._open()
  File "repo/venv/lib/python3.8/site-packages/PIL/PngImagePlugin.py", line 585, in _open
    cid, pos, length = self.png.read()
  File "repo/venv/lib/python3.8/site-packages/PIL/PngImagePlugin.py", line 121, in read
    pos = self.fp.tell()
io.UnsupportedOperation: seek
@metonics
Copy link

metonics commented Nov 5, 2020

I get exactly the same issue running basemap with windows 10.

I am using basemap 1.2.2 and python 3.8.6

http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/export?bbox=2506055.846693921,4410720.871992808,2506637.203006063,4411028.421318711&bboxSR=3110&imageSR=3110&size=1000,529&dpi=100&format=png32&transparent=true&f=image
Traceback (most recent call last):
File "C:\Machine Learning\Casey Datasets\Balwyn_Map.py", line 12, in
m.arcgisimage(service='World_Street_Map',xpixels=1000,verbose=True,ypixels=None,dpi=100)
File "C:\Users\peter\AppData\Local\Programs\Python\Python38\lib\site-packages\mpl_toolkits\basemap_init_.py", line 4263, in arcgisimage
return self.imshow(imread(urlopen(basemap_url)),ax=ax,
File "C:\Users\peter\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\image.py", line 1490, in imread
with img_open(fname) as image:
File "C:\Users\peter\AppData\Local\Programs\Python\Python38\lib\site-packages\PIL\ImageFile.py", line 121, in init
self._open()
File "C:\Users\peter\AppData\Local\Programs\Python\Python38\lib\site-packages\PIL\PngImagePlugin.py", line 692, in _open
cid, pos, length = self.png.read()
File "C:\Users\peter\AppData\Local\Programs\Python\Python38\lib\site-packages\PIL\PngImagePlugin.py", line 162, in read
pos = self.fp.tell()
io.UnsupportedOperation: seek

I need to solve this issue!

@malcolmw
Copy link

malcolmw commented Dec 1, 2020

I have the same issue.

# Name                    Version                   Build  Channel
basemap                   1.2.2            py38h85717e3_3    conda-forge
basemap-data-hires        1.2.2                         0    conda-forge
matplotlib                3.3.3            py38h578d9bd_0    conda-forge
matplotlib-base           3.3.3            py38h5c7f4ab_0    conda-forge
pillow                    8.0.1            py38h70fbd49_0    conda-forge
python                    3.8.6           h852b56e_0_cpython    conda-forge
---------------------------------------------------------------------------
UnsupportedOperation                      Traceback (most recent call last)
<ipython-input-37-05bc67db5411> in <module>
     15     linewidth=0.5
     16 )
---> 17 bm.arcgisimage(service="World_Shaded_Relief",
     18                          xpixels=3000,
     19                          verbose=True)

~/local/anaconda3/envs/py38a/lib/python3.8/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 

~/local/anaconda3/envs/py38a/lib/python3.8/site-packages/matplotlib/image.py in imread(fname, format)
   1494                     response = io.BytesIO(response.read())
   1495                 return imread(response, format=ext)
-> 1496     with img_open(fname) as image:
   1497         return (_pil_png_to_float_array(image)
   1498                 if isinstance(image, PIL.PngImagePlugin.PngImageFile) else

~/local/anaconda3/envs/py38a/lib/python3.8/site-packages/PIL/ImageFile.py in __init__(self, fp, filename)
    119         try:
    120             try:
--> 121                 self._open()
    122             except (
    123                 IndexError,  # end of data

~/local/anaconda3/envs/py38a/lib/python3.8/site-packages/PIL/PngImagePlugin.py in _open(self)
    690             # get next chunk
    691 
--> 692             cid, pos, length = self.png.read()
    693 
    694             try:

~/local/anaconda3/envs/py38a/lib/python3.8/site-packages/PIL/PngImagePlugin.py in read(self)
    160             s = self.fp.read(8)
    161             cid = s[4:]
--> 162             pos = self.fp.tell()
    163             length = i32(s)
    164 

UnsupportedOperation: seek

@guziy
Copy link
Contributor

guziy commented Dec 1, 2020

This pull request is supposed to fix the problem:

#505

You are welcome to try and test it and maybe there will be more motivation to merge it.

@metonics
Copy link

metonics commented Dec 2, 2020 via email

@guziy
Copy link
Contributor

guziy commented Dec 3, 2020

Yes Peter:

Please test the one in my repo: https://github.com/guziy/basemap/tree/fix_arcgis_image

Just use the fix_arcgis_image branch.

When you checkout the branch try using

pip install . -U --user 

You might need to specify the path to geos installation:

$(geos-config --prefix) pip install . -U --user

Cheers

@metonics
Copy link

metonics commented Dec 4, 2020 via email

@guziy
Copy link
Contributor

guziy commented Dec 4, 2020

Sorry, Peter:

I have no idea about windows, the commands I wrote are for Linux, might work on a mac...

Cheers

@metonics
Copy link

metonics commented Dec 6, 2020 via email

@guziy
Copy link
Contributor

guziy commented Dec 7, 2020

I guess you need to specify the correct branch as they say here. Sorry I just sent you the HTML view link...

https://stackoverflow.com/questions/20101834/pip-install-from-git-repo-branch

pip install [email protected]:guziy/basemap.git@fix_arcgis_image

or https

pip install git+https://github.com/guziy/basemap.git@fix_arcgis_image

Cheers

@metonics
Copy link

metonics commented Dec 8, 2020 via email

@guziy
Copy link
Contributor

guziy commented Dec 8, 2020

It is a good idea to move to cartopy. But your error message is still saying it is using imread, whereas in my version of the code imread is removed...

c4a19b7#diff-cd2bf9b319d30dd03cdbcd9fd49b22e0735faf3c2797ae78ab60a775d1349d1cR4286

Not sure how you install or use things, but you might still be using some other version of basemap...

PS: please use the GitHub interface for messages, it is hard to follow when your email client copies so many links...

Cheers

@metonics
Copy link

pip install git+https://github.com/guziy/basemap.git@fix_arcgis_image - eventually worked to install the forked version

Thanks for all your efforts!

Yes, it is now working - or at least not crashing. I am having issues getting the imagery to load up however and will do more investigation with the test codes.

@metonics
Copy link

this seems to now work correctly. I was having issues with the epsg parameter - If I leave it off the images install fine.

@molinav
Copy link
Member

molinav commented Dec 23, 2020

I just merged the PR #505 by @guziy into the master branch, this problem should be fixed now.

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