matplotlib / basemap

Plot on map projections (with coastlines and political boundaries) using matplotlib
MIT License
775 stars 392 forks source link

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

Closed ReagentX closed 2 years ago

ReagentX commented 4 years ago
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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

This pull request is supposed to fix the problem:

https://github.com/matplotlib/basemap/pull/505

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

metonics commented 3 years ago

Sasha

Thanks for your efforts. Is there a version of basemap I can use that will work with arcgisimage?

Peter

From: Huziy Oleksandr (Sasha) notifications@github.com Sent: Wednesday, December 2, 2020 3:21 AM To: matplotlib/basemap basemap@noreply.github.com Cc: metonics peterryan2005@hotmail.com; Comment comment@noreply.github.com Subject: Re: [matplotlib/basemap] arcgisimage() fails with io.UnsupportedOperation: seek (#499)

This pull request is supposed to fix the problem:

505https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fbasemap%2Fpull%2F505&data=04%7C01%7C%7C6a4b1726bfe044f6476508d896151e94%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637424364730222812%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=Y4fyF6ZSECeqRKbBKOaeDrYMiphEihi%2BGtJCPKa5Nco%3D&reserved=0

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fbasemap%2Fissues%2F499%23issuecomment-736658792&data=04%7C01%7C%7C6a4b1726bfe044f6476508d896151e94%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637424364730232810%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=hPbc%2BzDDyI1PZrJXiFHxKFFtZ18ql0jSEHJaAWdevY0%3D&reserved=0, or unsubscribehttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FARORH5IOFXSKKHICMF7NRLDSSUJXPANCNFSM4Q2FSIXA&data=04%7C01%7C%7C6a4b1726bfe044f6476508d896151e94%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637424364730232810%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=0qTCunNYpe1fNi8GiVViDpLVZJSzgEMBwCulcLiA74w%3D&reserved=0.

guziy commented 3 years ago

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 commented 3 years ago

Sasha

Sorry – I need more help

How do I get the .whl file from github to install? Or should this line work?

py -m pip install --user git+https://github.com/guziy/basemap/tree/fix_arcgis_image/basemap.git

I am using windows 10

Peter

From: Huziy Oleksandr (Sasha) notifications@github.com Sent: Friday, December 4, 2020 9:06 AM To: matplotlib/basemap basemap@noreply.github.com Cc: metonics peterryan2005@hotmail.com; Comment comment@noreply.github.com Subject: Re: [matplotlib/basemap] arcgisimage() fails with io.UnsupportedOperation: seek (#499)

Yes Peter:

Please test the one in my repo: https://github.com/guziy/basemap/tree/fix_arcgis_imagehttps://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fguziy%2Fbasemap%2Ftree%2Ffix_arcgis_image&data=04%7C01%7C%7Cfcc36336c83a4107e6ba08d897d7a0aa%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637426299647320341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=%2F5vbDpIRlYS3lsCf7P09OnP5CVKUeVECXJ3bEQNmwNQ%3D&reserved=0

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fbasemap%2Fissues%2F499%23issuecomment-738347709&data=04%7C01%7C%7Cfcc36336c83a4107e6ba08d897d7a0aa%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637426299647330339%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=DAXHc9nZz8bm2umOPlV3cC4GyvNdbFbNqNctQ0MBHgQ%3D&reserved=0, or unsubscribehttps://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FARORH5IURBVA55YHDFY3VLLSTADUVANCNFSM4Q2FSIXA&data=04%7C01%7C%7Cfcc36336c83a4107e6ba08d897d7a0aa%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637426299647340318%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=JljIR%2FtRJ56jXQPQ95B32f4uMEhAvV6aAU%2FeveGNCZI%3D&reserved=0.

guziy commented 3 years ago

Sorry, Peter:

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

Cheers

metonics commented 3 years ago

Sasha

Windows/DOS installation very similar to linux

In windows/DOS this installs a version of basemap that still has the seek error

py -m pip install git+https://github.com/guziy/basemap.git

but if I do this and try to install the fix_arcgis_image version I get

C:\Windows\system32>py -m pip install git+https://github.com/guziy/basemap/tree/fix_arcgis_image Collecting git+https://github.com/guziy/basemap/tree/fix_arcgis_image Cloning https://github.com/guziy/basemap/tree/fix_arcgis_image to c:\users\peter\appdata\local\temp\pip-req-build-chx_u_x6 ERROR: Command errored out with exit status 128: git clone -q https://github.com/guziy/basemap/tree/fix_arcgis_image 'C:\Users\peter\AppData\Local\Temp\pip-req-build-chx_u_x6' Check the logs for full command output.

Is there some issue with that repo?

Regards

Peter

From: Huziy Oleksandr (Sasha) notifications@github.com Sent: Saturday, December 5, 2020 3:19 AM To: matplotlib/basemap basemap@noreply.github.com Cc: metonics peterryan2005@hotmail.com; Comment comment@noreply.github.com Subject: Re: [matplotlib/basemap] arcgisimage() fails with io.UnsupportedOperation: seek (#499)

Sorry, Peter:

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

Cheers

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fbasemap%2Fissues%2F499%23issuecomment-738873855&data=04%7C01%7C%7C5d0dd02aba4946bd7ba308d8987046d7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637426955271633154%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=Cht5OcwcNjw0N620dIX3Rbseo8rFGXWnNFW7GXv5Qis%3D&reserved=0, or unsubscribehttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FARORH5NRLVD2PPOQ3AMACJ3STEDWNANCNFSM4Q2FSIXA&data=04%7C01%7C%7C5d0dd02aba4946bd7ba308d8987046d7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637426955271633154%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=sAO5ccbFVrWwVVCmRIo4MuTfErJa%2FNI3wnAcPZwO8Yw%3D&reserved=0.

guziy commented 3 years ago

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 git+git@github.com:guziy/basemap.git@fix_arcgis_image

or https

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

Cheers

metonics commented 3 years ago

Dear Sasha

Yes, that installs fine on Windows 10.

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

However I still get the seek error?

Traceback (most recent call last): File "C:\Machine Learning\Waste\WCC_Bin_Map_URL.py", line 22, in m.arcgisimage(service='World_Street_Map',xpixels=1000,ypixels=None,dpi=400) File "C:\Users\peter\AppData\Local\Programs\Python\Python38\lib\site-packages\mpl_toolkits\basemap__init.py", line 4271, 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 1496, 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 am moving to Cartopy so if it is too hard to fix this issue, I suggest abandoning it!

Regards

Peter

From: Huziy Oleksandr (Sasha) notifications@github.com Sent: Tuesday, December 8, 2020 6:06 AM To: matplotlib/basemap basemap@noreply.github.com Cc: metonics peterryan2005@hotmail.com; Comment comment@noreply.github.com Subject: Re: [matplotlib/basemap] arcgisimage() fails with io.UnsupportedOperation: seek (#499)

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-branchhttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F20101834%2Fpip-install-from-git-repo-branch&data=04%7C01%7C%7C7f333c6d63604acdfd7508d89ae32e74%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637429647808503529%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=9epPX3Y7n32uiuWpGe%2FjvkiEoxH%2FbsWPGA59ussGB84%3D&reserved=0

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

or https

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

Cheers

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fbasemap%2Fissues%2F499%23issuecomment-740118380&data=04%7C01%7C%7C7f333c6d63604acdfd7508d89ae32e74%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637429647808503529%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=81D6hZAj8SGOwWNrfM%2BxZH%2Fcb7fWPJhReWKiKEJCDtA%3D&reserved=0, or unsubscribehttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FARORH5PF3BZYMF4AX5V7NF3STURSXANCNFSM4Q2FSIXA&data=04%7C01%7C%7C7f333c6d63604acdfd7508d89ae32e74%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637429647808513525%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=zTnpid5%2B00sSon3PHPGeB9XaHCuSxEf3efyCqTrnXDs%3D&reserved=0.

guziy commented 3 years ago

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...

https://github.com/matplotlib/basemap/pull/505/commits/c4a19b79ce80deab23f80007e6056e13ed393a10#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 commented 3 years ago

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 commented 3 years ago

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

molinav commented 3 years ago

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