pyvista / pyvista

3D plotting and mesh analysis through a streamlined interface for the Visualization Toolkit (VTK)
https://docs.pyvista.org
MIT License
2.67k stars 490 forks source link

movie.py example does not work #5130

Open ldv1 opened 12 months ago

ldv1 commented 12 months ago

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

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

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

tkoyama010 commented 12 months ago

Note: This is from https://github.com/pyvista/pyvista/discussions/5114 .

dcbr commented 12 months ago
  • 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 commented 12 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 7 months ago

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'