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
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
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.
From your own data you need three things: a trace as a [1, T] tensor of corrected
dF/F, the injection bin, and the sampling rate. For a cohort, additionally the
animal and drug index vectors. Preprocessing (isosbestic correction, bleaching,
dF/F) happens upstream of this package.
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.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| photosvi-1.0.0.tar.gz | 272.5 kB | With provenance | Details for photosvi-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| photosvi-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for photosvi-1.0.0-py3-none-any.whl |
Total release size: 513.6 kB
Release files / photosvi-1.0.0.tar.gz
| Download URL | photosvi-1.0.0.tar.gz |
|---|---|
| Size | 272.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a479def76d9d87e0d687da472b2ba6990efaa16f1bc05d7313f0a45869265c99
|
|
BLAKE2b-256 checksum How to use checksums |
30b3e881a820a8f78531f6f0a53cf0cf7678660cca93f9be0672080741f33bda
|
| 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 logRelease files / photosvi-1.0.0-py3-none-any.whl
| Download URL | photosvi-1.0.0-py3-none-any.whl |
|---|---|
| Size | 241.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
20525993780217244e1a7145c12a28debd68b01c3a48d9febce10d8af704aa22
|
|
BLAKE2b-256 checksum How to use checksums |
3c94d8ccc7f92536ad5287bd3eb4e373ea9e8231b949106e2c22fd370703ed5e
|
| 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 logSecurity for photosvi 1.0.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.
Attestation for photosvi-1.0.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 logA 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.