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:
HookFill 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
figuresdirectory for plots or aquality_checkdirectory for quality check outputs ormorphometrydirectory for morphometry outputs.- Parameters:
- plottingbool
If True, add a
figuresupper level directory in the output directory. Default False.- quality_checkbool
If True, add a
quality_checkupper level directory in the output directory. Default False.- morphometrybool
If True, add a
morphometryupper 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') )
- 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_dirargument.