IO#
Note
The IO module associates the files generated/required by beorn with their corresponding parameters. As such it is particularly useful when dealing with many simulations with different parameters.
IO module that handles reading and writing of computed data.
- class beorn.io.Handler(file_root: Path, input_tag: str = None, clear: bool = False, write_kwargs: dict = None)[source]#
Manage a persistence directory and delegate read/write calls.
The handler wraps the read/write methods implemented by classes deriving from
beorn.structs.base_struct.BaseStruct, storing a commonfile_rootdirectory and optional defaultwrite_kwargsthat are passed to write operations.- clear()[source]#
Remove and recreate the handler’s persistence directory.
This deletes all files under
file_root. Use with caution.- Returns:
None
- load_file(parameters: Parameters, cls: type[BaseStructDerived], **kwargs) BaseStructDerived[source]#
Load an instance of
clsfrom the persistence directory.This convenience wrapper calls
BaseStruct.read()on the provided class with the handler’sfile_rootand returns the instantiated object.- Parameters:
parameters (Parameters) – Parameters instance used to identify the file to load.
cls (type[BaseStructDerived]) – Class implementing
readthat returns an instance ofBaseStruct.**kwargs – Additional keyword arguments forwarded to``cls.read``.
- Returns:
Loaded instance of
cls.- Return type:
BaseStructDerived
- save_logs(parameters: Parameters) None[source]#
Configure a file handler to save application logs.
The log file is named to match the output
igm_cubes_*.h5file, using the sameinput_tagandbeorn_hashso logs and output sit side-by-side and are trivially associated.- Parameters:
parameters (Parameters) – Parameters object used to derive the log file name.
- Returns:
None
- write_file(parameters: Parameters, obj: BaseStructDerived, **kwargs) None[source]#
Write
objto the handler’s persistence directory.This convenience wrapper calls the
BaseStruct.write()implementation ofobjwith the configuredfile_rootand merges any providedkwargswith the handler’swrite_kwargs.- Parameters:
parameters (Parameters) – Parameters instance used to create or uniquely identify the object.
obj (BaseStructDerived) – Instance providing a
writemethod.**kwargs – Additional keyword arguments forwarded to
obj.write. These are often used to distinguish file names or control writing behaviour.
- Returns:
None