OSCR

Computational optimization of two-photon holographic stimulation sites<i>in vivo</i>.

Code ↔ Paper

The paper beside its authors' code: matches between them have not been computed for this paper yet.

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

  1. # %%
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. import matplotlib
  5. from matplotlib import cm #
  6. from matplotlib.patches import Circle
  7. from matplotlib.colors import Normalize
  8. from matplotlib.cm import get_cmap, ScalarMappable
  9. np.random.seed(35)
  10. # %%
  11. import stim_opt as so
  12. from stim_opt import experimental_design
  13. # %%
  14. fontsize = 12
  15. pixel_size = 411/512
  16. # %% [markdown]
  17. # # Setup simulation and plot neuron locations
  18. # %%
  19. N = 350
  20. sim = so.Simulation(N)
  21. # %%
  22. plt.figure(figsize=(3, 3))
  23. for x, y in sim.neuron_locations:
  24. circ = Circle((x, y), radius=6/pixel_size, edgecolor='teal', facecolor='None')
  25. plt.gca().add_patch(circ)
  26. plt.xlim([0, 411])
  27. plt.ylim([0, 411])
  28. plt.xticks(np.arange(0, 401, 100), fontsize=fontsize)
  29. plt.yticks(np.arange(0, 401, 100), fontsize=fontsize)
  30. # plt.grid(linestyle='--')
  31. plt.xlabel('Distance (μm)', fontsize=fontsize)
  32. plt.ylabel('Distance (μm)', fontsize=fontsize)
  33. plt.show()
  34. # %% [markdown]
  35. # ## Visualize ORFs
  36. # %%
  37. vmax = 3.
  38. scalebar = 20 / pixel_size
  39. # %%
  40. nrows = 4
  41. ncols = 8
  42. panel_size = 1.5
  43. plt.figure(figsize=(ncols * panel_size, nrows * panel_size))
  44. for n in range(nrows * ncols):
  45. grid, X1, X2, extent = so.nbfr.generate_grid(sim.neurons[n].location, grid_width=30)
  46. Z = sim.neurons[n].predict(grid).reshape(100, 100)
  47. vmax = np.max(Z)
  48. plt.subplot(nrows, ncols, n + 1)
  49. plt.imshow(Z, interpolation='nearest', aspect='auto', cmap='coolwarm', vmin=-vmax, vmax=vmax, extent=extent, origin='lower')
  50. plt.contour(X1, X2, Z, levels=5, colors='black', linewidths=0.5, extent=extent) # Add contour lines
  51. plt.gca().add_patch(Circle((sim.neurons[n].location), radius=6/pixel_size, edgecolor='teal', facecolor='None', zorder=100, lw=3, ls='-'))
  52. plt.xticks([])
  53. plt.yticks([])
  54. if n == 0:
  55. 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')
  56. for spine in plt.gca().spines.values():
  57. spine.set_linewidth(1.5)
  58. plt.show()
  59. # %% [markdown]
  60. # # Map ORFs from an artificial exeriment
  61. # %%
  62. stim_size = 10
  63. stim_powers = [1.]
  64. noise_std = 0.5
  65. # %%
  66. %%time
  67. 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)
  68. # %%
  69. %%time
  70. stim_responses = sim.population_response(stim_design)
  71. noise = np.random.normal(0, noise_std, stim_responses.shape)
  72. models = so.Models(sim.neuron_locations)
  73. models.fit(stim_design, stim_responses + noise)
  74. # %% [markdown]
  75. # # Optimize stimulation pattern
  76. # %%
  77. target_neurons = np.array([261, 197, 43])
  78. nontarget_neurons = np.setdiff1d(np.arange(N), target_neurons)
  79. stim_opt, stim_hist, objs = so.nbfr.optimize_stimulus(models, target_neurons, save_history=True, stepsize=5e0, n_iters=30)
  80. stim_som = sim.neuron_locations[target_neurons]
  81. # %%
  82. plt.figure(figsize=(2, 2))
  83. plt.plot(objs)
  84. plt.xlabel('Iterations')
  85. plt.xticks(np.arange(0, 31, 10))
  86. plt.ylabel('Objective function')
  87. plt.show()
  88. # %% [markdown]
  89. # # Visualize results
  90. # %%
  91. population_response_opt = sim.population_response(stim_opt[np.newaxis]).squeeze()
  92. population_response_som = sim.population_response(stim_som[np.newaxis]).squeeze()
  93. # %%
  94. fov_center = [160, 80]
  95. fov_width = 90
  96. 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]
  97. vmax = np.max([np.max(population_response_opt), np.max(population_response_som)])
  98. vmin = -vmax
  99. norm = Normalize(vmin=vmin, vmax=vmax)
  100. cmap_response = matplotlib.colormaps.get_cmap('coolwarm') # for stim responses
  101. cmap = matplotlib.colormaps.get_cmap('YlOrRd') # for stim opt path
  102. # %%
  103. plt.figure(figsize=(2, 2))
  104. for (x, y), response in zip(sim.neuron_locations, population_response_som):
  105. color = cmap_response(norm(response))
  106. circ = Circle((x, y), radius=6/pixel_size, edgecolor='k', facecolor=color)
  107. plt.gca().add_patch(circ)
  108. plt.xlim(sample_fov_extent[:2])
  109. plt.ylim(sample_fov_extent[2:])
  110. plt.xticks(np.arange(120, 201, 20), fontsize=fontsize)
  111. plt.yticks(np.arange(40, 121, 20), fontsize=fontsize)
  112. plt.xlabel('Distance (μm)', fontsize=fontsize)
  113. plt.ylabel('Distance (μm)', fontsize=fontsize)
  114. plt.title('Somatic stimulation')
  115. plt.show()
  116. # %%
  117. plt.figure(figsize=(2, 2))
  118. for (x, y), response in zip(sim.neuron_locations, population_response_opt):
  119. color = cmap_response(norm(response))
  120. circ = Circle((x, y), radius=6/pixel_size, edgecolor='k', facecolor=color)
  121. plt.gca().add_patch(circ)
  122. # Progressive color for stim_hist
  123. for j in range(3):
  124. N_steps = stim_hist.shape[0]
  125. for t in range(N_steps - 1):
  126. frac = t / (N_steps - 1) # normalize to 0–1
  127. color = cmap(frac)
  128. x0, y0 = stim_hist[t, j]
  129. x1, y1 = stim_hist[t+1, j]
  130. plt.plot([x0, x1], [y0, y1], '-', color=color, zorder=1000, lw=2.5)
  131. plt.plot(x0, y0, 'o', color=color, markersize=3, markerfacecolor='w', zorder=1000)
  132. plt.xlim(sample_fov_extent[:2])
  133. plt.ylim(sample_fov_extent[2:])
  134. plt.xticks(np.arange(120, 201, 20), fontsize=fontsize)
  135. plt.yticks(fontsize=fontsize)
  136. plt.xlabel('Distance (μm)', fontsize=fontsize)
  137. plt.ylabel('Distance (μm)', fontsize=fontsize)
  138. plt.title('Optimized')
  139. plt.show()
  140. # %% [markdown]
  141. # # Loss surface
  142. # %%
  143. xsteps = np.arange(sample_fov_extent[0], sample_fov_extent[1] + 0.1, 1)
  144. ysteps = np.arange(sample_fov_extent[2], sample_fov_extent[3] + 0.1, 1)
  145. xs, ys = np.meshgrid(xsteps, ysteps)
  146. sample_grid = np.c_[xs.flatten(), ys.flatten()]
  147. D = xs.shape[0]
  148. # %%
  149. # Difference between target and non-target objective functions
  150. sum_orf = np.sum([sim.neurons[n].predict(sample_grid).reshape(D, D) for n in target_neurons], 0) \
  151. - np.sum([sim.neurons[n].predict(sample_grid).reshape(D, D) for n in nontarget_neurons], 0)
  152. # %%
  153. plt.figure(figsize=(2, 2))
  154. n = 0
  155. im = plt.imshow(sum_orf, origin='lower', cmap='coolwarm', vmin=-vmax, vmax=vmax, extent=sample_fov_extent)
  156. ax = plt.gca()
  157. # Progressive color for stim_hist
  158. for j in range(3):
  159. N_steps = stim_hist.shape[0]
  160. for t in range(N_steps - 1):
  161. frac = t / (N_steps - 1) # normalize to 0–1
  162. color = cmap(frac)
  163. x0, y0 = stim_hist[t, j]
  164. x1, y1 = stim_hist[t+1, j]
  165. plt.plot([x0, x1], [y0, y1], '-', color=color, zorder=1000, mew=1)
  166. plt.plot(x0, y0, 'o', color=color, markersize=3, markerfacecolor='w', zorder=1000, mew=1)
  167. plt.xlim(sample_fov_extent[:2])
  168. plt.ylim(sample_fov_extent[2:])
  169. plt.xticks(np.arange(120, 201, 20), fontsize=fontsize)
  170. plt.yticks(fontsize=fontsize)
  171. plt.xlabel('Distance (μm)', fontsize=fontsize)
  172. plt.ylabel('Distance (μm)', fontsize=fontsize)
  173. for (x, y), response in zip(sim.neuron_locations, population_response_opt):
  174. color = cmap_response(norm(response))
  175. circ = Circle((x, y), radius=6/pixel_size, edgecolor='k', facecolor='None')
  176. plt.gca().add_patch(circ)
  177. n += 1
  178. cbar = plt.colorbar(im, ax=ax, fraction=0.046, pad=0.04)
  179. cbar.ax.tick_params(labelsize=fontsize)
  180. cbar.set_label('Objective function', rotation=270, fontsize=fontsize, labelpad=12)
  181. plt.show()

