Skip to content

Commit

Permalink
Add execution report (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-luke authored Aug 5, 2021
1 parent 8e212a5 commit a85b010
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
4 changes: 2 additions & 2 deletions fnirsapp_qr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 34 additions & 1 deletion fnirsapp_qr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={}):
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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",
Expand All @@ -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)

0 comments on commit a85b010

Please sign in to comment.