Skip to content

Add z-stack imaging (stimulation at the home z) - #76

Draft
Harrison-Oatman wants to merge 1 commit into
mainfrom
claude/project-thread-4uankm
Draft

Harrison-Oatman wants to merge 1 commit into
mainfrom
claude/project-thread-4uankm

Conversation

@Harrison-Oatman

Copy link
Copy Markdown
Collaborator

Requested by Harrison · project thread

Each xy position can now take a z-stack per imaging channel; the stack goes to the segmentation method; the DMD stimulation stays one frame per position at the home z.

Config

[imaging]
z_stack = { from_um = -10, to_um = 10, step_um = 2 }   # offsets from each position's own z

[channels.638]
z_stack = false            # per-channel override (or its own range)

[segmentation]
method = "cellpose"
z_projection = "none"      # default: the method gets the (z, y, x) stack; "max" gives a 2D projection

pyclm_config.toml [acquisition] z_settle_seconds (default 0) waits after each focus step.

What happens

  • Microscope (_acquire_stack): home z = focus position after the move; one snap per offset; always back to home z. PositionMover.stack_begin/stack_end hooks: the PFS mover turns focus maintenance off for the stack and back on (with a wait for lock) at home z. Grids: each tile is stacked, each slice stitched.
  • Stimulation: never stacked, so it is one frame at the home z.
  • Segmentation: SegmentationMethod.segment_stack(stack); the default segments the max projection. Cellpose uses its 3D mode (do_3D, anisotropy) or per-slice + stitch_threshold. 3D labels are max-projected to 2D for tracking, patterns and storage.
  • Pattern methods: context.raw() is the max projection; context.raw_stack() is the stack.
  • Storage: OME-Zarr stacked groups are (T, C, Z, Y, X) (own cadence group, z_offsets_um in group metadata); HDF5 datasets are (Z, Y, X) with z_offsets_um, z_home_um, z_positions_um attrs. pyclm.io frame() returns projections, so export, movies, viewer and watch keep working; stack() returns the stack.
  • Timing estimate counts one exposure per slice.

Not done / to check on hardware

  • Not run on a real microscope. Cellpose 3D path not run here (no cellpose in the test env).
  • Stored labels are 2D projections; 3D labels are not kept.
  • Frames table has no per-slice z columns (the HDF5 attrs and zarr metadata hold them).

Tests

tests/test_z_stack.py: schema, microscope stack positions and return to home, dry runs (zarr and HDF5) with a stack-recording segmentation and a pattern method that checks projection shapes, and z_projection = "max". Full suite: 635 passed, 21 skipped.


Generated by Claude Code

…n at the home z

z_stack = { from_um, to_um, step_um } in [imaging] or a channel table
(z_stack = false turns it off) takes imaging channels as z-stacks around
each position's home z; the stimulation stays one frame at the home z.
Segmentation receives the (z, y, x) stack through segment_stack (Cellpose
in 3D or per slice with stitch_threshold; other methods default to the
maximum projection), or the projection with z_projection = "max". Labels,
tracking and pattern methods work in 2D; PatternContext.raw_stack gives the
stack. OME-Zarr stores stacked groups as (T, C, Z, Y, X), HDF5 as (Z, Y, X)
datasets; pyclm.io frame() returns projections and stack() the stack. The
pfs mover switches focus maintenance off for a stack and waits for lock at
the home z; [acquisition] z_settle_seconds waits after each focus step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pjqs6ZVKxsT9T2e9MCHviJ
@Harrison-Oatman Harrison-Oatman self-assigned this Dec 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants