autods_pet.ops.mask_discovery#
Discover manual lesion masks (NIfTI/NRRD/DICOM SEG) for a patient.
This module is the single source of truth for finding the file (or DICOM segment) that backs each configured target ROI section.
Two complementary lookup mechanisms run in parallel:
DICOM SEG path - recursively walks the patient input directory, filters
.dcmfiles viais_dicom_seg(), keeps only those whoseReferencedSeriesSequenceincludes the patient’s PETSeriesInstanceUID, then matches each segment’sSegmentLabel(case-insensitive) against thesegment_labelkeys configured in the target sections. One SEG file may supply multiple targets.File path - recursively walks for
.nii.gz/.nii/.nrrdfiles whose stem matches one of themask_filenamevalues configured in the target sections.
When a target has both a DICOM SEG match and a file match, DICOM SEG
wins. The walker is bounded by max_depth and skips the global
output_dir (when nested under input_dir) so that previously
written result masks are not rediscovered as inputs.
- class autods_pet.ops.mask_discovery.DiscoveredMask(target_name, path, format, segment_label=None, segment_number=None)[source]#
Bases:
objectA resolved manual mask for a single target ROI.
- Parameters:
- target_name: str#
Config section name (
"focal_lesion","paramedullary","extramedullary", or a customtargets.<name>key).
- autods_pet.ops.mask_discovery.discover_file_masks(input_dir, targets, *, max_depth=4, skip_dirs=None)[source]#
Recursively find NIfTI/NRRD masks for each target by filename stem.
- Parameters:
input_dir (
Path) – Patient input directory to walk recursively.targets (
list[dict[str,Any]]) – Target config entries (fromautods_pet.config.get_all_targets()).max_depth (
int(default:4)) – Maximum recursion depth.skip_dirs (
set[Path] |None(default:None)) – Absolute directories to exclude from the walk (e.g. the globaloutput_dirwhen nested underinput_dir).
- Returns:
Map from target name to the first matching file found.
- Return type:
- autods_pet.ops.mask_discovery.discover_dicom_seg_masks(input_dir, targets, pet_series_uid, *, max_depth=4, skip_dirs=None)[source]#
Recursively find DICOM SEG masks for each target by SegmentLabel.
- Parameters:
input_dir (
Path) – Patient input directory to walk recursively.pet_series_uid (
str|None) – The patient’s PETSeriesInstanceUID. When None the UID match is bypassed (any DICOM SEG is considered) and an informational message is added to the warnings list.max_depth (
int(default:4)) – Maximum recursion depth.skip_dirs (
set[Path] |None(default:None)) – Absolute directories to exclude from the walk.
- Returns:
(matches, info_messages). Info messages capture unmatched-segment notes and “found SEG but UID didn’t match” notes that callers may want to log.- Return type:
- autods_pet.ops.mask_discovery.discover_all_masks(input_dir, targets, pet_series_uid, *, max_depth=4, skip_dirs=None)[source]#
Discover masks for every target via both DICOM SEG and file paths.
DICOM SEG matches override file matches when both formats resolve the same target.
- Returns:
(target_name -> DiscoveredMask, warnings).warningscontains caller-actionable messages: missing-mask warnings (one per target whose section is enabled but no match was found), unmatched-segment notes, and conflict notes when both formats matched the same target.- Return type:
- Parameters: