A lightweight desktop viewer for synchronized AVI/TIF playback with ROI trace inspection and motion artifact detection.
- Paired session loading from JSON config
- Side-by-side behavior video (AVI) and 2-photon imaging (TIF) frames
- ROI border overlay on TIF
- ROI fluorescence trace with cursor sync
- Motion energy computation with threshold, smoothing, and min-duration filtering
- Artifact regions overlaid on both motion plot and fluorescence trace
- Time pins and pin-time copy
- Python 3.10+
- numpy
- opencv-python
- tifffile
- pyqtgraph
- PyQt6 (or PyQt5 / PySide6)
pip install numpy opencv-python tifffile pyqtgraph PyQt6python viewer.py --root "<DATA_ROOT>" --config "pairs.example.json"You can also load or reload a JSON config from the menu:
File > Open JSON Config...File > Reload JSON Config
viewer_core.py contains the motion energy functions with no Qt/pyqtgraph dependency.
Use it directly in analysis scripts without a display:
from viewer_core import compute_motion_energy, moving_average, enforce_min_duration
import numpy as np
# Compute motion energy from an AVI file
energies, times = compute_motion_energy("path/to/video.avi")
# Smooth (e.g. 1-second window at 30 fps → win=30)
y_smooth = moving_average(energies, win=30)
# Threshold + remove short bursts (< 1s)
above = y_smooth >= 1.4
above_filtered = enforce_min_duration(above, dt=1/30, min_s=1.0)
# Quiet segments: ~above_filteredpairs.example.json shows the expected schema.
Required per pair:
idcellstatevariantavitifsuite2p_dir
Optional per pair:
session_index(omit to auto-infer from TIF filename)tif_fps(omit to use CLI default)
Notes:
- Paths may be absolute or relative to
base_root. - A pair is skipped if any required file is missing.
| Control | Description |
|---|---|
Motion threshold |
Energy level above which a frame is flagged as artifact |
Smooth (s) |
Moving-average window in seconds applied before thresholding |
Min duration (s) |
Minimum duration of a flagged region; shorter bursts are ignored |
Pipeline:
- Frame-to-frame pixel difference → raw motion energy
- Moving-average smoothing
- Threshold
- Remove runs shorter than min duration
- Overlay artifact regions on motion plot and fluorescence trace
| File | Description |
|---|---|
viewer.py |
GUI entry point (requires Qt + pyqtgraph) |
viewer_core.py |
Core motion energy functions — no Qt dependency, CLI-safe |
pairs.example.json |
Example JSON config |
requirements.txt |
Python dependencies |