Repository navigation
workflow: keep BIDS entities and fix T2w/FLAIR defaing reference #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
3999dcb
b947502
027b721
4ccfb95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,38 @@ | |
| print_warn, | ||
| ) | ||
|
|
||
| def bids_basename( | ||
| entities: dict[str], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indent as other functions. |
||
| ) -> str: | ||
| """ | ||
| Build a BIDS-like file basename from parsed BIDS entities. | ||
|
|
||
| The recognized entities are kept in canonical BIDS order, so that | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplify the description by giving the supported BIDS keys that are returned in this strict order if availalbe (add a note on missing "" values that are ignored). |
||
| input files differing only by entities such as ``acq`` or ``rec`` | ||
| yield distinct derivative names. The ``mod`` and ``modality`` keys | ||
| are ignored: the modality is handled by the callers through the | ||
| file suffix. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| entities : dict[str] | ||
| A dictionary of parsed BIDS entities, as returned by | ||
| :func:`parse_bids_keys`. | ||
|
|
||
| Returns | ||
| ------- | ||
| basename : str | ||
| The BIDS-like basename, e.g. ``sub-01_ses-M00_acq-3DT1_run-01``. | ||
| """ | ||
| order = ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. order -> ordered_keys |
||
| "sub", "ses", "task", "acq", "ce", "rec", "dir", | ||
| "echo", "part", "run", "space", "res", "recording", | ||
| ) | ||
| return "_".join( | ||
| f"{key}-{entities[key]}" | ||
| for key in order | ||
| if key in entities and entities[key] != "" | ||
| ) | ||
|
|
||
| def coerce_to_list( | ||
| value: Any, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,6 +54,7 @@ def brainprep_defacing( | |
| anatomical_file: File, | ||
| output_dir: Directory, | ||
| keep_intermediate: bool = False, | ||
| t1w_run_id: str | None = None, | ||
| **kwargs: dict, | ||
| ) -> Bunch: | ||
| """ | ||
|
|
@@ -82,6 +83,10 @@ def brainprep_defacing( | |
| If True, retains intermediate results (e.g., reoriented image); useful | ||
| for debugging. | ||
| Default False. | ||
| t1w_run_id : str | None | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. t1w_run_id -> t1_run |
||
| Optional run identifier to select a specific defaced T1w image when | ||
| defacing T2w or FLAIR images. Required when multiple T1w images exist | ||
| in the same session. Default None. | ||
| **kwargs : dict | ||
| entities: dict | ||
| Dictionary of parsed BIDS entities. | ||
|
|
@@ -197,10 +202,19 @@ def brainprep_defacing( | |
| "defacemask.nii.gz" | ||
| ) | ||
| ) | ||
| if len(t1_file) != 1 or len(mask_t1_file) != 1: | ||
| if (len(t1_file) > 1 or len(mask_t1_file) > 1): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if t1w_run_id is None: | ||
| raise ValueError( | ||
| f"Multiple T1w defaced images found: {t1_file}, {mask_t1_file}. " | ||
| "Please specify a run identifier run-<t1w_run_id> using the 't1w_run_id' parameter." | ||
| ) | ||
| t1_file = [f for f in t1_file if f"run-{t1w_run_id}_" in str(f)] | ||
| mask_t1_file = [f for f in mask_t1_file if f"run-{t1w_run_id}_" in str(f)] | ||
| if len(t1_file) == 0 or len(mask_t1_file) == 0: | ||
| raise ValueError( | ||
| f"No T1w defaced image found: {t1_file}, {mask_t1_file}" | ||
| ) | ||
|
|
||
| t1_file, mask_t1_file = t1_file[0], mask_t1_file[0] | ||
| print_info(f"using T1w: {t1_file}") | ||
| print_info(f"using defacing mask: {mask_t1_file}") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this function in the PR.