Creation (pymia.data.creation package)¶
Callback (pymia.data.creation.callback module)¶
- class pymia.data.creation.callback.Callback[source]¶
Bases:
objectBase class for the interaction with the dataset creation.
Implementations of the
Callbackclass 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
Traversercontaining subject specific information and data.
- class pymia.data.creation.callback.ComposeCallback(callbacks: List[Callback])[source]¶
Bases:
CallbackComposes many
Callbackinstances and behaves like an singleCallbackinstance.This class allows passing multiple
CallbacktoTraverser.traverse().- Parameters:
callbacks (list) – A list of
Callbackinstances.
- 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
Traversercontaining subject specific information and data.
- class pymia.data.creation.callback.MonitoringCallback[source]¶
Bases:
CallbackCallback 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
Traversercontaining subject specific information and data.
- class pymia.data.creation.callback.WriteDataCallback(writer: Writer)[source]¶
Bases:
CallbackCallback 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
Traversercontaining subject specific information and data.
- class pymia.data.creation.callback.WriteEssentialCallback(writer: Writer)[source]¶
Bases:
CallbackCallback 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
Traversercontaining subject specific information and data.
- class pymia.data.creation.callback.WriteFilesCallback(writer: Writer)[source]¶
Bases:
CallbackCallback 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
Traversercontaining subject specific information and data.
- class pymia.data.creation.callback.WriteImageInformationCallback(writer: Writer, category='images')[source]¶
Bases:
CallbackCallback 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
Traversercontaining subject specific information and data.
- class pymia.data.creation.callback.WriteNamesCallback(writer: Writer)[source]¶
Bases:
CallbackCallback 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: Writer, meta_only=False) 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:
ABCInterface for loading the data during the dataset creation in
Traverser.traverse()- abstract __call__(file_name: str, id_: str, category: str, subject_id: str) Tuple[ndarray, ImageProperties | None][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
ImagePropertiesdescribing the data.ImagePropertiesisNoneif the loaded data does not contain further properties.- Return type:
tuple
Traverser (pymia.data.creation.traverser module)¶
- class pymia.data.creation.traverser.Traverser(categories: str | Tuple[str, ...] | None = None)[source]¶
Bases:
objectClass managing the dataset creation process.
- Parameters:
categories (str or tuple of str) – The categories to traverse. If None, then all categories of a
SubjectFilewill be traversed.
- traverse(subject_files: ~typing.List[~pymia.data.subjectfile.SubjectFile], load=<pymia.data.creation.fileloader.LoadDefault object>, callback: ~pymia.data.creation.callback.Callback | None = None, transform: ~pymia.data.transformation.Transform | None = 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
SubjectFileto be processes.load (callable) – A load function or
Loadinstance 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[ndarray]) 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:
WriterWriter 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: IndexExpression | None = 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:
ABCRepresents the abstract dataset writer defining an interface for the writing process.
- abstract fill(entry: str, data, index: IndexExpression | None = 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) 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
Writerclass. Alternative writers need to be added to this registry in order to useget_writer().