diff --git a/fnirsapp_qr.json b/fnirsapp_qr.json index ce3d4c6..f78dc33 100644 --- a/fnirsapp_qr.json +++ b/fnirsapp_qr.json @@ -2,11 +2,11 @@ "name": "fNIRS Apps: Quality Reports", "description": "Generate quality reports for fNIRS data", "author": "Robert Luke", - "tool-version": "v0.3.1", + "tool-version": "v0.3.2", "schema-version": "0.5", "command-line": "/run.py [InputDataset] [OutputLocation] [SubjectLabel] [SessionLabel] [TaskLabel] [SCIThreshold] [PeakPowerThreshold]", "container-image": { - "image": "ghcr.io/rob-luke/fnirs-apps-quality-reports/app:v0.3.1", + "image": "ghcr.io/rob-luke/fnirs-apps-quality-reports/app:v0.3.2", "index": "ghcr.io", "type": "docker", "entrypoint": true diff --git a/fnirsapp_qr.py b/fnirsapp_qr.py index 45bf3df..f75f92d 100755 --- a/fnirsapp_qr.py +++ b/fnirsapp_qr.py @@ -15,10 +15,15 @@ import os import subprocess from mne.utils import logger +from pathlib import Path +from datetime import datetime +import json +import hashlib +from pprint import pprint matplotlib.use('agg') -__version__ = "v0.3.1" +__version__ = "v0.3.2" def fnirsapp_qr(command, env={}): @@ -74,6 +79,19 @@ def fnirsapp_qr(command, env={}): f'{__version__}') args = parser.parse_args() +def create_report(app_name=None, pargs=None): + + exec_rep = dict() + exec_rep["ExecutionStart"] = datetime.now().isoformat() + exec_rep["ApplicationName"] = app_name + exec_rep["ApplicationVersion"] = __version__ + exec_rep["Arguments"] = vars(pargs) + + return exec_rep + +exec_files = dict() +exec_rep =create_report(app_name="fNIRS-Apps: Quality Reports", pargs=args) + mne.set_log_level("INFO") logger.info("\n") @@ -263,11 +281,16 @@ def run_report(path, path_out): for ses in sess: logger.info(f"Processing: sub-{sub}/ses-{ses}/task-{task}") + exec_files[f"sub-{sub}_ses-{ses}_task-{task}"] = dict() + in_path = BIDSPath(subject=sub, task=task, session=ses, root=f"{args.input_datasets}", datatype="nirs", suffix="nirs", extension=".snirf") + exec_files[f"sub-{sub}_ses-{ses}_task-{task}"]["FileName"] = str(in_path.fpath) + exec_files[f"sub-{sub}_ses-{ses}_task-{task}"]["FileHash"] = hashlib.md5(open(in_path.fpath, 'rb').read()).hexdigest() + out_path = BIDSPath(subject=sub, task=task, session=ses, root=f"{args.output_location}", datatype="nirs", suffix="qualityReport", @@ -279,3 +302,13 @@ def run_report(path, path_out): run_report(in_path, out_path) else: logger.info(f" No file exists: {in_path}") + +exec_rep["Files"] = exec_files +exec_path = f"{args.input_datasets}/execution" +exec_rep["ExecutionEnd"] = datetime.now().isoformat() + +Path(exec_path).mkdir(parents=True, exist_ok=True) +with open(f"{exec_path}/{exec_rep['ExecutionStart'].replace(':', '-')}-quality_reports.json", "w") as fp: + json.dump(exec_rep, fp) + +pprint(exec_rep)