Skip to content

Commit

Permalink
[FIX] handle exceptions for QC at group level when participants are m…
Browse files Browse the repository at this point in the history
…issing QC data (#217)

* handle qc at the group level when subject level qc is missing

* fix printed str
  • Loading branch information
Remi-Gau authored Aug 5, 2024
1 parent 3e570df commit 89f18ea
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
11 changes: 10 additions & 1 deletion bidsmreye/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def collect_group_qc_data(cfg: Config) -> pd.DataFrame | None:
with open(file) as f:
data = json.loads(f.read())

print(data)

df = pd.json_normalize(data)
df["filename"] = Path(file).name
df["subject"] = entities["subject"]
Expand All @@ -87,7 +89,14 @@ def collect_group_qc_data(cfg: Config) -> pd.DataFrame | None:
"eye1XVar",
"eye1YVar",
]
qc_data = qc_data[cols]
try:
qc_data = qc_data[cols]
except KeyError:
log.error(
f"""Sidecar files seem to be missing the keys: {cols}.
To fix try to run the qc at the participant level first."""
)
return None

return qc_data

Expand Down
26 changes: 26 additions & 0 deletions tests/test_visualize.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import json
import shutil

import pandas as pd
Expand Down Expand Up @@ -32,6 +33,31 @@ def test_group_report(tmp_path, data_dir):
assert (target_dir / "group_eyetrack.tsv").exists()


def test_group_report_missing_qc(tmp_path, data_dir):
"""Regression test for https://github.com/cpp-lln-lab/bidsMReye/issues/171 ."""
src_dir = data_dir / "derivatives" / "bidsmreye"
target_dir = tmp_path / "bidsmreye"
target_dir.mkdir()
shutil.copytree(src_dir, target_dir, dirs_exist_ok=True)

file_to_modify = (
target_dir
/ "sub-9001"
/ "ses-1"
/ "func"
/ "sub-9001_ses-1_task-rest_desc-bidsmreye_eyetrack.json"
)

with open(file_to_modify, "w") as f:
json.dump({"SamplingFrequency": 0.14285714285714285}, f)

cfg = Config(input_dir=target_dir, output_dir=target_dir.parent, subjects=["9001"])

group_report(cfg)

assert not (target_dir / "group_eyetrack.html").exists()


def test_group_report_cli(tmp_path, data_dir):

src_dir = data_dir / "derivatives" / "bidsmreye"
Expand Down

0 comments on commit 89f18ea

Please sign in to comment.