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

movie.py example does not work #5130

Open
ldv1 opened this issue Oct 25, 2023 · 6 comments
Open

movie.py example does not work #5130

ldv1 opened this issue Oct 25, 2023 · 6 comments
Labels
bug Uh-oh! Something isn't working as expected.

Comments

@ldv1
Copy link

ldv1 commented Oct 25, 2023

Describe the bug, what's wrong, and what you expected.

The movie.py example does not work. There are two issues:

  • One issue is that we should have
    plotter = pv.Plotter(off_screen=True)
  • The other one is that, depending on the environment the example is run in, imageio might have been installed with the tifffile option. If so, plotter.write_frame() will trigger the error message
    TypeError: TiffWriter.write() got an unexpected keyword argument fps
    imageio with the tifffile option is not currently supported by pyvista. At least, users should be informed about this issue, and advised to install imageio with the ffmpeg option as in pip install imageio[ffmpeg]==2.31.4. This advise could appear at the bottom of the example.

Steps to reproduce the bug.

import numpy as np

import pyvista as pv

filename = "sphere-shrinking.mp4"

mesh = pv.Sphere()
mesh.cell_data["data"] = np.random.random(mesh.n_cells)

plotter = pv.Plotter()
# Open a movie file
plotter.open_movie(filename)

# Add initial mesh
plotter.add_mesh(mesh, scalars="data", clim=[0, 1])
# Add outline for shrinking reference
plotter.add_mesh(mesh.outline_corners())

plotter.show(auto_close=False)  # only necessary for an off-screen movie

# Run through each frame
plotter.write_frame()  # write initial data

# Update scalars on each frame
for i in range(100):
    random_points = np.random.random(mesh.points.shape)
    mesh.points = random_points * 0.01 + mesh.points * 0.99
    mesh.points -= mesh.points.mean(0)
    mesh.cell_data["data"] = np.random.random(mesh.n_cells)
    plotter.add_text(f"Iteration: {i}", name='time-label')
    plotter.write_frame()  # Write this frame

# Be sure to close the plotter when finished
plotter.close()

System Information

--------------------------------------------------------------------------------
  Date: Wed Oct 25 20:05:59 2023 CEST

                OS : Linux
            CPU(s) : 8
           Machine : x86_64
      Architecture : 64bit
               RAM : 15.5 GiB
       Environment : Python
       File system : btrfs
        GPU Vendor : Intel
      GPU Renderer : Mesa Intel(R) HD Graphics 4600 (HSW GT2)
       GPU Version : 4.6 (Core Profile) Mesa 22.3.5
  MathText Support : False

  Python 3.11.5 (main, Sep 06 2023, 11:21:05) [GCC]

           pyvista : 0.42.3
               vtk : 9.2.6
             numpy : 1.25.2
        matplotlib : 3.7.2
            scooby : 0.7.2
             pooch : v1.7.0
            pillow : 10.0.0
           imageio : 2.31.4
             PyQt5 : 5.15.9
             scipy : 1.11.2
              tqdm : 4.66.1
--------------------------------------------------------------------------------
>>>

Screenshots

No response

@ldv1 ldv1 added the bug Uh-oh! Something isn't working as expected. label Oct 25, 2023
@tkoyama010
Copy link
Member

tkoyama010 commented Oct 25, 2023

Note: This is from #5114 .

@dcbr
Copy link
Contributor

dcbr commented Oct 26, 2023

  • One issue is that we should have
    plotter = pv.Plotter(off_screen=True)

I remember this not being required in the past, so this might be an actual bug?

@banesullivan
Copy link
Member

off_scren is not required for this. The trick might be to use the q key to close the plotter (not the exit button) so that the after the show(auto_close=False) line, the rest executes, generating the movie. I believe this behavior can vary depending on system

This example works fine for me locally.

users should be informed about this issue, and advised to install imageio with the ffmpeg option

Agreed

@ldv1
Copy link
Author

ldv1 commented Nov 4, 2023

off_scren is not required for this. The trick might be to use the q key to close the plotter

If I press 'q', then I get

  File "/home/myname/movie.py", line 22, in <module>
    plotter.write_frame()  # write initial data
    ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pyvista/plotting/plotter.py", line 5018, in write_frame
    self.mwriter.append_data(self.image)
  File "/usr/lib/python3.11/site-packages/imageio/core/format.py", line 572, in append_data
    self._checkClosed()
  File "/usr/lib/python3.11/site-packages/imageio/core/format.py", line 364, in _checkClosed
    raise RuntimeError(msg)
RuntimeError: I/O operation on closed Writer.

It is unclear to me how to get past the plot window (on linux) without getting an error.

Anyway, off_screen=True works fine for me.

@banesullivan
Copy link
Member

If I recall correctly, there are some system-specific issues and sometimes we have to close the plotter (thus also closing the imagio writer) when the exit button or q is pressed. I'll try to reproduce this when I have a chance as there is likely a workaround

@zhongzhengwang118
Copy link

Hi: My environment is Ubuntu 22.04, The error message for running stable video is as follows:
Sampler: EulerEDMSampler
Discretization: EDMDiscretization
Guider: LinearPredictionGuider
Sampling with EulerEDMSampler for 26 steps: 0%| | 0/26 [00:00<?, ?it/s]/usr/local/lib/python3.10/dist-packages/torch/utils/checkpoint.py:31: UserWarning: None of the inputs have requires_grad=True. Gradients will be None
warnings.warn("None of the inputs have requires_grad=True. Gradients will be None")
Sampling with EulerEDMSampler for 26 steps: 96%|████████████████████████████████████████████████████▉ | 25/26 [00:41<00:01, 1.67s/it]
2024-03-25 10:49:21.284 Uncaught app exception
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/streamlit/runtime/scriptrunner/script_runner.py", line 542, in _run_script
exec(code, module.dict)
File "/home/generative-models/scripts/demo/video_sampling.py", line 280, in
save_video_as_grid_and_mp4(samples, save_path, T, fps=saving_fps)
File "/home/generative-models/scripts/demo/streamlit_helpers.py", line 912, in save_video_as_grid_and_mp4
imageio.mimwrite(video_path, vid, fps=fps)
File "/usr/local/lib/python3.10/dist-packages/imageio/v2.py", line 495, in mimwrite
return file.write(ims, is_batch=True, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/imageio/plugins/tifffile_v3.py", line 224, in write
self._fh.write(image, **kwargs)
TypeError: TiffWriter.write() got an unexpected keyword argument 'fps'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Uh-oh! Something isn't working as expected.
Projects
None yet
Development

No branches or pull requests

5 participants