-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENH] generate a single report per subject for each action (#231)
* generate single report * add test * fix type * update requirements.txt * use union * rm type annotation
- Loading branch information
Showing
24 changed files
with
300 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ logs | |
# files | ||
*.nii | ||
*.h5 | ||
*.html | ||
*desc-bidsmreye_eyetrack.tsv | ||
pybids_db | ||
tmp.py | ||
|
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
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
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
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
File renamed without changes.
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
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,80 @@ | ||
"""Compile outputs from all tasks, spaces, runs into a single HTML.""" | ||
|
||
import datetime | ||
from pathlib import Path | ||
|
||
from jinja2 import Environment, FileSystemLoader, select_autoescape | ||
|
||
from bidsmreye._version import __version__ | ||
from bidsmreye.logger import bidsmreye_log | ||
|
||
log = bidsmreye_log(name="bidsmreye") | ||
|
||
TEMPLATES_DIR = Path(__file__).parent / "templates" | ||
|
||
|
||
def return_jinja_env(searchpath=None) -> Environment: | ||
if searchpath is None: | ||
searchpath = TEMPLATES_DIR / "report" | ||
return Environment( | ||
loader=FileSystemLoader(searchpath), | ||
autoescape=select_autoescape(), | ||
lstrip_blocks=True, | ||
trim_blocks=True, | ||
) | ||
|
||
|
||
def generate_report(output_dir: Path, subject_label: str, action: str) -> None: | ||
|
||
env = return_jinja_env() | ||
template = env.get_template("base.html") | ||
|
||
if action == "prepare": | ||
input_files = sorted(output_dir.glob(f"sub-{subject_label}/**/*report.html")) | ||
elif action == "generalize": | ||
input_files = sorted(output_dir.glob(f"sub-{subject_label}/**/*eyetrack.html")) | ||
|
||
files = [] | ||
for html_report in input_files: | ||
with open(html_report) as f: | ||
content = f.read() | ||
|
||
name: str = html_report.stem | ||
if action == "prepare": | ||
name = name.replace("_desc-eye_report", "_desc-preproc_bold") | ||
|
||
files.append({"name": name, "content": content, "path": html_report}) | ||
|
||
date = datetime.datetime.now().astimezone().replace(microsecond=0).isoformat() | ||
|
||
report = template.render( | ||
action=action, | ||
files=files, | ||
subject_label=subject_label, | ||
date=date, | ||
version=__version__, | ||
) | ||
|
||
report_filename = ( | ||
output_dir / f"sub-{subject_label}" / f"sub-{subject_label}_{action}.html" | ||
) | ||
|
||
with open(report_filename, "w") as f: | ||
f.write(report) | ||
|
||
log.info(f"Report saved at: '{report_filename}'.") | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
cwd = Path("/home/remi/github/cpp-lln-lab/bidsMReye") | ||
|
||
output_dir = cwd / "outputs" / "moae_fmriprep" / "derivatives" / "bidsmreye" | ||
subject = "01" | ||
|
||
output_dir = Path("/home/remi/gin/CPP/yin/bidsmreye") | ||
subject_label = "02" | ||
|
||
action = "prepare" | ||
|
||
generate_report(output_dir, subject_label, action) |
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,59 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
|
||
<title>bidsmreye report - sub-{{ subject_label }} - {{ action }}</title> | ||
|
||
<link rel="icon" type="image/x-icon" href="https://raw.githubusercontent.com/cpp-lln-lab/bidsMReye/main/docs/source/images/bidsMReye_logo.png"> | ||
|
||
<link | ||
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" | ||
rel="stylesheet" | ||
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" | ||
crossorigin="anonymous" | ||
/> | ||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" | ||
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" | ||
crossorigin="anonymous"> | ||
</script> | ||
|
||
</head> | ||
|
||
<body> | ||
|
||
<header>{% include "header.html" %}</header> | ||
|
||
<main class="container-fluid"> | ||
|
||
<h2 class="mt-5 pt-5">subject {{ subject_label }}: {{ action }}</h2> | ||
|
||
{% for file in files %} | ||
<section id="{{ file.name }}"> | ||
<div class="row pt-4 px-5"> | ||
<h3 class="pt-3">{{ file.name }}</h3> | ||
<div class="rounded-2 {% if action == 'prepare' %} bg-black {% else %} bg-white {% endif %}"> | ||
<div class="m-2 p-2">{{ file.content|safe }}</div> | ||
</div> | ||
</div> | ||
</section> | ||
{% endfor %} | ||
|
||
<section id="about"> | ||
<h2 class="mt-3">About</h2> | ||
<p> | ||
Report generated | ||
<ul> | ||
<li>on: {{ date }}</li> | ||
<li>with bidsmreye {{ version }}</li> | ||
</ul> | ||
</p> | ||
</section> | ||
|
||
</main> | ||
|
||
<footer>{% include "footer.html" %}</footer> | ||
|
||
</body> | ||
</html> |
Oops, something went wrong.