Skip to content

Commit

Permalink
update astrocytes for 3.7 nest, kernel 24.04
Browse files Browse the repository at this point in the history
  • Loading branch information
jessica-mitchell committed Jun 10, 2024
1 parent e1fe678 commit fac1a72
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
10 changes: 5 additions & 5 deletions notebooks/notebooks/astrocytes/astrocyte_brunel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
},
"outputs": [],
"source": [
"def plot_dynamics(astro_data, neuron_data, start):\n \"\"\"Plot the dynamics in neurons and astrocytes.\n\n The dynamics in the given neuron and astrocyte nodes are plotted. The\n dynamics in clude IP3 and calcium in the astrocytes, and the SIC input to\n the neurons.\n\n Parameters\n ---------\n astro_data\n Data of IP3 and calcium dynamics in the astrocytes.\n neuron_data\n Data of SIC input to the neurons.\n start\n Start time of the plotted dynamics.\n\n \"\"\"\n print(\"Plotting dynamics ...\")\n # astrocyte data\n astro_mask = astro_data[\"times\"] > start\n astro_ip3 = astro_data[\"IP3\"][astro_mask]\n astro_cal = astro_data[\"Ca\"][astro_mask]\n astro_times = astro_data[\"times\"][astro_mask]\n astro_times_set = list(set(astro_times))\n ip3_means = np.array([np.mean(astro_ip3[astro_times == t]) for t in astro_times_set])\n ip3_sds = np.array([np.std(astro_ip3[astro_times == t]) for t in astro_times_set])\n cal_means = np.array([np.mean(astro_cal[astro_times == t]) for t in astro_times_set])\n cal_sds = np.array([np.std(astro_cal[astro_times == t]) for t in astro_times_set])\n # neuron data\n neuron_mask = neuron_data[\"times\"] > start\n neuron_sic = neuron_data[\"I_SIC\"][neuron_mask]\n neuron_times = neuron_data[\"times\"][neuron_mask]\n neuron_times_set = list(set(neuron_times))\n sic_means = np.array([np.mean(neuron_sic[neuron_times == t]) for t in neuron_times_set])\n sic_sds = np.array([np.std(neuron_sic[neuron_times == t]) for t in neuron_times_set])\n # set plots\n fig, axes = plt.subplots(2, 1, sharex=True)\n color_ip3 = \"tab:blue\"\n color_cal = \"tab:green\"\n color_sic = \"tab:purple\"\n # astrocyte plot\n axes[0].set_title(f\"{r'IP$_{3}$'} and {r'Ca$^{2+}$'} in astrocytes (n={len(set(astro_data['senders']))})\")\n axes[0].set_ylabel(r\"IP$_{3}$ ($\\mu$M)\")\n axes[0].tick_params(axis=\"y\", labelcolor=color_ip3)\n axes[0].fill_between(\n astro_times_set, ip3_means + ip3_sds, ip3_means - ip3_sds, alpha=0.3, linewidth=0.0, color=color_ip3\n )\n axes[0].plot(astro_times_set, ip3_means, linewidth=2, color=color_ip3)\n ax = axes[0].twinx()\n ax.set_ylabel(r\"Ca$^{2+}$ ($\\mu$M)\")\n ax.tick_params(axis=\"y\", labelcolor=color_cal)\n ax.fill_between(\n astro_times_set, cal_means + cal_sds, cal_means - cal_sds, alpha=0.3, linewidth=0.0, color=color_cal\n )\n ax.plot(astro_times_set, cal_means, linewidth=2, color=color_cal)\n # neuron plot\n axes[1].set_title(f\"SIC in neurons (n={len(set(neuron_data['senders']))})\")\n axes[1].set_ylabel(\"SIC (pA)\")\n axes[1].set_xlabel(\"Time (ms)\")\n axes[1].fill_between(\n neuron_times_set, sic_means + sic_sds, sic_means - sic_sds, alpha=0.3, linewidth=0.0, color=color_sic\n )\n axes[1].plot(neuron_times_set, sic_means, linewidth=2, color=color_sic)"
"def plot_dynamics(astro_data, neuron_data, start):\n \"\"\"Plot the dynamics in neurons and astrocytes.\n\n The dynamics in the given neuron and astrocyte nodes are plotted. The\n dynamics in clude IP3 and calcium in the astrocytes, and the SIC input to\n the neurons.\n\n Parameters\n ---------\n astro_data\n Data of IP3 and calcium dynamics in the astrocytes.\n neuron_data\n Data of SIC input to the neurons.\n start\n Start time of the plotted dynamics.\n\n \"\"\"\n print(\"Plotting dynamics ...\")\n # astrocyte data\n astro_mask = astro_data[\"times\"] > start\n astro_ip3 = astro_data[\"IP3\"][astro_mask]\n astro_cal = astro_data[\"Ca_astro\"][astro_mask]\n astro_times = astro_data[\"times\"][astro_mask]\n astro_times_set = list(set(astro_times))\n ip3_means = np.array([np.mean(astro_ip3[astro_times == t]) for t in astro_times_set])\n ip3_sds = np.array([np.std(astro_ip3[astro_times == t]) for t in astro_times_set])\n cal_means = np.array([np.mean(astro_cal[astro_times == t]) for t in astro_times_set])\n cal_sds = np.array([np.std(astro_cal[astro_times == t]) for t in astro_times_set])\n # neuron data\n neuron_mask = neuron_data[\"times\"] > start\n neuron_sic = neuron_data[\"I_SIC\"][neuron_mask]\n neuron_times = neuron_data[\"times\"][neuron_mask]\n neuron_times_set = list(set(neuron_times))\n sic_means = np.array([np.mean(neuron_sic[neuron_times == t]) for t in neuron_times_set])\n sic_sds = np.array([np.std(neuron_sic[neuron_times == t]) for t in neuron_times_set])\n # set plots\n fig, axes = plt.subplots(2, 1, sharex=True)\n color_ip3 = \"tab:blue\"\n color_cal = \"tab:green\"\n color_sic = \"tab:purple\"\n # astrocyte plot\n axes[0].set_title(f\"{r'IP$_{3}$'} and {r'Ca$^{2+}$'} in astrocytes (n={len(set(astro_data['senders']))})\")\n axes[0].set_ylabel(r\"IP$_{3}$ ($\\mu$M)\")\n axes[0].tick_params(axis=\"y\", labelcolor=color_ip3)\n axes[0].fill_between(\n astro_times_set, ip3_means + ip3_sds, ip3_means - ip3_sds, alpha=0.3, linewidth=0.0, color=color_ip3\n )\n axes[0].plot(astro_times_set, ip3_means, linewidth=2, color=color_ip3)\n ax = axes[0].twinx()\n ax.set_ylabel(r\"Ca$^{2+}$ ($\\mu$M)\")\n ax.tick_params(axis=\"y\", labelcolor=color_cal)\n ax.fill_between(\n astro_times_set, cal_means + cal_sds, cal_means - cal_sds, alpha=0.3, linewidth=0.0, color=color_cal\n )\n ax.plot(astro_times_set, cal_means, linewidth=2, color=color_cal)\n # neuron plot\n axes[1].set_title(f\"SIC in neurons (n={len(set(neuron_data['senders']))})\")\n axes[1].set_ylabel(\"SIC (pA)\")\n axes[1].set_xlabel(\"Time (ms)\")\n axes[1].fill_between(\n neuron_times_set, sic_means + sic_sds, sic_means - sic_sds, alpha=0.3, linewidth=0.0, color=color_sic\n )\n axes[1].plot(neuron_times_set, sic_means, linewidth=2, color=color_sic)"
]
},
{
Expand All @@ -148,7 +148,7 @@
},
"outputs": [],
"source": [
"def run_simulation():\n \"\"\"Run simulation of a neuron-astrocyte network.\"\"\"\n # NEST configuration\n nest.ResetKernel()\n nest.resolution = sim_params[\"dt\"]\n nest.local_num_threads = sim_params[\"n_threads\"]\n nest.print_time = True\n nest.overwrite_files = True\n\n # use random seed for reproducible sampling\n random.seed(sim_params[\"seed\"])\n\n # simulation settings\n pre_sim_time = sim_params[\"pre_sim_time\"]\n sim_time = sim_params[\"sim_time\"]\n\n # create and connect nodes\n exc, inh, astro, noise = create_astro_network()\n connect_astro_network(exc, inh, astro, noise)\n\n # create and connect recorders (multimeter default resolution = 1 ms)\n sr_neuron = nest.Create(\"spike_recorder\")\n mm_neuron = nest.Create(\"multimeter\", params={\"record_from\": [\"I_SIC\"]})\n mm_astro = nest.Create(\"multimeter\", params={\"record_from\": [\"IP3\", \"Ca\"]})\n\n # select nodes randomly and connect them with recorders\n print(\"Connecting recorders ...\")\n neuron_list = (exc + inh).tolist()\n astro_list = astro.tolist()\n n_neuron_rec_spk = min(len(neuron_list), sim_params[\"N_rec_spk\"])\n n_neuron_rec_mm = min(len(neuron_list), sim_params[\"N_rec_mm\"])\n n_astro_rec = min(len(astro), sim_params[\"N_rec_mm\"])\n neuron_list_for_sr = neuron_list[: min(len(neuron_list), n_neuron_rec_spk)]\n neuron_list_for_mm = sorted(random.sample(neuron_list, n_neuron_rec_mm))\n astro_list_for_mm = sorted(random.sample(astro_list, n_astro_rec))\n nest.Connect(neuron_list_for_sr, sr_neuron)\n nest.Connect(mm_neuron, neuron_list_for_mm)\n nest.Connect(mm_astro, astro_list_for_mm)\n\n # run pre-simulation\n print(\"Running pre-simulation ...\")\n nest.Simulate(pre_sim_time)\n\n # run simulation\n print(\"Running simulation ...\")\n nest.Simulate(sim_time)\n\n # read out recordings\n neuron_spikes = sr_neuron.events\n neuron_data = mm_neuron.events\n astro_data = mm_astro.events\n\n # make raster plot\n nest.raster_plot.from_device(\n sr_neuron, hist=True, title=f\"Raster plot of neuron {neuron_list_for_sr[0]} to {neuron_list_for_sr[-1]}\"\n )\n\n # plot dynamics in astrocytes and neurons\n plot_dynamics(astro_data, neuron_data, 0.0)\n\n # show plots\n plt.show()"
"def run_simulation():\n \"\"\"Run simulation of a neuron-astrocyte network.\"\"\"\n # NEST configuration\n nest.ResetKernel()\n nest.resolution = sim_params[\"dt\"]\n nest.local_num_threads = sim_params[\"n_threads\"]\n nest.print_time = True\n nest.overwrite_files = True\n\n # use random seed for reproducible sampling\n random.seed(sim_params[\"seed\"])\n\n # simulation settings\n pre_sim_time = sim_params[\"pre_sim_time\"]\n sim_time = sim_params[\"sim_time\"]\n\n # create and connect nodes\n exc, inh, astro, noise = create_astro_network()\n connect_astro_network(exc, inh, astro, noise)\n\n # create and connect recorders (multimeter default resolution = 1 ms)\n sr_neuron = nest.Create(\"spike_recorder\")\n mm_neuron = nest.Create(\"multimeter\", params={\"record_from\": [\"I_SIC\"]})\n mm_astro = nest.Create(\"multimeter\", params={\"record_from\": [\"IP3\", \"Ca_astro\"]})\n\n # select nodes randomly and connect them with recorders\n print(\"Connecting recorders ...\")\n neuron_list = (exc + inh).tolist()\n astro_list = astro.tolist()\n n_neuron_rec_spk = min(len(neuron_list), sim_params[\"N_rec_spk\"])\n n_neuron_rec_mm = min(len(neuron_list), sim_params[\"N_rec_mm\"])\n n_astro_rec = min(len(astro), sim_params[\"N_rec_mm\"])\n neuron_list_for_sr = neuron_list[: min(len(neuron_list), n_neuron_rec_spk)]\n neuron_list_for_mm = sorted(random.sample(neuron_list, n_neuron_rec_mm))\n astro_list_for_mm = sorted(random.sample(astro_list, n_astro_rec))\n nest.Connect(neuron_list_for_sr, sr_neuron)\n nest.Connect(mm_neuron, neuron_list_for_mm)\n nest.Connect(mm_astro, astro_list_for_mm)\n\n # run pre-simulation\n print(\"Running pre-simulation ...\")\n nest.Simulate(pre_sim_time)\n\n # run simulation\n print(\"Running simulation ...\")\n nest.Simulate(sim_time)\n\n # read out recordings\n neuron_spikes = sr_neuron.events\n neuron_data = mm_neuron.events\n astro_data = mm_astro.events\n\n # make raster plot\n nest.raster_plot.from_device(\n sr_neuron, hist=True, title=f\"Raster plot of neuron {neuron_list_for_sr[0]} to {neuron_list_for_sr[-1]}\"\n )\n\n # plot dynamics in astrocytes and neurons\n plot_dynamics(astro_data, neuron_data, 0.0)\n\n # show plots\n plt.show()"
]
},
{
Expand All @@ -172,9 +172,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "EBRAINS-23.09",
"display_name": "EBRAINS-24.04",
"language": "python",
"name": "ebrains-23.09"
"name": "ebrains-24.04"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -191,4 +191,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
4 changes: 2 additions & 2 deletions notebooks/notebooks/astrocytes/astrocyte_brunel.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def plot_dynamics(astro_data, neuron_data, start):
# astrocyte data
astro_mask = astro_data["times"] > start
astro_ip3 = astro_data["IP3"][astro_mask]
astro_cal = astro_data["Ca"][astro_mask]
astro_cal = astro_data["Ca_astro"][astro_mask]
astro_times = astro_data["times"][astro_mask]
astro_times_set = list(set(astro_times))
ip3_means = np.array([np.mean(astro_ip3[astro_times == t]) for t in astro_times_set])
Expand Down Expand Up @@ -329,7 +329,7 @@ def run_simulation():
# create and connect recorders (multimeter default resolution = 1 ms)
sr_neuron = nest.Create("spike_recorder")
mm_neuron = nest.Create("multimeter", params={"record_from": ["I_SIC"]})
mm_astro = nest.Create("multimeter", params={"record_from": ["IP3", "Ca"]})
mm_astro = nest.Create("multimeter", params={"record_from": ["IP3", "Ca_astro"]})

# select nodes randomly and connect them with recorders
print("Connecting recorders ...")
Expand Down
10 changes: 5 additions & 5 deletions notebooks/notebooks/astrocytes/astrocyte_interaction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
},
"outputs": [],
"source": [
"astrocyte = nest.Create(\"astrocyte_lr_1994\", params=params_astro)\nmm_astro = nest.Create(\"multimeter\", params={\"record_from\": [\"IP3\", \"Ca\"]})\nnest.Connect(mm_astro, astrocyte)"
"astrocyte = nest.Create(\"astrocyte_lr_1994\", params=params_astro)\nmm_astro = nest.Create(\"multimeter\", params={\"record_from\": [\"IP3\", \"Ca_astro\"]})\nnest.Connect(mm_astro, astrocyte)"
]
},
{
Expand Down Expand Up @@ -130,15 +130,15 @@
},
"outputs": [],
"source": [
"fig, ax = plt.subplots(2, 2, sharex=True, figsize=(6.4, 4.8), dpi=100)\naxes = ax.flat\naxes[0].plot(data_pre[\"times\"], data_pre[\"V_m\"])\naxes[1].plot(data_astro[\"times\"], data_astro[\"IP3\"])\naxes[2].plot(data_post[\"times\"], data_post[\"I_SIC\"])\naxes[3].plot(data_astro[\"times\"], data_astro[\"Ca\"])\naxes[0].set_title(f\"Presynaptic neuron\\n(Poisson rate = {poisson_rate_neuro} Hz)\")\naxes[0].set_ylabel(\"Membrane potential (mV)\")\naxes[2].set_title(\"Postsynaptic neuron\")\naxes[2].set_ylabel(\"Slow inward current (pA)\")\naxes[2].set_xlabel(\"Time (ms)\")\naxes[1].set_title(\"Astrocyte\")\naxes[1].set_ylabel(r\"[IP$_{3}$] ($\\mu$M)\")\naxes[3].set_ylabel(r\"[Ca$^{2+}$] ($\\mu$M)\")\naxes[3].set_xlabel(\"Time (ms)\")\nplt.tight_layout()\nplt.show()\nplt.close()"
"fig, ax = plt.subplots(2, 2, sharex=True, figsize=(6.4, 4.8), dpi=100)\naxes = ax.flat\naxes[0].plot(data_pre[\"times\"], data_pre[\"V_m\"])\naxes[1].plot(data_astro[\"times\"], data_astro[\"IP3\"])\naxes[2].plot(data_post[\"times\"], data_post[\"I_SIC\"])\naxes[3].plot(data_astro[\"times\"], data_astro[\"Ca_astro\"])\naxes[0].set_title(f\"Presynaptic neuron\\n(Poisson rate = {poisson_rate_neuro} Hz)\")\naxes[0].set_ylabel(\"Membrane potential (mV)\")\naxes[2].set_title(\"Postsynaptic neuron\")\naxes[2].set_ylabel(\"Slow inward current (pA)\")\naxes[2].set_xlabel(\"Time (ms)\")\naxes[1].set_title(\"Astrocyte\")\naxes[1].set_ylabel(r\"[IP$_{3}$] ($\\mu$M)\")\naxes[3].set_ylabel(r\"[Ca$^{2+}$] ($\\mu$M)\")\naxes[3].set_xlabel(\"Time (ms)\")\nplt.tight_layout()\nplt.show()\nplt.close()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "EBRAINS-23.09",
"display_name": "EBRAINS-24.04",
"language": "python",
"name": "ebrains-23.09"
"name": "ebrains-24.04"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -155,4 +155,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
4 changes: 2 additions & 2 deletions notebooks/notebooks/astrocytes/astrocyte_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
# Create and connect the astrocyte and its devices.

astrocyte = nest.Create("astrocyte_lr_1994", params=params_astro)
mm_astro = nest.Create("multimeter", params={"record_from": ["IP3", "Ca"]})
mm_astro = nest.Create("multimeter", params={"record_from": ["IP3", "Ca_astro"]})
nest.Connect(mm_astro, astrocyte)

###############################################################################
Expand Down Expand Up @@ -133,7 +133,7 @@
axes[0].plot(data_pre["times"], data_pre["V_m"])
axes[1].plot(data_astro["times"], data_astro["IP3"])
axes[2].plot(data_post["times"], data_post["I_SIC"])
axes[3].plot(data_astro["times"], data_astro["Ca"])
axes[3].plot(data_astro["times"], data_astro["Ca_astro"])
axes[0].set_title(f"Presynaptic neuron\n(Poisson rate = {poisson_rate_neuro} Hz)")
axes[0].set_ylabel("Membrane potential (mV)")
axes[2].set_title("Postsynaptic neuron")
Expand Down
10 changes: 5 additions & 5 deletions notebooks/notebooks/astrocytes/astrocyte_single.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
},
"outputs": [],
"source": [
"astrocyte = nest.Create(\"astrocyte_lr_1994\", params=params_astro)\nps_astro = nest.Create(\"poisson_generator\", params={\"rate\": poisson_rate})\nmm_astro = nest.Create(\"multimeter\", params={\"record_from\": [\"IP3\", \"Ca\"]})\nnest.Connect(ps_astro, astrocyte, syn_spec={\"weight\": poisson_weight})\nnest.Connect(mm_astro, astrocyte)"
"astrocyte = nest.Create(\"astrocyte_lr_1994\", params=params_astro)\nps_astro = nest.Create(\"poisson_generator\", params={\"rate\": poisson_rate})\nmm_astro = nest.Create(\"multimeter\", params={\"record_from\": [\"IP3\", \"Ca_astro\"]})\nnest.Connect(ps_astro, astrocyte, syn_spec={\"weight\": poisson_weight})\nnest.Connect(mm_astro, astrocyte)"
]
},
{
Expand Down Expand Up @@ -94,15 +94,15 @@
},
"outputs": [],
"source": [
"fig, axes = plt.subplots(2, 1, sharex=True, figsize=(6.4, 4.8), dpi=100)\naxes[0].plot(data[\"times\"], data[\"IP3\"])\naxes[1].plot(data[\"times\"], data[\"Ca\"])\naxes[0].set_ylabel(r\"[IP$_{3}$] ($\\mu$M)\")\naxes[1].set_ylabel(r\"[Ca$^{2+}$] ($\\mu$M)\")\naxes[1].set_xlabel(\"Time (ms)\")\nplt.tight_layout()\nplt.show()\nplt.close()"
"fig, axes = plt.subplots(2, 1, sharex=True, figsize=(6.4, 4.8), dpi=100)\naxes[0].plot(data[\"times\"], data[\"IP3\"])\naxes[1].plot(data[\"times\"], data[\"Ca_astro\"])\naxes[0].set_ylabel(r\"[IP$_{3}$] ($\\mu$M)\")\naxes[1].set_ylabel(r\"[Ca$^{2+}$] ($\\mu$M)\")\naxes[1].set_xlabel(\"Time (ms)\")\nplt.tight_layout()\nplt.show()\nplt.close()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "EBRAINS-23.09",
"display_name": "EBRAINS-24.04",
"language": "python",
"name": "ebrains-23.09"
"name": "ebrains-24.04"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -119,4 +119,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
4 changes: 2 additions & 2 deletions notebooks/notebooks/astrocytes/astrocyte_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@

astrocyte = nest.Create("astrocyte_lr_1994", params=params_astro)
ps_astro = nest.Create("poisson_generator", params={"rate": poisson_rate})
mm_astro = nest.Create("multimeter", params={"record_from": ["IP3", "Ca"]})
mm_astro = nest.Create("multimeter", params={"record_from": ["IP3", "Ca_astro"]})
nest.Connect(ps_astro, astrocyte, syn_spec={"weight": poisson_weight})
nest.Connect(mm_astro, astrocyte)

Expand All @@ -93,7 +93,7 @@

fig, axes = plt.subplots(2, 1, sharex=True, figsize=(6.4, 4.8), dpi=100)
axes[0].plot(data["times"], data["IP3"])
axes[1].plot(data["times"], data["Ca"])
axes[1].plot(data["times"], data["Ca_astro"])
axes[0].set_ylabel(r"[IP$_{3}$] ($\mu$M)")
axes[1].set_ylabel(r"[Ca$^{2+}$] ($\mu$M)")
axes[1].set_xlabel("Time (ms)")
Expand Down
Loading

0 comments on commit fac1a72

Please sign in to comment.