napari / napari-animation

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

[BUG] Displayed data persists after visible is set to False #106

Closed JoOkuma closed 3 years ago

JoOkuma commented 3 years ago

I'm trying to make a movie where some layers are turned on and off.

Making them visible is working, but sometimes it is not possible to make the layer invisible (it works in a few cases, but I couldn't narrow it down).

Minimal reproducing example:

import napari
from napari_animation import Animation

viewer = napari.Viewer()
viewer.open_sample('scikit-image', 'cells3d')

viewer.dims.ndisplay = 3
viewer.layers[0].visible = False

animation = Animation(viewer)
animation.capture_keyframe()

viewer.camera.angles = (0.0, 90, 180.0)
animation.capture_keyframe(steps=60)

viewer.layers[0].visible = True
viewer.camera.angles = (0.0, 180, 270.0)

animation.capture_keyframe(steps=60)

viewer.layers[0].visible = False
viewer.camera.angles = (0.0, 270, 0)

animation.capture_keyframe(steps=60)

animation.animate('demo.mov')

Video, I expected the membranes to be invisible after the second "bounce".

https://user-images.githubusercontent.com/21022743/130722072-67f6f598-9f31-4645-8c9f-dcc7ce9e28a5.mov

alisterburt commented 3 years ago

Hi @JoOkuma - thanks for the nice and complete report, much appreciated! I'll take a look when I find some time but no guarantees of a timely fix. From twitter it looks like you managed to find a workable solution, do you have a better idea under what causes you were seeing this now? Is it possibly only happening at the end of an animation?

JoOkuma commented 3 years ago

Hi, Alister. Sorry for the late response.

I found the bug this morning, the issue is with the interpolation.

I just learned that booleans are considered numbers in python so a boolean change of state calls the interpolate_num which results in a float between 0 and 1 that is interpreted as True except when it's zero, hence it's hardly ever updated.

I can change the if conditions to call interpolate_bool if one of them is bool, but this leads to the behavior of the change occurring in-between steps, for instance, in the above code the change happens after 30 steps

This is expected because it only changes when it crosses the 0.5 fraction, but shouldn't booleans changes happen instantly? `

alisterburt commented 3 years ago

@JoOkuma no worries! I had totally forgotten about this myself so thanks for coming back to it

Super interesting, thanks for delving deeper! Agreed, it seems like we should modify the interpolate_bool function so that the change happens instantly šŸ‘šŸ¼

alisterburt commented 3 years ago

closed by #108