Optional: camera movement and acquired time

Optional: camera movement and acquired time#

Run this notebook independently after the main lesson. Use the small teaching data. You will compare a short fixed-time camera animation with a fixed-camera acquired time series. Keep the viewer open until exports finish. The helper create_scene simply repeats the layer calls explained in the main notebook.

%gui qt
from pathlib import Path
ROOT = next(p for p in (Path.cwd(), *Path.cwd().parents)
            if (p / "data" / "zenodo-manifest.json").is_file())
DATA = ROOT / "data" / "teaching"
print(DATA)
from napari_workshop.render import create_scene, export_time_series
from napari_animation import Animation
from datetime import datetime
viewer, metadata = create_scene(DATA)
OUTPUT = ROOT / "outputs" / datetime.now().strftime("animation-%Y%m%d-%H%M%S-%f")
OUTPUT.mkdir(parents=True)

Use a small camera turn first. Rotation angles describe the view; they do not change the sample or track coordinates. Both keyframes below use acquired frame 10. You may also capture these states through the animation wizard in the Plugins menu.

viewer.dims.set_current_step(0, 10)
animation = Animation(viewer)
viewer.camera.angles = (0, 0, 90)
animation.capture_keyframe()
viewer.camera.angles = (25, 15, 110)
animation.capture_keyframe(steps=30)
animation.animate(str(OUTPUT / "rotation.mp4"), fps=10, canvas_only=True)

Next, hold the camera still and export one screenshot per acquired frame. The helper streams frames to the encoder, then reads the movie to verify its frame count and dimensions. It creates a new subfolder and records export settings in export.json. Do not reuse an existing subfolder for another run.

movie = export_time_series(viewer, OUTPUT / "acquired-time", metadata["timepoints"], fps=5)
print(movie)

Compare: the camera animation moves your viewpoint around one observation. The time-series movie changes the observed data. Neither creates additional measured timepoints. If combining the two, label time clearly and explain which changes are due to viewing geometry.

Try it: change playback fps to 10 and export into a new folder. How does duration change? Is the inferred experimental acquisition interval altered? Save a preferred view before trying longer exports. PNG screenshots remain a useful fallback if video playback is unavailable.

viewer.close()