Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Bug] bytes-like error when exporting from g.gui.animation and g.gui.tplot #827

Closed
veroandreo opened this issue Jul 23, 2020 · 9 comments · Fixed by #899
Closed

[Bug] bytes-like error when exporting from g.gui.animation and g.gui.tplot #827

veroandreo opened this issue Jul 23, 2020 · 9 comments · Fixed by #899
Labels
bug Something isn't working GUI wxGUI related
Milestone

Comments

@veroandreo
Copy link
Contributor

veroandreo commented Jul 23, 2020

When trying to export an animation as gif out of g.gui.animation, I get the following:

image

The same error appears when I try to export a csv file from g.gui.tplot:

g.gui.tplot strds=LST_Day_monthly_celsius coordinates=4323478.531282977,6541664.09350761 title="Monthly LST. City center of Cordoba" xlabel="Time" ylabel="LST" csv=cba_monthly_LST.csv
06:43:23 PM: Debug: Adding duplicate image handler for 'Windows bitmap file'
Traceback (most recent call last):
  File "/usr/lib64/grass78/scripts/g.gui.tplot", line 174, in <module>
    main()
  File "/usr/lib64/grass78/scripts/g.gui.tplot", line 160, in main
    frame.SetDatasets(rasters, vectors, coords, cats, attr, title, xlabel,
  File "/usr/lib64/grass78/gui/wxpython/tplot/frame.py", line 1018, in SetDatasets
    self._redraw()
  File "/usr/lib64/grass78/gui/wxpython/tplot/frame.py", line 898, in _redraw
    self._drawFigure()
  File "/usr/lib64/grass78/gui/wxpython/tplot/frame.py", line 621, in _drawFigure
    self.drawR()
  File "/usr/lib64/grass78/gui/wxpython/tplot/frame.py", line 695, in drawR
    self._writeCSV(xcsv, ycsv)
  File "/usr/lib64/grass78/gui/wxpython/tplot/frame.py", line 660, in _writeCSV
    writer.writerows(zipped)
TypeError: a bytes-like object is required, not 'str'

If I remove the csv part in the command, then it works, but I get the following warning (which also appears after using g.gui.timeline):

06:44:53 PM: Debug: Adding duplicate image handler for 'Windows bitmap file'
/usr/lib64/grass78/gui/wxpython/tplot/frame.py:1127: MatplotlibDeprecationWarning: 
The iterable function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use np.iterable instead.
  if not cbook.iterable(artists):

System description:

GRASS version: 7.8.3                                                            
Code revision: exported                                                         
Build date: 2020-06-26                                                          
Build platform: x86_64-redhat-linux-gnu                                         
GDAL: 3.0.4                                                                     
PROJ: 6.3.2                                                                     
GEOS: 3.8.1                                                                     
SQLite: 3.32.3                                                                  
Python: 3.8.3                                                                   
wxPython: 4.0.7                                                                 
Platform: Linux-5.7.8-200.fc32.x86_64-x86_64-with-glibc2.2.5  
@veroandreo veroandreo added bug Something isn't working GUI wxGUI related labels Jul 23, 2020
@veroandreo veroandreo added this to the 7.8.4 milestone Jul 23, 2020
@veroandreo veroandreo changed the title [Bug] error when exporting animation as gif from g.gui.animation [Bug] bytes-like error when exporting from g.gui.animation and g.gui.tplot Jul 25, 2020
@petrasovaa
Copy link
Contributor

I believe the tplot error was solved in #690

@petrasovaa
Copy link
Contributor

If you have Pillow >= 3.4.0, export to GIF should work (works for me). Otherwise it uses a different implementation, which produces the error you posted.

@veroandreo
Copy link
Contributor Author

I believe the tplot error was solved in #690

Indeed, I don't get this error in grass-dev. Was it backported?

@veroandreo
Copy link
Contributor Author

If you have Pillow >= 3.4.0, export to GIF should work (works for me). Otherwise it uses a different implementation, which produces the error you posted.

My system reports python3-pillow-7.0.0-4.fc32.x86_64 installed. How to know if it uses (or needs) something else? I get the same error in grass-dev

@petrasovaa
Copy link
Contributor

I believe the tplot error was solved in #690

Indeed, I don't get this error in grass-dev. Was it backported?

Yes

@petrasovaa
Copy link
Contributor

try:

from PIL import PILLOW_VERSION
print(PILLOW_VERSION)

@veroandreo
Copy link
Contributor Author

Seems PILLOW_VERSION is deprecated (python-pillow/Pillow#3082).
Only help(PIL) or PIL.__version__ gave me some info, and PIL.version says 7.0.0 (same that dnf provides python3-pillow had said)

@neteler
Copy link
Member

neteler commented Aug 11, 2020

Test with NC sample data:

https://grass.osgeo.org/download/data/#SpecialTopicDatasets
--> Time series - MODIS Land Surface Temperature mapset

cd ~/grassdata/nc_spm_08_grass7/
wget https://grass.osgeo.org/sampledata/north_carolina/nc_spm_mapset_modis2015_2016_lst.zip
unzip nc_spm_mapset_modis2015_2016_lst.zip
rm -f nc_spm_mapset_modis2015_2016_lst.zip

# full example for reproduction
grass79 ~/grassdata/nc_spm_08_grass7/modis_lst/
g.extension t.upgrade
t.upgrade
t.list 
t.rast.list LST_Day_monthly

# get e.g. center coordinates for query
g.region -c

# plot (note that this are the scaled LST values, to be converted to Celsius)
g.gui.tplot strds=LST_Day_monthly coordinates=551334.464115,172180.124115 title="Scaled Monthly LST, NC"  xlabel="Time" ylabel="LST"

image

# no error here (any more?), just a warning:
g.gui.tplot strds=LST_Day_monthly coordinates=551334.464115,172180.124115 title="Scaled Monthly LST, NC"  xlabel="Time" ylabel="LST" csv=NC_monthly_LST.csv
09:15:06 PM: Debug: Adding duplicate image handler for 'Windows bitmap file'
/home/mneteler/software/grass_master/dist.x86_64-pc-linux-gnu/gui/wxpython/tplot/frame.py:1127: MatplotlibDeprecationWarning: 
The iterable function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use np.iterable instead.
  if not cbook.iterable(artists):

# export of GIF:
g.gui.animation raster=$(g.list raster pattern="MOD*" sep=comma)

image

Error also here (may contain typos since I used OCR to convert it to text):

Error

a bytes-like object is required, not 'str'

Reason: a bytes-like object is required, not ‘str’

Traceback (most recent call last):
File "/home/mneteler/software/grass_master/dist.x86_64-pc-linux-gnu/gui/wxpython/animation/controller. py", line 634, in _export
writeGif(filename=exportinfo['file'], images=pilImages,
File "shome/mneteler/sottware/grass_master/dist.x86_64-pc-linux-gnu/etc/python/grass/imaging/images2gif.py", line 503, in writeGif
writeGifVisvis(filename, images, duration, repeat, **kwargs)
File "/home/mneteler/software/grass_master/dist.x86_64-pc-linux-gnu/etc/python/grass/imaging/images2gif.py". line 614, in writeGifVisvis
gifWriter.writeGiffoFile(fp, images, duration, loops, xy, dispose)
File "/home/mneteler/software/grass_master/dist.x86_64-pc-linux-gnu/etc/python/grass/imaging/images2gif.py", line 440, in writeGifToFile
 fp.write(header)
TypeError: a bytes-like object is required, not 'str'

@petrasovaa petrasovaa linked a pull request Aug 22, 2020 that will close this issue
petrasovaa added a commit that referenced this issue Aug 22, 2020
petrasovaa added a commit that referenced this issue Aug 22, 2020
@petrasovaa
Copy link
Contributor

Just a note here, there are 2 implementations in images2gif, one calls Pillow and if Pillow is not available, then there is custom implementation. This fixes detection of Pillow, so if you have reasonably new Pillow, it will use the Pillow implementation. The other implementation is still broken, but it's unlikely somebody would use it.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working GUI wxGUI related
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants