Getting started¶
Install¶
pip install photosvi
Python 3.10 or newer. The heavy dependencies are PyTorch and Pyro; everything else is
the usual scientific stack. For a CUDA build of PyTorch, install it first as described
at pytorch.org; pip then keeps it. The
interactive benchmark views (BenchmarkResult.pr_figure(), .dashboard()) need
plotly:
pip install "photosvi[plots]"
To reproduce the paper, run the examples below as they are written, or run the test suite, install from a clone:
git clone https://github.com/AbanteLab/photosvi.git
cd photosvi
pip install -e ".[dev]"
GPU
Optional, and it only pays for the cohort model. A single-trace fit is about as
fast on one CPU core as on a GPU, so many of them run best as a CPU fan-out; a
cohort fit is batched, and there the per-step cost is nearly flat in the number
of sessions. photosvi.inference.points.resolve_device("auto", batch=S) applies
that rule. See Choosing your settings.
Check the install¶
photosvi --help
From a clone, the test suite checks everything:
pytest tests/ -q
A first fit¶
The example below is run by the test suite on every push. It
uses the toy configuration shipped with the package, config_path("toy.yaml"): two
minutes of recording instead of forty, so it finishes in seconds. Without a clone,
download single_trace.py
and run it with python single_trace.py.
python docs/examples/single_trace.py
rate ratio 4.31x (simulated 4.00x)
beta_inj +1.460 +- 0.134
expected events 42 (simulated 31)
These numbers are not the paper's
At two minutes a recording carries a few dozen transients, and the fit runs for
600 steps rather than tens of thousands. The estimate is dominated by counting
noise and the fit has not converged. Use the toy configuration to learn the API;
the settings of the paper are in configs/final_detection_48.yaml (one recording)
and configs/final_cohort_48.yaml (a cohort), also shipped with the package and
found with config_path.
What you need from your own data¶
For each recording:
- The signal: either the raw sensor channel with its isosbestic control, or a trace already corrected to dF/F.
- The injection time, in seconds (or read from a Doric file's events).
- The sampling rate.
For a cohort, additionally which animal and which condition each recording belongs to.
The loaders do the isosbestic correction: a Doric file is corrected on loading, and so
is any other file that gives the control channel (load_session(...,
isosbestic_column=...)) or a pair of arrays (Session.from_channels). A trace already
corrected to dF/F is used as it is. The example above works one level below, on a
[1, T] tensor of dF/F and the injection bin, which is what the models themselves take.
To fit a recording from a file, from the command line or with one function call, see
Fit your own recordings.