Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Render brainsprite htmls for streamline density (and other?) maps #526

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions examples/plot_brainsprite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""
Streamline count viewer
==========================
Generate a brainsprite viewer for a streamline coun map with an anatomical
background, by populating an html template.
"""

from brainsprite import viewer_substitute
import tempita

anat = './callosal_tract_profile/dti_FA.nii.gz'
stat_img = './callosal_tract_profile/afq_AntFrontal_density_map.nii.gz'

bsprite = viewer_substitute(vmin=0, cmap="hot", symmetric_cmap=False,
title="streamline_count")
bsprite.fit(stat_img, bg_img=anat)

template = \
"""
<!DOCTYPE html>
<html lang="en">
<body>
<!-- This is the div that will host the html brainsprite code -->
<div id="div_viewer">
<!-- Note the curly brackets are here to tell tempita to update this element. -->
{{ html }}
</div>

<!-- Import jquery and brainsprite javascript libraries -->
<script src="https://code.jquery.com/jquery-3.5.0.min.js"></script>
<script>
// We'll inject brainsprite.js here, to make the html self-contained.
{{ bsprite }}
</script>

<!-- That's where the js brainsprite code will live -->
<script>
// On load: build all figures
$( window ).on('load',function() {
// Create brain slices
var brain = brainsprite(
// that's where all the brainsprite parameters will be injected.
{{ js }}
);
});
</script>
</body>
</html>
"""

template = tempita.Template(template)

viewer = bsprite.transform(template, javascript='js', html='html', library='bsprite')
output_fname = 'plot_stat_map.html'
viewer.save_as_html(output_fname)

viewer
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,6 @@ fury =
vtk==9.0.1
fury==0.6.0
xvfbwrapper==0.2.9
brainsprite =
brainsprite