Source code for thesis.workflows.mrtrix3.config.params

"""MRtrix3 tractography parameter extraction.

Reads parameters from :class:`thesis.core.config.TractographyConfig` (the
MRtrix-specific fields added there) and produces a flat ``TypedDict`` that
the node builders consume.
"""

from typing import Optional, TypedDict

from thesis.core.config import PipelineConfig

DEFAULT_TCKGEN_ALGORITHM = "iFOD2"
DEFAULT_TCKGEN_SELECT = 5000
DEFAULT_TCKGEN_SEEDS = 5_000_000
DEFAULT_TCKGEN_MINLENGTH = 30.0
DEFAULT_TCKGEN_MAXLENGTH = 250.0
DEFAULT_RESPONSE_ALGORITHM = "dhollander"
DEFAULT_FOD_ALGORITHM = "msmt_csd"
DEFAULT_FIVETT_ALGORITHM = "fsl"
DEFAULT_MASK_SOURCE = "fsl_nodif"
DEFAULT_MASK_DILATE_VOXELS = 1
DEFAULT_SEED_STRATEGY = "roi"


[docs] class MRtrix3Params(TypedDict): """Runtime parameters for MRtrix3 tractography nodes.""" tckgen_algorithm: str tckgen_select: int tckgen_seeds: int tckgen_minlength: float tckgen_maxlength: float tckgen_backtrack: bool tckgen_crop_at_gmwmi: bool tckgen_cutoff: Optional[float] response_algorithm: str fod_algorithm: str use_mtnormalise: bool fivett_algorithm: str mask_source: str mask_dilate_voxels: int use_sift2: bool seed_strategy: str gmwmi_apply_roi_filters: bool
[docs] def prepare_mrtrix3_params(config: PipelineConfig) -> MRtrix3Params: """Extract MRtrix3 tractography parameters from the pipeline config. Args: config: Validated pipeline configuration. Returns: Flat dictionary of parameters consumed by MRtrix3 node builders. """ tract_cfg = getattr(config, "tractography", None) return { "tckgen_algorithm": getattr(tract_cfg, "tckgen_algorithm", DEFAULT_TCKGEN_ALGORITHM), "tckgen_select": int(getattr(tract_cfg, "tckgen_select", DEFAULT_TCKGEN_SELECT)), "tckgen_seeds": int(getattr(tract_cfg, "tckgen_seeds", DEFAULT_TCKGEN_SEEDS)), "tckgen_minlength": float(getattr(tract_cfg, "tckgen_minlength", DEFAULT_TCKGEN_MINLENGTH)), "tckgen_maxlength": float(getattr(tract_cfg, "tckgen_maxlength", DEFAULT_TCKGEN_MAXLENGTH)), "tckgen_backtrack": bool(getattr(tract_cfg, "tckgen_backtrack", True)), "tckgen_crop_at_gmwmi": bool(getattr(tract_cfg, "tckgen_crop_at_gmwmi", True)), "tckgen_cutoff": getattr(tract_cfg, "tckgen_cutoff", None), "response_algorithm": getattr(tract_cfg, "response_algorithm", DEFAULT_RESPONSE_ALGORITHM), "fod_algorithm": getattr(tract_cfg, "fod_algorithm", DEFAULT_FOD_ALGORITHM), "use_mtnormalise": bool(getattr(tract_cfg, "use_mtnormalise", True)), "fivett_algorithm": getattr(tract_cfg, "fivett_algorithm", DEFAULT_FIVETT_ALGORITHM), "mask_source": getattr(tract_cfg, "mask_source", DEFAULT_MASK_SOURCE), "mask_dilate_voxels": int( getattr(tract_cfg, "mask_dilate_voxels", DEFAULT_MASK_DILATE_VOXELS) ), "use_sift2": bool(getattr(tract_cfg, "use_sift2", True)), "seed_strategy": getattr(tract_cfg, "seed_strategy", DEFAULT_SEED_STRATEGY), "gmwmi_apply_roi_filters": bool(getattr(tract_cfg, "gmwmi_apply_roi_filters", True)), }