|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "(np-utils:stimscan)=\n", |
| 8 | + "# Stimulation parameter scan\n", |
| 9 | + "\n", |
| 10 | + "This utility allows you to automatically search for optimal stimulation parameters on a given MEA.\n", |
| 11 | + "\n", |
| 12 | + "```{note}\n", |
| 13 | + "Neuroplatform access (and booking for shared access) is required to use this utility.\n", |
| 14 | + "```\n", |
| 15 | + "\n", |
| 16 | + "\n", |
| 17 | + "## Installation\n", |
| 18 | + "\n", |
| 19 | + "To install all dependencies, run the following command:\n", |
| 20 | + "\n", |
| 21 | + "```bash\n", |
| 22 | + "pip install git+https://github.com/FinalSpark-np/np-utils.git#egg=np_utils[SSN]\n", |
| 23 | + "```\n", |
| 24 | + "\n", |
| 25 | + "## Usage\n", |
| 26 | + "\n", |
| 27 | + "### Imports\n", |
| 28 | + "\n", |
| 29 | + "Import the needed classes :\n" |
| 30 | + ] |
| 31 | + }, |
| 32 | + { |
| 33 | + "cell_type": "code", |
| 34 | + "execution_count": null, |
| 35 | + "metadata": {}, |
| 36 | + "outputs": [], |
| 37 | + "source": [ |
| 38 | + "from neuroplatform import Experiment, StimPolarity\n", |
| 39 | + "from np_utils.stim_scan import StimParamGrid, StimScan, MEAType" |
| 40 | + ] |
| 41 | + }, |
| 42 | + { |
| 43 | + "cell_type": "markdown", |
| 44 | + "metadata": {}, |
| 45 | + "source": [ |
| 46 | + "### Defining a StimParamGrid" |
| 47 | + ] |
| 48 | + }, |
| 49 | + { |
| 50 | + "cell_type": "code", |
| 51 | + "execution_count": null, |
| 52 | + "metadata": {}, |
| 53 | + "outputs": [], |
| 54 | + "source": [ |
| 55 | + "grid = StimParamGrid(\n", |
| 56 | + " amplitudes=[1, 2, 3],\n", |
| 57 | + " durations=[100, 200],\n", |
| 58 | + " polarities=[StimPolarity.NegativeFirst, StimPolarity.PositiveFirst],\n", |
| 59 | + " mea_type=MEAType.MEA4x8, # OR MEAType.MEA32\n", |
| 60 | + ")\n", |
| 61 | + "print(grid.total_combinations())\n", |
| 62 | + "grid.display_grid()" |
| 63 | + ] |
| 64 | + }, |
| 65 | + { |
| 66 | + "cell_type": "markdown", |
| 67 | + "metadata": {}, |
| 68 | + "source": [ |
| 69 | + "### Running the scan\n", |
| 70 | + "````{margin}\n", |
| 71 | + "```{seealso}\n", |
| 72 | + "See [Experiment and token](core:exp-and-tokens) for relevant API usage.\n", |
| 73 | + "```\n", |
| 74 | + "````\t\n", |
| 75 | + "\n", |
| 76 | + "Next, define which channels to run the scan on (in absolute index, e.g. for MEA2, channels 32-64)\n", |
| 77 | + "Provide your experiment, the grid of parameters, and the delays as well as number of repeats per channel." |
| 78 | + ] |
| 79 | + }, |
| 80 | + { |
| 81 | + "cell_type": "code", |
| 82 | + "execution_count": null, |
| 83 | + "metadata": {}, |
| 84 | + "outputs": [], |
| 85 | + "source": [ |
| 86 | + "EXPERIMENT = Experiment(\"...\") # use your token here\n", |
| 87 | + "scan = StimScan(\n", |
| 88 | + " fs_experiment=EXPERIMENT,\n", |
| 89 | + " parameter_grid=grid,\n", |
| 90 | + " delay_btw_stim=1, # delay between stimulations\n", |
| 91 | + " delay_btw_channels=5, # delay between channels\n", |
| 92 | + " repeats_per_channel=5, # number of repeats per channel for a single parameter set\n", |
| 93 | + " scan_channels=range(\n", |
| 94 | + " 32, 64\n", |
| 95 | + " ), # channels to scan, here MEA2. Must match electrodes allowed by your token\n", |
| 96 | + ")" |
| 97 | + ] |
| 98 | + }, |
| 99 | + { |
| 100 | + "cell_type": "code", |
| 101 | + "execution_count": null, |
| 102 | + "metadata": {}, |
| 103 | + "outputs": [], |
| 104 | + "source": [ |
| 105 | + "scan.run()" |
| 106 | + ] |
| 107 | + }, |
| 108 | + { |
| 109 | + "cell_type": "markdown", |
| 110 | + "metadata": {}, |
| 111 | + "source": [ |
| 112 | + "### Displaying results\n", |
| 113 | + "\n", |
| 114 | + "#### Showing all stimulations\n", |
| 115 | + "\n", |
| 116 | + "To access the list of all stimulations and associated parameters, use :" |
| 117 | + ] |
| 118 | + }, |
| 119 | + { |
| 120 | + "cell_type": "code", |
| 121 | + "execution_count": null, |
| 122 | + "metadata": {}, |
| 123 | + "outputs": [], |
| 124 | + "source": [ |
| 125 | + "stim_df = scan.get_stimulation_parameter_history()\n", |
| 126 | + "stim_df" |
| 127 | + ] |
| 128 | + }, |
| 129 | + { |
| 130 | + "cell_type": "markdown", |
| 131 | + "metadata": {}, |
| 132 | + "source": [ |
| 133 | + "Finally, to show all events after stimulation :" |
| 134 | + ] |
| 135 | + }, |
| 136 | + { |
| 137 | + "cell_type": "code", |
| 138 | + "execution_count": null, |
| 139 | + "metadata": {}, |
| 140 | + "outputs": [], |
| 141 | + "source": [ |
| 142 | + "scan.plot_all_stims(\n", |
| 143 | + " s_before=1, s_after=2.5\n", |
| 144 | + ") # arguments define how long to show before the first stim and after the last respectively" |
| 145 | + ] |
| 146 | + }, |
| 147 | + { |
| 148 | + "cell_type": "markdown", |
| 149 | + "metadata": {}, |
| 150 | + "source": [ |
| 151 | + "You may also use `scan.plot_all_stims_for_param` and `scan.plot_all_stims_for_channel` to visualize the stimulation events specifically for a given parameter or channel.\n", |
| 152 | + "\n", |
| 153 | + "#### Additional plotting options\n", |
| 154 | + "\n", |
| 155 | + "##### Selecting specific channels\n", |
| 156 | + "\n", |
| 157 | + "The `show_electrodes` argument lets you pick which channels to display. By default, all channels are displayed.\n", |
| 158 | + "\n", |
| 159 | + "##### Event interval visualization\n", |
| 160 | + "\n", |
| 161 | + "Finally, you can use the `guideline_freq`argument to show lines every `guideline_freq` seconds. This can be useful to visualize the stimulation events in relation to the stimulation frequency.\n", |
| 162 | + "\n", |
| 163 | + "To do this, define the `guideline_freq` argument as the desired period in seconds as such : \"{n_sec}s\" (e.g. \"1s\" for 1 second).\n", |
| 164 | + "\n", |
| 165 | + "This is None by default, which will not display any guidelines.\n", |
| 166 | + "\n", |
| 167 | + "## Future additions\n", |
| 168 | + "\n", |
| 169 | + "Summary metrics as well as best parameter automated selection may be added in a future version.\n" |
| 170 | + ] |
| 171 | + } |
| 172 | + ], |
| 173 | + "metadata": { |
| 174 | + "kernelspec": { |
| 175 | + "display_name": "fspark", |
| 176 | + "language": "python", |
| 177 | + "name": "python3" |
| 178 | + }, |
| 179 | + "language_info": { |
| 180 | + "name": "python", |
| 181 | + "version": "3.11.9" |
| 182 | + } |
| 183 | + }, |
| 184 | + "nbformat": 4, |
| 185 | + "nbformat_minor": 2 |
| 186 | +} |
0 commit comments