hnn-core 0.4.2.dev1__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. hnn_core-0.5.0/PKG-INFO +217 -0
  2. hnn_core-0.5.0/README.md +118 -0
  3. hnn_core-0.5.0/examples/howto/optimize_evoked.py +295 -0
  4. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/examples/howto/optimize_rhythmic.py +8 -5
  5. hnn_core-0.5.0/examples/howto/plot_replaying_spike_data_as_input.py +174 -0
  6. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/examples/workflows/plot_simulate_beta.py +6 -6
  7. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/examples/workflows/plot_simulate_evoked.py +1 -1
  8. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/examples/workflows/plot_simulate_gamma.py +1 -1
  9. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/__init__.py +7 -1
  10. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/cells_default.py +4 -4
  11. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/dipole.py +2 -1
  12. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/drives.py +44 -12
  13. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/gui/gui.py +309 -38
  14. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/hnn_io.py +110 -11
  15. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/network.py +667 -110
  16. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/network_builder.py +52 -18
  17. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/network_models.py +91 -12
  18. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/optimization/general_optimization.py +68 -16
  19. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/optimization/objective_functions.py +23 -14
  20. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/optimization/optimize_evoked.py +6 -1
  21. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/parallel_backends.py +7 -7
  22. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/param/jones2009_base.json +1244 -1170
  23. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/tests/regenerate_test_network.py +22 -3
  24. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/tests/test_cell.py +2 -2
  25. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/tests/test_cells_default.py +26 -3
  26. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/tests/test_dipole.py +28 -0
  27. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/tests/test_general_optimization.py +150 -2
  28. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/tests/test_gui.py +237 -11
  29. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/tests/test_io.py +50 -2
  30. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/tests/test_network.py +626 -21
  31. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/tests/test_optimize_evoked.py +1 -1
  32. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/tests/test_viz.py +13 -12
  33. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/viz.py +2 -2
  34. hnn_core-0.5.0/hnn_core.egg-info/PKG-INFO +217 -0
  35. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core.egg-info/SOURCES.txt +1 -0
  36. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core.egg-info/requires.txt +1 -1
  37. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/pyproject.toml +3 -3
  38. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/setup.py +8 -3
  39. hnn_core-0.4.2.dev1/PKG-INFO +0 -215
  40. hnn_core-0.4.2.dev1/README.md +0 -121
  41. hnn_core-0.4.2.dev1/examples/howto/optimize_evoked.py +0 -214
  42. hnn_core-0.4.2.dev1/hnn_core.egg-info/PKG-INFO +0 -215
  43. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/LICENSE +0 -0
  44. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/MANIFEST.in +0 -0
  45. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/examples/README.txt +0 -0
  46. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/examples/howto/README.txt +0 -0
  47. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/examples/howto/plot_batch_simulate.py +0 -0
  48. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/examples/howto/plot_connectivity.py +0 -0
  49. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/examples/howto/plot_firing_pattern.py +0 -0
  50. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/examples/howto/plot_hnn_animation.py +0 -0
  51. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/examples/howto/plot_record_extracellular_potentials.py +0 -0
  52. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/examples/howto/plot_simulate_mpi_backend.py +0 -0
  53. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/examples/workflows/README.txt +0 -0
  54. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/examples/workflows/plot_simulate_alpha.py +0 -0
  55. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/examples/workflows/plot_simulate_somato.py +0 -0
  56. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/batch_simulate.py +0 -0
  57. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/cell.py +0 -0
  58. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/cell_response.py +0 -0
  59. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/check.py +0 -0
  60. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/docs.py +0 -0
  61. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/externals/__init__.py +0 -0
  62. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/externals/bayesopt.py +0 -0
  63. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/externals/mne.py +0 -0
  64. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/extracellular.py +0 -0
  65. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/gui/__init__.py +0 -0
  66. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/gui/_logging.py +0 -0
  67. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/gui/_viz_manager.py +0 -0
  68. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/gui/hnn_widget.ipynb +0 -0
  69. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/mod/ar.mod +0 -0
  70. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/mod/ca.mod +0 -0
  71. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/mod/cad.mod +0 -0
  72. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/mod/cat.mod +0 -0
  73. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/mod/dipole.mod +0 -0
  74. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/mod/dipole_pp.mod +0 -0
  75. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/mod/hh2.mod +0 -0
  76. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/mod/kca.mod +0 -0
  77. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/mod/km.mod +0 -0
  78. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/mod/vecevent.mod +0 -0
  79. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/mpi_child.py +0 -0
  80. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/optimization/__init__.py +0 -0
  81. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/param/N20.json +0 -0
  82. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/param/default.json +0 -0
  83. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/param/gamma_L5weak_L2weak.json +0 -0
  84. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/params.py +0 -0
  85. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/params_default.py +0 -0
  86. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/tests/conftest.py +0 -0
  87. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/tests/test_batch_simulate.py +0 -0
  88. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/tests/test_cell_response.py +0 -0
  89. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/tests/test_drives.py +0 -0
  90. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/tests/test_extracellular.py +0 -0
  91. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/tests/test_mpi_child.py +0 -0
  92. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/tests/test_parallel_backends.py +0 -0
  93. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/tests/test_params.py +0 -0
  94. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/tests/test_utils.py +0 -0
  95. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core/utils.py +0 -0
  96. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core.egg-info/dependency_links.txt +0 -0
  97. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core.egg-info/entry_points.txt +0 -0
  98. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/hnn_core.egg-info/top_level.txt +0 -0
  99. {hnn_core-0.4.2.dev1 → hnn_core-0.5.0}/setup.cfg +0 -0
@@ -0,0 +1,217 @@
1
+ Metadata-Version: 2.4
2
+ Name: hnn-core
3
+ Version: 0.5.0
4
+ Summary: Code for biophysical simulation of a cortical column using Neuron
5
+ Home-page:
6
+ Download-URL: http://github.com/jonescompneurolab/hnn-core
7
+ Maintainer: Mainak Jas
8
+ Maintainer-email: mainakjas@gmail.com
9
+ License: BSD (3-clause)
10
+ Platform: any
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved
14
+ Classifier: Programming Language :: Python
15
+ Classifier: Topic :: Software Development
16
+ Classifier: Topic :: Scientific/Engineering
17
+ Classifier: Operating System :: Microsoft :: Windows
18
+ Classifier: Operating System :: POSIX
19
+ Classifier: Operating System :: Unix
20
+ Classifier: Operating System :: MacOS
21
+ Classifier: Programming Language :: Python :: 3.9
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Programming Language :: Python :: 3.13
26
+ Requires-Python: >=3.9, <3.14
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Requires-Dist: numpy>=1.14
30
+ Requires-Dist: NEURON<=8.2.7,>=7.7; platform_system != "Windows"
31
+ Requires-Dist: matplotlib>=3.5.3
32
+ Requires-Dist: scipy
33
+ Requires-Dist: h5io
34
+ Provides-Extra: opt
35
+ Requires-Dist: scikit-learn; extra == "opt"
36
+ Provides-Extra: parallel
37
+ Requires-Dist: joblib; extra == "parallel"
38
+ Requires-Dist: psutil; extra == "parallel"
39
+ Provides-Extra: test
40
+ Requires-Dist: codespell; extra == "test"
41
+ Requires-Dist: pytest; extra == "test"
42
+ Requires-Dist: pytest-cov; extra == "test"
43
+ Requires-Dist: pytest-xdist; extra == "test"
44
+ Requires-Dist: ruff; extra == "test"
45
+ Provides-Extra: docs
46
+ Requires-Dist: mne; extra == "docs"
47
+ Requires-Dist: myst-parser; extra == "docs"
48
+ Requires-Dist: nibabel; extra == "docs"
49
+ Requires-Dist: numpydoc; extra == "docs"
50
+ Requires-Dist: pillow; extra == "docs"
51
+ Requires-Dist: pooch; extra == "docs"
52
+ Requires-Dist: pydata-sphinx-theme; extra == "docs"
53
+ Requires-Dist: sphinx; extra == "docs"
54
+ Requires-Dist: sphinx-gallery; extra == "docs"
55
+ Requires-Dist: sphinx-copybutton; extra == "docs"
56
+ Requires-Dist: tdqm; extra == "docs"
57
+ Provides-Extra: gui
58
+ Requires-Dist: ipywidgets>=8.0.0; extra == "gui"
59
+ Requires-Dist: ipykernel; extra == "gui"
60
+ Requires-Dist: ipympl; extra == "gui"
61
+ Requires-Dist: voila; extra == "gui"
62
+ Provides-Extra: dev
63
+ Requires-Dist: scikit-learn; extra == "dev"
64
+ Requires-Dist: joblib; extra == "dev"
65
+ Requires-Dist: psutil; extra == "dev"
66
+ Requires-Dist: codespell; extra == "dev"
67
+ Requires-Dist: pytest; extra == "dev"
68
+ Requires-Dist: pytest-cov; extra == "dev"
69
+ Requires-Dist: pytest-xdist; extra == "dev"
70
+ Requires-Dist: ruff; extra == "dev"
71
+ Requires-Dist: mne; extra == "dev"
72
+ Requires-Dist: myst-parser; extra == "dev"
73
+ Requires-Dist: nibabel; extra == "dev"
74
+ Requires-Dist: numpydoc; extra == "dev"
75
+ Requires-Dist: pillow; extra == "dev"
76
+ Requires-Dist: pooch; extra == "dev"
77
+ Requires-Dist: pydata-sphinx-theme; extra == "dev"
78
+ Requires-Dist: sphinx; extra == "dev"
79
+ Requires-Dist: sphinx-gallery; extra == "dev"
80
+ Requires-Dist: sphinx-copybutton; extra == "dev"
81
+ Requires-Dist: tdqm; extra == "dev"
82
+ Requires-Dist: ipywidgets>=8.0.0; extra == "dev"
83
+ Requires-Dist: ipykernel; extra == "dev"
84
+ Requires-Dist: ipympl; extra == "dev"
85
+ Requires-Dist: voila; extra == "dev"
86
+ Dynamic: classifier
87
+ Dynamic: description
88
+ Dynamic: description-content-type
89
+ Dynamic: download-url
90
+ Dynamic: license
91
+ Dynamic: license-file
92
+ Dynamic: maintainer
93
+ Dynamic: maintainer-email
94
+ Dynamic: platform
95
+ Dynamic: provides-extra
96
+ Dynamic: requires-dist
97
+ Dynamic: requires-python
98
+ Dynamic: summary
99
+
100
+
101
+ <h1 align="center">
102
+ <img src="https://raw.githubusercontent.com/jonescompneurolab/jones-website/master/images/frontpage/logos/logo-hnn-medium.png" width="300">
103
+ </h1><br>
104
+
105
+ # hnn-core
106
+
107
+ [![tests](https://github.com/jonescompneurolab/hnn-core/actions/workflows/unix_unit_tests.yml/badge.svg?branch=master)](https://github.com/jonescompneurolab/hnn-core/actions/?query=branch:master+event:push)
108
+ [![CircleCI](https://circleci.com/gh/jonescompneurolab/hnn-core.svg?style=svg)](https://circleci.com/gh/jonescompneurolab/hnn-core)
109
+ [![Codecov](https://codecov.io/gh/jonescompneurolab/hnn-core/branch/master/graph/badge.svg)](https://codecov.io/gh/jonescompneurolab/hnn-core)
110
+ [![PyPI](https://img.shields.io/pypi/dm/hnn-core.svg?label=PyPI%20downloads)](https://pypi.org/project/hnn-core/)
111
+ [![Gitter](https://badges.gitter.im/jonescompneurolab/hnn_core.svg)](https://gitter.im/jonescompneurolab/hnn-core?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
112
+ [![JOSS](https://joss.theoj.org/papers/10.21105/joss.05848/status.svg)](https://doi.org/10.21105/joss.05848)
113
+
114
+ ![HNN-GUI](https://raw.githubusercontent.com/jonescompneurolab/hnn-core/acbcc4a598610dc3be5d4b0b7c59f98251ea7690/.github/images/hnn_gui.png)
115
+
116
+ # About
117
+
118
+ The [Human Neocortical Neurosolver (HNN)](https://hnn.brown.edu) is an open-source
119
+ neural modeling tool designed to help researchers/clinicians interpret human brain
120
+ imaging data. This repository, called **HNN-core**, houses the source code for HNN.
121
+
122
+ With only a few lines of code, HNN provides a convenient way to run simulations of an
123
+ anatomically- and biophysically-detailed dynamical system model of human thalamocortical
124
+ brain circuits. Given its modular, object-oriented design, HNN makes it easy to generate
125
+ and evaluate hypotheses on the mechanistic origin of signals measured with
126
+ magnetoencephalography (MEG), electroencephalography (EEG), or intracranial
127
+ electrocorticography (ECoG). A unique feature of the HNN model is that it accounts for
128
+ the biophysics generating the primary electric currents underlying such data. Simulation
129
+ results are *directly* comparable to source-localized data (current dipoles in units of
130
+ nano-Ampere-meters), enabling precise tuning of model parameters to match
131
+ characteristics of recorded signals. Multimodal neurophysiology data such as local field
132
+ potential (LFP), current-source density (CSD), and spiking dynamics can also be
133
+ simulated simultaneously with current dipoles.
134
+
135
+ You can view [HNN's frontpage here](https://hnn.brown.edu) for an overview of all that
136
+ HNN can do. For how to use HNN, we provide scientific documentation, tutorials, and
137
+ examples aplenty on our [HNN Textbook website][]. There, we describe the use of HNN in
138
+ studying the circuit-level origin of some of the most commonly measured MEG/EEG and ECoG
139
+ signals: event related potentials (ERPs) and low-frequency rhythms (alpha/beta/gamma).
140
+
141
+ The HNN API, written in Python and built on top of
142
+ [NEURON](https://nrn.readthedocs.io), is designed to be flexible and serve
143
+ users with varying levels of coding expertise, while the [HNN
144
+ GUI](https://jonescompneurolab.github.io/textbook/content/04_using_hnn_gui/gui_quickstart.html)
145
+ is designed to be useful to researchers with no formal computational neural modeling or
146
+ coding experience.
147
+
148
+ The terms HNN, HNN-core, and `hnn-core` are effectively equivalent, as they are all
149
+ different names for the same codebase. Historically, HNN-core was developed based on
150
+ the [original, deprecated HNN repository](https://github.com/jonescompneurolab/hnn), however that
151
+ repository is **no longer supported or developed**. It is kept online only for the sake
152
+ of scientific reproducibility.
153
+
154
+ Please consider supporting HNN development efforts by voluntarily [providing your
155
+ demographic information
156
+ here](https://docs.google.com/forms/d/e/1FAIpQLSfN2F4IkGATs6cy1QBO78C6QJqvm9y14TqsCUsuR4Rrkmr1Mg/viewform)!
157
+ Note that any demographic information we collect is anonymized and aggregated for
158
+ reporting on the grants that fund the continued development of HNN. All questions are
159
+ voluntary.
160
+
161
+ # Installation
162
+
163
+ You can try HNN **in your browser for free, with no local installation required!** At
164
+ the top of our [Installation Guide][], you can find links that describe how to run HNN
165
+ online in the cloud, either using Google CoLab notebooks or using the [Neuroscience Gateway
166
+ Portal](https://www.nsgportal.org/).
167
+
168
+ To install HNN locally, see our [Installation Guide][] located at the [HNN Textbook
169
+ website][]. The easiest way to install `hnn-core` with the all its dependencies on Mac,
170
+ Linux, or Windows (using "Windows Subsystem for Linux"), is to first install the
171
+ [Anaconda Python Distribution](https://www.anaconda.com/download/success) and then run
172
+ the following commands:
173
+
174
+ ```
175
+ conda create -y -q -n hnn-core-env python=3.12
176
+ conda activate hnn-core-env
177
+ conda install hnn-core-all -c jonescompneurolab -c conda-forge
178
+ ```
179
+
180
+ Our Anaconda packages currently only support Python 3.12. However, installing `hnn-core`
181
+ through `pip` currently supports **Python 3.9 through 3.13**, inclusively. Please see
182
+ our [Installation Guide][] for detailed instructions on the various ways you can install
183
+ HNN.
184
+
185
+ # Usage
186
+
187
+ Once you have installed `hnn-core` and the dependencies for the features you want, you
188
+ can find tutorials, examples, and scientific documentation at our [HNN Textbook
189
+ website][].
190
+
191
+ # Problems?
192
+
193
+ You can use the [GitHub Issues
194
+ tracker](https://github.com/jonescompneurolab/hnn-core/issues) to report bugs. For user
195
+ questions, installation help, and scientific discussions, please see our [GitHub
196
+ Discussions page](https://github.com/jonescompneurolab/hnn-core/discussions).
197
+
198
+ # Interested in Contributing?
199
+
200
+ Contributors are always welcome! Please read our [Contributing Guide][] and make sure to
201
+ abide by our [Code of
202
+ Conduct](https://github.com/jonescompneurolab/hnn-core/blob/master/CODE_OF_CONDUCT.md). Our
203
+ [governance structure can be found
204
+ here](https://jonescompneurolab.github.io/hnn-core/stable/governance.html).
205
+
206
+ # Citing
207
+
208
+ If you use HNN-core in your work, please cite our [publication in
209
+ JOSS](https://doi.org/10.21105/joss.05848):
210
+
211
+ > Jas et al., (2023). HNN-core: A Python software for cellular and
212
+ > circuit-level interpretation of human MEG/EEG. *Journal of Open Source
213
+ > Software*, 8(92), 5848, <https://doi.org/10.21105/joss.05848>
214
+
215
+ [Contributing Guide]: https://jonescompneurolab.github.io/hnn-core/stable/contributing.html
216
+ [HNN Textbook website]: https://jonescompneurolab.github.io/textbook/content/preface.html
217
+ [Installation Guide]: https://jonescompneurolab.github.io/textbook/content/01_getting_started/installation.html
@@ -0,0 +1,118 @@
1
+
2
+ <h1 align="center">
3
+ <img src="https://raw.githubusercontent.com/jonescompneurolab/jones-website/master/images/frontpage/logos/logo-hnn-medium.png" width="300">
4
+ </h1><br>
5
+
6
+ # hnn-core
7
+
8
+ [![tests](https://github.com/jonescompneurolab/hnn-core/actions/workflows/unix_unit_tests.yml/badge.svg?branch=master)](https://github.com/jonescompneurolab/hnn-core/actions/?query=branch:master+event:push)
9
+ [![CircleCI](https://circleci.com/gh/jonescompneurolab/hnn-core.svg?style=svg)](https://circleci.com/gh/jonescompneurolab/hnn-core)
10
+ [![Codecov](https://codecov.io/gh/jonescompneurolab/hnn-core/branch/master/graph/badge.svg)](https://codecov.io/gh/jonescompneurolab/hnn-core)
11
+ [![PyPI](https://img.shields.io/pypi/dm/hnn-core.svg?label=PyPI%20downloads)](https://pypi.org/project/hnn-core/)
12
+ [![Gitter](https://badges.gitter.im/jonescompneurolab/hnn_core.svg)](https://gitter.im/jonescompneurolab/hnn-core?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
13
+ [![JOSS](https://joss.theoj.org/papers/10.21105/joss.05848/status.svg)](https://doi.org/10.21105/joss.05848)
14
+
15
+ ![HNN-GUI](https://raw.githubusercontent.com/jonescompneurolab/hnn-core/acbcc4a598610dc3be5d4b0b7c59f98251ea7690/.github/images/hnn_gui.png)
16
+
17
+ # About
18
+
19
+ The [Human Neocortical Neurosolver (HNN)](https://hnn.brown.edu) is an open-source
20
+ neural modeling tool designed to help researchers/clinicians interpret human brain
21
+ imaging data. This repository, called **HNN-core**, houses the source code for HNN.
22
+
23
+ With only a few lines of code, HNN provides a convenient way to run simulations of an
24
+ anatomically- and biophysically-detailed dynamical system model of human thalamocortical
25
+ brain circuits. Given its modular, object-oriented design, HNN makes it easy to generate
26
+ and evaluate hypotheses on the mechanistic origin of signals measured with
27
+ magnetoencephalography (MEG), electroencephalography (EEG), or intracranial
28
+ electrocorticography (ECoG). A unique feature of the HNN model is that it accounts for
29
+ the biophysics generating the primary electric currents underlying such data. Simulation
30
+ results are *directly* comparable to source-localized data (current dipoles in units of
31
+ nano-Ampere-meters), enabling precise tuning of model parameters to match
32
+ characteristics of recorded signals. Multimodal neurophysiology data such as local field
33
+ potential (LFP), current-source density (CSD), and spiking dynamics can also be
34
+ simulated simultaneously with current dipoles.
35
+
36
+ You can view [HNN's frontpage here](https://hnn.brown.edu) for an overview of all that
37
+ HNN can do. For how to use HNN, we provide scientific documentation, tutorials, and
38
+ examples aplenty on our [HNN Textbook website][]. There, we describe the use of HNN in
39
+ studying the circuit-level origin of some of the most commonly measured MEG/EEG and ECoG
40
+ signals: event related potentials (ERPs) and low-frequency rhythms (alpha/beta/gamma).
41
+
42
+ The HNN API, written in Python and built on top of
43
+ [NEURON](https://nrn.readthedocs.io), is designed to be flexible and serve
44
+ users with varying levels of coding expertise, while the [HNN
45
+ GUI](https://jonescompneurolab.github.io/textbook/content/04_using_hnn_gui/gui_quickstart.html)
46
+ is designed to be useful to researchers with no formal computational neural modeling or
47
+ coding experience.
48
+
49
+ The terms HNN, HNN-core, and `hnn-core` are effectively equivalent, as they are all
50
+ different names for the same codebase. Historically, HNN-core was developed based on
51
+ the [original, deprecated HNN repository](https://github.com/jonescompneurolab/hnn), however that
52
+ repository is **no longer supported or developed**. It is kept online only for the sake
53
+ of scientific reproducibility.
54
+
55
+ Please consider supporting HNN development efforts by voluntarily [providing your
56
+ demographic information
57
+ here](https://docs.google.com/forms/d/e/1FAIpQLSfN2F4IkGATs6cy1QBO78C6QJqvm9y14TqsCUsuR4Rrkmr1Mg/viewform)!
58
+ Note that any demographic information we collect is anonymized and aggregated for
59
+ reporting on the grants that fund the continued development of HNN. All questions are
60
+ voluntary.
61
+
62
+ # Installation
63
+
64
+ You can try HNN **in your browser for free, with no local installation required!** At
65
+ the top of our [Installation Guide][], you can find links that describe how to run HNN
66
+ online in the cloud, either using Google CoLab notebooks or using the [Neuroscience Gateway
67
+ Portal](https://www.nsgportal.org/).
68
+
69
+ To install HNN locally, see our [Installation Guide][] located at the [HNN Textbook
70
+ website][]. The easiest way to install `hnn-core` with the all its dependencies on Mac,
71
+ Linux, or Windows (using "Windows Subsystem for Linux"), is to first install the
72
+ [Anaconda Python Distribution](https://www.anaconda.com/download/success) and then run
73
+ the following commands:
74
+
75
+ ```
76
+ conda create -y -q -n hnn-core-env python=3.12
77
+ conda activate hnn-core-env
78
+ conda install hnn-core-all -c jonescompneurolab -c conda-forge
79
+ ```
80
+
81
+ Our Anaconda packages currently only support Python 3.12. However, installing `hnn-core`
82
+ through `pip` currently supports **Python 3.9 through 3.13**, inclusively. Please see
83
+ our [Installation Guide][] for detailed instructions on the various ways you can install
84
+ HNN.
85
+
86
+ # Usage
87
+
88
+ Once you have installed `hnn-core` and the dependencies for the features you want, you
89
+ can find tutorials, examples, and scientific documentation at our [HNN Textbook
90
+ website][].
91
+
92
+ # Problems?
93
+
94
+ You can use the [GitHub Issues
95
+ tracker](https://github.com/jonescompneurolab/hnn-core/issues) to report bugs. For user
96
+ questions, installation help, and scientific discussions, please see our [GitHub
97
+ Discussions page](https://github.com/jonescompneurolab/hnn-core/discussions).
98
+
99
+ # Interested in Contributing?
100
+
101
+ Contributors are always welcome! Please read our [Contributing Guide][] and make sure to
102
+ abide by our [Code of
103
+ Conduct](https://github.com/jonescompneurolab/hnn-core/blob/master/CODE_OF_CONDUCT.md). Our
104
+ [governance structure can be found
105
+ here](https://jonescompneurolab.github.io/hnn-core/stable/governance.html).
106
+
107
+ # Citing
108
+
109
+ If you use HNN-core in your work, please cite our [publication in
110
+ JOSS](https://doi.org/10.21105/joss.05848):
111
+
112
+ > Jas et al., (2023). HNN-core: A Python software for cellular and
113
+ > circuit-level interpretation of human MEG/EEG. *Journal of Open Source
114
+ > Software*, 8(92), 5848, <https://doi.org/10.21105/joss.05848>
115
+
116
+ [Contributing Guide]: https://jonescompneurolab.github.io/hnn-core/stable/contributing.html
117
+ [HNN Textbook website]: https://jonescompneurolab.github.io/textbook/content/preface.html
118
+ [Installation Guide]: https://jonescompneurolab.github.io/textbook/content/01_getting_started/installation.html
@@ -0,0 +1,295 @@
1
+ """
2
+ =================================================
3
+ 05. Optimize simulated evoked response parameters
4
+ =================================================
5
+
6
+ This example demonstrates how to optimize the parameters
7
+ of the model simulation to match an experimental dipole waveform.
8
+ """
9
+
10
+ # Authors: Carolina Fernandez <cxf418@miami.edu>
11
+ # Nick Tolley <nicholas_tolley@brown.edu>
12
+ # Ryan Thorpe <ryan_thorpe@brown.edu>
13
+ # Mainak Jas <mjas@mgh.harvard.edu>
14
+
15
+ from hnn_core.optimization import Optimizer
16
+ from urllib.request import urlretrieve
17
+ import os.path as op
18
+
19
+ import matplotlib.pyplot as plt
20
+ from matplotlib.lines import Line2D
21
+
22
+ ###############################################################################
23
+ # 1. Import libraries and set up environment
24
+ # ------------------------------------------
25
+ #
26
+ # We'll start by importing the necessary `hnn_core` modules and other libraries
27
+ # required for this tutorial.
28
+
29
+ import hnn_core
30
+ from hnn_core import (MPIBackend, jones_2009_model, simulate_dipole,
31
+ read_dipole)
32
+ from hnn_core.viz import plot_dipole
33
+
34
+ hnn_core_root = op.join(op.dirname(hnn_core.__file__))
35
+
36
+ # The number of cores may need modifying depending on your current machine.
37
+ n_procs = 10
38
+
39
+ ###############################################################################
40
+ # 2. Load experimental dipole
41
+ # ---------------------------
42
+ #
43
+ # Our goal is to optimize our model to match experimental data.
44
+ #
45
+ # We'll load a pre-recorded MEG dipole waveform, which represents early evoked
46
+ # activity from primary somatosensory cortex in response to a brief tap to
47
+ # the finger. This data will serve as our *target dipole* for the optimization
48
+ # process.
49
+
50
+ data_url = ('https://raw.githubusercontent.com/jonescompneurolab/hnn/master/'
51
+ 'data/MEG_detection_data/yes_trial_S1_ERP_all_avg.txt')
52
+ urlretrieve(data_url, 'yes_trial_S1_ERP_all_avg.txt')
53
+ dipole_experimental = read_dipole('yes_trial_S1_ERP_all_avg.txt')
54
+
55
+ # Plot
56
+ fig, ax = plt.subplots(figsize=(6, 6))
57
+ dipole_experimental.plot(ax=ax, layer='agg', show=False,
58
+ color='tab:blue')
59
+ ax.legend(['experimental'])
60
+
61
+ ###############################################################################
62
+ # 3. Simulate initial dipole
63
+ # --------------------------
64
+ #
65
+ # Now, we'll simulate the initial dipole using a predefined set of parameters
66
+ # we arrived to after some hand-tuning. This simulation will provide a baseline
67
+ # to compare against the experimental data before optimization.
68
+
69
+ net_initial = jones_2009_model()
70
+
71
+ n_drive_cells = 1
72
+ cell_specific = False
73
+
74
+ # Proximal 1
75
+ weights_ampa_p1 = {'L2_basket': 0.08831, 'L2_pyramidal': 0.01525,
76
+ 'L5_basket': 0.19934, 'L5_pyramidal': 0.00865}
77
+ synaptic_delays_p = {'L2_basket': 0.1, 'L2_pyramidal': 0.1,
78
+ 'L5_basket': 1., 'L5_pyramidal': 1.}
79
+ net_initial.add_evoked_drive('evprox1',
80
+ mu=26.61,
81
+ sigma=2.47,
82
+ numspikes=1,
83
+ location='proximal',
84
+ weights_ampa=weights_ampa_p1,
85
+ synaptic_delays=synaptic_delays_p,
86
+ n_drive_cells=n_drive_cells,
87
+ cell_specific=cell_specific)
88
+
89
+ # Distal
90
+ weights_ampa_d1 = {'L2_basket': 0.006562, 'L2_pyramidal': .000007,
91
+ 'L5_pyramidal': 0.142300}
92
+ weights_nmda_d1 = {'L2_basket': 0.019482, 'L2_pyramidal': 0.004317,
93
+ 'L5_pyramidal': 0.080074}
94
+ synaptic_delays_d1 = {'L2_basket': 0.1, 'L2_pyramidal': 0.1,
95
+ 'L5_pyramidal': 0.1}
96
+ net_initial.add_evoked_drive('evdist1',
97
+ mu=63.53,
98
+ sigma=3.85,
99
+ numspikes=1,
100
+ location='distal',
101
+ weights_ampa=weights_ampa_d1,
102
+ weights_nmda=weights_nmda_d1,
103
+ synaptic_delays=synaptic_delays_d1,
104
+ n_drive_cells=n_drive_cells,
105
+ cell_specific=cell_specific)
106
+
107
+ # Proximal 2
108
+ weights_ampa_p2 = {'L2_basket': 0.000003, 'L2_pyramidal': 1.438840,
109
+ 'L5_basket': 0.008958, 'L5_pyramidal': 0.1}
110
+ net_initial.add_evoked_drive('evprox2',
111
+ mu=120.,
112
+ sigma=1.,
113
+ numspikes=1,
114
+ location='proximal',
115
+ weights_ampa=weights_ampa_p2,
116
+ synaptic_delays=synaptic_delays_p,
117
+ n_drive_cells=n_drive_cells,
118
+ cell_specific=cell_specific)
119
+
120
+ # Simulate initial dipole
121
+ n_trials = 3
122
+ tstop = dipole_experimental.times[-1]
123
+ with MPIBackend(n_procs=n_procs, mpi_cmd='mpiexec'):
124
+ dipoles_initial = simulate_dipole(
125
+ net_initial, tstop=tstop, n_trials=n_trials)
126
+
127
+ # Smooth and scale
128
+ window_length = 30
129
+ scaling_factor = 3000
130
+ for dipole in dipoles_initial:
131
+ dipole.smooth(window_length).scale(scaling_factor)
132
+
133
+ # Plot
134
+ fig, ax = plt.subplots(figsize=(6, 6))
135
+ dipole_experimental.plot(ax=ax, layer='agg', show=False,
136
+ color='tab:blue')
137
+ plot_dipole(dipoles_initial.copy(), ax=ax, layer='agg', show=False,
138
+ color='tab:orange', average=True)
139
+
140
+ # Legend
141
+ legend_handles = [Line2D([0], [0], color='tab:blue', lw=1.0),
142
+ Line2D([0], [0], color='tab:orange', lw=1.0)]
143
+ ax.legend(legend_handles, ['experimental', 'initial'])
144
+
145
+ ###############################################################################
146
+ # 4. Define the ``set_params`` function
147
+ # -----------------------------------
148
+ #
149
+ # Now we can begin the optimization!
150
+ #
151
+ # First, we'll define a ``set_params`` function. This function tells the optimizer
152
+ # how to apply the chosen parameters to the network during each iteration.
153
+ #
154
+ # Comparison of the initial dipoles reveals that the second positive peak of the
155
+ # experimental dipole (blue) has a larger amplitude, later latency, and broader
156
+ # temporal distribution than the corresponding peak in the initial dipole (orange).
157
+ #
158
+ # Let's optimize the relevant parameters for the second proximal (evprox2) drive,
159
+ # as it is primarily responsible for this component of the dipole.
160
+
161
+
162
+ def set_params(net, params):
163
+
164
+ # Proximal 1
165
+ net.add_evoked_drive('evprox1',
166
+ mu=26.61,
167
+ sigma=2.47,
168
+ numspikes=1,
169
+ location='proximal',
170
+ weights_ampa=weights_ampa_p1,
171
+ synaptic_delays=synaptic_delays_p,
172
+ n_drive_cells=n_drive_cells,
173
+ cell_specific=cell_specific)
174
+
175
+ # Distal
176
+ net.add_evoked_drive('evdist1',
177
+ mu=63.53,
178
+ sigma=3.85,
179
+ numspikes=1,
180
+ location='distal',
181
+ weights_ampa=weights_ampa_d1,
182
+ weights_nmda=weights_nmda_d1,
183
+ synaptic_delays=synaptic_delays_d1,
184
+ n_drive_cells=n_drive_cells,
185
+ cell_specific=cell_specific)
186
+
187
+ # Proximal 2
188
+ weights_ampa_p2 = {'L2_basket': 0.000003, 'L2_pyramidal': 1.438840,
189
+ 'L5_basket': 0.008958, 'L5_pyramidal': params['evprox2_ampa_L5_pyramidal']}
190
+ net.add_evoked_drive('evprox2',
191
+ mu=params['evprox2_mu'],
192
+ sigma=params['evprox2_sigma'],
193
+ numspikes=1,
194
+ location='proximal',
195
+ weights_ampa=weights_ampa_p2,
196
+ synaptic_delays=synaptic_delays_p,
197
+ n_drive_cells=n_drive_cells,
198
+ cell_specific=cell_specific)
199
+
200
+ ###############################################################################
201
+ # 5. Define optimization constraints
202
+ # ----------------------------------
203
+ #
204
+ # The constraints define the permissible range (lower and upper bounds) for each
205
+ # parameter during the optimization process.
206
+ #
207
+ # The ranges for synaptic weights (µS) are set to maintain physiologically
208
+ # realistic model behavior, rather than solely relying on existing literature values.
209
+
210
+
211
+ constraints = dict({'evprox2_ampa_L5_pyramidal': (0.01, 1.0),
212
+ 'evprox2_mu': (100., 150.),
213
+ 'evprox2_sigma': (1., 20.)})
214
+
215
+ ###############################################################################
216
+ # 6. Define the initial parameters
217
+ # --------------------------------
218
+ #
219
+ # For optimal results, set initial_params to your hand-tuned values since they
220
+ # already provide a good fit.
221
+ #
222
+ # If ``initial_params`` is not set, the optimizer will use the midpoint of the
223
+ # constraints as the initial parameters.
224
+
225
+ initial_params = dict({'evprox2_ampa_L5_pyramidal': 0.1,
226
+ 'evprox2_mu': 120.,
227
+ 'evprox2_sigma': 1.})
228
+
229
+ ###############################################################################
230
+ # 7. Initialize and run the optimizer
231
+ # -----------------------------------
232
+ #
233
+ # Finally, let's initialize and run the optimizer. We'll instantiate the Optimizer
234
+ # class, providing our network, simulation time, constraints, and the ``set_params``
235
+ # function.
236
+ #
237
+ # By default, the Optimizer aims to minimize the Root Mean Square Error (RMSE)
238
+ # between the simulated and experimental dipoles.
239
+ #
240
+ # To capture the model's average behavior, it's recommended to set ``n_trials``
241
+ # to a value greater than 1. Using ``n_trials=1`` might find a parameter set that
242
+ # works well for a single, specific simulation run but performs poorly on average.
243
+ #
244
+ # Additionally, while ``max_iter`` is set to 50 in this example for a quicker
245
+ # demonstration, you can set it to any value. The default is 200.
246
+ #
247
+ # .. note:: A custom objective function can also be supplied.
248
+
249
+ net = jones_2009_model()
250
+ optim = Optimizer(net, tstop=tstop, constraints=constraints,
251
+ set_params=set_params, initial_params=initial_params, max_iter=50)
252
+ with MPIBackend(n_procs=n_procs, mpi_cmd='mpiexec'):
253
+ optim.fit(target=dipole_experimental, n_trials=n_trials, scale_factor=scaling_factor,
254
+ smooth_window_len=window_length)
255
+
256
+ ###############################################################################
257
+ # 8. Simulate the optimized dipole
258
+ # --------------------------------
259
+ #
260
+ # Now, we can simulate the dipole using the newly found optimized parameters
261
+ # to see how well they match the experimental data.
262
+
263
+ with MPIBackend(n_procs=n_procs, mpi_cmd='mpiexec'):
264
+ dipoles_optimized = simulate_dipole(
265
+ optim.net_, tstop=tstop, n_trials=n_trials)
266
+
267
+ # Smooth and scale
268
+ for dipole in dipoles_optimized:
269
+ dipole.smooth(window_length).scale(scaling_factor)
270
+
271
+ ###############################################################################
272
+ # 9. Visualize the results
273
+ # ------------------------
274
+ #
275
+ # Finally, we can compare the experimental, initial, and optimized dipoles.
276
+ #
277
+ # We can also plot the convergence.
278
+
279
+ fig, ax = plt.subplots(sharex=True, figsize=(6, 6))
280
+ dipole_experimental.plot(ax=ax, layer='agg', show=False,
281
+ color='tab:blue')
282
+ plot_dipole(dipoles_initial.copy(), ax=ax, layer='agg', show=False,
283
+ color='tab:orange', average=True)
284
+ plot_dipole(dipoles_optimized.copy(), ax=ax, layer='agg',
285
+ show=False, color='tab:green', average=True)
286
+
287
+ # Legend
288
+ legend_handles = [Line2D([0], [0], color='tab:blue', lw=1.0),
289
+ Line2D([0], [0], color='tab:orange', lw=1.0),
290
+ Line2D([0], [0], color='tab:green', lw=1.0)]
291
+ ax.legend(legend_handles, ['experimental', 'initial', 'optimized'])
292
+
293
+ # Convergence plot
294
+ optim.plot_convergence()
295
+ plt.show()