Skip to content

Show2D: saved microscope-stage view states from the widget UI #155

Description

@bobleesj

Problem

A scientist often drives Show2D interactively inside a notebook: they draw ROIs, tune contrast, turn on FFT, add padding, hide panels, and select a panel or local slice. When they find a meaningful inspection state, they should not have to write Python export/state code just to come back to that view later.

The missing workflow is a lightweight in-widget "microscope stage position" list: named view states saved from the UI, restored later, and preserved in notebook widget state without duplicating raw image data.

Proposed solution

Add a Show2D saved-view-state workflow that keeps the API first-class while exposing a simple UI layer.

Expected user behavior

A user opens a notebook with Show2D, interacts with the widget, then uses More → Save State to save named states such as:

  • defect A ROI
  • 20% padding drift check
  • raw vs corrected, residual hidden

The More menu should show the saved states and let the user:

  • Load a state.
  • Update an existing state after moving an ROI or changing padding/contrast.
  • Delete one state.
  • Delete all states.

The Python API should expose the same behavior:

w.save_view_state("defect A ROI")
w.load_view_state("defect A ROI")
w.delete_view_state("defect A ROI")
w.clear_view_states()

Saved states should include lightweight UI/view state such as ROI list, selected ROI, selected panel, hidden panels, panel order, local stack frame indices, contrast, colormap, FFT, denoise/filter, crop, padding, zoom/view box, and scale-bar settings.

Saved states must not embed another copy of raw image data, frame_bytes, panel_stack_bytes, detail tiles, or standalone HTML payloads.

Agent visual verification checklist

  • In live JupyterLab, open a Show2D single image, draw an ROI, enable FFT, zoom/pan, add padding, and save defect A ROI from the More menu.
  • Save a second state with a different ROI position, hidden/visible panels, selected panel, contrast, and padding.
  • Load each state repeatedly and verify the canvas, ROI overlay, FFT toggle/view, padding border, selected panel, hidden panels, histogram/contrast, and scale bar visibly match the saved state.
  • Update one state after moving an ROI; reload it and verify the updated ROI is the one shown.
  • Delete one state and verify the other remains loadable. Delete all and verify the list is empty and the widget still works.
  • Save/reopen the notebook or round-trip state_dict() / load_state_dict() and verify the named state list survives.
  • Inspect saved widget state for heavy-buffer leaks: no raw data duplication inside each saved state.
  • Attach screenshots or an HTML/browser report showing the saved-state menu and at least two loaded states.

Existing local draft context

A local branch has an initial implementation and tests:

  • src/quantem/widget/show2d.py
  • js/show2d/index.tsx
  • tests/test_show2d_saved_view_states.py
  • docs/api/show2d.md
  • docs/maintainer/storyboard-show2d.md (S2D-10B)

Local commit at time of issue drafting: 8d39b01 feat: add saved view and playback stories on branch show2d-roi-static-preview.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions