Note

This page is a reference documentation. It only explains the class signature, and not how to use it. Please refer to the user guide for the big picture.

brainprep.decorators.OutputdirHook

class brainprep.decorators.OutputdirHook(plotting=False, quality_check=False, morphometry=False)[source]

Bases: Hook

Fill and create the output directory.

This hook ensures that the output directory exists before the wrapped function is executed. Optional subdirectories can also be created, such as a figures directory for plots or a quality_check directory for quality check outputs or morphometry directory for morphometry outputs.

Parameters:
plottingbool

If True, add a figures upper level directory in the output directory. Default False.

quality_checkbool

If True, add a quality_check upper level directory in the output directory. Default False.

morphometrybool

If True, add a morphometry upper level directory in the output directory. Default False.

Examples

>>> from brainprep.decorators import step, OutputdirHook
>>> from brainprep.typing import Directory
>>> from brainprep.utils import Bunch
>>> @step(
...     hooks=[OutputdirHook(plotting=True)]
... )
... def myfunc(output_dir: Directory):
...     '''Fill and create the output directory.'''
...     return Bunch(output_dir=output_dir)
>>> result = myfunc("/tmp")
>>> print(result)
Bunch(
    output_dir: PosixPath('/tmp/figures')
)
__init__(plotting=False, quality_check=False, morphometry=False)[source]
before_call(func, inputs)[source]

Transform and inspect inputs before the function call.

Parameters:
funcCallable

The function to be decorated.

inputsdict[str, Any]

Positional and keyword arguments passed to func.

Returns:
inputsdict[str, Any]

Positional and keyword arguments passed to func where the output_dir` argument has been updated and created.

Raises:
ValueError

If the decorated function has no output_dir argument.