Skip to content

Commit

Permalink
ENH: add drives before simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmainak committed Apr 15, 2021
1 parent fc69efd commit 18b98a6
Showing 1 changed file with 81 additions and 67 deletions.
148 changes: 81 additions & 67 deletions hnn_widget.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,18 @@
"params = read_params(params_fname)\n",
"\n",
"variables = dict(net=None, dpls=None)\n",
"variables['net'] = Network(params, add_drives_from_params=True)"
"variables['net'] = Network(params, add_drives_from_params=False)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from ipywidgets import AppLayout, Button, Layout"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# HNN Banner\n",
"from ipywidgets import Button, Layout\n",
"\n",
"def create_expanded_button(description, button_style):\n",
" return Button(description=description, button_style=button_style, layout=Layout(height='10', width='auto'))\n",
"\n",
Expand All @@ -44,7 +37,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -107,7 +100,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -127,10 +120,11 @@
")\n",
"\n",
"drives_out = Output()\n",
"drive_boxes = list()\n",
"drive_widgets = list()\n",
"drive_titles = list()\n",
"drive_boxes = list()\n",
"\n",
"def add_drive_options(drive_type):\n",
"def add_drive_widget(drive_type):\n",
"\n",
" drives_out.clear_output()\n",
" with drives_out:\n",
Expand All @@ -144,13 +138,14 @@
" burst_std = FloatText(value=7.5, description='Burst std dev:', layout=layout)\n",
" location = RadioButtons(options=['proximal', 'distal'])\n",
"\n",
" drive = VBox([tstart, tstart_std, tstop, burst_rate, burst_std, location])\n",
" variables['net'].add_bursty_drive(name=drive_title,\n",
" tstart=tstart.value,\n",
" tstart_std=tstart_std.value,\n",
" burst_rate=burst_rate.value,\n",
" burst_std=burst_std.value,\n",
" location=location.value)\n",
" drive_box = VBox([tstart, tstart_std, tstop, burst_rate, burst_std, location])\n",
" drive = dict(type='Rhythmic', name=drive_title,\n",
" tstart=tstart,\n",
" tstart_std=tstart_std,\n",
" burst_rate=burst_rate,\n",
" burst_std=burst_std,\n",
" location=location\n",
" )\n",
" elif drive_type['new'] == 'Poisson': \n",
" tstart = FloatText(value=7.5, description='Start time:', layout=layout)\n",
" tstop = FloatText(value=8.5, description='Stop time:', layout=layout)\n",
Expand All @@ -159,17 +154,16 @@
" weights_ampa_L5Pyr = FloatText(value=8.5, description='AMPA (L5 Pyr):', layout=layout)\n",
" weights_nmda_L5Pyr = FloatText(value=8.5, description='NMDA (L5 Pyr):', layout=layout)\n",
" \n",
" drive = VBox([tstart, tstop, rate_constant, location,\n",
" weights_ampa_L5Pyr, weights_nmda_L5Pyr])\n",
" variables['net'].add_poisson_drive(name=drive_title,\n",
" tstart=tstart.value, \n",
" tstop=tstop.value,\n",
" rate_constant=rate_constant.value, \n",
" location=location.value, \n",
" weights_ampa=dict(L5_pyramidal=weights_ampa_L5Pyr.value), \n",
" weights_nmda=dict(L5_pyramidal=weights_nmda_L5Pyr.value), \n",
" space_constant=100.0\n",
" )\n",
" drive_box = VBox([tstart, tstop, rate_constant, location,\n",
" weights_ampa_L5Pyr, weights_nmda_L5Pyr])\n",
" drive = dict(type='Poisson', name=drive_title,\n",
" tstart=tstart, \n",
" tstop=tstop,\n",
" rate_constant=rate_constant, \n",
" location=location, \n",
" weights_ampa_L5Pyr=weights_ampa_L5Pyr, \n",
" weights_nmda_L5Pyr=weights_nmda_L5Pyr\n",
" )\n",
" elif drive_type['new'] == 'Evoked': \n",
" mu = FloatText(value=7.5, description='Mean time:', layout=layout)\n",
" sigma = FloatText(value=8.5, description='Std dev time:', layout=layout)\n",
Expand All @@ -178,19 +172,20 @@
" weights_ampa_L5Pyr = FloatText(value=8.5, description='AMPA (L5 Pyr):', layout=layout)\n",
" weights_nmda_L5Pyr = FloatText(value=8.5, description='NMDA (L5 Pyr):', layout=layout)\n",
"\n",
" drive = VBox([mu, sigma, numspikes, location, weights_ampa_L5Pyr, weights_nmda_L5Pyr])\n",
" variables['net'].add_evoked_drive(name=drive_title,\n",
" mu=mu.value, \n",
" sigma=sigma.value, \n",
" numspikes=numspikes.value, \n",
" sync_within_trial=False, \n",
" location=location.value, \n",
" weights_ampa=dict(L5_pyramidal=weights_ampa_L5Pyr.value), \n",
" weights_nmda=dict(L5_pyramidal=weights_nmda_L5Pyr.value), \n",
" space_constant=3.0)\n",
" drive_box = VBox([mu, sigma, numspikes, location, weights_ampa_L5Pyr, weights_nmda_L5Pyr])\n",
" drive = dict(type='Evoked', name=drive_title,\n",
" mu=mu,\n",
" sigma=sigma, \n",
" numspikes=numspikes, \n",
" sync_within_trial=False, \n",
" location=location, \n",
" weights_ampa_L5Pyr=weights_ampa_L5Pyr, \n",
" weights_nmda_L5Pyr=weights_nmda_L5Pyr, \n",
" space_constant=3.0)\n",
"\n",
" drive_titles.append(drive_title)\n",
" drive_boxes.append(drive)\n",
" drive_boxes.append(drive_box)\n",
" drive_widgets.append(drive)\n",
"\n",
" accordion = Accordion(children=drive_boxes,\n",
" selected_index=len(drive_boxes) - 1)\n",
Expand All @@ -199,14 +194,14 @@
" display(accordion)\n",
"\n",
"# XXX: should be simpler to use Stacked class starting from IPywidgets > 8.0\n",
"interactive(add_drive_options, drive_type='Evoked')\n",
"drives_dropdown.observe(add_drive_options, 'value')\n",
"interactive(add_drive_widget, drive_type='Evoked')\n",
"drives_dropdown.observe(add_drive_widget, 'value')\n",
"drives_options = VBox([drives_dropdown, drives_out])"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -220,7 +215,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -256,7 +251,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -270,7 +265,39 @@
"def on_button_clicked(b, variables):\n",
" \"\"\"Run the simulation and plot outputs.\"\"\"\n",
" with log_out:\n",
" # XXX: loop over drives and add them here\n",
" for drive in drive_widgets:\n",
" if drive['type'] == 'Poisson':\n",
" variables['net'].add_poisson_drive(\n",
" name=drive['name'],\n",
" tstart=drive['tstart'].value, \n",
" tstop=drive['tstop'].value,\n",
" rate_constant=dict(L5_pyramidal=drive['rate_constant'].value), \n",
" location=drive['location'].value,\n",
" weights_ampa=dict(L5_pyramidal=drive['weights_ampa_L5Pyr'].value), \n",
" weights_nmda=dict(L5_pyramidal=drive['weights_nmda_L5Pyr'].value), \n",
" space_constant=100.0\n",
" )\n",
" elif drive['type'] == 'Evoked':\n",
" variables['net'].add_evoked_drive(\n",
" name=drive['name'],\n",
" mu=drive['mu'].value,\n",
" sigma=drive['sigma'].value, \n",
" numspikes=drive['numspikes'].value, \n",
" sync_within_trial=False, \n",
" location=drive['location'].value, \n",
" weights_ampa=dict(L5_pyramidal=drive['weights_ampa_L5Pyr'].value), \n",
" weights_nmda=dict(L5_pyramidal=drive['weights_nmda_L5Pyr'].value), \n",
" space_constant=3.0\n",
" )\n",
" elif drive['type'] == 'Rhythmic':\n",
" variables['net'].add_bursty_drive(\n",
" name=drive['name'],\n",
" tstart=drive['tstart'].value,\n",
" tstart_std=drive['tstart_std'].value,\n",
" burst_rate=drive['burst_rate'].value,\n",
" burst_std=drive['burst_std'].value,\n",
" location=drive['location'].value\n",
" )\n",
" variables['dpls'] = simulate_dipole(variables['net'], n_trials=1)\n",
" with plot_out:\n",
" variables['dpls'][0].plot()\n",
Expand All @@ -285,30 +312,17 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7c9e9b80108748b4b4ec346e90db1ee7",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"AppLayout(children=(Button(button_style='success', description='Human Neocortical Neurosolver', layout=Layout(…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"# Final layout of the app\n",
"from ipywidgets import AppLayout\n",
"\n",
"AppLayout(header=header_button,\n",
" left_sidebar=left_tab,\n",
" center=log_out,\n",
Expand Down Expand Up @@ -336,7 +350,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
"version": "3.7.4"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 18b98a6

Please sign in to comment.