From 6bc95d23fdb770109c344f0f306cd76d551ad06a Mon Sep 17 00:00:00 2001 From: Gaelle Date: Fri, 6 Oct 2023 12:17:42 +0200 Subject: [PATCH 1/6] doc probe geometry --- .../loading_data/loading_raw_ephys_data.ipynb | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/examples/loading_data/loading_raw_ephys_data.ipynb b/examples/loading_data/loading_raw_ephys_data.ipynb index 3c5b3153d..f8fd8ed37 100644 --- a/examples/loading_data/loading_raw_ephys_data.ipynb +++ b/examples/loading_data/loading_raw_ephys_data.ipynb @@ -326,6 +326,58 @@ "destriped = destripe(raw, fs=sr.fs)" ] }, + { + "cell_type": "markdown", + "source": [ + "## Get the probe geometry" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "markdown", + "source": [ + "### Using the `eid` and `probe` information" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": null, + "outputs": [], + "source": [ + "import brainbox\n", + "channels = brainbox.io.one.load_channel_locations(eid, probe)\n", + "channels[probe][\"localCoordinates\"]" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "markdown", + "source": [ + "### Using the reader and the `.cbin` file" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": null, + "outputs": [], + "source": [ + "sr = spikeglx.Reader(bin_file)\n", + "sr.geometry" + ], + "metadata": { + "collapsed": false + } + }, { "cell_type": "markdown", "id": "9851b10d", From f8b7ad216e18b093f7c16662ed117961a45e7652 Mon Sep 17 00:00:00 2001 From: Gaelle Date: Wed, 18 Oct 2023 15:05:39 +0200 Subject: [PATCH 2/6] raw audio spectrogram example --- .../loading_data/loading_raw_audio_data.ipynb | 168 ++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 examples/loading_data/loading_raw_audio_data.ipynb diff --git a/examples/loading_data/loading_raw_audio_data.ipynb b/examples/loading_data/loading_raw_audio_data.ipynb new file mode 100644 index 000000000..cbd88aa03 --- /dev/null +++ b/examples/loading_data/loading_raw_audio_data.ipynb @@ -0,0 +1,168 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "5683982d", + "metadata": {}, + "source": [ + "# Loading Raw Audio Data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6b2485da", + "metadata": { + "nbsphinx": "hidden" + }, + "outputs": [], + "source": [ + "# Turn off logging, this is a hidden cell on docs page\n", + "import logging\n", + "logger = logging.getLogger('ibllib')\n", + "logger.setLevel(logging.CRITICAL)" + ] + }, + { + "cell_type": "markdown", + "id": "16345774", + "metadata": {}, + "source": [ + "The audio file is saved from the microphone. It is useful to look at it to plot a spectrogram and confirm the sounds played during the task are indeed audible." + ] + }, + { + "cell_type": "markdown", + "id": "8d62c890", + "metadata": {}, + "source": [ + "## Relevant datasets\n", + "* _iblrig_micData.raw.flac\n" + ] + }, + { + "cell_type": "markdown", + "id": "bc23fdf7", + "metadata": {}, + "source": [ + "## Loading" + ] + }, + { + "cell_type": "markdown", + "id": "9103084d", + "metadata": {}, + "source": [ + "### Loading raw audio file" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2b807296", + "metadata": { + "ibl_execute": false + }, + "outputs": [], + "source": [ + "from one.api import ONE\n", + "import soundfile as sf\n", + "\n", + "one = ONE()\n", + "eid = '4ecb5d24-f5cc-402c-be28-9d0f7cb14b3a'\n", + "\n", + "# -- Get raw data\n", + "filename = one.load_dataset(eid, '_iblrig_micData.raw.flac', download_only=True)\n", + "with open(filename, 'rb') as f:\n", + " wav, fs = sf.read(f)" + ] + }, + { + "cell_type": "markdown", + "id": "203d23c1", + "metadata": {}, + "source": [ + "## Plot the spectrogram" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "811e3533", + "metadata": { + "ibl_execute": false + }, + "outputs": [], + "source": [ + "from ibllib.io.extractors.training_audio import welchogram\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "\n", + "# -- Compute spectrogram over first 2 minutes\n", + "t_idx = 120 * fs\n", + "tscale, fscale, W, detect = welchogram(fs, wav[:t_idx])\n", + "\n", + "# -- Put data into single variable\n", + "TF = {}\n", + "\n", + "TF['power'] = W.astype(np.single)\n", + "TF['frequencies'] = fscale[None, :].astype(np.single)\n", + "TF['onset_times'] = detect\n", + "TF['times_mic'] = tscale[:, None].astype(np.single)\n", + "\n", + "# # -- Plot spectrogram\n", + "tlims = TF['times_mic'][[0, -1]].flatten()\n", + "flims = TF['frequencies'][0, [0, -1]].flatten()\n", + "fig = plt.figure(figsize=[16, 7])\n", + "ax = plt.axes()\n", + "im = ax.imshow(20 * np.log10(TF['power'].T), aspect='auto', cmap=plt.get_cmap('magma'),\n", + " extent=np.concatenate((tlims, flims)),\n", + " origin='lower')\n", + "ax.set_xlabel(r'Time (s)')\n", + "ax.set_ylabel(r'Frequency (Hz)')\n", + "plt.colorbar(im)\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "id": "bef6702e", + "metadata": {}, + "source": [ + "## More details\n", + "* [Description of audio datasets](https://docs.google.com/document/d/1OqIqqakPakHXRAwceYLwFY9gOrm8_P62XIfCTnHwstg/edit#heading=h.n61f0vdcplxp)" + ] + }, + { + "cell_type": "markdown", + "id": "4e9dd4b9", + "metadata": {}, + "source": [ + "## Useful modules\n", + "* [ibllib.io.extractors.training_audio](https://int-brain-lab.github.io/iblenv/_autosummary/ibllib.io.extractors.training_audio.html#module-ibllib.io.extractors.training_audio)" + ] + } + ], + "metadata": { + "celltoolbar": "Edit Metadata", + "kernelspec": { + "display_name": "Python [conda env:iblenv] *", + "language": "python", + "name": "conda-env-iblenv-py" + }, + "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.9.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 183a68d7dee9d9e730c137f3090705f0621a1ede Mon Sep 17 00:00:00 2001 From: Gaelle Date: Wed, 18 Oct 2023 15:58:56 +0200 Subject: [PATCH 3/6] fix from brainbox.io.one import load_channel_locations --- examples/loading_data/loading_raw_ephys_data.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/loading_data/loading_raw_ephys_data.ipynb b/examples/loading_data/loading_raw_ephys_data.ipynb index f8fd8ed37..42cfb3517 100644 --- a/examples/loading_data/loading_raw_ephys_data.ipynb +++ b/examples/loading_data/loading_raw_ephys_data.ipynb @@ -349,8 +349,8 @@ "execution_count": null, "outputs": [], "source": [ - "import brainbox\n", - "channels = brainbox.io.one.load_channel_locations(eid, probe)\n", + "from brainbox.io.one import load_channel_locations\n", + "channels = load_channel_locations(eid, probe)\n", "channels[probe][\"localCoordinates\"]" ], "metadata": { From 21233e34177d3863f28167960abebf6011c329b4 Mon Sep 17 00:00:00 2001 From: Mayo Faulkner Date: Thu, 19 Oct 2023 15:09:23 +0100 Subject: [PATCH 4/6] fix the docs --- .../loading_data/loading_raw_ephys_data.ipynb | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/examples/loading_data/loading_raw_ephys_data.ipynb b/examples/loading_data/loading_raw_ephys_data.ipynb index 42cfb3517..9394b675e 100644 --- a/examples/loading_data/loading_raw_ephys_data.ipynb +++ b/examples/loading_data/loading_raw_ephys_data.ipynb @@ -328,55 +328,57 @@ }, { "cell_type": "markdown", + "id": "723df072", + "metadata": {}, "source": [ "## Get the probe geometry" - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "markdown", + "id": "35a0db60", + "metadata": {}, "source": [ "### Using the `eid` and `probe` information" - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "code", "execution_count": null, + "id": "c2335beb", + "metadata": {}, "outputs": [], "source": [ "from brainbox.io.one import load_channel_locations\n", - "channels = load_channel_locations(eid, probe)\n", - "channels[probe][\"localCoordinates\"]" - ], - "metadata": { - "collapsed": false - } + "from one.api import ONE\n", + "import spikeglx\n", + "import numpy as np\n", + "one = ONE()\n", + "\n", + "pid = 'da8dfec1-d265-44e8-84ce-6ae9c109b8bd'\n", + "eid, probe = one.pid2eid(pid)\n", + "channels = load_channel_locations(eid, probe)[probe]\n", + "channel_geometry = np.c_[channels['axial_um'], channels['lateral_um']]" + ] }, { "cell_type": "markdown", + "id": "360f668c", + "metadata": {}, "source": [ "### Using the reader and the `.cbin` file" - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "code", "execution_count": null, + "id": "763d6ac8", + "metadata": {}, "outputs": [], "source": [ "sr = spikeglx.Reader(bin_file)\n", "sr.geometry" - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "markdown", @@ -395,9 +397,9 @@ "metadata": { "celltoolbar": "Edit Metadata", "kernelspec": { - "display_name": "Python [conda env:iblenv] *", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": "conda-env-iblenv-py" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -409,7 +411,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.7" + "version": "3.9.16" } }, "nbformat": 4, From eb41a3157c79c31120926ea65be8d2d41e926df0 Mon Sep 17 00:00:00 2001 From: Gaelle Date: Tue, 24 Oct 2023 12:38:59 +0200 Subject: [PATCH 5/6] doc raw data probe geometry --- .../loading_data/loading_raw_ephys_data.ipynb | 57 +++++++++---------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/examples/loading_data/loading_raw_ephys_data.ipynb b/examples/loading_data/loading_raw_ephys_data.ipynb index 9394b675e..56716f450 100644 --- a/examples/loading_data/loading_raw_ephys_data.ipynb +++ b/examples/loading_data/loading_raw_ephys_data.ipynb @@ -152,7 +152,7 @@ "\n", "# Use spikeglx reader to read in the whole raw data\n", "sr = spikeglx.Reader(bin_file)\n", - "sr.shape\n" + "print(sr.shape)" ] }, { @@ -328,57 +328,56 @@ }, { "cell_type": "markdown", - "id": "723df072", - "metadata": {}, "source": [ "## Get the probe geometry" - ] + ], + "metadata": { + "collapsed": false + } }, { "cell_type": "markdown", - "id": "35a0db60", - "metadata": {}, "source": [ "### Using the `eid` and `probe` information" - ] + ], + "metadata": { + "collapsed": false + } }, { "cell_type": "code", "execution_count": null, - "id": "c2335beb", - "metadata": {}, "outputs": [], "source": [ "from brainbox.io.one import load_channel_locations\n", - "from one.api import ONE\n", - "import spikeglx\n", - "import numpy as np\n", - "one = ONE()\n", - "\n", - "pid = 'da8dfec1-d265-44e8-84ce-6ae9c109b8bd'\n", - "eid, probe = one.pid2eid(pid)\n", - "channels = load_channel_locations(eid, probe)[probe]\n", - "channel_geometry = np.c_[channels['axial_um'], channels['lateral_um']]" - ] + "channels = load_channel_locations(eid, probe)\n", + "channels[probe][\"localCoordinates\"]" + ], + "metadata": { + "collapsed": false + } }, { "cell_type": "markdown", - "id": "360f668c", - "metadata": {}, "source": [ "### Using the reader and the `.cbin` file" - ] + ], + "metadata": { + "collapsed": false + } }, { "cell_type": "code", "execution_count": null, - "id": "763d6ac8", - "metadata": {}, "outputs": [], "source": [ - "sr = spikeglx.Reader(bin_file)\n", + "# You would have loaded the bin file as per the loading example above\n", + "# sr = spikeglx.Reader(bin_file)\n", "sr.geometry" - ] + ], + "metadata": { + "collapsed": false + } }, { "cell_type": "markdown", @@ -397,9 +396,9 @@ "metadata": { "celltoolbar": "Edit Metadata", "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:iblenv] *", "language": "python", - "name": "python3" + "name": "conda-env-iblenv-py" }, "language_info": { "codemirror_mode": { @@ -411,7 +410,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.9.7" } }, "nbformat": 4, From f76e29d0213d8b996faf4794f9a7358cd322199d Mon Sep 17 00:00:00 2001 From: Gaelle Date: Tue, 24 Oct 2023 12:54:36 +0200 Subject: [PATCH 6/6] local coordinates not existing as a key --- examples/loading_data/loading_raw_ephys_data.ipynb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/loading_data/loading_raw_ephys_data.ipynb b/examples/loading_data/loading_raw_ephys_data.ipynb index 56716f450..fbe95d3fb 100644 --- a/examples/loading_data/loading_raw_ephys_data.ipynb +++ b/examples/loading_data/loading_raw_ephys_data.ipynb @@ -351,7 +351,10 @@ "source": [ "from brainbox.io.one import load_channel_locations\n", "channels = load_channel_locations(eid, probe)\n", - "channels[probe][\"localCoordinates\"]" + "print(channels[probe].keys())\n", + "# Use the axial and lateral coordinates ; Print example first 4 channels\n", + "print(channels[probe][\"axial_um\"][0:4])\n", + "print(channels[probe][\"lateral_um\"][0:4])" ], "metadata": { "collapsed": false