example.ipynb at commit 6e5f7bb, under GPL-3.0 · at the source

Overview

  1. Mortimer B. Zuckerman Mind Brain Behavior Institute, Columbia University, New York, NY, United States of America
  2. Grossman Center for the Statistics of Mind, Columbia University, New York, NY, United States of America
  3. Center for Theoretical Neuroscience, Columbia University, New York, NY, United States of America
  4. Department of Statistics, Columbia University, New York, NY, United States of America
  5. Wolfson Institute for Biomedical Research, University College London, London, United Kingdom
  6. School of Biomedical Sciences, The University of Hong Kong, Hong Kong Special Administrative Region of China, People’s Republic of China
Institutions: Mortimer B. Zuckerman Mind Brain Behavior Institute (United States); Columbia University (United States); University College London (United Kingdom); University of Hong Kong (Hong Kong SAR China)
Journal: Journal of neural engineering, volume 23, issue 2, article 026015
Dates: received 15 August 2025; accepted 23 February 2026; published online 25 March 2026; in print 1 April 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.1088/1741-2552/ae4925 · PMID 41878953 · PMCID PMC13014349 · OpenAlex W7140320479
Open access: hybrid, a free copy (OpenAlex)
Status: code verified (how the code is found and verified)
Categories: optical imaging (calcium, voltage, 2-photon) (modality), mouse (organism)
Methods: Spectral & time-frequency, fMRI & imaging, Single-unit activity, calcium imaging
Keywords: computational neuroscience, holographic optogenetics, neural stimulation, calcium imaging
MeSH: Hippocampus*, Holography*, Models, Neurological*, Neurons*, Optogenetics*, Photic Stimulation*, Animals, Computer Simulation, Mice, Photons (* major topic)
Topic: Photoreceptor and optogenetics research (Cellular and Molecular Neuroscience, Neuroscience), according to OpenAlex
Funding: NEI NIH HHS (R01 EY033950); Wellcome Trust (224688, 201225, 695709, PRF 201225); Engineering and Physical Sciences Research Council (EP/R513143/1 and EP/W524335/1); Gatsby Charitable Foundation (GAT3708); Medical Research Council (MR/T022922/1); Kavli Foundation; European Research Council (695709, AdG 695709); National Science Foundation (PHY-2229929); Biotechnology and Biological Sciences Research Council (BB/N009835/1); NINDS NIH HHS (K99 NS135649); Boehringer Ingelheim Fonds; NIH (K99NS135649); Zuckerman Institute Team Science Funds
Citations: cited by 2 papers (Europe PMC); 44 references in the paper

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

