Skip to content

Commit 37cac32

Browse files
committed
circular flatmap examples
1 parent ca5d424 commit 37cac32

File tree

3 files changed

+83
-33
lines changed

3 files changed

+83
-33
lines changed

examples/atlas/atlas_circular_pyramidal_flatmap.ipynb

Lines changed: 65 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,31 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"id": "3bf392ab",
5+
"id": "f199bec2",
66
"metadata": {},
77
"source": [
88
"# Plotting brain region values on circular flatmap"
99
]
1010
},
1111
{
12-
"cell_type": "code",
13-
"execution_count": null,
14-
"id": "72266ba4",
12+
"cell_type": "markdown",
13+
"id": "94c08e66",
1514
"metadata": {},
16-
"outputs": [],
1715
"source": [
1816
"This example walks through various ways to overlay brain region values on a circular flatmap"
1917
]
2018
},
2119
{
2220
"cell_type": "markdown",
23-
"id": "54faf5f5",
21+
"id": "17fd07ec",
2422
"metadata": {},
2523
"source": [
2624
"## The circular flatmap"
2725
]
2826
},
2927
{
3028
"cell_type": "markdown",
31-
"id": "d5799f85",
29+
"id": "3ca88864",
3230
"metadata": {},
3331
"source": [
3432
"The circular flatmap is obtained by sampling the volume using concentric circles through the brain."
@@ -37,7 +35,7 @@
3735
{
3836
"cell_type": "code",
3937
"execution_count": null,
40-
"id": "110cd0ce",
38+
"id": "1178246b",
4139
"metadata": {},
4240
"outputs": [],
4341
"source": [
@@ -48,7 +46,7 @@
4846
{
4947
"cell_type": "code",
5048
"execution_count": null,
51-
"id": "d7ae44f1",
49+
"id": "490614c3",
5250
"metadata": {},
5351
"outputs": [],
5452
"source": [
@@ -59,7 +57,7 @@
5957
},
6058
{
6159
"cell_type": "markdown",
62-
"id": "037bf3c3",
60+
"id": "135dd187",
6361
"metadata": {},
6462
"source": [
6563
"This results in a flatmap that can be displayed in the following way"
@@ -68,18 +66,18 @@
6866
{
6967
"cell_type": "code",
7068
"execution_count": null,
71-
"id": "965f1ab1",
69+
"id": "8b8c4223",
7270
"metadata": {},
7371
"outputs": [],
7472
"source": [
7573
"import matplotlib.pyplot as plt\n",
76-
"fig, ax = plt.subplots(figsize=(20,4))\n",
74+
"fig, ax = plt.subplots(figsize=(18,4))\n",
7775
"flmap_cr.plot_flatmap(ax)"
7876
]
7977
},
8078
{
8179
"cell_type": "markdown",
82-
"id": "5c4317cf",
80+
"id": "ec15f88c",
8381
"metadata": {},
8482
"source": [
8583
"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"
@@ -88,7 +86,7 @@
8886
{
8987
"cell_type": "code",
9088
"execution_count": null,
91-
"id": "072b12d5",
89+
"id": "7461e3f8",
9290
"metadata": {},
9391
"outputs": [],
9492
"source": [
@@ -99,7 +97,7 @@
9997
{
10098
"cell_type": "code",
10199
"execution_count": null,
102-
"id": "d47484a5",
100+
"id": "1f78b2ab",
103101
"metadata": {},
104102
"outputs": [],
105103
"source": [
@@ -109,15 +107,15 @@
109107
},
110108
{
111109
"cell_type": "markdown",
112-
"id": "60589bee",
110+
"id": "e7af738a",
113111
"metadata": {},
114112
"source": [
115113
"## Data preparation"
116114
]
117115
},
118116
{
119117
"cell_type": "markdown",
120-
"id": "13a160d9",
118+
"id": "40fa09d0",
121119
"metadata": {},
122120
"source": [
123121
"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 [LINK TO PLOTTING SCALAR]"
@@ -126,25 +124,21 @@
126124
{
127125
"cell_type": "code",
128126
"execution_count": null,
129-
"id": "86f3d236",
127+
"id": "20a1db83",
130128
"metadata": {},
131129
"outputs": [],
132130
"source": [
133131
"import numpy as np\n",
134132
"# prepare array of acronyms\n",
135-
"acronyms = np.array(['ACAd1', 'ACAv1', 'AId1', 'AIp1', 'AIv1', 'AUDd1', 'AUDp1','AUDpo1', 'AUDv1', \n",
136-
" 'SSp-m1', 'SSp-n1', 'SSp-tr1', 'SSp-ul1','SSp-un1', 'SSs1', \n",
137-
" 'VISC1', 'VISa1', 'VISal1', 'VISam1', 'VISl1', 'VISli1', 'VISp1', 'VISp2/3', 'VISpl1', 'VISpm1', \n",
138-
" 'SSp-n2/3', 'SSp-tr2/3', 'SSp-ul2/3', 'SSp-un2/3', 'SSs2/3',\n",
139-
" 'VISC2/3', 'VISa2/3', 'VISal2/3', 'VISam2/3', 'VISl2/3','VISli2/3', 'VISp2/3', 'VISpl1', 'VISpl2/3'])\n",
133+
"acronyms = np.array(['VPM', 'PO', 'LP', 'CA1', 'DG-mo', 'VISa5', 'SSs5'])\n",
140134
"# assign data to each acronym\n",
141135
"values = np.arange(acronyms.size)"
142136
]
143137
},
144138
{
145139
"cell_type": "code",
146140
"execution_count": null,
147-
"id": "3f7aec63",
141+
"id": "e6ae51d0",
148142
"metadata": {},
149143
"outputs": [],
150144
"source": [
@@ -158,7 +152,7 @@
158152
{
159153
"cell_type": "code",
160154
"execution_count": null,
161-
"id": "fa067a5f",
155+
"id": "3724b968",
162156
"metadata": {},
163157
"outputs": [],
164158
"source": [
@@ -170,7 +164,7 @@
170164
},
171165
{
172166
"cell_type": "markdown",
173-
"id": "14f4b521",
167+
"id": "74fe528a",
174168
"metadata": {},
175169
"source": [
176170
"## Examples"
@@ -179,11 +173,54 @@
179173
{
180174
"cell_type": "code",
181175
"execution_count": null,
182-
"id": "58f4162e",
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",
183216
"metadata": {},
184217
"outputs": [],
185218
"source": [
186-
"from ibllib.atlas"
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)"
187224
]
188225
}
189226
],

ibllib/atlas/plots.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def reorder_data(acronyms, values, brain_regions=None):
3939
:param brain_regions: BrainRegions object
4040
:return: ordered array of acronyms and values
4141
"""
42-
# TODO test
42+
4343
br = brain_regions or BrainRegions()
4444
atlas_id = br.acronym2id(acronyms, hemisphere='right')
4545
all_ids = br.id[br.order][:br.n_lr + 1]
@@ -228,10 +228,12 @@ def plot_scalar_on_flatmap(regions, values, depth=0, flatmap='dorsal_cortex', ma
228228
vmax=clevels[1], ax=ax)
229229
ba.plot_flatmap(d_idx, volume='boundary', mapping=map, ax=ax, cmap=cmap_bound, vmin=0.01, vmax=0.8)
230230

231-
if hemisphere == 'left':
232-
ax.set_xlim(0, np.ceil(ba.flatmap.shape[1] / 2))
233-
elif hemisphere == 'right':
234-
ax.set_xlim(np.ceil(ba.flatmap.shape[1] / 2), ba.flatmap.shape[1])
231+
# For circle flatmap we don't want to cut the axis
232+
if ba.name != 'circles':
233+
if hemisphere == 'left':
234+
ax.set_xlim(0, np.ceil(ba.flatmap.shape[1] / 2))
235+
elif hemisphere == 'right':
236+
ax.set_xlim(np.ceil(ba.flatmap.shape[1] / 2), ba.flatmap.shape[1])
235237

236238
return fig, ax
237239

ibllib/atlas/regions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ def __init__(self):
5959
self.mappings = {k: mappings[k].to_numpy() for k in mappings}
6060
self.n_lr = int((len(self.id) - 1) / 2)
6161

62+
def _compute_order(self):
63+
"""
64+
Compute the order of regions, per region order by left hemisphere and then right hemisphere
65+
:return:
66+
"""
67+
orders = np.zeros_like(self.id)
68+
# Left hemisphere first
69+
orders[1::2] = np.arange(self.n_lr) + self.n_lr + 1
70+
# Then right hemisphere
71+
orders[2::2] = np.arange(self.n_lr) + 1
72+
6273
def _compute_mappings(self):
6374
"""
6475
Recomputes the mapping indices for all mappings

0 commit comments

Comments
 (0)