{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Plotting" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`Sinaps` includes a convenient way to directly plot a neuron geometry and simulation results, through the .plot accesor. This is based on the [holoview](http://holoviews.org/) library." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To illustrate the plotting tool, we first create a simulation of voltage propagation and calcium electrodiffusion, in a simple neuron. Calcium dynamics includes buffering and extrusion.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import sinaps as sn\n", "\n", "# Defining the nueron\n", "nrn = sn.Neuron([(0,1),(1,2),(1,3),(3,4)])\n", "\n", "# Setting up channels\n", "nrn[0].clear_channels()#Reset all channels, useful if you re-run this cell (does nothing the first time)\n", "nrn[0].add_channel(sn.channels.PulseCurrent(200,2,3),0)\n", "nrn[0].add_channel(sn.channels.PulseCurrent(200,22,23),0)\n", "nrn[0].add_channel(sn.channels.Hodgkin_Huxley())\n", "nrn[0].add_channel(sn.channels.Hodgkin_Huxley_Ca(gCa=14.5,V_Ca=115)) \n", "\n", "# Defining and running the simulation\n", "sim = sn.Simulation(nrn,dx=10)\n", "sim.run((0,60))\n", "\n", "#Setting initial concentrations\n", "for s in nrn.sections:\n", " s.C0[sn.Species.Ca]=10**(-4)\n", " s.C0[sn.Species.Buffer]=2*10**(-3)\n", " s.C0[sn.Species.Buffer_Ca]=0\n", "\n", "# Adding chemical reactions: claicum binding to a buffer, and calcium extrusion\n", "nrn.add_reaction(\n", " {sn.Species.Ca:1,\n", " sn.Species.Buffer:1},\n", " {sn.Species.Buffer_Ca:1},\n", " k1=0.2,\n", " k2=0.1)\n", "\n", "nrn.add_reaction(\n", " {sn.Species.Ca:1},\n", " {},\n", " k1=0.05,k2=0)\n", "\n", "# Running electro-diffusion simulations\n", "sim.run_diff(max_step=1)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Neuronal geometry" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import hvplot\n", "hvplot.__version__" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To plot the neuron geometry:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nrn.plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Potential" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`sim.plot.V` plots the voltage dynamics at nodes evenly distributed on the neuron. Default number of curves is 10, change number with `max_plot`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.plot.V(max_plot=2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Specific sections can be accesed through their names:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim['Section0000'].plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Holoview or matplotlib can be used directly through the [pandas](https://pandas.pydata.org/) Dataframe structure of the data: " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.V" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.V.loc[:,'Section0000'][25].hvplot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "is equivalent to:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim['Section0000'].V.loc[:,25].hvplot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The name of the sections can be accessed through the columns function. See the [pandas](https://pandas.pydata.org/) doc for more features." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.V.columns" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.V[('Section0000', 25.0)].plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Field plots are also acccessible through the API. The time can be zoomed through the command `time`. See the [holoview](https://holoviews.org/) doc for more features. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.plot.V_field(time=(0,30))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To help navigating in the field plot, the neuronal geometry is plotted on the left, with a colorbar legend mapping the linear position on the field to the geometry. In a live notebook, the view is interactive. Passing the mouse on the field plot will enhance the corresponding section on the neuronal geometry. \n", "\n", "Setting the parameter `neuron` to False displays only the field plot." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plotting the currents" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The currents computed by the simulation environment are stored in a [pandas](https://pandas.pydata.org/) Dataframe. They are positive when they go toward inside.\n", "\n", "`sim.plot.I(ChannelClass)` plots the currents for the channels of type ChannelClass" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.plot.I(sn.channels.Hodgkin_Huxley)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The field plots are also accessible:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.plot.I_field(sn.channels.Hodgkin_Huxley)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If several channels of the same type are defined on a section, sim.plot.I will plot the sum of all the currents:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim['Section0000'].plot.I(sn.channels.PulseCurrent)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Holoview or matplotlib can be used directly through the [pandas](https://pandas.pydata.org/) Dataframe structure of the data: " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.current(sn.channels.Hodgkin_Huxley) " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.current(sn.channels.PulseCurrent)['Section0000'].hvplot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plotting the species dynamics" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The species concentration dynamics computed by the simulation environment are stored in a [pandas](https://pandas.pydata.org/) Dataframe.\n", "\n", "`sim.plot.C(Species)` plots the concentration of Class Species:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.plot.C(sn.Species.Ca)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim['Section0000'].plot.C(sn.Species.Ca)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The species dynamics are stored in a [pandas](https://pandas.pydata.org/) Dataframe, and are accessible via their class:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.C[sn.Species.Ca]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim.C[sn.Species.Ca].loc[:,'Section0000'][25].hvplot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "is equivalent to:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim['Section0000'].C(sn.Species.Ca).loc[:,25].hvplot()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim['Section0000'].C(sn.Species.Buffer_Ca).loc[:,5].hvplot()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 4 }