widgetti / ipyvolume

3d plotting for Python in the Jupyter notebook based on IPython widgets using WebGL
MIT License
1.95k stars 236 forks source link

Save as movie example not working #401

Open Pieter53 opened 2 years ago

Pieter53 commented 2 years ago

Hallo,

I'm trying to save a rotation of a 3D ipv.volshow image as a movie.gif file. However, I don't seem to be able to run a simple example code. It seems that the code is unable to capture screenshots and convert it to a gif.

Jupyter example code for 3 frames movie

import ipyvolume as ipv import ipywidgets as widget V = np.zeros((128,128,128)) # our 3d array

V[30:-30,30:-30,30:-30] = 0.75 V[35:-35,35:-35,35:-35] = 0.0 V[50:-50,50:-50,50:-50] = 0.25 V[55:-55,55:-55,55:-55] = 0.0

fig = ipv.figure() s = ipv.volshow(V, level=[0.25, 0.75], opacity=0.03, level_width=0.1, data_min=0, data_max=1) ipv.show()

def set_view(figure, framenr, fraction): ipv.view(fraction, 0) ipv.movie('wave.gif', set_view, fps=1, frames=3)

Error messages


ValueError Traceback (most recent call last) localdir/cpyvenv/lib/python3.9/site-packages/ipyvolume/pylab.py in _screenshot_data(timeout_seconds, output_widget, format, width, height, fig, headless, devmode) 850 with output_widget: 851 if timeout and not done[0]: --> 852 raise ValueError("timed out, no image data returned") 853 finally: 854 with output_widget:

ValueError: timed out, no image data returned


AttributeError Traceback (most recent call last) localdir/cpyvenv/lib/python3.9/site-packages/ipyvolume/pylab.py in movie(f, function, fps, frames, endpoint, cmd_template_ffmpeg, cmd_template_gif, gif_loop) 792 function(fig, i, fraction) 793 frame_filename = os.path.join(tempdir, "frame-%05d.png" % i) --> 794 savefig(frame_filename, output_widget=output) 795 with output: 796 if movie_filename.endswith(".gif"):

localdir/cpyvenv/lib/python3.9/site-packages/ipyvolume/pylab.py in savefig(filename, width, height, fig, timeout_seconds, output_widget, headless, devmode) 898 assert format in ['png','jpeg','svg'], "image format must be png, jpeg or svg" 899 with open(filename, "wb") as f: --> 900 f.write(_screenshot_data(timeout_seconds=timeout_seconds, output_widget=output_widget, 901 format=format, width=width, height=height, fig=fig, headless=headless, devmode=devmode)) 902

/localdir/cpyvenv/lib/python3.9/site-packages/ipyvolume/pylab.py in _screenshot_data(timeout_seconds, output_widget, format, width, height, fig, headless, devmode) 855 fig.on_screenshot(screenshot_handler, remove=True) 856 data = data[0] --> 857 data = data[data.find(",") + 1:] 858 return base64.b64decode(data) 859

AttributeError: 'NoneType' object has no attribute 'find'


ValueError Traceback (most recent call last) localdir/cpyvenv/lib/python3.9/site-packages/ipyvolume/pylab.py in _screenshot_data(timeout_seconds, output_widget, format, width, height, fig, headless, devmode) 850 with output_widget: 851 if timeout and not done[0]: --> 852 raise ValueError("timed out, no image data returned") 853 finally: 854 with output_widget:

ValueError: timed out, no image data returned


AttributeError Traceback (most recent call last) localdir/cpyvenv/lib/python3.9/site-packages/ipyvolume/pylab.py in movie(f, function, fps, frames, endpoint, cmd_template_ffmpeg, cmd_template_gif, gif_loop) 792 function(fig, i, fraction) 793 frame_filename = os.path.join(tempdir, "frame-%05d.png" % i) --> 794 savefig(frame_filename, output_widget=output) 795 with output: 796 if movie_filename.endswith(".gif"):

localdir/cpyvenv/lib/python3.9/site-packages/ipyvolume/pylab.py in savefig(filename, width, height, fig, timeout_seconds, output_widget, headless, devmode) 898 assert format in ['png','jpeg','svg'], "image format must be png, jpeg or svg" 899 with open(filename, "wb") as f: --> 900 f.write(_screenshot_data(timeout_seconds=timeout_seconds, output_widget=output_widget, 901 format=format, width=width, height=height, fig=fig, headless=headless, devmode=devmode)) 902

