Creation (pymia.data.creation
package)¶
Callback (pymia.data.creation.callback
module)¶
- class pymia.data.creation.callback.Callback[source]¶
Bases:
object
Base class for the interaction with the dataset creation.
Implementations of the
Callback
class can be provided toTraverser.traverse()
in order to write/process specific information of the original data.- on_end(params: dict)[source]¶
Called at the end of
Traverser.traverse()
.- Parameters
params (dict) – Parameters provided by the
Traverser
. The provided parameters will differ fromCallback.on_subject()
.
- on_start(params: dict)[source]¶
Called at the beginning of
Traverser.traverse()
.- Parameters
params (dict) – Parameters provided by the
Traverser
. The provided parameters will differ fromCallback.on_subject()
.
- on_subject(params: dict)[source]¶
Called for each subject of
Traverser.traverse()
.- Parameters
params (dict) – Parameters provided by the
Traverser
containing subject specific information and data.
- class pymia.data.creation.callback.ComposeCallback(callbacks: List[pymia.data.creation.callback.Callback])[source]¶
Bases:
pymia.data.creation.callback.Callback
Composes many
Callback
instances and behaves like an singleCallback
instance.This class allows passing multiple
Callback
toTraverser.traverse()
.- Parameters
callbacks (list) – A list of
Callback
instances.
- on_end(params: dict)[source]¶
Called at the end of
Traverser.traverse()
.- Parameters
params (dict) – Parameters provided by the
Traverser
. The provided parameters will differ fromCallback.on_subject()
.
- on_start(params: dict)[source]¶
Called at the beginning of
Traverser.traverse()
.- Parameters
params (dict) – Parameters provided by the
Traverser
. The provided parameters will differ fromCallback.on_subject()
.
- on_subject(params: dict)[source]¶
Called for each subject of
Traverser.traverse()
.- Parameters
params (dict) – Parameters provided by the
Traverser
containing subject specific information and data.
- class pymia.data.creation.callback.MonitoringCallback[source]¶
Bases:
pymia.data.creation.callback.Callback
Callback that monitors the dataset creation process by logging the progress to the console.
- on_end(params: dict)[source]¶
Called at the end of
Traverser.traverse()
.- Parameters
params (dict) – Parameters provided by the
Traverser
. The provided parameters will differ fromCallback.on_subject()
.
- on_start(params: dict)[source]¶
Called at the beginning of
Traverser.traverse()
.- Parameters
params (dict) – Parameters provided by the
Traverser
. The provided parameters will differ fromCallback.on_subject()
.
- on_subject(params: dict)[source]¶
Called for each subject of
Traverser.traverse()
.- Parameters
params (dict) – Parameters provided by the
Traverser
containing subject specific information and data.
- class pymia.data.creation.callback.WriteDataCallback(writer: pymia.data.creation.writer.Writer)[source]¶
Bases:
pymia.data.creation.callback.Callback
Callback that writes the raw data to the dataset.
- Parameters
writer (.creation.writer.Writer) – The writer used to write the data.
- on_subject(params: dict)[source]¶
Called for each subject of
Traverser.traverse()
.- Parameters
params (dict) – Parameters provided by the
Traverser
containing subject specific information and data.
- class pymia.data.creation.callback.WriteEssentialCallback(writer: pymia.data.creation.writer.Writer)[source]¶
Bases:
pymia.data.creation.callback.Callback
Callback that writes the essential information to the dataset.
- Parameters
writer (.creation.writer.Writer) – The writer used to write the data.
- on_start(params: dict)[source]¶
Called at the beginning of
Traverser.traverse()
.- Parameters
params (dict) – Parameters provided by the
Traverser
. The provided parameters will differ fromCallback.on_subject()
.
- on_subject(params: dict)[source]¶
Called for each subject of
Traverser.traverse()
.- Parameters
params (dict) – Parameters provided by the
Traverser
containing subject specific information and data.
- class pymia.data.creation.callback.WriteFilesCallback(writer: pymia.data.creation.writer.Writer)[source]¶
Bases:
pymia.data.creation.callback.Callback
Callback that writes the file names to the dataset.
- Parameters
writer (.creation.writer.Writer) – The writer used to write the data.
- on_start(params: dict)[source]¶
Called at the beginning of
Traverser.traverse()
.- Parameters
params (dict) – Parameters provided by the
Traverser
. The provided parameters will differ fromCallback.on_subject()
.
- on_subject(params: dict)[source]¶
Called for each subject of
Traverser.traverse()
.- Parameters
params (dict) – Parameters provided by the
Traverser
containing subject specific information and data.
- class pymia.data.creation.callback.WriteImageInformationCallback(writer: pymia.data.creation.writer.Writer, category='images')[source]¶
Bases:
pymia.data.creation.callback.Callback
Callback that writes the image information (shape, origin, direction, spacing) to the dataset.
- Parameters
writer (.creation.writer.Writer) – The writer used to write the data.
category (str) – The category from which to extract the information from.
- on_start(params: dict)[source]¶
Called at the beginning of
Traverser.traverse()
.- Parameters
params (dict) – Parameters provided by the
Traverser
. The provided parameters will differ fromCallback.on_subject()
.
- on_subject(params: dict)[source]¶
Called for each subject of
Traverser.traverse()
.- Parameters
params (dict) – Parameters provided by the
Traverser
containing subject specific information and data.
- class pymia.data.creation.callback.WriteNamesCallback(writer: pymia.data.creation.writer.Writer)[source]¶
Bases:
pymia.data.creation.callback.Callback
Callback that writes the names of the category entries to the dataset.
- Parameters
writer (.creation.writer.Writer) – The writer used to write the data.
- on_start(params: dict)[source]¶
Called at the beginning of
Traverser.traverse()
.- Parameters
params (dict) – Parameters provided by the
Traverser
. The provided parameters will differ fromCallback.on_subject()
.
- pymia.data.creation.callback.get_default_callbacks(writer: pymia.data.creation.writer.Writer, meta_only=False) pymia.data.creation.callback.ComposeCallback [source]¶
Provides a selection of commonly used callbacks to write the most important information to the dataset.
- Parameters
writer (.creation.writer.Writer) – The writer used to write the data.
meta_only (bool) – Whether only callbacks for a metadata dataset creation should be returned.
- Returns
The composed selection of common callbacks.
- Return type
File loader (pymia.data.creation.fileloader
module)¶
- class pymia.data.creation.fileloader.Load[source]¶
Bases:
abc.ABC
Interface for loading the data during the dataset creation in
Traverser.traverse()
- abstract __call__(file_name: str, id_: str, category: str, subject_id: str) Tuple[numpy.ndarray, Optional[pymia.data.conversion.ImageProperties]] [source]¶
Loads the data from the file system according to the implementation.
- Parameters
file_name (str) – Path to the corresponding data.
id (str) – Identifier for the entry of the category, e.g., “Flair”.
category (str) – Name of the category, e.g., ‘images’.
subject_id (str) – Identifier of the current subject.
- Returns
A numpy array containing the loaded data and
ImageProperties
describing the data.ImageProperties
isNone
if the loaded data does not contain further properties.- Return type
tuple
- class pymia.data.creation.fileloader.LoadDefault[source]¶
Bases:
pymia.data.creation.fileloader.Load
The default loader.
It loads every data item (id/entry, category) for each subject as
sitk.Image
and the correspondingImageProperties
.
Traverser (pymia.data.creation.traverser
module)¶
- class pymia.data.creation.traverser.Traverser(categories: Optional[Union[str, Tuple[str, ...]]] = None)[source]¶
Bases:
object
Class managing the dataset creation process.
- Parameters
categories (str or tuple of str) – The categories to traverse. If None, then all categories of a
SubjectFile
will be traversed.
- traverse(subject_files: typing.List[pymia.data.subjectfile.SubjectFile], load=<pymia.data.creation.fileloader.LoadDefault object>, callback: typing.Optional[pymia.data.creation.callback.Callback] = None, transform: typing.Optional[pymia.data.transformation.Transform] = None, concat_fn=<function default_concat>)[source]¶
Controls the actual dataset creation. It goes through the file list, loads the files, applies transformation to the data, and calls the callbacks to do the storing (or other stuff).
- Parameters
subject_files (list) – list of
SubjectFile
to be processes.load (callable) – A load function or
Load
instance that performs the data loadingcallback (.Callback) – A callback or composed (
ComposeCallback
) callback performing the storage of the loaded data (and other things such as logging).transform (.Transform) – Transformation to be applied to the data after loading and before
Callback.on_subject()
is calledconcat_fn (callable) – Function that concatenates all the entries of a category (e.g. T1, T2 data from “images” category). Default is
default_concat()
.
- pymia.data.creation.traverser.default_concat(data: List[numpy.ndarray]) numpy.ndarray [source]¶
Default concatenation function used to combine all entries from a category (e.g. T1, T2 data from “images” category) in
Traverser.traverse()
- Parameters
data (list) – List of numpy.ndarray entries to be concatenated.
- Returns
Concatenated entry.
- Return type
numpy.ndarray
Writer (pymia.data.creation.writer
module)¶
- class pymia.data.creation.writer.Hdf5Writer(file_path: str)[source]¶
Bases:
pymia.data.creation.writer.Writer
Writer class for HDF5 file type.
- Parameters
file_path (str) – The path to the dataset file to write.
- close()[source]¶
see
Writer.close()
- fill(entry: str, data, index: Optional[pymia.data.indexexpression.IndexExpression] = None)[source]¶
see
Writer.fill()
- open()[source]¶
see
Writer.open()
- reserve(entry: str, shape: tuple, dtype=None)[source]¶
see
Writer.reserve()
- write(entry: str, data, dtype=None)[source]¶
see
Writer.write()
- class pymia.data.creation.writer.Writer[source]¶
Bases:
abc.ABC
Represents the abstract dataset writer defining an interface for the writing process.
- abstract fill(entry: str, data, index: Optional[pymia.data.indexexpression.IndexExpression] = None)[source]¶
Fill parts of a reserved dataset entry.
- Parameters
entry (str) – The dataset entry to be filled.
data (object) – The data to write.
index (.IndexExpression) – The slicing expression.
- pymia.data.creation.writer.get_writer(file_path: str) pymia.data.creation.writer.Writer [source]¶
Get the dataset writer corresponding to the file extension.
- Parameters
file_path (str) – The path of the dataset file to be written.
- Returns
Writer corresponding to dataset file extension.
- Return type
.creation.writer.Writer
- pymia.data.creation.writer.writer_registry = {'.h5': <class 'pymia.data.creation.writer.Hdf5Writer'>, '.hdf5': <class 'pymia.data.creation.writer.Hdf5Writer'>}¶
Registry defining the mapping between file extension and
Writer
class. Alternative writers need to be added to this registry in order to useget_writer()
.