From 640103f0193969c9c9013284ee6900630d61b457 Mon Sep 17 00:00:00 2001 From: Michael Deistler Date: Thu, 21 Nov 2024 16:13:53 +0100 Subject: [PATCH] Fixup in tutorial on synapse indexing (#526) * Fixup in tutorial on synapse indexing * Remove jx.utils.swc from docs --- docs/reference/jaxley.utils.rst | 2 - docs/tutorials/09_advanced_indexing.ipynb | 341 +++++++++------------- mkdocs/docs/reference/utils.md | 1 - 3 files changed, 145 insertions(+), 199 deletions(-) diff --git a/docs/reference/jaxley.utils.rst b/docs/reference/jaxley.utils.rst index cbe7df69..67e1f55c 100644 --- a/docs/reference/jaxley.utils.rst +++ b/docs/reference/jaxley.utils.rst @@ -4,8 +4,6 @@ Utils :members: .. automodule:: jaxley.utils.plot_utils :members: -.. automodule:: jaxley.utils.swc - :members: .. automodule:: jaxley.utils.jax_utils :members: .. automodule:: jaxley.utils.syn_utils diff --git a/docs/tutorials/09_advanced_indexing.ipynb b/docs/tutorials/09_advanced_indexing.ipynb index 1314137b..d9144b21 100644 --- a/docs/tutorials/09_advanced_indexing.ipynb +++ b/docs/tutorials/09_advanced_indexing.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "273681a2", + "id": "1710a74b", "metadata": {}, "source": [ "# Customizing synaptic parameters" @@ -10,7 +10,7 @@ }, { "cell_type": "markdown", - "id": "8fc65919", + "id": "1597ec00", "metadata": {}, "source": [ "In this tutorial, you will learn how to:\n", @@ -43,7 +43,7 @@ }, { "cell_type": "markdown", - "id": "3fbb3088", + "id": "fd9a49de", "metadata": {}, "source": [ "In a [previous tutorial](https://jaxley.readthedocs.io/en/latest/tutorials/02_small_network.html) you learned how to set parameters of a `jx.Network`. In that tutorial, we briefly mentioned the `select()` method which allowed to set individual synapses to particular values. In this tutorial, we will go into detail in how you can fully customize your `Jaxley` simulation.\n", @@ -54,7 +54,7 @@ { "cell_type": "code", "execution_count": 1, - "id": "30ebd3be", + "id": "78266a05", "metadata": { "tags": [] }, @@ -68,7 +68,7 @@ }, { "cell_type": "markdown", - "id": "f2c5eeb0", + "id": "22d63dcf", "metadata": {}, "source": [ "### Preface: Building the network\n", @@ -79,7 +79,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "615db52b", + "id": "4603896e", "metadata": { "tags": [] }, @@ -97,7 +97,7 @@ }, { "cell_type": "markdown", - "id": "c9a7159b", + "id": "396be7bd", "metadata": {}, "source": [ "### Setting individual synapse parameters\n", @@ -108,7 +108,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "312ee464", + "id": "15604d2e", "metadata": { "tags": [] }, @@ -134,255 +134,204 @@ " \n", " \n", " \n", - " pre_locs\n", - " post_locs\n", - " pre_branch_index\n", - " post_branch_index\n", - " pre_cell_index\n", - " post_cell_index\n", + " global_edge_index\n", + " pre_global_comp_index\n", + " post_global_comp_index\n", " type\n", " type_ind\n", - " global_pre_comp_index\n", - " global_post_comp_index\n", - " global_pre_branch_index\n", - " global_post_branch_index\n", + " pre_locs\n", + " post_locs\n", " IonotropicSynapse_gS\n", " IonotropicSynapse_e_syn\n", " IonotropicSynapse_k_minus\n", " IonotropicSynapse_s\n", + " controlled_by_param\n", " \n", " \n", " \n", " \n", " 0\n", - " 0.25\n", - " 0.75\n", " 0\n", - " 1\n", " 0\n", - " 3\n", + " 13\n", " IonotropicSynapse\n", " 0\n", - " 0\n", - " 15\n", - " 0\n", - " 7\n", + " 0.25\n", + " 0.75\n", " 0.0001\n", " 0.0\n", " 0.025\n", " 0.2\n", + " 0\n", " \n", " \n", " 1\n", - " 0.25\n", - " 0.25\n", - " 0\n", " 1\n", " 0\n", - " 4\n", + " 19\n", " IonotropicSynapse\n", " 0\n", - " 0\n", - " 18\n", - " 0\n", - " 9\n", + " 0.25\n", + " 0.75\n", " 0.0001\n", " 0.0\n", " 0.025\n", " 0.2\n", + " 0\n", " \n", " \n", " 2\n", - " 0.25\n", - " 0.75\n", - " 0\n", - " 1\n", + " 2\n", " 0\n", - " 5\n", + " 20\n", " IonotropicSynapse\n", " 0\n", - " 0\n", - " 23\n", - " 0\n", - " 11\n", + " 0.25\n", + " 0.25\n", " 0.0001\n", " 0.0\n", " 0.025\n", " 0.2\n", + " 0\n", " \n", " \n", " 3\n", - " 0.25\n", - " 0.75\n", - " 0\n", - " 0\n", - " 1\n", " 3\n", + " 4\n", + " 12\n", " IonotropicSynapse\n", " 0\n", - " 4\n", - " 13\n", - " 2\n", - " 6\n", + " 0.25\n", + " 0.25\n", " 0.0001\n", " 0.0\n", " 0.025\n", " 0.2\n", + " 0\n", " \n", " \n", " 4\n", - " 0.25\n", - " 0.75\n", - " 0\n", - " 0\n", - " 1\n", " 4\n", + " 4\n", + " 16\n", " IonotropicSynapse\n", " 0\n", - " 4\n", - " 17\n", - " 2\n", - " 8\n", + " 0.25\n", + " 0.25\n", " 0.0001\n", " 0.0\n", " 0.025\n", " 0.2\n", + " 0\n", " \n", " \n", " 5\n", - " 0.25\n", - " 0.75\n", - " 0\n", - " 1\n", - " 1\n", " 5\n", + " 4\n", + " 21\n", " IonotropicSynapse\n", " 0\n", - " 4\n", - " 23\n", - " 2\n", - " 11\n", + " 0.25\n", + " 0.75\n", " 0.0001\n", " 0.0\n", " 0.025\n", " 0.2\n", + " 0\n", " \n", " \n", " 6\n", - " 0.25\n", - " 0.25\n", - " 0\n", - " 0\n", - " 2\n", - " 3\n", + " 6\n", + " 8\n", + " 13\n", " IonotropicSynapse\n", " 0\n", - " 8\n", - " 12\n", - " 4\n", - " 6\n", + " 0.25\n", + " 0.75\n", " 0.0001\n", " 0.0\n", " 0.025\n", " 0.2\n", + " 0\n", " \n", " \n", " 7\n", - " 0.25\n", - " 0.25\n", - " 0\n", - " 0\n", - " 2\n", - " 4\n", + " 7\n", + " 8\n", + " 17\n", " IonotropicSynapse\n", " 0\n", - " 8\n", - " 16\n", - " 4\n", - " 8\n", + " 0.25\n", + " 0.75\n", " 0.0001\n", " 0.0\n", " 0.025\n", " 0.2\n", + " 0\n", " \n", " \n", " 8\n", - " 0.25\n", - " 0.75\n", - " 0\n", - " 1\n", - " 2\n", - " 5\n", + " 8\n", + " 8\n", + " 21\n", " IonotropicSynapse\n", " 0\n", - " 8\n", - " 23\n", - " 4\n", - " 11\n", + " 0.25\n", + " 0.75\n", " 0.0001\n", " 0.0\n", " 0.025\n", " 0.2\n", + " 0\n", " \n", " \n", "\n", "" ], "text/plain": [ - " pre_locs post_locs pre_branch_index post_branch_index pre_cell_index \\\n", - "0 0.25 0.75 0 1 0 \n", - "1 0.25 0.25 0 1 0 \n", - "2 0.25 0.75 0 1 0 \n", - "3 0.25 0.75 0 0 1 \n", - "4 0.25 0.75 0 0 1 \n", - "5 0.25 0.75 0 1 1 \n", - "6 0.25 0.25 0 0 2 \n", - "7 0.25 0.25 0 0 2 \n", - "8 0.25 0.75 0 1 2 \n", + " global_edge_index pre_global_comp_index post_global_comp_index \\\n", + "0 0 0 13 \n", + "1 1 0 19 \n", + "2 2 0 20 \n", + "3 3 4 12 \n", + "4 4 4 16 \n", + "5 5 4 21 \n", + "6 6 8 13 \n", + "7 7 8 17 \n", + "8 8 8 21 \n", "\n", - " post_cell_index type type_ind global_pre_comp_index \\\n", - "0 3 IonotropicSynapse 0 0 \n", - "1 4 IonotropicSynapse 0 0 \n", - "2 5 IonotropicSynapse 0 0 \n", - "3 3 IonotropicSynapse 0 4 \n", - "4 4 IonotropicSynapse 0 4 \n", - "5 5 IonotropicSynapse 0 4 \n", - "6 3 IonotropicSynapse 0 8 \n", - "7 4 IonotropicSynapse 0 8 \n", - "8 5 IonotropicSynapse 0 8 \n", + " type type_ind pre_locs post_locs IonotropicSynapse_gS \\\n", + "0 IonotropicSynapse 0 0.25 0.75 0.0001 \n", + "1 IonotropicSynapse 0 0.25 0.75 0.0001 \n", + "2 IonotropicSynapse 0 0.25 0.25 0.0001 \n", + "3 IonotropicSynapse 0 0.25 0.25 0.0001 \n", + "4 IonotropicSynapse 0 0.25 0.25 0.0001 \n", + "5 IonotropicSynapse 0 0.25 0.75 0.0001 \n", + "6 IonotropicSynapse 0 0.25 0.75 0.0001 \n", + "7 IonotropicSynapse 0 0.25 0.75 0.0001 \n", + "8 IonotropicSynapse 0 0.25 0.75 0.0001 \n", "\n", - " global_post_comp_index global_pre_branch_index global_post_branch_index \\\n", - "0 15 0 7 \n", - "1 18 0 9 \n", - "2 23 0 11 \n", - "3 13 2 6 \n", - "4 17 2 8 \n", - "5 23 2 11 \n", - "6 12 4 6 \n", - "7 16 4 8 \n", - "8 23 4 11 \n", + " IonotropicSynapse_e_syn IonotropicSynapse_k_minus IonotropicSynapse_s \\\n", + "0 0.0 0.025 0.2 \n", + "1 0.0 0.025 0.2 \n", + "2 0.0 0.025 0.2 \n", + "3 0.0 0.025 0.2 \n", + "4 0.0 0.025 0.2 \n", + "5 0.0 0.025 0.2 \n", + "6 0.0 0.025 0.2 \n", + "7 0.0 0.025 0.2 \n", + "8 0.0 0.025 0.2 \n", "\n", - " IonotropicSynapse_gS IonotropicSynapse_e_syn IonotropicSynapse_k_minus \\\n", - "0 0.0001 0.0 0.025 \n", - "1 0.0001 0.0 0.025 \n", - "2 0.0001 0.0 0.025 \n", - "3 0.0001 0.0 0.025 \n", - "4 0.0001 0.0 0.025 \n", - "5 0.0001 0.0 0.025 \n", - "6 0.0001 0.0 0.025 \n", - "7 0.0001 0.0 0.025 \n", - "8 0.0001 0.0 0.025 \n", - "\n", - " IonotropicSynapse_s \n", - "0 0.2 \n", - "1 0.2 \n", - "2 0.2 \n", - "3 0.2 \n", - "4 0.2 \n", - "5 0.2 \n", - "6 0.2 \n", - "7 0.2 \n", - "8 0.2 " + " controlled_by_param \n", + "0 0 \n", + "1 0 \n", + "2 0 \n", + "3 0 \n", + "4 0 \n", + "5 0 \n", + "6 0 \n", + "7 0 \n", + "8 0 " ] }, "execution_count": 3, @@ -396,7 +345,7 @@ }, { "cell_type": "markdown", - "id": "485dd830", + "id": "c35637f5", "metadata": {}, "source": [ "This table has nine rows, each corresponding to one synapse. This makes sense because we fully connected three neurons (0, 1, 2) to three other neurons (3, 4, 5), giving a total of `3x3=9` synapses.\n", @@ -407,7 +356,7 @@ { "cell_type": "code", "execution_count": 4, - "id": "034247a0", + "id": "9cfd34e6", "metadata": {}, "outputs": [], "source": [ @@ -416,7 +365,7 @@ }, { "cell_type": "markdown", - "id": "c87be6d5", + "id": "ba4ed5b8", "metadata": {}, "source": [ "Above, we are modifying the synapses with indices `[3, 4, 5]` (i.e., the indices of the `net.edges` DataFrame). The resulting values are indeed changed:" @@ -425,7 +374,7 @@ { "cell_type": "code", "execution_count": 5, - "id": "bcfcce14", + "id": "cf2902aa", "metadata": {}, "outputs": [ { @@ -454,7 +403,7 @@ }, { "cell_type": "markdown", - "id": "86d940c7", + "id": "194124de", "metadata": {}, "source": [ "### Example 1: Setting synaptic parameters which connect particular neurons" @@ -462,7 +411,7 @@ }, { "cell_type": "markdown", - "id": "11cea815", + "id": "0aea923c", "metadata": {}, "source": [ "This is great, but setting synaptic parameters just by their index can be exhausting, in particular in very large networks. Instead, we would want to, for example, set the maximal conductance of all synapses that connect from cell 0 or 1 to any other neuron.\n", @@ -473,7 +422,7 @@ { "cell_type": "code", "execution_count": 6, - "id": "c3292eb9", + "id": "6d3ce515", "metadata": {}, "outputs": [], "source": [ @@ -489,7 +438,7 @@ { "cell_type": "code", "execution_count": 7, - "id": "ddc9f60d", + "id": "bcd60d95", "metadata": {}, "outputs": [ { @@ -518,7 +467,7 @@ }, { "cell_type": "markdown", - "id": "6370f460", + "id": "4eab6004", "metadata": {}, "source": [ "Indeed, the first six synapses now have the value `0.23`! Let's look at the individual lines to understand how this worked:" @@ -526,7 +475,7 @@ }, { "cell_type": "markdown", - "id": "c3159220", + "id": "a05bfa60", "metadata": {}, "source": [ "We want to set parameter by cell index. However, by default, the pre- or post-synaptic cell-indices are not listed in `net.edges`. We can add the cell index to the `.edges` dataframe by calling `.copy_node_property_to_edges()`:\n", @@ -537,7 +486,7 @@ }, { "cell_type": "markdown", - "id": "2c19dea8", + "id": "09572528", "metadata": {}, "source": [ "After this, the pre- and post-synaptic cell indices are listed in `net.edges` as `pre_global_cell_index` and `post_global_cell_index`." @@ -545,7 +494,7 @@ }, { "cell_type": "markdown", - "id": "1a5ebcc5", + "id": "4c710e44", "metadata": {}, "source": [ "Next, we take `.edges`, which is a [pandas DataFrame](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html):\n", @@ -556,7 +505,7 @@ }, { "cell_type": "markdown", - "id": "5524765c", + "id": "24c7f242", "metadata": {}, "source": [ "We then modify this DataFrame to only contain those rows where the global cell index is in 0 or 1:\n", @@ -567,10 +516,10 @@ }, { "cell_type": "markdown", - "id": "9ed887d8", + "id": "0c0ee839", "metadata": {}, "source": [ - "For the above step, you use any column of the DataFrame to filter it (you can see all columns with `df.columns`). Note that, while we used `.query()` here, you can really filter the pandas DataFrame however you want. For example, the `query` above is identical to `df = df[df[\"global_pre_cell_index\"].isin([0, 1])]`.\n", + "For the above step, you use any column of the DataFrame to filter it (you can see all columns with `df.columns`). Note that, while we used `.query()` here, you can really filter the pandas DataFrame however you want. For example, the `query` above is identical to `df = df[df[\"pre_global_cell_index\"].isin([0, 1])]`.\n", "\n", "Finally, we use the `.select()` method, which returns a subset of the `Network` at the specified indices. This subset of the network can be modified with `.set()`:\n", "```python\n", @@ -580,7 +529,7 @@ }, { "cell_type": "markdown", - "id": "58e30f27", + "id": "7a2db8c6", "metadata": {}, "source": [ "### Example 2: Setting parameters given pre- and post-synaptic cell indices" @@ -588,7 +537,7 @@ }, { "cell_type": "markdown", - "id": "6970798d", + "id": "33a79f6d", "metadata": {}, "source": [ "Say you want to select all synapses that have cells 1 or 2 as presynaptic neuron and cell 4 or 5 as postsynaptic neuron." @@ -597,7 +546,7 @@ { "cell_type": "code", "execution_count": 8, - "id": "377807ba", + "id": "343a5bb6", "metadata": {}, "outputs": [], "source": [ @@ -607,7 +556,7 @@ }, { "cell_type": "markdown", - "id": "5933a3b9", + "id": "9bd83ab7", "metadata": {}, "source": [ "Just like before, we can simply use `.query()` as already shown above. However, this time, call `.query()` to twice to filter by pre- and post-synaptic cell indices:" @@ -616,7 +565,7 @@ { "cell_type": "code", "execution_count": 9, - "id": "c03923d9", + "id": "34855241", "metadata": {}, "outputs": [], "source": [ @@ -631,7 +580,7 @@ { "cell_type": "code", "execution_count": 10, - "id": "76000c26", + "id": "58514a0f", "metadata": {}, "outputs": [ { @@ -660,7 +609,7 @@ }, { "cell_type": "markdown", - "id": "a047a9ae", + "id": "9fa849be", "metadata": {}, "source": [ "### Example 3: Applying this strategy to cell level parameters" @@ -668,7 +617,7 @@ }, { "cell_type": "markdown", - "id": "7ec67cf1", + "id": "fe6be17f", "metadata": {}, "source": [ "You had previously seen that you can modify parameters with, e.g., `net.cell(0).set(...)`. However, if you need more flexibility than this, you can also use the above strategy to modify cell-level parameters:" @@ -677,7 +626,7 @@ { "cell_type": "code", "execution_count": 11, - "id": "ed9101e0", + "id": "5945b258", "metadata": {}, "outputs": [], "source": [ @@ -691,7 +640,7 @@ }, { "cell_type": "markdown", - "id": "8c9fbf3e", + "id": "ea91ca1e", "metadata": {}, "source": [ "### Example 4: Flexibly setting parameters based on their `groups`" @@ -699,7 +648,7 @@ }, { "cell_type": "markdown", - "id": "a89376bb", + "id": "b8785888", "metadata": {}, "source": [ "If you are using groups, as shown in [this tutorial](https://jaxley.readthedocs.io/en/latest/tutorials/06_groups.html), then you can also use this for querying synapses. To demonstrate this, let's create a group of excitatory neurons (e.g., cells 0, 3, 5):" @@ -708,7 +657,7 @@ { "cell_type": "code", "execution_count": 12, - "id": "33e5bb5d", + "id": "073c2612", "metadata": {}, "outputs": [], "source": [ @@ -721,7 +670,7 @@ }, { "cell_type": "markdown", - "id": "2a362d8f", + "id": "57b9343a", "metadata": {}, "source": [ "Now, say we want all synapses that start from these excitatory neurons. You can do this as follows:" @@ -730,7 +679,7 @@ { "cell_type": "code", "execution_count": 13, - "id": "8ea9e21a", + "id": "6be209b1", "metadata": {}, "outputs": [], "source": [ @@ -746,7 +695,7 @@ }, { "cell_type": "markdown", - "id": "d3c0c2a3", + "id": "3fd67f11", "metadata": {}, "source": [ "### Example 5: Setting synaptic parameters based on properties of the presynaptic cell" @@ -754,7 +703,7 @@ }, { "cell_type": "markdown", - "id": "c4b1d18c", + "id": "223b04e2", "metadata": {}, "source": [ "Let's discuss one more example: Imagine we only want to modify those synapses whose presynaptic compartment has a sodium channel. Let's first add a sodium channel to some of the cells:" @@ -763,7 +712,7 @@ { "cell_type": "code", "execution_count": 14, - "id": "8bd15f6a", + "id": "ff757547", "metadata": {}, "outputs": [], "source": [ @@ -776,7 +725,7 @@ }, { "cell_type": "markdown", - "id": "42c4a577", + "id": "1481d591", "metadata": {}, "source": [ "Now, let us query which cells have the desired synapses:" @@ -785,7 +734,7 @@ { "cell_type": "code", "execution_count": 15, - "id": "1352bf55", + "id": "84520493", "metadata": {}, "outputs": [], "source": [ @@ -796,7 +745,7 @@ }, { "cell_type": "markdown", - "id": "a359edcd", + "id": "e22b558c", "metadata": {}, "source": [ "`indices_of_sodium_compartments` lists all compartments which contained sodium:" @@ -805,7 +754,7 @@ { "cell_type": "code", "execution_count": 16, - "id": "7d04f731", + "id": "b8f35873", "metadata": {}, "outputs": [ { @@ -822,7 +771,7 @@ }, { "cell_type": "markdown", - "id": "3ba3092b", + "id": "40274381", "metadata": {}, "source": [ "Then, we can proceed as always and filter for the global pre-synaptic **compartment** index:" @@ -830,20 +779,20 @@ }, { "cell_type": "code", - "execution_count": 17, - "id": "9a818fc3", + "execution_count": 18, + "id": "bda373bc", "metadata": {}, "outputs": [], "source": [ "df = net.edges\n", - "df = df.query(f\"global_pre_comp_index in {indices_of_sodium_compartments}\")\n", + "df = df.query(f\"pre_global_comp_index in {indices_of_sodium_compartments}\")\n", "net.select(edges=df.index).set(\"IonotropicSynapse_gS\", 0.6)" ] }, { "cell_type": "code", - "execution_count": 18, - "id": "04f2f9ae", + "execution_count": 19, + "id": "c1fcf3dc", "metadata": {}, "outputs": [ { @@ -861,7 +810,7 @@ "Name: IonotropicSynapse_gS, dtype: float64" ] }, - "execution_count": 18, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -872,7 +821,7 @@ }, { "cell_type": "markdown", - "id": "492c6f3b", + "id": "f111f537", "metadata": {}, "source": [ "Indeed, only synapses coming from the first neuron were modified (as its presynaptic compartment contained sodium), in contrast to synapses from neuron 2 (whose presynaptic compartment did not)." @@ -880,7 +829,7 @@ }, { "cell_type": "markdown", - "id": "f3fe95d2", + "id": "b7872d80", "metadata": {}, "source": [ "### Summary\n", diff --git a/mkdocs/docs/reference/utils.md b/mkdocs/docs/reference/utils.md index 141ccca1..f54f8da0 100644 --- a/mkdocs/docs/reference/utils.md +++ b/mkdocs/docs/reference/utils.md @@ -1,5 +1,4 @@ ::: jaxley.utils.cell_utils ::: jaxley.utils.plot_utils -::: jaxley.utils.swc ::: jaxley.utils.jax_utils ::: jaxley.utils.syn_utils \ No newline at end of file