Computational optimization of two-photon holographic stimulation sites<i>in vivo</i>.
Paper
Loaded from Europe PMC by your browser; OSCR does not store it: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
Jupyter notebook · 220 lines · 6.9 KB · GPL-3.0
- # %%
- import numpy as np
- import matplotlib.pyplot as plt
- import matplotlib
- from matplotlib import cm #
- from matplotlib.patches import Circle
- from matplotlib.colors import Normalize
- from matplotlib.cm import get_cmap, ScalarMappable
- np.random.seed(35)
- # %%
- import stim_opt as so
- from stim_opt import experimental_design
- # %%
- fontsize = 12
- pixel_size = 411/512
- # %% [markdown]
- # # Setup simulation and plot neuron locations
- # %%
- N = 350
- sim = so.Simulation(N)
- # %%
- plt.figure(figsize=(3, 3))
- for x, y in sim.neuron_locations:
- circ = Circle((x, y), radius=6/pixel_size, edgecolor='teal', facecolor='None')
- plt.gca().add_patch(circ)
- plt.xlim([0, 411])
- plt.ylim([0, 411])
- plt.xticks(np.arange(0, 401, 100), fontsize=fontsize)
- plt.yticks(np.arange(0, 401, 100), fontsize=fontsize)
- # plt.grid(linestyle='--')
- plt.xlabel('Distance (μm)', fontsize=fontsize)
- plt.ylabel('Distance (μm)', fontsize=fontsize)
- plt.show()
- # %% [markdown]
- # ## Visualize ORFs
- # %%
- vmax = 3.
- scalebar = 20 / pixel_size
- # %%
- nrows = 4
- ncols = 8
- panel_size = 1.5
- plt.figure(figsize=(ncols * panel_size, nrows * panel_size))
- for n in range(nrows * ncols):
- grid, X1, X2, extent = so.nbfr.generate_grid(sim.neurons[n].location, grid_width=30)
- Z = sim.neurons[n].predict(grid).reshape(100, 100)
- vmax = np.max(Z)
- plt.subplot(nrows, ncols, n + 1)
- plt.imshow(Z, interpolation='nearest', aspect='auto', cmap='coolwarm', vmin=-vmax, vmax=vmax, extent=extent, origin='lower')
- plt.contour(X1, X2, Z, levels=5, colors='black', linewidths=0.5, extent=extent) # Add contour lines
- plt.gca().add_patch(Circle((sim.neurons[n].location), radius=6/pixel_size, edgecolor='teal', facecolor='None', zorder=100, lw=3, ls='-'))
- plt.xticks([])
- plt.yticks([])
- if n == 0:
- plt.plot([sim.neurons[n].location[0], sim.neurons[n].location[0]+ scalebar], [sim.neurons[n].location[1] - 25, sim.neurons[n].location[1] - 25], lw=2, color='k')
- for spine in plt.gca().spines.values():
- spine.set_linewidth(1.5)
- plt.show()
- # %% [markdown]
- # # Map ORFs from an artificial exeriment
- # %%
- stim_size = 10
- stim_powers = [1.]
- noise_std = 0.5
- # %%
- %%time
- stim_design = experimental_design.generate_stimuli(sim.neuron_locations, pixel_size=pixel_size, stim_size=stim_size, stim_powers=stim_powers)[:, :2].reshape(-1, stim_size, 2)
- # %%
- %%time
- stim_responses = sim.population_response(stim_design)
- noise = np.random.normal(0, noise_std, stim_responses.shape)
- models = so.Models(sim.neuron_locations)
- models.fit(stim_design, stim_responses + noise)
- # %% [markdown]
- # # Optimize stimulation pattern
- # %%
- target_neurons = np.array([261, 197, 43])
- nontarget_neurons = np.setdiff1d(np.arange(N), target_neurons)
- stim_opt, stim_hist, objs = so.nbfr.optimize_stimulus(models, target_neurons, save_history=True, stepsize=5e0, n_iters=30)
- stim_som = sim.neuron_locations[target_neurons]
- # %%
- plt.figure(figsize=(2, 2))
- plt.plot(objs)
- plt.xlabel('Iterations')
- plt.xticks(np.arange(0, 31, 10))
- plt.ylabel('Objective function')
- plt.show()
- # %% [markdown]
- # # Visualize results
- # %%
- population_response_opt = sim.population_response(stim_opt[np.newaxis]).squeeze()
- population_response_som = sim.population_response(stim_som[np.newaxis]).squeeze()
- # %%
- fov_center = [160, 80]
- fov_width = 90
- sample_fov_extent = [fov_center[0] - fov_width/2, fov_center[0] + fov_width/2, fov_center[1] - fov_width/2, fov_center[1] + fov_width/2]
- vmax = np.max([np.max(population_response_opt), np.max(population_response_som)])
- vmin = -vmax
- norm = Normalize(vmin=vmin, vmax=vmax)
- cmap_response = matplotlib.colormaps.get_cmap('coolwarm') # for stim responses
- cmap = matplotlib.colormaps.get_cmap('YlOrRd') # for stim opt path
- # %%
- plt.figure(figsize=(2, 2))
- for (x, y), response in zip(sim.neuron_locations, population_response_som):
- color = cmap_response(norm(response))
- circ = Circle((x, y), radius=6/pixel_size, edgecolor='k', facecolor=color)
- plt.gca().add_patch(circ)
- plt.xlim(sample_fov_extent[:2])
- plt.ylim(sample_fov_extent[2:])
- plt.xticks(np.arange(120, 201, 20), fontsize=fontsize)
- plt.yticks(np.arange(40, 121, 20), fontsize=fontsize)
- plt.xlabel('Distance (μm)', fontsize=fontsize)
- plt.ylabel('Distance (μm)', fontsize=fontsize)
- plt.title('Somatic stimulation')
- plt.show()
- # %%
- plt.figure(figsize=(2, 2))
- for (x, y), response in zip(sim.neuron_locations, population_response_opt):
- color = cmap_response(norm(response))
- circ = Circle((x, y), radius=6/pixel_size, edgecolor='k', facecolor=color)
- plt.gca().add_patch(circ)
- # Progressive color for stim_hist
- for j in range(3):
- N_steps = stim_hist.shape[0]
- for t in range(N_steps - 1):
- frac = t / (N_steps - 1) # normalize to 0–1
- color = cmap(frac)
- x0, y0 = stim_hist[t, j]
- x1, y1 = stim_hist[t+1, j]
- plt.plot([x0, x1], [y0, y1], '-', color=color, zorder=1000, lw=2.5)
- plt.plot(x0, y0, 'o', color=color, markersize=3, markerfacecolor='w', zorder=1000)
- plt.xlim(sample_fov_extent[:2])
- plt.ylim(sample_fov_extent[2:])
- plt.xticks(np.arange(120, 201, 20), fontsize=fontsize)
- plt.yticks(fontsize=fontsize)
- plt.xlabel('Distance (μm)', fontsize=fontsize)
- plt.ylabel('Distance (μm)', fontsize=fontsize)
- plt.title('Optimized')
- plt.show()
- # %% [markdown]
- # # Loss surface
- # %%
- xsteps = np.arange(sample_fov_extent[0], sample_fov_extent[1] + 0.1, 1)
- ysteps = np.arange(sample_fov_extent[2], sample_fov_extent[3] + 0.1, 1)
- xs, ys = np.meshgrid(xsteps, ysteps)
- sample_grid = np.c_[xs.flatten(), ys.flatten()]
- D = xs.shape[0]
- # %%
- # Difference between target and non-target objective functions
- sum_orf = np.sum([sim.neurons[n].predict(sample_grid).reshape(D, D) for n in target_neurons], 0) \
- - np.sum([sim.neurons[n].predict(sample_grid).reshape(D, D) for n in nontarget_neurons], 0)
- # %%
- plt.figure(figsize=(2, 2))
- n = 0
- im = plt.imshow(sum_orf, origin='lower', cmap='coolwarm', vmin=-vmax, vmax=vmax, extent=sample_fov_extent)
- ax = plt.gca()
- # Progressive color for stim_hist
- for j in range(3):
- N_steps = stim_hist.shape[0]
- for t in range(N_steps - 1):
- frac = t / (N_steps - 1) # normalize to 0–1
- color = cmap(frac)
- x0, y0 = stim_hist[t, j]
- x1, y1 = stim_hist[t+1, j]
- plt.plot([x0, x1], [y0, y1], '-', color=color, zorder=1000, mew=1)
- plt.plot(x0, y0, 'o', color=color, markersize=3, markerfacecolor='w', zorder=1000, mew=1)
- plt.xlim(sample_fov_extent[:2])
- plt.ylim(sample_fov_extent[2:])
- plt.xticks(np.arange(120, 201, 20), fontsize=fontsize)
- plt.yticks(fontsize=fontsize)
- plt.xlabel('Distance (μm)', fontsize=fontsize)
- plt.ylabel('Distance (μm)', fontsize=fontsize)
- for (x, y), response in zip(sim.neuron_locations, population_response_opt):
- color = cmap_response(norm(response))
- circ = Circle((x, y), radius=6/pixel_size, edgecolor='k', facecolor='None')
- plt.gca().add_patch(circ)
- n += 1
- cbar = plt.colorbar(im, ax=ax, fraction=0.046, pad=0.04)
- cbar.ax.tick_params(labelsize=fontsize)
- cbar.set_label('Objective function', rotation=270, fontsize=fontsize, labelpad=12)
- plt.show()
example.ipynb at commit 6e5f7bb, under GPL-3.0 · at the source
Overview
- Mortimer B. Zuckerman Mind Brain Behavior Institute, Columbia University, New York, NY, United States of America
- Grossman Center for the Statistics of Mind, Columbia University, New York, NY, United States of America
- Center for Theoretical Neuroscience, Columbia University, New York, NY, United States of America
- Department of Statistics, Columbia University, New York, NY, United States of America
- Wolfson Institute for Biomedical Research, University College London, London, United Kingdom
- School of Biomedical Sciences, The University of Hong Kong, Hong Kong Special Administrative Region of China, People’s Republic of China
Abstract
Objective. Determining the intricate structure and function of neural circuits requires the ability to precisely manipulate circuit activity. Two-photon holographic optogenetics has emerged as a powerful tool for achieving this via flexible excitation of user-defined neural ensembles. However, the precision of two-photon optogenetics has been constrained by off-target stimulation (OTS), an effect where proximal non-target neurons can be unintentionally activated due to imperfect spatial confinement of light onto target neurons. New approaches are therefore needed to resolve the OTS problem. Approach. Here, we introduce a real-time computational method for mitigating OTS that first empirically samples each neuron’s sensitivity to stimulation at proximal locations, and then optimizes stimulation sites using a fast, interpretable model based on adaptive non-negative basis function regression (NBFR). Main results. NBFR is highly scalable, completing model fitting for hundreds of neurons in just a few seconds and then optimizing stimulation sites in several hundred milliseconds per stimulus—fast enough for most closed-loop behavioral experiments. We characterize the performance of our approach in both simulations and in vivo experiments in mouse hippocampus, showing its efficacy under realistic experimental conditions. Significance. Our results thus establish NBFR-based photostimulus optimization as an important addition to an emerging computational toolkit for precise yet scalable holographic optogenetics.
Reproduced under the paper's license (CC BY), from the paper cited above.
Repository
Its files are read in the Code ↔ Paper reader above.
marcustriplett/photostim-optimizer
6e5f7bba8f92135de519fd83ab4ec6b04097fe2e, 15 August 2025Availability: 1 check, the latest on 30 September 2026: the link answers
- 30 September 2026: the link answers
9 files
- examples/
example.ipynb , Jupyter, 220 lines - setup.py, Python, 17 lines
- stim_opt/
__init__.py , Python, 2 lines - stim_opt/
experimental_design.py , Python, 59 lines - stim_opt/
nbfr.py , Python, 206 lines - stim_opt/
simulation.py , Python, 69 lines - stim_opt/
utils.py , Python, 142 lines - LICENSE, License, 674 lines
- README.md, Text, 27 lines
Code availability
Code for this manuscript is available at https://
Reproduced under the paper's license (CC BY), from the paper cited above.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 7 scripts, each with its path and the digest of its content;
- no match between paragraphs and code yet;
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
Datasets cited
- figshare:29923262, at figshare; found in “Data availability statement”
Data availability statement
The data that support the findings of this study are openly available at the following URL/
Reproduced under the paper's license (CC BY), from the paper cited above.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 1, 30 September 2026: the first record
Recorded: type, language, journal, volume, issue, pages, dates, 7 authors, 4 keywords, 10 MeSH terms, 13 funders, 40 references.
Cite
This paper
Triplett, M. A., Bäumler, E., Prodan, A., Stonis, R., Peterka, D. S., Häusser, M., & Paninski, L. (2026). Computational optimization of two-photon holographic stimulation sites&
BibTeX
@article{triplett2026com
author = {Triplett, Marcus A and Bäumler, Edgar and Prodan, Alex and Stonis, Rokas and Peterka, Darcy S and Häusser, Michael and Paninski, Liam},
title = {{Computational optimization of two-photon holographic stimulation sites\&
journal = {Journal of neural engineering},
year = {2026},
month = mar,
volume = {23},
number = {2},
pages = {026015},
publisher = {IOP Publishing},
issn = {1741-2560},
doi = {10.1088/
url = {https://
pmid = {41878953},
pmcid = {PMC13014349}
}
RIS
TY - JOUR
AU - Triplett, Marcus A
AU - Bäumler, Edgar
AU - Prodan, Alex
AU - Stonis, Rokas
AU - Peterka, Darcy S
AU - Häusser, Michael
AU - Paninski, Liam
TI - Computational optimization of two-photon holographic stimulation sites&
T2 - Journal of neural engineering
J2 - J Neural Eng
PY - 2026
DA - 2026/
VL - 23
IS - 2
SP - 026015
SN - 1741-2560
PB - IOP Publishing
DO - 10.1088/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1088/
"type": "article-journal",
"title": "Computational optimization of two-photon holographic stimulation sites&
"container-title": "Journal of neural engineering",
"author": [
{
"family": "Triplett",
"given": "Marcus A"
},
{
"family": "Bäumler",
"given": "Edgar"
},
{
"family": "Prodan",
"given": "Alex"
},
{
"family": "Stonis",
"given": "Rokas"
},
{
"family": "Peterka",
"given": "Darcy S"
},
{
"family": "Häusser",
"given": "Michael"
},
{
"family": "Paninski",
"given": "Liam"
}
],
"container-title-short":
"volume": "23",
"issue": "2",
"page": "026015",
"DOI": "10.1088/
"PMID": "41878953",
"PMCID": "PMC13014349",
"ISSN": "1741-2560",
"publisher": "IOP Publishing",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
3,
25
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1038/s41593-025-02053-7 [code]
- Rapid learning of neural circuitry from holographic ensemble stimulation enabled by model-based compressed sensing.Journal: Nature neuroscienceIn common: scikit-learn, SciPy, Matplotlib, 1 other tool, mouse, 13 references, author Marcus A Triplett
- [2] doi:10.1371/journal.pcbi.1012053 [code]
- Removing direct photocurrent artifacts in optogenetic connectivity mapping data via constrained matrix factorization.Journal: PLoS computational biologyIn common: scikit-learn, SciPy, Matplotlib, 1 other tool, mouse, 9 references, 2 authors
- [3] doi:10.1117/1.nph.11.1.015006 [code]
- Contribution of optical resolution to the spatial precision of two-photon optogenetic photostimulation <i>in vivo</
i>. Journal: NeurophotonicsIn common: SciPy, Matplotlib, NumPy, optical imaging (calcium, voltage, 2-photon), 14 references - [4] doi:10.1038/s41467-024-46484-5 [code]
- The influence of cortical activity on perception depends on behavioral state and sensory context.Journal: Nature communicationsIn common: SciPy, Matplotlib, NumPy, mouse, 9 references, author Michael Häusser
- [5] doi:10.1038/s41593-025-02024-y [code]
- High-throughput synaptic connectivity mapping using in vivo two-photon holographic optogenetics and compressive sensing.Journal: Nature neuroscienceIn common: optical imaging (calcium, voltage, 2-photon), mouse, 12 references
- [6] doi:10.1016/j.crmeth.2025.101180 [code]
- A real-time all-optical interface for dynamic perturbation of neural activity during behavior.Journal: Cell reports methodsIn common: SciPy, Matplotlib, NumPy, optical imaging (calcium, voltage, 2-photon), mouse, 8 references, author Michael Häusser
- [7] doi:10.1038/s41467-023-37416-w [code]
- Ultrafast light targeting for high-throughput precise control of neuronal networks.Journal: Nature communicationsIn common: optical imaging (calcium, voltage, 2-photon), mouse, 11 references
- [8] doi:10.1117/1.nph.9.4.041409 [code]
- Advances in computer-generated holography for targeted neuronal modulation.Journal: NeurophotonicsIn common: SciPy, Matplotlib, NumPy, optical imaging (calcium, voltage, 2-photon), 9 references
- [9] doi:10.1038/s41467-026-69419-8 [code]
- Active pixel power control for crosstalk-free all-optical neural interrogation.Journal: Nature communicationsIn common: optical imaging (calcium, voltage, 2-photon), 11 references
- [10] doi:10.1016/j.xinn.2024.100735
- Principles of visual cortex excitatory microcircuit organization.Journal: Innovation (Cambridge (Mass.))In common: 11 references
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 7 scripts, and 0 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:8bcd486e6c71f379…
Add the badge to the code's README
If you are an author or a maintainer of this paper's code, you can add this badge. It says what OSCR knows of the paper (its code, its validated tracing map) and links the code to this page. Paste one of these snippets under the README's title. Keep the two marks around it, so that the badge can be replaced in place and is never added twice. OSCR changes nothing in your repository.
Markdown
<!-- oscr-badge:start -->
[](https://openscicode.org/badge/doi/10.1088/1741-2552/ae4925)
<!-- oscr-badge:end -->reStructuredText
.. oscr-badge:start
.. image:: https://openscicode.org/badge/doi/10.1088/1741-2552/ae4925.svg
:target: https://openscicode.org/badge/doi/10.1088/1741-2552/ae4925
:alt: OSCR
.. oscr-badge:endHTML
<!-- oscr-badge:start -->
<a href="https://openscicode.org/badge/doi/10.1088/1741-2552/ae4925"><img src="https://openscicode.org/badge/doi/10.1088/1741-2552/ae4925.svg" alt="OSCR"></a>
<!-- oscr-badge:end -->On GitHub, open the README, choose Edit (the pencil), paste the snippet under the title, then "Commit changes".
If you choose to, you can have the badge kept up to date for you, with oscr badge --write from the command line or with the GitHub Action in your repository's workflows. Every other form and option (a card, AsciiDoc, LaTeX, shields.io) is on the badge page.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: code errors and mismatches between the code and the paper about this paper and its code, from readers and its authors, beside the paper and its tracing map.
Report a mismatch between the code and the paper · Report a code error (signed in)
Reproductions: reports from readers who ran the authors' code and did not get the paper's result, what they ran, with which environment, commit and data.
Report a reproduction failure (signed in)
Versions of its code: the releases of its code tied to a version of this paper (the preprint, the accepted manuscript, the version of record…), each with the tracing map versioned with it.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
