|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "f199bec2", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# Plotting brain region values on circular flatmap" |
| 9 | + ] |
| 10 | + }, |
| 11 | + { |
| 12 | + "cell_type": "markdown", |
| 13 | + "id": "94c08e66", |
| 14 | + "metadata": {}, |
| 15 | + "source": [ |
| 16 | + "This example walks through various ways to overlay brain region values on a circular flatmap" |
| 17 | + ] |
| 18 | + }, |
| 19 | + { |
| 20 | + "cell_type": "markdown", |
| 21 | + "id": "17fd07ec", |
| 22 | + "metadata": {}, |
| 23 | + "source": [ |
| 24 | + "## The circular flatmap" |
| 25 | + ] |
| 26 | + }, |
| 27 | + { |
| 28 | + "cell_type": "markdown", |
| 29 | + "id": "3ca88864", |
| 30 | + "metadata": {}, |
| 31 | + "source": [ |
| 32 | + "The circular flatmap is obtained by sampling the volume using concentric circles through the brain." |
| 33 | + ] |
| 34 | + }, |
| 35 | + { |
| 36 | + "cell_type": "code", |
| 37 | + "execution_count": null, |
| 38 | + "id": "1178246b", |
| 39 | + "metadata": {}, |
| 40 | + "outputs": [], |
| 41 | + "source": [ |
| 42 | + "from ibllib.atlas import FlatMap\n", |
| 43 | + "flmap_cr = FlatMap(flatmap='circles')" |
| 44 | + ] |
| 45 | + }, |
| 46 | + { |
| 47 | + "cell_type": "code", |
| 48 | + "execution_count": null, |
| 49 | + "id": "490614c3", |
| 50 | + "metadata": {}, |
| 51 | + "outputs": [], |
| 52 | + "source": [ |
| 53 | + "# Display the concentric circles used in flatmap\n", |
| 54 | + "ax = flmap_cr.plot_top(volume='image')\n", |
| 55 | + "ax.plot(flmap_cr.ml_scale * 1e6, flmap_cr.ap_scale * 1e6)" |
| 56 | + ] |
| 57 | + }, |
| 58 | + { |
| 59 | + "cell_type": "markdown", |
| 60 | + "id": "135dd187", |
| 61 | + "metadata": {}, |
| 62 | + "source": [ |
| 63 | + "This results in a flatmap that can be displayed in the following way" |
| 64 | + ] |
| 65 | + }, |
| 66 | + { |
| 67 | + "cell_type": "code", |
| 68 | + "execution_count": null, |
| 69 | + "id": "8b8c4223", |
| 70 | + "metadata": {}, |
| 71 | + "outputs": [], |
| 72 | + "source": [ |
| 73 | + "import matplotlib.pyplot as plt\n", |
| 74 | + "fig, ax = plt.subplots(figsize=(18,4))\n", |
| 75 | + "flmap_cr.plot_flatmap(ax)" |
| 76 | + ] |
| 77 | + }, |
| 78 | + { |
| 79 | + "cell_type": "markdown", |
| 80 | + "id": "ec15f88c", |
| 81 | + "metadata": {}, |
| 82 | + "source": [ |
| 83 | + "It is also possible to display this flatmap such that each circle is stacked on top of eachother. For this, the **pyramid** flatmap should be used" |
| 84 | + ] |
| 85 | + }, |
| 86 | + { |
| 87 | + "cell_type": "code", |
| 88 | + "execution_count": null, |
| 89 | + "id": "7461e3f8", |
| 90 | + "metadata": {}, |
| 91 | + "outputs": [], |
| 92 | + "source": [ |
| 93 | + "# Instantiate flatmap with circles arranged vetically on top of eachother\n", |
| 94 | + "flmap_py = FlatMap(flatmap='pyramid')" |
| 95 | + ] |
| 96 | + }, |
| 97 | + { |
| 98 | + "cell_type": "code", |
| 99 | + "execution_count": null, |
| 100 | + "id": "1f78b2ab", |
| 101 | + "metadata": {}, |
| 102 | + "outputs": [], |
| 103 | + "source": [ |
| 104 | + "fig, ax = plt.subplots(figsize=(8, 8))\n", |
| 105 | + "flmap_py.plot_flatmap(ax=ax)" |
| 106 | + ] |
| 107 | + }, |
| 108 | + { |
| 109 | + "cell_type": "markdown", |
| 110 | + "id": "e7af738a", |
| 111 | + "metadata": {}, |
| 112 | + "source": [ |
| 113 | + "## Data preparation" |
| 114 | + ] |
| 115 | + }, |
| 116 | + { |
| 117 | + "cell_type": "markdown", |
| 118 | + "id": "40fa09d0", |
| 119 | + "metadata": {}, |
| 120 | + "source": [ |
| 121 | + "In order to plot brain regions values on the flatmap an array of acronyms and an array of values corresponding to each acronym must be provided. A detailed overview of how to prepare your data can be found [here](https://int-brain-lab.github.io/iblenv/notebooks_external/atlas_plotting_scalar_on_slice.html#Data-preparation)" |
| 122 | + ] |
| 123 | + }, |
| 124 | + { |
| 125 | + "cell_type": "code", |
| 126 | + "execution_count": null, |
| 127 | + "id": "20a1db83", |
| 128 | + "metadata": {}, |
| 129 | + "outputs": [], |
| 130 | + "source": [ |
| 131 | + "import numpy as np\n", |
| 132 | + "# prepare array of acronyms\n", |
| 133 | + "acronyms = np.array(['VPM', 'PO', 'LP', 'CA1', 'DG-mo', 'VISa5', 'SSs5'])\n", |
| 134 | + "# assign data to each acronym\n", |
| 135 | + "values = np.arange(acronyms.size)" |
| 136 | + ] |
| 137 | + }, |
| 138 | + { |
| 139 | + "cell_type": "code", |
| 140 | + "execution_count": null, |
| 141 | + "id": "e6ae51d0", |
| 142 | + "metadata": {}, |
| 143 | + "outputs": [], |
| 144 | + "source": [ |
| 145 | + "from ibllib.atlas.regions import BrainRegions\n", |
| 146 | + "br = BrainRegions()\n", |
| 147 | + "# prepare array of acronyms with beryl mapping\n", |
| 148 | + "acronyms_beryl = np.unique(br.acronym2acronym(acronyms, mapping='Beryl'))\n", |
| 149 | + "values_beryl = np.arange(acronyms_beryl.size)" |
| 150 | + ] |
| 151 | + }, |
| 152 | + { |
| 153 | + "cell_type": "code", |
| 154 | + "execution_count": null, |
| 155 | + "id": "3724b968", |
| 156 | + "metadata": {}, |
| 157 | + "outputs": [], |
| 158 | + "source": [ |
| 159 | + "# prepare different values for left and right hemipshere for Beryl acronyms\n", |
| 160 | + "values_beryl_lh = np.random.randint(0, 10, acronyms_beryl.size)\n", |
| 161 | + "values_beryl_rh = np.random.randint(0, 10, acronyms_beryl.size)\n", |
| 162 | + "values_beryl_lr = np.c_[values_beryl_lh, values_beryl_rh]" |
| 163 | + ] |
| 164 | + }, |
| 165 | + { |
| 166 | + "cell_type": "markdown", |
| 167 | + "id": "74fe528a", |
| 168 | + "metadata": {}, |
| 169 | + "source": [ |
| 170 | + "## Examples" |
| 171 | + ] |
| 172 | + }, |
| 173 | + { |
| 174 | + "cell_type": "code", |
| 175 | + "execution_count": null, |
| 176 | + "id": "dfa2d623", |
| 177 | + "metadata": {}, |
| 178 | + "outputs": [], |
| 179 | + "source": [ |
| 180 | + "from ibllib.atlas.plots import plot_scalar_on_flatmap\n", |
| 181 | + "# Plot region values on the left hemisphere of circle flatmap overlaid on brain region boundaries using Allen mapping\n", |
| 182 | + "fig, ax = plt.subplots(figsize=(18,4))\n", |
| 183 | + "fig, ax = plot_scalar_on_flatmap(acronyms, values, hemisphere='left', mapping='Allen', flmap_atlas=flmap_cr, ax=ax)" |
| 184 | + ] |
| 185 | + }, |
| 186 | + { |
| 187 | + "cell_type": "code", |
| 188 | + "execution_count": null, |
| 189 | + "id": "cc78a1c7", |
| 190 | + "metadata": {}, |
| 191 | + "outputs": [], |
| 192 | + "source": [ |
| 193 | + "# Plot region values on the both hemispheres of circle flatmap overlaid on the dwi Allen image using Beryl mapping\n", |
| 194 | + "fig, ax = plt.subplots(figsize=(18,4))\n", |
| 195 | + "fig, ax = plot_scalar_on_flatmap(acronyms_beryl, values_beryl, hemisphere='both', mapping='Beryl', background='image', \n", |
| 196 | + " cmap='Reds', flmap_atlas=flmap_cr, ax=ax)" |
| 197 | + ] |
| 198 | + }, |
| 199 | + { |
| 200 | + "cell_type": "code", |
| 201 | + "execution_count": null, |
| 202 | + "id": "37bf7bd8", |
| 203 | + "metadata": {}, |
| 204 | + "outputs": [], |
| 205 | + "source": [ |
| 206 | + "# Plot region values on the right hemisphere of pyramidal flatmap overlaid on the dwi Allen image using Allen mapping\n", |
| 207 | + "fig, ax = plt.subplots(figsize=(8,8))\n", |
| 208 | + "fig, ax = plot_scalar_on_flatmap(acronyms, values, hemisphere='right', mapping='Allen', background='image', \n", |
| 209 | + " cmap='Reds', flmap_atlas=flmap_py, ax=ax)" |
| 210 | + ] |
| 211 | + }, |
| 212 | + { |
| 213 | + "cell_type": "code", |
| 214 | + "execution_count": null, |
| 215 | + "id": "28f7f30c", |
| 216 | + "metadata": {}, |
| 217 | + "outputs": [], |
| 218 | + "source": [ |
| 219 | + "# Plot two column region values on the both hemispheres of pyramidal flatmap overlaid on brain region boundaries \n", |
| 220 | + "# using Beryl mapping\n", |
| 221 | + "fig, ax = plt.subplots(figsize=(8,8))\n", |
| 222 | + "fig, ax = plot_scalar_on_flatmap(acronyms_beryl, values_beryl_lr, hemisphere='both', mapping='Beryl', \n", |
| 223 | + " background='boundary', cmap='Blues', flmap_atlas=flmap_py, ax=ax)" |
| 224 | + ] |
| 225 | + } |
| 226 | + ], |
| 227 | + "metadata": { |
| 228 | + "kernelspec": { |
| 229 | + "display_name": "Python [conda env:iblenv] *", |
| 230 | + "language": "python", |
| 231 | + "name": "conda-env-iblenv-py" |
| 232 | + }, |
| 233 | + "language_info": { |
| 234 | + "codemirror_mode": { |
| 235 | + "name": "ipython", |
| 236 | + "version": 3 |
| 237 | + }, |
| 238 | + "file_extension": ".py", |
| 239 | + "mimetype": "text/x-python", |
| 240 | + "name": "python", |
| 241 | + "nbconvert_exporter": "python", |
| 242 | + "pygments_lexer": "ipython3", |
| 243 | + "version": "3.9.7" |
| 244 | + } |
| 245 | + }, |
| 246 | + "nbformat": 4, |
| 247 | + "nbformat_minor": 5 |
| 248 | +} |
0 commit comments