Skip to content

REF: generalised anat references 2.0 #477

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

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
47 changes: 47 additions & 0 deletions src/smriprep/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#
"""Self-contained utilities to be used within Function nodes."""

import typing as ty


def apply_lut(in_dseg, lut, newpath=None):
"""Map the input discrete segmentation to a new label set (lookup table, LUT)."""
Expand Down Expand Up @@ -95,3 +97,48 @@ def fs_isRunning(subjects_dir, subject_id, mtime_tol=86400, logger=None):
if logger:
logger.warn(f'Removed "IsRunning*" files found under {subj_dir}')
return subjects_dir


def collect_anat(
subject_data: dict, precomputed: dict, reference_anat: ty.Literal['T1w', 'T2w'] = 'T1w'
):
"""
Collects the anatomical inputs for a given subject and organises the
files and associated information into ``reference`` and ``aux`` keys
to pass to :py:func:`init_anat_fit_wf`

Parameters
----------
subject_data: :obj:`dict`
lists of input data
precomputed: :obj:`dict`
cache of derivative files
reference_anat: :obj:`str`
MR image type (T1w, T2w, etc.) of primary anatomical scan

Returns
-------
anat_inputs: :obj:`dict`
"""
ref_anat = reference_anat.lower()
if ref_anat not in subject_data.keys():
raise FileNotFoundError

anat_inputs = {
modality: {
'data': subject_data[modality],
'n': len(subject_data[modality]),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdyt about

Suggested change
'n': len(subject_data[modality]),
'count': len(subject_data[modality]),

'precomputed': f'{modality}_preproc' in precomputed,
'role': 'reference' if modality.capitalize() == reference_anat else 'aux',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this just be a bool, since if not we will treat as auxillary

Suggested change
'role': 'reference' if modality.capitalize() == reference_anat else 'aux',
'is_ref': modality.capitalize() == reference_anat,

}
for modality in ['t1w', 't2w', 'flair']
if modality in subject_data.keys()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since i believe all keys are in subject_data, this will check if the list is not empty

Suggested change
if modality in subject_data.keys()
if subject_data.get(modality)

}
anat_inputs[reference_anat.lower()].update(
{
f'have_{preproc}': f'{reference_anat.lower()}_{preproc}' in precomputed
for preproc in ['mask', 'tpms', 'dseg']
}
)
Comment on lines +137 to +142
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at this, i wonder if this precomputed parsing would be better suited for a separate function


return anat_inputs
Loading