Skip to main content

PhotoSVI

Transient detection and drug-response rate estimation for fiber photometry, from one generative model.

A photometry trace carries two signals a threshold cannot separate. A drug can shift the baseline over minutes (the tonic response); individual dopamine transients ride on top of it over hundreds of milliseconds. A detector must decide where the baseline is before it can find transients above it, and that decision is the same one that determines how many transients there are.

PhotoSVI writes both into one model and estimates them together:

y_t = \underbrace{\hat{x}_t}_{\text{tonic carrier}}
+ \underbrace{(h * s_t a_t)}_{\text{marked point process}} + \varepsilon_t,
\qquad \log \lambda_t = \beta_0 + \beta_{\mathrm{inj}} g_t

The quantity an experiment asks about, the factor by which a drug changes the transient rate, $e^{\beta_{\mathrm{inj}}}$, is a parameter of the model, not something counted afterwards from a list of detections. Detection and rate estimation become two readouts of one posterior.

Two models

Both share the same phasic machinery and differ in what they are handed and what they can therefore answer.

SingleTraceModel: one recording

What the single-trace model returns

For asking what happened in a particular session: transients with times and amplitudes, the rate ratio $e^{\beta_{\mathrm{inj}}}$ for that recording with a credible interval, and that session's tonic response. Use it to screen recordings, to get event times for downstream analysis, or when the session itself is the unit of interest. Its interval has been checked against Hamiltonian Monte Carlo on the same recordings: its width is 0.97 times the exact one.

HierarchicalModel: a cohort

What the cohort model returns

For the question an experiment is usually designed around: whether two drugs differ, by how much, and with between-animal variability inside the interval rather than averaged out of it. It places the per-session coefficients, and the carrier, in an animal × drug hierarchy, reads the design off the index vectors, and includes only the variance components that design can identify. Along the way it returns the variance components themselves, which is what a power calculation for the next cohort needs, and the tonic response of each drug, pooled across animals.

On simulated cohorts the width of the interval on a contrast matches the spread of the estimate across cohorts. The estimate itself is shrunk toward zero (it recovered 76% of a simulated effect at medium SNR), so the 90% interval contained the true effect in 80% of cohorts. MODEL_CARD.md has the measurement.

Install

pip install photosvi

Python ≥ 3.10. The heavy dependencies are PyTorch and Pyro; a GPU is optional and only pays for the cohort model. For a CUDA build of PyTorch, install it first as described at pytorch.org. The interactive benchmark views need pip install "photosvi[plots]".

To reproduce the paper or run the test suite, install from a clone instead:

git clone https://github.com/AbanteLab/photosvi.git
cd photosvi
pip install -e ".[dev]"
pytest tests/ -q

Basic use

Two short scripts show the API: single_trace.py fits one recording and reads the rate ratio, and cohort.py fits a cohort and reads a drug contrast.

python single_trace.py
python cohort.py

Both run in seconds on the toy configuration shipped with the package (photosvi.api.config_path("toy.yaml")), and the test suite runs them on every push. The documentation covers fitting your own recordings, choosing settings for your sensor, and reproducing the benchmark.

Your own recordings, Doric files or dF/F traces, can be fitted from the command line:

photosvi kernel calibrate rec1.doric rec2.doric --out kernel.yaml   # if not dLight1.3b
photosvi fit session.doric --kernel kernel.yaml --out run/          # one recording
photosvi fit-cohort sessions.csv --reference vehicle --out run/     # a cohort

Fit your own recordings describes the inputs, the table of sessions and what each command writes.

From your own data you need, for each recording, the raw sensor channel with its isosbestic control (or a trace already corrected to dF/F), the injection time and the sampling rate; for a cohort, also the animal and the condition. The isosbestic correction to dF/F is done on loading, for Doric files and for any file that gives the control channel.

The transient kernel is fixed during a fit and should match your sensor. Calibrate it from your recordings first with photosvi kernel calibrate or api.calibrate_kernel, described in choosing your settings.

What is in the repository

src/photosvi/
├── models/points/     the generative blocks and the Pyro model/guide pairs
├── inference/points/  the SVI loop, the stopping criterion, device selection
├── benchmark/         detection scoring: matched filter, GuPPy, PR/F1, NMS
├── experiments/       the simulation studies behind the paper
├── kernel_calibration.py  fitting the transient kernel to a sensor, before a fit
└── data/              loading and preprocessing hooks
configs/               every experiment's settings, one YAML each (a link to
                       src/photosvi/configs/, which ships with the package)
scripts/               entry points for the studies, and the figure generators
docs/                  the documentation source, and the runnable examples

MODEL_CARD.md records what the shipped model is set to and the measurement behind each choice. Run outputs and generated figures are written outside the repository (see .gitignore); what makes a result reproducible (the config, the seed and the code version) is tracked here.

Status

Version 1.0.0 is the code of the paper. MODEL_CARD.md records what the shipped model is set to, the measurement behind each choice, and what is not yet defended.

Citation

If you use PhotoSVI, please cite the preprint:

G. Peytral, Z. Tariq, A. Essmann, Z. M. Garçon-Poca, D. Garcia Ortiz, C. Crook, J. Bonaventura and J. Abante. Disentangling tonic and phasic dopamine in fiber photometry from single recordings to cohorts. bioRxiv (2026). https://doi.org/10.64898/2026.11.16.767032

@article{peytral2026photosvi,
  title   = {Disentangling tonic and phasic dopamine in fiber photometry from single recordings to cohorts},
  author  = {Peytral, Gabriel and Tariq, Zinnera and Essmann, Amelie and Gar{\c{c}}on-Poca, Zelai M. and Garcia Ortiz, David and Crook, Caitlin and Bonaventura, Jordi and Abante, Jordi},
  journal = {bioRxiv},
  year    = {2026},
  doi     = {10.64898/2026.11.16.767032}
}

License

MIT; see LICENSE.

Metadata

Release files for photosvi 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for photosvi 1.2.0
File Size Uploaded Provenance Actions
photosvi-1.2.0.tar.gz 287.3 kB With provenance Details for photosvi-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for photosvi 1.2.0
File Interpreter ABI Platform Actions
photosvi-1.2.0-py3-none-any.whl Python 3 none any Details for photosvi-1.2.0-py3-none-any.whl

Total release size: 542.0 kB

Release files / photosvi-1.2.0.tar.gz

Download URL photosvi-1.2.0.tar.gz
Size 287.3 kB
Tags Source
SHA-256 checksum
How to use checksums
871ecc5e78511eddbb9828b8dbe3793632bcaa4e7a9879892565c9f7d7f6384c
BLAKE2b-256 checksum
How to use checksums
13d3d77298e863ad5a758f6dff55f7bba18d10364c7d2e2005652461c47c4053
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / photosvi-1.2.0-py3-none-any.whl

Download URL photosvi-1.2.0-py3-none-any.whl
Size 254.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5dc8148de9484be0b51c2e076ece1e6c7280520195383dc6b3f30b4bbf9f84a5
BLAKE2b-256 checksum
How to use checksums
867525797add1b3b35832deb770eed6f5973cb7b9813fc8b9cf33a9a979137a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for photosvi 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for photosvi-1.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page