utils
tit.pre.qsi.utils ¶
Utility functions for QSI integration.
This module provides path resolution, validation, and helper functions for the QSI Docker-out-of-Docker integration.
resolve_host_project_path ¶
Resolve a container path to the corresponding host path for Docker mounts.
When running inside the SimNIBS container, project directories are mounted at /mnt/$PROJECT_DIR_NAME. However, sibling containers (QSIPrep/QSIRecon) need to mount the original host path, not the container path.
The LOCAL_PROJECT_DIR environment variable contains the host machine's absolute path to the project directory.
Parameters¶
container_path : str Path as seen from inside the SimNIBS container (e.g., /mnt/myproject).
Returns¶
str The corresponding host path for Docker volume mounts.
Raises¶
ValueError If LOCAL_PROJECT_DIR is not set or the path cannot be resolved.
Source code in tit/pre/qsi/utils.py
get_host_project_dir ¶
get_host_project_dir() -> str
Get the host machine's project directory path.
Returns¶
str Absolute path to the project directory on the host machine.
Raises¶
ValueError If LOCAL_PROJECT_DIR is not set.
Source code in tit/pre/qsi/utils.py
check_image_exists ¶
Check if a Docker image exists locally.
Parameters¶
image : str Docker image name (e.g., 'pennlinc/qsiprep'). tag : str Image tag (e.g., '1.1.1').
Returns¶
bool True if the image exists locally.
Source code in tit/pre/qsi/utils.py
pull_image_if_needed ¶
Pull a Docker image if it doesn't exist locally.
Parameters¶
image : str Docker image name. tag : str Image tag. logger : logging.Logger Logger for status messages.
Returns¶
bool True if image is available (either existed or was pulled successfully).
Source code in tit/pre/qsi/utils.py
validate_bids_dwi ¶
Validate that DWI data exists for a subject in BIDS format.
Parameters¶
project_dir : str Path to the BIDS project root. subject_id : str Subject identifier (without 'sub-' prefix). logger : logging.Logger Logger for status messages.
Returns¶
tuple[bool, str | None] (is_valid, error_message). If valid, error_message is None.
Source code in tit/pre/qsi/utils.py
validate_qsiprep_output ¶
Validate that QSIPrep output exists for a subject.
Parameters¶
project_dir : str Path to the project root. subject_id : str Subject identifier.
Returns¶
tuple[bool, str | None] (is_valid, error_message). If valid, error_message is None.
Source code in tit/pre/qsi/utils.py
get_freesurfer_license_path ¶
get_freesurfer_license_path() -> str | None
Get the FreeSurfer license file path.
QSIPrep and QSIRecon require a FreeSurfer license for certain operations. This function checks common locations for the license file.
Returns¶
str | None Path to the license file, or None if not found.
Source code in tit/pre/qsi/utils.py
format_memory_limit ¶
get_container_resource_limits ¶
Return (cpu_limit, mem_limit_bytes) for the current container.
- cpu_limit: integer number of CPUs available via cgroups/cpuset if limited, otherwise None.
- mem_limit_bytes: memory limit in bytes via cgroups if limited, otherwise None.
Source code in tit/pre/qsi/utils.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
get_inherited_dood_resources ¶
Determine DooD resource defaults that match the current container.
Returns (cpus, memory_gb) with conservative rounding.