Metadata-Version: 2.4
Name: closed-loop-microscopy
Version: 1.2.0
Summary: Closed-loop feedback control for optogenetic microscopy in Python
Keywords: microscopy,optogenetics,closed-loop,micro-manager,DMD
Author: Harrison-Oatman
Author-email: Harrison-Oatman <ho6729@princeton.edu>
License-Expression: MIT
License-File: LICENSE.md
Classifier: Programming Language :: Python :: 3
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: Topic :: Scientific/Engineering :: Image Processing
Requires-Dist: h5py>=3.14.0
Requires-Dist: natsort>=8.4.0
Requires-Dist: numpy
Requires-Dist: opencv-python-headless>=4.12.0.88
Requires-Dist: pyarrow>=15
Requires-Dist: pydantic>=2
Requires-Dist: pymmcore-plus>=0.14.0
Requires-Dist: pymmcore>=11.2.1.71.0
Requires-Dist: pyyaml>=6.0.3
Requires-Dist: scikit-image>=0.25.2
Requires-Dist: scipy
Requires-Dist: tifffile>=2025.9.20
Requires-Dist: useq-schema>=0.9.2
Requires-Dist: zarr>=3.0
Requires-Dist: pycromanager>=1.0.2 ; extra == 'calibration'
Requires-Dist: cellpose>=4.2.0 ; extra == 'cellpose'
Requires-Dist: torch ; extra == 'cellpose'
Requires-Dist: torchvision ; extra == 'cellpose'
Requires-Dist: napari>=0.9.0 ; extra == 'gui'
Requires-Dist: pyside6>=6.10.2 ; extra == 'gui'
Requires-Python: >=3.11
Project-URL: Documentation, https://pyclm.readthedocs.io
Project-URL: Homepage, https://github.com/toettchlab/PyCLM
Project-URL: Issues, https://github.com/toettchlab/PyCLM/issues
Provides-Extra: calibration
Provides-Extra: cellpose
Provides-Extra: gui
Description-Content-Type: text/markdown

# PyCLM

[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.20385964.svg)](https://doi.org/10.5281/zenodo.20385964)
[![Documentation](https://readthedocs.org/projects/pyclm/badge/?version=latest)](https://pyclm.readthedocs.io/en/latest/)

A modular closed-loop microscopy software in Python.

PyCLM runs many optogenetic experiments at once on one microscope. Each
imaging position gets its own light pattern, projected through a DMD, that
can be fixed, change over time, follow individual cells, or respond to what
the cells are doing.

## Using PyCLM with Claude Code

PyCLM ships a plugin for [Claude Code](https://claude.com/claude-code) that
sets PyCLM up on a microscope and designs, checks, runs, follows and exports
experiments with you, using the `pyclm` commands below. On the microscope PC,
with Claude Code installed:

```bash
claude plugin marketplace add toettchlab/PyCLM
claude plugin install pyclm@pyclm-plugins
claude
```

![](https://raw.githubusercontent.com/toettchlab/PyCLM/main/documentation/imgs/plugin/six_steps.svg "The six steps of a run")

[Using PyCLM with Claude Code](https://pyclm.readthedocs.io/en/latest/agent_skills.html)
covers setup, launching on a shared microscope PC, each step of a run,
Remote Control from a Claude project, and a worked example.

## How PyCLM works

Experiments are written as short TOML files, so running a new one needs no
programming; a new kind of light rule is a small Python class. Microscope
control, segmentation, tracking, pattern generation and saving run as
separate processes in parallel, so the microscope rarely waits and the
number of simultaneous experiments is limited mainly by the hardware. Data
is written as the run goes (OME-Zarr by default), and ImageJ hyperstacks are
exported at the end.

![](https://raw.githubusercontent.com/toettchlab/PyCLM/main/documentation/imgs/pyclm-overview.png "PyCLM Overview")

## Start here

| I want to... | Go to |
|---|---|
| Set up and run experiments with Claude Code | **[Using PyCLM with Claude Code](https://pyclm.readthedocs.io/en/latest/agent_skills.html)** |
| See what light patterns PyCLM can make | **[Method zoo](https://pyclm.readthedocs.io/en/latest/method_zoo.html)**: every built-in pattern method on a sample image, with a `[pattern]` table to copy |
| Try it without a microscope | The demo below |
| Set PyCLM up on my microscope | [First-time setup](https://pyclm.readthedocs.io/en/latest/first_time_setup.html) |
| Write an experiment | [Experiment TOMLs](https://pyclm.readthedocs.io/en/latest/experiment_tomls.html) and [the `pyclm` command](https://pyclm.readthedocs.io/en/latest/command_line.html) |
| Write my own light rule | [Custom pattern methods](https://pyclm.readthedocs.io/en/latest/custom_pattern_methods.html) |
| Open the data from a run | [Data format and export](https://pyclm.readthedocs.io/en/latest/data_format.html) |

The full documentation is at [pyclm.readthedocs.io](https://pyclm.readthedocs.io/en/latest/).

## Install and try it yourself

```bash
pip install "closed-loop-microscopy[gui]"
pyclm new demo --demo
pyclm run demo --dry --gui
```

The package is `closed-loop-microscopy`; the import name and the command are
`pyclm`. Leave out `[gui]` for a headless install (checking, previews, dry
runs, reading data). For development, clone the repository and run `uv sync`.

The demo runs two experiments on the virtual microscope (`--dry`) with
synthetic cells: a sweeping bar of light, and a closed loop that segments the
cells and lights the outward half of each. Pick a method from the
[zoo](https://pyclm.readthedocs.io/en/latest/method_zoo.html), paste its
`[pattern]` table over the one in `demo/cells.toml` (keep `channel = "545"`,
the demo's channel), and run it again.

Running on a real microscope needs [Micro-Manager](https://micro-manager.org),
which PyCLM drives through
[pymmcore-plus](https://github.com/pymmcore-plus/pymmcore-plus); point
`config_path` in `pyclm_config.toml` at your Micro-Manager `.cfg` file. The
[installation page](https://pyclm.readthedocs.io/en/latest/installation.html)
covers the extras and matching the Micro-Manager device interface.

## Citation

If you use PyCLM in your research, please cite:

> Oatman HR, Lad BC, Nguyen L, Gubbens JH, Toettcher JE. An optogenetic smart
> microscopy platform reveals signaling dynamics-dependent control over
> collective cell migration. *Cell Systems* 17(9) (2026).
> [doi:10.1016/j.cels.2026.101674](https://doi.org/10.1016/j.cels.2026.101674)

The paper describes version 1.0.1. To record the version you used, also cite
that release: every release has its own DOI on Zenodo, all listed under
[doi:10.5281/zenodo.20385964](https://doi.org/10.5281/zenodo.20385964)
(which always resolves to the latest). GitHub's "Cite this repository" button
gives both, from `CITATION.cff`.
