From f539ecf1a34f65d0fe4ecc7f55d840375e4e0d3f Mon Sep 17 00:00:00 2001 From: Oliver Ruebel Date: Thu, 24 Oct 2019 18:37:31 -0700 Subject: [PATCH 1/2] Fix #9 Update example to show how we can query for specific ids --- .../icephys_meta_simple_example.ipynb | 358 +++++++++++++++++- 1 file changed, 337 insertions(+), 21 deletions(-) diff --git a/src/pynwb/examples/icephys_meta_simple_example.ipynb b/src/pynwb/examples/icephys_meta_simple_example.ipynb index ec6cb42..fce1967 100644 --- a/src/pynwb/examples/icephys_meta_simple_example.ipynb +++ b/src/pynwb/examples/icephys_meta_simple_example.ipynb @@ -140,7 +140,7 @@ "### Add an intracelluar recording\n", "Add a intracellular recording consisting of and electrode, stimulus, and reponse. A recording may optionally also consist of just an electrode and stimulus or electrode and response, but at least one of stimulus or response are required. Optionally, the user may set the ``id`` field for the recording. If the ``id`` is omitted then PyNWB will automatically number recordings in sequences (i.e., id is the same as the row number).\n", "\n", - "**Note:** The IntracellularRecordings table is optional and will be created automatically by ICEphysFile the first time the able is being modified. \n", + "**Note:** The IntracellularRecordings table is optional and will be created automatically by ICEphysFile the first time the table is being modified. \n", "\n", "**Note:** If the given electrode, stimulus, or response are not part of the nwbfile object, then they will be automatically added to it here" ] @@ -157,6 +157,36 @@ " id=10)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Note** The IntracellularRecordigns, Sweeps, SweepSequences, Runs and Conditions tables all enforce unique ids when adding rows. I.e., adding an intracellular recording with the same id results in an error, e.g.,:" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ValueError raised with message: 'id 10 already in the table' \n" + ] + } + ], + "source": [ + "try:\n", + " nwbfile.add_intracellular_recording(electrode=electrode,\n", + " stimulus=stimulus,\n", + " response=response,\n", + " id=10)\n", + "except ValueError as e:\n", + " print(\"ValueError raised with message: '%s' \" % str(e))" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -167,13 +197,31 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "nwbfile.add_ic_sweep(recordings=[0], id=12)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Note** The `recordings`` argument is the list of indicies of the rows in our intracellular recordings table that we want to references. The indices are determined by the order in which added the elements to the table. \n", + "\n", + "If we don't know the row indicies, but only the id's of the intracellular recordings that we want to reference, then we can search for the id's as follows:" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "row_indicies = (nwbfile.intracellular_recordings.id == [12,])" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -184,7 +232,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -201,7 +249,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -218,7 +266,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -234,7 +282,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -253,7 +301,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -313,7 +361,7 @@ "10 elec0 pynwb.icephys.IntracellularElectrode at ... " ] }, - "execution_count": 11, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -324,7 +372,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -370,7 +418,7 @@ "12 [(10, (0, 5, ccss pynwb.icephys.CurrentClampSt..." ] }, - "execution_count": 12, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -381,7 +429,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -427,7 +475,7 @@ "15 [(12, [(10, (0, 5, ccss pynwb.icephys.CurrentC..." ] }, - "execution_count": 13, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -438,7 +486,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -484,7 +532,7 @@ "17 [(15, [(12, [(10, (0, 5, ccss pynwb.icephys.Cu..." ] }, - "execution_count": 14, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -495,7 +543,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -550,7 +598,7 @@ "21 [(17, [(15, [(12, [(10, (0, 5, ccss pynwb.icep... 3" ] }, - "execution_count": 15, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -570,7 +618,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -582,7 +630,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -602,9 +650,263 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
stimulusresponseelectrode
id
10(0, 5, ccss pynwb.icephys.CurrentClampStimulus...(0, 5, vcs pynwb.icephys.VoltageClampSeries at...elec0 pynwb.icephys.IntracellularElectrode at ...
\n", + "
" + ], + "text/plain": [ + " stimulus \\\n", + "id \n", + "10 (0, 5, ccss pynwb.icephys.CurrentClampStimulus... \n", + "\n", + " response \\\n", + "id \n", + "10 (0, 5, vcs pynwb.icephys.VoltageClampSeries at... \n", + "\n", + " electrode \n", + "id \n", + "10 elec0 pynwb.icephys.IntracellularElectrode at ... " + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
recordings
id
12[(10, [0, 5, ccss pynwb.icephys.CurrentClampSt...
\n", + "
" + ], + "text/plain": [ + " recordings\n", + "id \n", + "12 [(10, [0, 5, ccss pynwb.icephys.CurrentClampSt..." + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sweeps
id
15[(12, [(10, (0, 5, ccss pynwb.icephys.CurrentC...
\n", + "
" + ], + "text/plain": [ + " sweeps\n", + "id \n", + "15 [(12, [(10, (0, 5, ccss pynwb.icephys.CurrentC..." + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sweep_sequences
id
17[(15, [(12, [(10, (0, 5, ccss pynwb.icephys.Cu...
\n", + "
" + ], + "text/plain": [ + " sweep_sequences\n", + "id \n", + "17 [(15, [(12, [(10, (0, 5, ccss pynwb.icephys.Cu..." + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
runstag
id
19[(17, [(15, [(12, [(10, (0, 5, ccss pynwb.icep...0
21[(17, [(15, [(12, [(10, (0, 5, ccss pynwb.icep...3
\n", + "
" + ], + "text/plain": [ + " runs tag\n", + "id \n", + "19 [(17, [(15, [(12, [(10, (0, 5, ccss pynwb.icep... 0\n", + "21 [(17, [(15, [(12, [(10, (0, 5, ccss pynwb.icep... 3" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "# Read the data back in\n", "with NWBHDF5IO(testpath, 'r') as io:\n", @@ -636,9 +938,23 @@ " assert np.all(infile.ic_conditions['runs'].target.data[:] == nwbfile.ic_conditions['runs'].target.data[:])\n", " assert np.all(infile.ic_conditions['runs'] .data[:] == nwbfile.ic_conditions['runs'].data[:])\n", " assert infile.ic_conditions['runs'].target.table.name == nwbfile.ic_conditions['runs'].target.table.name \n", - " assert np.all(infile.ic_conditions['tag'][:] == nwbfile.ic_conditions['tag'][:])" + " assert np.all(infile.ic_conditions['tag'][:] == nwbfile.ic_conditions['tag'][:])\n", + " \n", + " # Show all the tables for visual validation\n", + " display(infile.intracellular_recordings.to_dataframe())\n", + " display(infile.ic_sweeps.to_dataframe())\n", + " display(infile.ic_sweep_sequences.to_dataframe())\n", + " display(infile.ic_runs.to_dataframe())\n", + " display(infile.ic_conditions.to_dataframe())" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, From ac6e2506be5c753c7b977a50a27b674c84e0bab8 Mon Sep 17 00:00:00 2001 From: Oliver Ruebel Date: Thu, 24 Oct 2019 18:45:55 -0700 Subject: [PATCH 2/2] Clarify comments in notebook --- .../icephys_meta_simple_example.ipynb | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/pynwb/examples/icephys_meta_simple_example.ipynb b/src/pynwb/examples/icephys_meta_simple_example.ipynb index fce1967..33c2cb1 100644 --- a/src/pynwb/examples/icephys_meta_simple_example.ipynb +++ b/src/pynwb/examples/icephys_meta_simple_example.ipynb @@ -138,11 +138,7 @@ "metadata": {}, "source": [ "### Add an intracelluar recording\n", - "Add a intracellular recording consisting of and electrode, stimulus, and reponse. A recording may optionally also consist of just an electrode and stimulus or electrode and response, but at least one of stimulus or response are required. Optionally, the user may set the ``id`` field for the recording. If the ``id`` is omitted then PyNWB will automatically number recordings in sequences (i.e., id is the same as the row number).\n", - "\n", - "**Note:** The IntracellularRecordings table is optional and will be created automatically by ICEphysFile the first time the table is being modified. \n", - "\n", - "**Note:** If the given electrode, stimulus, or response are not part of the nwbfile object, then they will be automatically added to it here" + "Add a intracellular recording consisting of and electrode, stimulus, and reponse. Optionally, the user may set the ``id`` field for the recording. " ] }, { @@ -161,6 +157,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ + "**Note:** A recording may optionally also consist of just an electrode and stimulus or electrode and response, but at least one of stimulus or response are required.\n", + "\n", + "**Note:** If the ``id`` is omitted then PyNWB will automatically number recordings in sequences (i.e., id is the same as the row number).\n", + "\n", + "**Note:** The IntracellularRecordings table is optional and will be created automatically by ICEphysFile the first time the table is being modified. \n", + "\n", + "**Note:** If the given electrode, stimulus, or response are not part of the nwbfile object, then they will be automatically added to it here.\n", + "\n", "**Note** The IntracellularRecordigns, Sweeps, SweepSequences, Runs and Conditions tables all enforce unique ids when adding rows. I.e., adding an intracellular recording with the same id results in an error, e.g.,:" ] }, @@ -208,7 +212,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**Note** The `recordings`` argument is the list of indicies of the rows in our intracellular recordings table that we want to references. The indices are determined by the order in which added the elements to the table. \n", + "**Note** The `recordings`` argument is the list of indicies of the rows in our intracellular recordings table that we want to reference. The indices are determined by the order in which added the elements to the table. \n", "\n", "If we don't know the row indicies, but only the id's of the intracellular recordings that we want to reference, then we can search for the id's as follows:" ] @@ -217,9 +221,25 @@ "cell_type": "code", "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0]\n" + ] + } + ], + "source": [ + "row_indicies = (nwbfile.intracellular_recordings.id == [10,])\n", + "print(row_indicies)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, "source": [ - "row_indicies = (nwbfile.intracellular_recordings.id == [12,])" + "**Note:** The same is true for our other tables as well, i.e., referencing is done by indices of rows (NOT ids). If we only know ids we can search for them in the same manner on the other tables as well, e.g,. ```nwbfile.sweeps == 15```. In the search we can use a list of integer ids or a single it. " ] }, {