Skip to content

Commit

Permalink
update mri scanner info
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Feb 7, 2024
1 parent 1ca1add commit 3821bb5
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 292 deletions.
27 changes: 22 additions & 5 deletions bids/ext/reports/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def institution_info(files: list[BIDSFile]):
return ""


def mri_scanner_info(files: list[BIDSFile]):
first_file = files[0]
metadata = first_file.get_metadata()
return templates.mri_scanner_info(metadata)


def common_mri_desc(
img: None | nib.Nifti1Image,
metadata: dict[str, Any],
Expand Down Expand Up @@ -299,17 +305,20 @@ def parse_files(
# Group files into individual runs
data_files = collect_associated_files(layout, data_files, extra_entities=["run"])

# print(data_files)

# Will only get institution from the first file.
# This assumes that ALL files from ALL datatypes
# were acquired in the same institution.
description_list = [institution_info(data_files[0])]

print(description_list)

# %% MRI
mri_datatypes = ["anat", "func", "fmap", "perf", "dwi"]
mri_scanner_info_done = False
for group in data_files:

if not mri_scanner_info_done and group[0].entities["datatype"] in mri_datatypes:
description_list.append(mri_scanner_info(group))
mri_scanner_info_done = True

if group[0].entities["datatype"] == "func":
group_description = func_info(group, config, layout)

Expand All @@ -334,7 +343,15 @@ def parse_files(
] == "phasediff":
group_description = fmap_info(layout, group, config)

elif group[0].entities["datatype"] in [
description_list.append(group_description)

# %% other
for group in data_files:

if group[0].entities["datatype"] in mri_datatypes:
continue

if group[0].entities["datatype"] in [

Check warning on line 354 in bids/ext/reports/parsing.py

View check run for this annotation

Codecov / codecov/patch

bids/ext/reports/parsing.py#L354

Added line #L354 was not covered by tests
"eeg",
"meg",
"pet",
Expand Down
15 changes: 11 additions & 4 deletions bids/ext/reports/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ def render(template_name: str, data: dict[str, Any] | None = None) -> str:
return tmp


def highlight_missing_tags(foo: str) -> str:
def highlight_missing_tags(foo: str, color="cyan") -> str:
"""Highlight missing tags in a rendered template."""
foo = f"[blue]{foo}[/blue]"
foo = foo.replace("{{", "[/blue][red]{{")
foo = foo.replace("}}", "}}[/red][blue]")
foo = f"[{color}]{foo}[/{color}]"
open_del = "{{"
foo = foo.replace("{{", f"[/{color}][red]{open_del}")
close_del = "}}"
foo = foo.replace("}}", f"{close_del}[/red][{color}]")
return foo


Expand All @@ -40,6 +42,11 @@ def footer() -> str:
return f"This section was (in part) generated automatically using pybids {__version__}."


def mri_scanner_info(desc_data: dict[str, Any]) -> str:
"""Generate mri scanner info report."""
return render(template_name="mri_scanner_info.mustache", data=desc_data)


def institution_info(desc_data: dict[str, Any]) -> str:
"""Generate institution report."""
return render(template_name="institution.mustache", data=desc_data)

Check warning on line 52 in bids/ext/reports/templates.py

View check run for this annotation

Codecov / codecov/patch

bids/ext/reports/templates.py#L52

Added line #L52 was not covered by tests
Expand Down
Loading

0 comments on commit 3821bb5

Please sign in to comment.