diff --git a/examples/exploring_data/data_download.ipynb b/examples/exploring_data/data_download.ipynb index bfaca800f..48d706d2d 100644 --- a/examples/exploring_data/data_download.ipynb +++ b/examples/exploring_data/data_download.ipynb @@ -37,10 +37,10 @@ "source": [ "## Installation\n", "### Environment\n", - "To use IBL data you will need a python environment with python > 3.8. To create a new environment from scratch you can install [anaconda](https://www.anaconda.com/products/distribution#download-section) and follow the instructions below to create a new python environment (more information can also be found [here](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html))\n", + "To use IBL data you will need a python environment with python > 3.10, although Python 3.12 is recommended. To create a new environment from scratch you can install [anaconda](https://www.anaconda.com/products/distribution#download-section) and follow the instructions below to create a new python environment (more information can also be found [here](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html))\n", "\n", "```\n", - "conda create --name ibl python=3.11\n", + "conda create --name ibl python=3.12\n", "```\n", "Make sure to always activate this environment before installing or working with the IBL data\n", "```\n", @@ -138,9 +138,33 @@ "outputs": [], "source": [ "# Each session is represented by a unique experiment id (eID)\n", - "print(sessions[0])" + "print(sessions[0],)" ] }, + { + "metadata": {}, + "cell_type": "markdown", + "source": [ + "### Find recordings of a specific brain region\n", + "If we are interested in a given brain region, we can use the `search_insertions` method to find all recordings associated with that region. For example, to find all recordings associated with the **Rhomboid Nucleus (RH)** region of the thalamus." + ] + }, + { + "metadata": {}, + "cell_type": "code", + "source": [ + "# this is the query that yields the few recordings for the Rhomboid Nucleus (RH) region\n", + "insertions_rh = one.search_insertions(atlas_acronym='RH', datasets='spikes.times.npy', project='brainwide')\n", + "\n", + "# if we want to extend the search to all thalamic regions, we can do the following\n", + "insertions_th = one.search_insertions(atlas_acronym='TH', datasets='spikes.times.npy', project='brainwide')\n", + "\n", + "# the Allen brain regions parcellation is hierarchical, and searching for Thalamus will return all child Rhomboid Nucleus (RH) regions\n", + "assert set(insertions_rh).issubset(set(insertions_th))\n" + ], + "outputs": [], + "execution_count": null + }, { "cell_type": "markdown", "metadata": {}, @@ -402,9 +426,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.11.9" } }, "nbformat": 4, - "nbformat_minor": 1 + "nbformat_minor": 4 } diff --git a/examples/loading_data/loading_spike_waveforms.ipynb b/examples/loading_data/loading_spike_waveforms.ipynb deleted file mode 100644 index 44b659980..000000000 --- a/examples/loading_data/loading_spike_waveforms.ipynb +++ /dev/null @@ -1,184 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "f73e02ee", - "metadata": {}, - "source": [ - "# Loading Spike Waveforms" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ea70eb4a", - "metadata": { - "nbsphinx": "hidden" - }, - "outputs": [], - "source": [ - "# Turn off logging and disable tqdm this is a hidden cell on docs page\n", - "import logging\n", - "import os\n", - "\n", - "logger = logging.getLogger('ibllib')\n", - "logger.setLevel(logging.CRITICAL)\n", - "\n", - "os.environ[\"TQDM_DISABLE\"] = \"1\"" - ] - }, - { - "cell_type": "markdown", - "id": "64cec921", - "metadata": {}, - "source": [ - "Sample of spike waveforms extracted during spike sorting" - ] - }, - { - "cell_type": "markdown", - "id": "dca47f09", - "metadata": {}, - "source": [ - "## Relevant Alf objects\n", - "* \\_phy_spikes_subset" - ] - }, - { - "cell_type": "markdown", - "id": "eb34d848", - "metadata": {}, - "source": [ - "## Loading" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "c5d32232", - "metadata": {}, - "outputs": [], - "source": [ - "%%capture\n", - "from one.api import ONE\n", - "from brainbox.io.one import SpikeSortingLoader\n", - "from iblatlas.atlas import AllenAtlas\n", - "\n", - "one = ONE()\n", - "ba = AllenAtlas()\n", - "pid = 'da8dfec1-d265-44e8-84ce-6ae9c109b8bd' \n", - "\n", - "# Load in the spikesorting\n", - "sl = SpikeSortingLoader(pid=pid, one=one, atlas=ba)\n", - "spikes, clusters, channels = sl.load_spike_sorting()\n", - "clusters = sl.merge_clusters(spikes, clusters, channels)\n", - "\n", - "# Load the spike waveforms\n", - "spike_wfs = one.load_object(sl.eid, '_phy_spikes_subset', collection=sl.collection)" - ] - }, - { - "cell_type": "markdown", - "id": "327a23e7", - "metadata": {}, - "source": [ - "## More details\n", - "* [Description of datasets](https://docs.google.com/document/d/1OqIqqakPakHXRAwceYLwFY9gOrm8_P62XIfCTnHwstg/edit#heading=h.vcop4lz26gs9)" - ] - }, - { - "cell_type": "markdown", - "id": "257fb8b8", - "metadata": {}, - "source": [ - "## Useful modules\n", - "* COMING SOON" - ] - }, - { - "cell_type": "markdown", - "id": "157bf219", - "metadata": {}, - "source": [ - "## Exploring sample waveforms" - ] - }, - { - "cell_type": "markdown", - "id": "a617f8fb", - "metadata": {}, - "source": [ - "### Example 1: Finding the cluster ID for each sample waveform" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1ac805b6", - "metadata": {}, - "outputs": [], - "source": [ - "# Find the cluster id for each sample waveform\n", - "wf_clusterIDs = spikes['clusters'][spike_wfs['spikes']]" - ] - }, - { - "cell_type": "markdown", - "id": "baf9eb11", - "metadata": {}, - "source": [ - "### Example 2: Compute average waveform for cluster" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3d8a729c", - "metadata": {}, - "outputs": [], - "source": [ - "import numpy as np\n", - "\n", - "# define cluster of interest\n", - "clustID = 2\n", - "\n", - "# Find waveforms for this cluster\n", - "wf_idx = np.where(wf_clusterIDs == clustID)[0]\n", - "wfs = spike_wfs['waveforms'][wf_idx, :, :]\n", - "\n", - "# Compute average waveform on channel with max signal (chn_index 0)\n", - "wf_avg_chn_max = np.mean(wfs[:, :, 0], axis=0)" - ] - }, - { - "cell_type": "markdown", - "id": "a20b24ea", - "metadata": {}, - "source": [ - "## Other relevant examples\n", - "* COMING SOON" - ] - } - ], - "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.11.6" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/examples/loading_data/loading_spikesorting_data.ipynb b/examples/loading_data/loading_spikesorting_data.ipynb index f711414a1..db568215b 100644 --- a/examples/loading_data/loading_spikesorting_data.ipynb +++ b/examples/loading_data/loading_spikesorting_data.ipynb @@ -43,7 +43,8 @@ "## Relevant Alf objects\n", "* channels\n", "* clusters\n", - "* spikes" + "* spikes\n", + "* waveforms" ] }, { @@ -74,9 +75,10 @@ "outputs": [], "source": [ "pid = 'da8dfec1-d265-44e8-84ce-6ae9c109b8bd' \n", - "sl = SpikeSortingLoader(pid=pid, one=one)\n", - "spikes, clusters, channels = sl.load_spike_sorting()\n", - "clusters = sl.merge_clusters(spikes, clusters, channels)" + "ssl = SpikeSortingLoader(pid=pid, one=one)\n", + "spikes, clusters, channels = ssl.load_spike_sorting()\n", + "clusters = ssl.merge_clusters(spikes, clusters, channels)\n", + "waveforms = ssl.load_spike_sorting_object('waveforms') # loads in the template waveforms" ] }, {