The module fff2.viz.activation_maps provides functions to plot visualization of activation maps in a non-interactive way.
2D cuts of an activation map can be plotted and superimposed on an anatomical map using matplotlib. In addition, Mayavi2 can be used to plot 3D maps, using volumetric rendering. Some emphasis is made on automatic choice of default parameters, such as cut coordinates, to give a sensible view of a map in a purely automatic way, for instance to save a summary of the output of a calculation.
from fff2.viz.activation_maps import plot_map, mni_sform, \
coord_transform
# First, create a fake activation map: a 3D image in MNI space with
# a large rectangle of activation around Brodmann Area 26
import numpy as np
mni_sform_inv = np.linalg.inv(mni_sform)
map = np.zeros((182, 218, 182))
x, y, z = -6, -53, 9
x_map, y_map, z_map = coord_transform(x, y, z, mni_sform_inv)
map[x_map-30:x_map+30, y_map-3:y_map+3, z_map-10:z_map+10] = 1
# And now, visualize it:
plot_map(map, mni_sform, cut_coords=(x, y, z), vmin=0.5)
This creates the following image:
The same plot can be obtained fully automaticaly, by using auto_plot_map() to find the activation threshold vmin and the cut coordinnates:
from fff2.viz.activation_maps import auto_plot_map
auto_plot_map(map, mni_sform)
In this simple example, the code will easily detect the bar as activation and position the cut at the center of the bar.
coord_transform | |
find_activation | |
find_cut_coords | |
plot_map_2d | |
plot_map_3d | |
auto_plot_map | |
plot_niftifile |
In addition to the above functions, callable from Python, there is also script plot_activation that can be used to easily render previews from Nifti files. It can also optionally output an html file, to summarize many maps on one screen.
In its simplest use, it is called like this:
plot_activation file1.nii file2.nii [...]
The plot_activation script has several many options: