napari / napari-animation

A napari plugin for making animations
https://napari.github.io/napari-animation/
Other
76 stars 27 forks source link

ValueError with animations using Labels or Points layers #180

Closed psobolewskiPhD closed 9 months ago

psobolewskiPhD commented 1 year ago

Run the animate2D.py example which will print the following traceback or just make a labels layer and paint something then try to animate it, which will spam this traceback in notifications

Traceback (most recent call last):
  File "/Users/sobolp/Downloads/animate2D.py", line 32, in <module>
    animation.animate('demo2D.mov', canvas_only=False)
  File "/Users/sobolp/micromamba/envs/napari-418/lib/python3.10/site-packages/napari_animation/animation.py", line 225, in animate
    for frame_index, image in enumerate(frame_generator):
  File "/Users/sobolp/micromamba/envs/napari-418/lib/python3.10/site-packages/napari_animation/frame_sequence.py", line 152, in iter_frames
    frame = state.render(viewer, canvas_only=canvas_only)
  File "/Users/sobolp/micromamba/envs/napari-418/lib/python3.10/site-packages/napari_animation/viewer_state.py", line 79, in render
    self.apply(viewer)
  File "/Users/sobolp/micromamba/envs/napari-418/lib/python3.10/site-packages/napari_animation/viewer_state.py", line 58, in apply
    if not np.array_equal(original_value, value):
  File "/Users/sobolp/micromamba/envs/napari-418/lib/python3.10/site-packages/numpy/core/numeric.py", line 2439, in array_equal
    return bool(asarray(a1 == a2).all())
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Edit: the same error happens with Points.

psobolewskiPhD commented 1 year ago

Ok, so the issue is the color dict, which is a dict of np.array. It can be fixed by checking the key/value pairs. However, if the use shuffles colors, it will re-shuffle the colors every step of the animation, which is weird—not sure this is a real use case though.

imagesc-bot commented 10 months ago

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/issue-saving-animations-in-napari-animation/88868/2