Plotting brain region values on the Swanson flat map

The Swanson flatmap is a 2D representation of the mouse brain to facilitate comparative analysis of brain data. We extended the mouse atlas presented by Hahn et al. to interface programmatically with the Allen Atlas regions.

The swanson flatmap

import numpy as np
from ibllib.atlas.flatmaps import plot_swanson
from ibllib.atlas import BrainRegions
br = BrainRegions()



Plotting values on the swanson flatmap

Simple example with acronyms

The flatmap is used when each of the region is assigned a scalar value, displayed on a color scale.

# prepare array of acronyms
acronyms = ['ACAd1', 'ACAv1', 'AId1', 'AIp1', 'AIv1', 'AUDd1', 'AUDp1', 'AUDpo1', 'AUDv1',
            'SSp-m1', 'SSp-n1', 'SSp-tr1', 'SSp-ul1', 'SSp-un1', 'SSs1',
            'VISC1', 'VISa1', 'VISal1', 'VISam1', 'VISl1', 'VISli1', 'VISp1', 'VISp2/3', 'VISpl1', 'VISpm1',
            'SSp-n2/3', 'SSp-tr2/3', 'SSp-ul2/3', 'SSp-un2/3', 'SSs2/3',
            'VISC2/3', 'VISa2/3', 'VISal2/3', 'VISam2/3', 'VISl2/3', 'VISli2/3', 'VISp2/3', 'VISpl1', 'VISpl2/3']
# assign a scalar to each acronym
values = np.arange(len(acronyms))

# and display on a single hemishphere, using a blue colormap
plot_swanson(acronyms, values, cmap='Blues', br=br)

Lateralized display

A more advanced example is when each hemisphere is assigned a different value.

# In our atlas convention, differentiating between hemishperes is done using negative indices
regions_rl = np.r_[br.acronym2id(acronyms), -br.acronym2id(acronyms)]
# assign random values for the sake of this example
values_rl = np.random.randn(regions_rl.size)
# display with an explicit dual hemisphere setup
plot_swanson(regions_rl, values_rl, hemisphere='both', cmap='magma', br=br)