Sample output
sample_output
#
AnnotatedPathSequence
#
AnnotatedPathSequence(
paths: typing.List[pathlib.Path],
errors: (
typing.List[
imgtools.io.sample_output.FailedToSaveSingleImageError
]
| None
) = None,
)
Bases: list
Custom sequence of paths that behaves like a list but includes an errors attribute.
This class is returned by SampleOutput.call to allow access to any errors that occurred during the save process while still behaving like a regular sequence of paths.
Attributes:
Name | Type | Description |
---|---|---|
errors |
typing.List[imgtools.io.sample_output.FailedToSaveSingleImageError]
|
List of errors that occurred during the save process. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
typing.List[pathlib.Path]
|
List of paths to saved files. |
required |
|
typing.List[imgtools.io.sample_output.FailedToSaveSingleImageError]
|
List of errors that occurred during the save process. |
None
|
Source code in src/imgtools/io/sample_output.py
FailedToSaveSingleImageError
#
SampleOutput
#
Bases: pydantic.BaseModel
Configuration model for saving medical imaging outputs.
This class provides a standardized configuration for saving medical images, supporting various file formats and output organization strategies.
Attributes:
Name | Type | Description |
---|---|---|
directory |
pathlib.Path
|
Directory where output files will be saved. Must exist and be writable. |
filename_format |
str
|
Format string for output filenames with placeholders for metadata values. |
existing_file_mode |
imgtools.io.writers.ExistingFileMode
|
How to handle existing files (FAIL, SKIP, OVERWRITE). |
extra_context |
typing.Dict[str, typing.Any]
|
Additional metadata to include when saving files. |
Examples:
>>> from imgtools.io import SampleOutput
>>> from imgtools.io.writers import ExistingFileMode
>>> output = SampleOutput(
... directory="results/patient_scans",
... filename_format="{PatientID}/{Modality}/{ImageID}.nii.gz",
... existing_file_mode=ExistingFileMode.SKIP,
... )
>>> output(scan_list) # Save all scans in the list
Methods:
Name | Description |
---|---|
default |
Create a default instance of SampleOutput. |
model_post_init |
Initialize the writer after model initialization. |
validate_directory |
Validate that the output directory exists or can be created, and is writable. |
default
classmethod
#
default() -> imgtools.io.sample_output.SampleOutput
Create a default instance of SampleOutput.
Source code in src/imgtools/io/sample_output.py
model_post_init
#
Initialize the writer after model initialization.
Source code in src/imgtools/io/sample_output.py
validate_directory
classmethod
#
Validate that the output directory exists or can be created, and is writable.