License: GPL-3.0
State: the link answers, verified on 30 September 2026
Evidence: files inventoried
Commit: 6e5f7bba8f92135de519fd83ab4ec6b04097fe2e, 15 August 2025
Languages: Python (6), Jupyter (1)
Size: 9 files, 7 scripts
Software Heritage: not archived
Found in: “Code availability”
Holds: README, license file, environment (setup.py), 1 notebook
Not found: CITATION.cff, tests, continuous integration, documentation
Tools: NumPy (6 files), scikit-learn (4 files), Matplotlib (3 files), SciPy (2 files)
Availability: 1 check, the latest on 30 September 2026: the link answers
  • 30 September 2026: the link answers
9 files

Code availability

Code for this manuscript is available at https://github.com/marcustriplett/photostim-optimizer.

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

Data availability statement

The data that support the findings of this study are openly available at the following URL/DOI: https://doi.org/10.6084/m9.figshare.29923262.

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<i>in vivo</i>. Journal of neural engineering, 23(2), 026015. https://doi.org/10.1088/1741-2552/ae4925

BibTeX

@article{triplett2026computational,
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\<i\>in vivo\</i\>}},
journal = {Journal of neural engineering},
year = {2026},
month = mar,
volume = {23},
number = {2},
pages = {026015},
publisher = {IOP Publishing},
issn = {1741-2560},
doi = {10.1088/1741-2552/ae4925},
url = {https://doi.org/10.1088/1741-2552/ae4925},
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<i>in vivo</i>
T2 - Journal of neural engineering
J2 - J Neural Eng
PY - 2026
DA - 2026/03/25
VL - 23
IS - 2
SP - 026015
SN - 1741-2560
PB - IOP Publishing
DO - 10.1088/1741-2552/ae4925
UR - https://doi.org/10.1088/1741-2552/ae4925
LA - en
ER -

CSL-JSON

{
"id": "10.1088/1741-2552/ae4925",
"type": "article-journal",
"title": "Computational optimization of two-photon holographic stimulation sites<i>in vivo</i>",
"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": "J Neural Eng",
"volume": "23",
"issue": "2",
"page": "026015",
"DOI": "10.1088/1741-2552/ae4925",
"PMID": "41878953",
"PMCID": "PMC13014349",
"ISSN": "1741-2560",
"publisher": "IOP Publishing",
"URL": "https://doi.org/10.1088/1741-2552/ae4925",
"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 neuroscience
In 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 biology
In 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: Neurophotonics
In 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 communications
In 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 neuroscience
In 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 methods
In 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 communications
In 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: Neurophotonics
In 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 communications
In 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.

Add the badge to the code's README

OSCR: the badge of this paper

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 -->
[![OSCR](https://openscicode.org/badge/doi/10.1088/1741-2552/ae4925.svg)](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:end
HTML
<!-- 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.