{ "cells": [ { "cell_type": "markdown", "id": "d22a9306", "metadata": {}, "source": [ "# Probes\n", "[](https://colab.research.google.com/github/VirtualBrainLab/urchin-examples/blob/main/basics/probes.ipynb)" ] }, { "cell_type": "markdown", "id": "ac0754d0", "metadata": {}, "source": [ "## Install Urchin\n", "\n", "Urchin is a Python package stored on PyPI, the following code needs to be run the first time you use Urchin in a Python environment. \n", "\n", "Urchin's full documentation can be found [on our website](https://virtualbrainlab.org/urchin/installation_and_use.html)." ] }, { "cell_type": "code", "execution_count": null, "id": "8f04ec05", "metadata": {}, "outputs": [], "source": [ "#Installing urchin\n", "!pip install oursin -U\n", "\n", "# Pandas also required for this tutorial\n", "!pip install pandas" ] }, { "cell_type": "markdown", "id": "d359d23b", "metadata": {}, "source": [ "## Setup Urchin and open the renderer webpage \n", "\n", "By default Urchin opens the 3D renderer in a webpage. Make sure pop-ups are enabled, or the page won't open properly. You can also open the renderer site yourself by replacing [ID here] with the ID that is output by the call to `.setup()` at https://data.virtualbrainlab.org/Urchin/?ID=[ID here]\n", "\n", "Note that Urchin communicates to the renderer webpage through an internet connection, we don't currently support offline use (we hope to add support in the future)." ] }, { "cell_type": "code", "execution_count": 1, "id": "b384b2b7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(URN) connected to server\n", "Login sent with ID: 0d284442, copy this ID into the renderer to connect.\n" ] } ], "source": [ "#Importing necessary libraries:\n", "import oursin as urchin\n", "import pandas as pd\n", "urchin.setup()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Download data\n", "For this tutorial, let's explore the dataset from [Steinmetz et al. 2019](https://www.nature.com/articles/s41586-019-1787-x). We'll get the position of all the insertions and then display them within a 3D mesh of the brain, recreating figure 1h.\n", "\n", "" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Define a quick convenience function for loading data\n", "def get_data(url):\n", " data = url.replace(\"/edit#gid=\", \"/export?format=csv&gid=\")\n", " df = pd.read_csv(data)\n", " return df" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The angles in the original dataset also need to be rotated to match the conventions in Urchin." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "probe_data = get_data('https://docs.google.com/spreadsheets/d/1T-RG3d_MIBXZKmrGmLnsU-O7GmwY09Z0FY6yqbYyZXI/edit#gid=1457359713')\n", "probe_data[\"theta\"] = 90 - probe_data[\"theta\"]\n", "probe_data[\"phi\"] = 270 - probe_data[\"phi\"] " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Data overview\n", "ML, AP, and DV, refer to the coordinates of the tip of the probe along the medial-lateral, anterior-posterior, and dorsal-ventral axes, within the CCF coordinate space. The phi and theta angles correspond to yaw (azimuth) and pitch (elevation) in Urchin." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | session | \n", "ml | \n", "ap | \n", "dv | \n", "phi | \n", "theta | \n", "color | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "1 | \n", "4990.354988 | \n", "4463.941496 | \n", "4907.275550 | \n", "367.040203 | \n", "98.599869 | \n", "#EE204D | \n", "
1 | \n", "1 | \n", "3170.782413 | \n", "8732.329581 | \n", "4900.724878 | \n", "217.514548 | \n", "105.903551 | \n", "#EE204D | \n", "
2 | \n", "2 | \n", "2562.465091 | \n", "7686.413000 | \n", "4851.170969 | \n", "215.946819 | \n", "107.513591 | \n", "#EE204D | \n", "
3 | \n", "2 | \n", "3707.683990 | \n", "9400.993675 | \n", "4086.404032 | \n", "381.000255 | \n", "98.227467 | \n", "#EE204D | \n", "
4 | \n", "3 | \n", "3312.941208 | \n", "8478.681979 | \n", "4061.106429 | \n", "387.548431 | \n", "104.063265 | \n", "#EE204D | \n", "