1- {
2- "cells" : [
3- {
4- "cell_type" : " markdown" ,
5- "metadata" : {},
6- "source" : [
7- " # Plotting brain region values on the Swanson flat map"
8- ]
9- },
10- {
11- "cell_type" : " markdown" ,
12- "metadata" : {},
13- "source" : [
14- " The Swanson flatmap is a 2D representation of the mouse brain to facilitate comparative analysis of brain data.\n " ,
15- " We extended the mouse atlas presented by [Hahn et al.](https://onlinelibrary.wiley.com/doi/full/10.1002/cne.24966?casa_token=kRb4fuUae6wAAAAA%3AHoiNx1MNVgZNUXT-MZN_mU6LAjKBiz5OE5cFj2Aj-GUE9l-oBllFUaM11XwCtEbpJyxKrwaMRnXC7MjY)\n " ,
16- " to interface programmatically with the Allen Atlas regions."
17- ]
18- },
19- {
20- "cell_type" : " markdown" ,
21- "metadata" : {},
22- "source" : [
23- " ## The swanson flatmap"
24- ]
25- },
26- {
27- "cell_type" : " code" ,
28- "execution_count" : null ,
29- "metadata" : {
30- "pycharm" : {
31- "name" : " #%%\n "
32- }
33- },
34- "outputs" : [],
35- "source" : [
36- " import numpy as np\n " ,
37- " from ibllib.atlas.flatmaps import plot_swanson\n " ,
38- " from ibllib.atlas import BrainRegions\n " ,
39- " br = BrainRegions()\n " ,
40- " \n " ,
41- " plot_swanson(br=br)\n "
42- ]
43- },
44- {
45- "cell_type" : " markdown" ,
46- "metadata" : {
47- "pycharm" : {
48- "name" : " #%% md\n "
49- }
50- },
51- "source" : [
52- " ## Plotting values on the swanson flatmap\n " ,
53- " \n " ,
54- " ### Simple example with acronyms\n " ,
55- " The flatmap is used when each of the region is assigned a scalar value, displayed on a color scale."
56- ]
57- },
58- {
59- "cell_type" : " code" ,
60- "execution_count" : null ,
61- "metadata" : {
62- "pycharm" : {
63- "name" : " #%%\n "
64- }
65- },
66- "outputs" : [],
67- "source" : [
68- " # prepare array of acronyms\n " ,
69- " acronyms = ['ACAd1', 'ACAv1', 'AId1', 'AIp1', 'AIv1', 'AUDd1', 'AUDp1', 'AUDpo1', 'AUDv1',\n " ,
70- " 'SSp-m1', 'SSp-n1', 'SSp-tr1', 'SSp-ul1', 'SSp-un1', 'SSs1',\n " ,
71- " 'VISC1', 'VISa1', 'VISal1', 'VISam1', 'VISl1', 'VISli1', 'VISp1', 'VISp2/3', 'VISpl1', 'VISpm1',\n " ,
72- " 'SSp-n2/3', 'SSp-tr2/3', 'SSp-ul2/3', 'SSp-un2/3', 'SSs2/3',\n " ,
73- " 'VISC2/3', 'VISa2/3', 'VISal2/3', 'VISam2/3', 'VISl2/3', 'VISli2/3', 'VISp2/3', 'VISpl1', 'VISpl2/3']\n " ,
74- " # assign a scalar to each acronym\n " ,
75- " values = np.arange(len(acronyms))\n " ,
76- " \n " ,
77- " # and display on a single hemishphere, using a blue colormap\n " ,
78- " plot_swanson(acronyms, values, cmap='Blues', br=br)"
79- ]
80- },
81- {
82- "cell_type" : " markdown" ,
83- "metadata" : {
84- "pycharm" : {
85- "name" : " #%% md\n "
86- }
87- },
88- "source" : [
89- " ### Lateralized display\n " ,
90- " A more advanced example is when each hemisphere is assigned a different value."
91- ]
92- },
93- {
94- "cell_type" : " code" ,
95- "execution_count" : null ,
96- "metadata" : {
97- "pycharm" : {
98- "name" : " #%%\n "
99- }
100- },
101- "outputs" : [],
102- "source" : [
103- " # In our atlas convention, differentiating between hemishperes is done using negative indices\n " ,
104- " regions_rl = np.r_[br.acronym2id(acronyms), -br.acronym2id(acronyms)]\n " ,
105- " # assign random values for the sake of this example\n " ,
106- " values_rl = np.random.randn(regions_rl.size)\n " ,
107- " # display with an explicit dual hemisphere setup\n " ,
108- " plot_swanson(regions_rl, values_rl, hemisphere='both', cmap='magma', br=br)\n "
109- ]
110- }
111- ],
112- "metadata" : {
113- "kernelspec" : {
114- "display_name" : " Python 3 (ipykernel)" ,
115- "language" : " python" ,
116- "name" : " python3"
117- },
118- "language_info" : {
119- "codemirror_mode" : {
120- "name" : " ipython" ,
121- "version" : 3
122- },
123- "file_extension" : " .py" ,
124- "mimetype" : " text/x-python" ,
125- "name" : " python" ,
126- "nbconvert_exporter" : " python" ,
127- "pygments_lexer" : " ipython3" ,
128- "version" : " 3.9.7"
129- }
130- },
131- "nbformat" : 4 ,
132- "nbformat_minor" : 1
133- }
1+ {
2+ "cells" : [
3+ {
4+ "cell_type" : " markdown" ,
5+ "metadata" : {},
6+ "source" : [
7+ " # Plotting brain region values on the Swanson flat map"
8+ ]
9+ },
10+ {
11+ "cell_type" : " markdown" ,
12+ "metadata" : {},
13+ "source" : [
14+ " The Swanson flatmap is a 2D representation of the mouse brain to facilitate comparative analysis of brain data.\n " ,
15+ " We extended the mouse atlas presented by [Hahn et al.](https://onlinelibrary.wiley.com/doi/full/10.1002/cne.24966?casa_token=kRb4fuUae6wAAAAA%3AHoiNx1MNVgZNUXT-MZN_mU6LAjKBiz5OE5cFj2Aj-GUE9l-oBllFUaM11XwCtEbpJyxKrwaMRnXC7MjY)\n " ,
16+ " to interface programmatically with the Allen Atlas regions."
17+ ]
18+ },
19+ {
20+ "cell_type" : " markdown" ,
21+ "metadata" : {},
22+ "source" : [
23+ " ## The swanson flatmap"
24+ ]
25+ },
26+ {
27+ "cell_type" : " code" ,
28+ "execution_count" : null ,
29+ "metadata" : {
30+ "pycharm" : {
31+ "name" : " #%%\n "
32+ }
33+ },
34+ "outputs" : [],
35+ "source" : [
36+ " import numpy as np\n " ,
37+ " from ibllib.atlas.flatmaps import plot_swanson\n " ,
38+ " from ibllib.atlas import BrainRegions\n " ,
39+ " br = BrainRegions()\n " ,
40+ " \n " ,
41+ " plot_swanson(br=br, annotate=True)\n "
42+ ]
43+ },
44+ {
45+ "cell_type" : " markdown" ,
46+ "metadata" : {
47+ "pycharm" : {
48+ "name" : " #%% md\n "
49+ }
50+ },
51+ "source" : [
52+ " ## Plotting values on the swanson flatmap\n " ,
53+ " \n " ,
54+ " ### Simple example with acronyms\n " ,
55+ " The flatmap is used when each of the region is assigned a scalar value, displayed on a color scale."
56+ ]
57+ },
58+ {
59+ "cell_type" : " code" ,
60+ "execution_count" : null ,
61+ "metadata" : {
62+ "pycharm" : {
63+ "name" : " #%%\n "
64+ }
65+ },
66+ "outputs" : [],
67+ "source" : [
68+ " # prepare array of acronyms\n " ,
69+ " acronyms = ['ACAd1', 'ACAv1', 'AId1', 'AIp1', 'AIv1', 'AUDd1', 'AUDp1', 'AUDpo1', 'AUDv1',\n " ,
70+ " 'SSp-m1', 'SSp-n1', 'SSp-tr1', 'SSp-ul1', 'SSp-un1', 'SSs1',\n " ,
71+ " 'VISC1', 'VISa1', 'VISal1', 'VISam1', 'VISl1', 'VISli1', 'VISp1', 'VISp2/3', 'VISpl1', 'VISpm1',\n " ,
72+ " 'SSp-n2/3', 'SSp-tr2/3', 'SSp-ul2/3', 'SSp-un2/3', 'SSs2/3',\n " ,
73+ " 'VISC2/3', 'VISa2/3', 'VISal2/3', 'VISam2/3', 'VISl2/3', 'VISli2/3', 'VISp2/3', 'VISpl1', 'VISpl2/3']\n " ,
74+ " # assign a scalar to each acronym\n " ,
75+ " values = np.arange(len(acronyms))\n " ,
76+ " \n " ,
77+ " # and display on a single hemishphere, using a blue colormap\n " ,
78+ " plot_swanson(acronyms, values, cmap='Blues', br=br)"
79+ ]
80+ },
81+ {
82+ "cell_type" : " markdown" ,
83+ "metadata" : {
84+ "pycharm" : {
85+ "name" : " #%% md\n "
86+ }
87+ },
88+ "source" : [
89+ " ### Lateralized display\n " ,
90+ " A more advanced example is when each hemisphere is assigned a different value."
91+ ]
92+ },
93+ {
94+ "cell_type" : " code" ,
95+ "execution_count" : null ,
96+ "metadata" : {
97+ "pycharm" : {
98+ "name" : " #%%\n "
99+ }
100+ },
101+ "outputs" : [],
102+ "source" : [
103+ " # In our atlas convention, differentiating between hemishperes is done using negative indices\n " ,
104+ " regions_rl = np.r_[br.acronym2id(acronyms), -br.acronym2id(acronyms)]\n " ,
105+ " # assign random values for the sake of this example\n " ,
106+ " values_rl = np.random.randn(regions_rl.size)\n " ,
107+ " # display with an explicit dual hemisphere setup\n " ,
108+ " plot_swanson(regions_rl, values_rl, hemisphere='both', cmap='magma', br=br)"
109+ ]
110+ },
111+ {
112+ "cell_type" : " markdown" ,
113+ "source" : [
114+ " One can also mirror the hemishperes and orient the display in portrait mode."
115+ ],
116+ "metadata" : {
117+ "collapsed" : false ,
118+ "pycharm" : {
119+ "name" : " #%% md\n "
120+ }
121+ }
122+ },
123+ {
124+ "cell_type" : " code" ,
125+ "execution_count" : null ,
126+ "outputs" : [],
127+ "source" : [
128+ " import numpy as np\n " ,
129+ " from ibllib.atlas.flatmaps import plot_swanson\n " ,
130+ " from ibllib.atlas import BrainRegions\n " ,
131+ " \n " ,
132+ " br = BrainRegions()\n " ,
133+ " \n " ,
134+ " acronyms = np.array(\n " ,
135+ " ['VPLpc', 'PO', 'LP', 'DG', 'CA1', 'PTLp', 'MRN', 'APN', 'POL',\n " ,
136+ " 'VISam', 'MY', 'PGRNl', 'IRN', 'PARN', 'SPVI', 'NTS', 'SPIV',\n " ,
137+ " 'NOD', 'IP', 'AON', 'ORBl', 'AId', 'MOs', 'GRN', 'P', 'CENT',\n " ,
138+ " 'CUL', 'COApm', 'PA', 'CA2', 'CA3', 'HY', 'ZI', 'MGv', 'LGd',\n " ,
139+ " 'LHA', 'SF', 'TRS', 'PVT', 'LSc', 'ACAv', 'ACAd', 'MDRNv', 'MDRNd',\n " ,
140+ " 'COPY', 'PRM', 'DCO', 'DN', 'SIM', 'MEA', 'SI', 'RT', 'MOp', 'PCG',\n " ,
141+ " 'ICd', 'CS', 'PAG', 'SCdg', 'SCiw', 'VCO', 'ANcr1', 'ENTm', 'ENTl',\n " ,
142+ " 'NOT', 'VPM', 'VAL', 'VPL', 'CP', 'SSp-ul', 'MV', 'VISl', 'LGv',\n " ,
143+ " 'SSp-bfd', 'ANcr2', 'DEC', 'LD', 'SSp-ll', 'V', 'SUT', 'PB', 'CUN',\n " ,
144+ " 'ICc', 'PAA', 'EPv', 'BLAa', 'CEAl', 'GPe', 'PPN', 'SCig', 'SCop',\n " ,
145+ " 'SCsg', 'RSPd', 'RSPagl', 'VISp', 'HPF', 'MGm', 'SGN', 'TTd', 'DP',\n " ,
146+ " 'ILA', 'PL', 'RSPv', 'SSp-n', 'ORBm', 'ORBvl', 'PRNc', 'ACB',\n " ,
147+ " 'SPFp', 'VM', 'SUV', 'OT', 'MA', 'BST', 'LSv', 'LSr', 'UVU',\n " ,
148+ " 'SSp-m', 'LA', 'CM', 'MD', 'SMT', 'PFL', 'MARN', 'PRE', 'POST',\n " ,
149+ " 'PRNr', 'SSp-tr', 'PIR', 'CTXsp', 'RN', 'PSV', 'SUB', 'LDT', 'PAR',\n " ,
150+ " 'SPVO', 'TR', 'VISpm', 'MS', 'COApl', 'BMAp', 'AMd', 'ICe', 'TEa',\n " ,
151+ " 'MOB', 'SNr', 'GU', 'VISC', 'SSs', 'AIp', 'NPC', 'BLAp', 'SPVC',\n " ,
152+ " 'PYR', 'AV', 'EPd', 'NLL', 'AIv', 'CLA', 'AAA', 'AUDv', 'TRN'],\n " ,
153+ " dtype='<U8')\n " ,
154+ " values = np.array([ 7.76948616, 25.51506047, 21.31094194, 23.11353701, 26.18071135,\n " ,
155+ " 16.42116195, 22.4522099 , 20.04564731, 9.98702368, 11.00518771,\n " ,
156+ " 11.23163309, 3.90841049, 11.44982496, 7.49984019, 10.59146742,\n " ,
157+ " 7.68845853, 10.38817938, 6.53187499, 14.22331705, 19.26731921,\n " ,
158+ " 14.6739601 , 10.37711987, 19.87087356, 12.56497513, 11.03204901,\n " ,
159+ " 12.85149192, 10.39367399, 5.26234078, 7.36780286, 7.77672633,\n " ,
160+ " 22.30843636, 9.63356153, 11.33369508, 7.70210975, 14.56984632,\n " ,
161+ " 7.95488849, 9.85956065, 10.40381726, 6.31529234, 7.82651245,\n " ,
162+ " 11.3339313 , 12.26268021, 8.67874273, 8.07579753, 10.14307203,\n " ,
163+ " 10.08081832, 7.88595354, 7.49586605, 12.6491355 , 7.92629876,\n " ,
164+ " 12.52110187, 14.27405322, 25.95808524, 6.52603939, 3.15160563,\n " ,
165+ " 11.60061018, 11.1043498 , 8.0733422 , 11.71522066, 4.62765218,\n " ,
166+ " 7.49833868, 18.78977643, 17.00685931, 6.3841865 , 21.0516987 ,\n " ,
167+ " 13.16635271, 13.32514284, 39.00407907, 10.17439742, 10.71338756,\n " ,
168+ " 12.98324876, 9.36698057, 18.72583288, 8.86341551, 8.59402471,\n " ,
169+ " 14.40309408, 11.2151223 , 8.54318159, 7.27041139, 7.54384726,\n " ,
170+ " 7.12004486, 8.61247715, 6.24836557, 7.61490273, 7.97743213,\n " ,
171+ " 5.90638179, 11.18067752, 9.60402511, 10.27972062, 4.88568098,\n " ,
172+ " 5.15238733, 9.48240265, 5.5200633 , 17.34425384, 20.51738915,\n " ,
173+ " 8.67575586, 10.13415575, 12.55792577, 11.28995505, 12.01846393,\n " ,
174+ " 16.44519718, 11.55540348, 12.6760064 , 14.59124425, 16.08650743,\n " ,
175+ " 5.49252396, 14.21853759, 9.80928243, 11.1998899 , 8.53843453,\n " ,
176+ " 8.95692822, 7.44622149, 9.41208445, 10.00368097, 18.36862111,\n " ,
177+ " 5.90905433, 18.73273459, 10.41462726, 10.38639344, 13.71164211,\n " ,
178+ " 8.1023596 , 7.57087137, 3.95315742, 12.24423806, 10.4316517 ,\n " ,
179+ " 10.75912468, 9.21246988, 21.71756051, 8.55320981, 10.69256597,\n " ,
180+ " 8.20796144, 24.13594074, 4.55095547, 12.43055174, 7.00374928,\n " ,
181+ " 4.72499044, 6.22081559, 6.50700078, 6.73499461, 12.77964412,\n " ,
182+ " 8.8475468 , 11.20443401, 6.59475644, 8.59815892, 7.16696761,\n " ,
183+ " 10.62813483, 7.77992602, 16.02889234, 9.21649532, 7.08618021,\n " ,
184+ " 5.56980282, 3.61976479, 6.86178595, 13.44050831, 11.9525432 ,\n " ,
185+ " 7.21974504, 6.28513041, 6.8381433 , 5.93095918, 8.12844537,\n " ,
186+ " 8.62486916])\n " ,
187+ " \n " ,
188+ " plot_swanson(acronyms=acronyms, values=values, orientation='portrait', cmap='Blues', hemisphere='mirror')"
189+ ],
190+ "metadata" : {
191+ "collapsed" : false ,
192+ "pycharm" : {
193+ "name" : " #%%\n "
194+ }
195+ }
196+ }
197+ ],
198+ "metadata" : {
199+ "kernelspec" : {
200+ "display_name" : " Python 3 (ipykernel)" ,
201+ "language" : " python" ,
202+ "name" : " python3"
203+ },
204+ "language_info" : {
205+ "codemirror_mode" : {
206+ "name" : " ipython" ,
207+ "version" : 3
208+ },
209+ "file_extension" : " .py" ,
210+ "mimetype" : " text/x-python" ,
211+ "name" : " python" ,
212+ "nbconvert_exporter" : " python" ,
213+ "pygments_lexer" : " ipython3" ,
214+ "version" : " 3.9.7"
215+ }
216+ },
217+ "nbformat" : 4 ,
218+ "nbformat_minor" : 1
219+ }
0 commit comments