localdir/cpyvenv/lib/python3.9/site-packages/ipyvolume/pylab.py in _screenshot_data(timeout_seconds, output_widget, format, width, height, fig, headless, devmode) 855 fig.on_screenshot(screenshot_handler, remove=True) 856 data = data[0] --> 857 data = data[data.find(",") + 1:] 858 return base64.b64decode(data) 859

AttributeError: 'NoneType' object has no attribute 'find'


ValueError Traceback (most recent call last) localdir/cpyvenv/lib/python3.9/site-packages/ipyvolume/pylab.py in _screenshot_data(timeout_seconds, output_widget, format, width, height, fig, headless, devmode) 850 with output_widget: 851 if timeout and not done[0]: --> 852 raise ValueError("timed out, no image data returned") 853 finally: 854 with output_widget:

ValueError: timed out, no image data returned


AttributeError Traceback (most recent call last) localdir/cpyvenv/lib/python3.9/site-packages/ipyvolume/pylab.py in movie(f, function, fps, frames, endpoint, cmd_template_ffmpeg, cmd_template_gif, gif_loop) 792 function(fig, i, fraction) 793 frame_filename = os.path.join(tempdir, "frame-%05d.png" % i) --> 794 savefig(frame_filename, output_widget=output) 795 with output: 796 if movie_filename.endswith(".gif"):

localdir/cpyvenv/lib/python3.9/site-packages/ipyvolume/pylab.py in savefig(filename, width, height, fig, timeout_seconds, output_widget, headless, devmode) 898 assert format in ['png','jpeg','svg'], "image format must be png, jpeg or svg" 899 with open(filename, "wb") as f: --> 900 f.write(_screenshot_data(timeout_seconds=timeout_seconds, output_widget=output_widget, 901 format=format, width=width, height=height, fig=fig, headless=headless, devmode=devmode)) 902

localdir/cpyvenv/lib/python3.9/site-packages/ipyvolume/pylab.py in _screenshot_data(timeout_seconds, output_widget, format, width, height, fig, headless, devmode) 855 fig.on_screenshot(screenshot_handler, remove=True) 856 data = data[0] --> 857 data = data[data.find(",") + 1:] 858 return base64.b64decode(data) 859

AttributeError: 'NoneType' object has no attribute 'find'

convert -delay 100.0 -loop 0 /tmp/tmpmmpt87li/frame-*.png wave.gif convert: improper image header /tmp/tmpmmpt87li/frame-00000.png' @ error/png.c/ReadPNGImage/4104. convert: improper image header/tmp/tmpmmpt87li/frame-00001.png' @ error/png.c/ReadPNGImage/4104. convert: improper image header /tmp/tmpmmpt87li/frame-00002.png' @ error/png.c/ReadPNGImage/4104. convert: no images definedwave.gif' @ error/convert.c/ConvertImageCommand/3235.

ssh to remote survers

It might be partly explained by the fact that I'm using jupyter notebook via ssh to remote servers That is typing the following in command promt for ssh connection: ssh -L 8080:localhost:8889 username@network And then typing in my laptop's internet browser: localhost:8080 to acces the jupyter notebook UI. but with acces to the data and computing power of the remote servers

Virtual environment saved

localdir is short for the rootdirectory where my python virtualenvironment /cpyvenv/ is intalled Notebook .ipynb file is accesed in a different folder close to localdir.

Internet browser

Using edge as browser (all the other ipyvolume functionality seems to work)

Could you please help me in figuring out how to solve this issue? Thanks in advance, Best, Cedric

Pieter53 commented 2 years ago

Headless=True on ipv.savefig and ipv.screenshot also doesn't work.

I found a workaround: I can make a movie using the following code:

import time import numpy as np frames = 2010 fps = 20 frac = np.linspace(0,1,frames) for i in range(4): for fraction in frac: ipv.view(180+fraction360, 0, distance=2.9) time.sleep(1/fps)

And then use WINDOWS+G to screen record a movie and crop in powerpoint. Alternatively, I can still manually save the screenshots to my downloadsfolder, and make a .gif out of those screenshots. But that's not fully automated and time consuming as well.