autods_pet.config#

Configuration loading and validation for autods_pet.

Reads an INI file with per-ROI parameters and statistics choices. Any key not provided in the user file falls back to built-in defaults. Uses only stdlib configparser - no external dependencies.

autods_pet.config.default_config()[source]#

Return a deep copy of the built-in default configuration.

Return type:

dict[str, Any]

autods_pet.config.load_config(path=None, *, validate=True)[source]#

Load an INI configuration file and merge it with built-in defaults.

Parameters:
  • path (str | Path | None (default: None)) – Path to an INI file. If None, returns the built-in defaults.

  • validate (bool (default: True)) – When True (default) the merged config is validated and a ValueError is raised on the first problem. Set to False to skip validation - useful when you want to run ConfigValidator yourself to collect all issues.

Returns:

Merged configuration (user values override defaults).

Return type:

dict[str, Any]

autods_pet.config.parse_stat(name)[source]#

Parse a stat name into (kind, param).

Parameters:

name (str) – Stat name such as "mean", "median", "p95".

Returns:

("percentile", 95.0) for "p95", ("mean", None) for "mean", etc.

Return type:

tuple[str, float | None]

Raises:

ValueError – If name is not a recognised statistic.

Examples

>>> from autods_pet.config import parse_stat
>>> parse_stat("mean")
('mean', None)
>>> parse_stat("p95")
('percentile', 95.0)
>>> parse_stat("median")
('median', None)
autods_pet.config.get_roi_config(cfg, roi)[source]#

Return the sub-dict for a single ROI, raising on unknown names.

Return type:

dict[str, Any]

Parameters:
autods_pet.config.get_all_targets(cfg)[source]#

Return a list of all configured target ROIs (named + custom).

Each entry is a dict with at least name, mask_filename, stats. Named targets (focal_lesion, paramedullary, extramedullary) are only included if the user explicitly added the section to the INI file. Custom targets from [targets.*] sections are always included.

Return type:

list[dict[str, Any]]

Parameters:

cfg (dict[str, Any])

class autods_pet.config.ValidationIssue(section, key, level, message)[source]#

Bases: object

A single validation problem found in a configuration.

Parameters:
section: str#
key: str | None#
level: str#
message: str#
class autods_pet.config.ConfigValidator(cfg)[source]#

Bases: object

Collect all validation issues from a merged configuration dict.

Unlike load_config(), which raises on the first error, this class accumulates every problem so that users can fix them all at once.

Parameters:

cfg (dict[str, Any]) – A merged configuration dict (as returned by load_config() with validate=False).

Examples

>>> from autods_pet.config import load_config, ConfigValidator
>>> cfg = load_config("config.ini", validate=False)
>>> v = ConfigValidator(cfg)
>>> v.validate()
>>> if not v.is_valid:
...     for issue in v.errors:
...         print(issue)
issues: list[ValidationIssue]#
property errors: list[ValidationIssue]#

Return only error-level issues.

property warnings: list[ValidationIssue]#

Return only warning-level issues.

property is_valid: bool#

Return True when no errors were found.

validate()[source]#

Run all checks and return the list of issues found.

The same list is also available as issues.

Return type:

list[ValidationIssue]

autods_pet.config.create_default_config(path, profile='standard')[source]#

Write a commented INI template for the given profile.

The generated file can be loaded by load_config() without errors and serves as a starting point for users to customise.

Parameters:
  • path (str | Path) – Destination file path.

  • profile (str (default: 'standard')) – Profile name (one of PROFILE_NAMES).

Returns:

The path that was written.

Return type:

Path

autods_pet.config.resolve_output_dir(cfg)[source]#

Return the resolved output directory from cfg.

Uses cfg["paths"]["output_dir"] when set (absolute or relative to the current working directory), otherwise falls back to CWD / "results".

Return type:

Path

Parameters:

cfg (dict[str, Any])