-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from rwblair/issue155
Issue155 [WIP]
- Loading branch information
Showing
15 changed files
with
548 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"sub_reports": | ||
[ | ||
{ | ||
"name": "Skull Strippings", | ||
"elements": | ||
[ | ||
{ | ||
"name": "t1_stripped_overlay", | ||
"file_pattern": "t1_stripped_overlay", | ||
"title": "Skull Stripped T1", | ||
"description": "Stripped T1 placed over an image of the unstripped T1" | ||
}, | ||
{ | ||
"name": "sbref_stripped_overlay", | ||
"file_pattern": "sbref_stripped_overlay", | ||
"title": "Skull Stripped Sbref", | ||
"description": "Unwarped and stripped sbref with a background image of an unwarped sbref" | ||
}, | ||
{ | ||
"name": "fmap_magnitude_stripped_overlay", | ||
"file_pattern": "fmap_magnitude_stripped_overlay", | ||
"title": "Skull Stripped Field Map Magnitude", | ||
"description": "Stripped fieldmap magnitude estimated phase-difference image and one or more magnitude images corresponding to two or more gradient echo sequence acquisitions" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "Registration Outputs", | ||
"elements": | ||
[ | ||
{ | ||
"name": "sbref_to_t1", | ||
"file_pattern": "sbref_to_t1", | ||
"title": "Sbref to T1", | ||
"description": "Corrected sbref image registred into t1 space." | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<meta name="generator" content="Docutils 0.12: http://docutils.sourceforge.net/" /> | ||
<title></title> | ||
<style type="text/css"> | ||
</style> | ||
</head> | ||
<body> | ||
|
||
|
||
|
||
{% for sub_report in sub_reports %} | ||
<h2>{{ sub_report.name }}</h2> | ||
{% for elem in sub_report.elements %} | ||
{{ elem.name }} | ||
{% for image in elem.files_contents %} | ||
{{ image }} | ||
{% endfor %} | ||
{% endfor %} | ||
{% endfor %} | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from __future__ import unicode_literals | ||
|
||
import codecs | ||
import json | ||
import re | ||
import os | ||
from os.path import join, exists, basename, dirname | ||
|
||
import jinja2 | ||
from pkg_resources import resource_filename as pkgrf | ||
|
||
class Element(object): | ||
|
||
def __init__(self, name, file_pattern, title, description): | ||
self.name = name | ||
self.file_pattern = re.compile(file_pattern) | ||
self.title = title | ||
self.description = description | ||
self.files = [] | ||
self.files_contents = [] | ||
|
||
|
||
class SubReport(object): | ||
|
||
def __init__(self, name, elements, **kwargs): | ||
self.name = name | ||
self.elements = [] | ||
for e in elements: | ||
element = Element(**e) | ||
self.elements.append(element) | ||
|
||
def generate_sub_report(self, report): | ||
env = jinja2.Environment( | ||
loader=jinja2.FileSystemLoader(searchpath='/'), | ||
trim_blocks=True, lstrip_blocks=True | ||
) | ||
sub_report_tpl = env.get_template('{}_tpl.html'.format(self.name)) | ||
sub_report_render = sub_report_tpl.render | ||
return sub_report_render | ||
|
||
class Report(object): | ||
|
||
def __init__(self, path, config, out_dir, out_filename='report.html'): | ||
self.root = path | ||
self.sub_reports = [] | ||
self._load_config(config) | ||
self.out_dir = out_dir | ||
self.out_filename = out_filename | ||
|
||
def _load_config(self, config): | ||
if isinstance(config, str): | ||
config = json.load(open(config, 'r')) | ||
|
||
for e in config['sub_reports']: | ||
sub_report = SubReport(**e) | ||
self.sub_reports.append(sub_report) | ||
|
||
self.index() | ||
|
||
def index(self): | ||
for root, directories, filenames in os.walk(self.root): | ||
for f in filenames: | ||
f = join(root, f) | ||
for sub_report in self.sub_reports: | ||
for element in sub_report.elements: | ||
if element.file_pattern.search(f) and f.split('.')[-1] == 'svg': | ||
element.files.append(f) | ||
with open(f) as fp: | ||
content = fp.read() | ||
content = '\n'.join(content.split('\n')[1:]) | ||
element.files_contents.append(content) | ||
|
||
def generate_report(self): | ||
searchpath = pkgrf('fmriprep', '/') | ||
env = jinja2.Environment( | ||
loader=jinja2.FileSystemLoader(searchpath=searchpath), | ||
trim_blocks=True, lstrip_blocks=True | ||
) | ||
report_tpl = env.get_template('viz/report.tpl') | ||
report_render = report_tpl.render(sub_reports=self.sub_reports) | ||
with open(os.path.join(self.out_dir, self.out_filename), 'w') as fp: | ||
fp.write(report_render) | ||
return report_render |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from pkg_resources import resource_filename as pkgrf | ||
|
||
from reports import Report | ||
|
||
if __name__ == '__main__': | ||
path = pkgrf('fmriprep', '../out/images/') | ||
out_dir = pkgrf('fmriprep', '../out/') | ||
config = pkgrf('fmriprep', 'viz/config.json') | ||
report = Report(path, config, out_dir) | ||
for sub_report in report.sub_reports: | ||
for element in sub_report.elements: | ||
print(element.files) | ||
print(element.title) | ||
print(report.generate_report()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.