Model tool
model_tool
¶
Attributes¶
Classes¶
ModelCreationTool
¶
ModelCreationTool(
root_directory: str | Path = root_directory,
directory_naming_method: DirectoryNamingMethod = NUMBERED,
working_directory: str | Path = working_directory,
**options
)
Bases: BaseAnalysisTool
A tool to create a model and set its default values.
Examples:
>>> from vimseo.tools.example_tool import MyTool
>>> tool = MyTool()
>>> tool.execute()
>>> print(tool.result)
# The result can be saved on disk.
>>> tool.save_results()
# Optionnaly, the current options of the tool can be saved on disk.
>>> tool.result.save_metadata_to_disk()
# The result saved on disk can be loaded.
>>> results = BaseTool.load_results(tool.working_directory /
>>> 'Tool_result.pickle')
# Then, the tool can plot the result. Note that the :meth:`plot_results` method
# takes the result as input. In the future, this method will be moved from the
# tools to a post processor class.
>>> tool.plot_results(results, save=True, show=False)
TODO allow passing pydantic model¶
Parameters:
-
root_directory(str | Path, default:root_directory) –The description is missing.
-
directory_naming_method(DirectoryNamingMethod, default:NUMBERED) –The description is missing.
-
working_directory(str | Path, default:working_directory) –The description is missing.
-
**options–The description is missing.
Source code in src/vimseo/tools/model_tool.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
Attributes¶
Functions¶
execute
¶
execute(
settings=ModelCreationSettings, **options
) -> ModelResult
The user-defined treatment called by :meth:execute.
Parameters:
-
options–The options of the execution.
Source code in src/vimseo/tools/model_tool.py
68 69 70 71 72 73 74 | |
load_options_from_metadata
¶
load_options_from_metadata(
file_path: str | Path | None = None,
)
Load a result of a tool from the disk.
Parameters:
-
file_path(str | Path | None, default:None) –The path to the file.
Source code in src/vimseo/tools/base_tool.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |
load_results
classmethod
¶
load_results(path: Path)
Load a result of a tool from the disk.
For a JSON file, only SpaceToolResult is supported.
This method must be called from class SpaceTool.
JSON format for tool results is deprecated.
Parameters:
-
path(Path) –The path to the file.
-
tool_name–The name of the tool associated with the result under stored
Source code in src/vimseo/tools/base_tool.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | |
plot_results
¶
plot_results(
result: ModelResult,
directory_path: str | Path = "",
save=False,
show=True,
**options
) -> Mapping[str, Figure]
Plot criteria for a given variable name.
Parameters:
-
result(ModelResult) –The result of the tool.
-
directory_path(str | Path, default:'') –The path under which the plots are saved.
-
save–Whether to save the plot on disk.
-
show–Whether to show the plot.
-
**options–The description is missing.
Source code in src/vimseo/tools/model_tool.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
save_results
¶
save_results(
prefix: str = "", file_format: str = "hdf5"
) -> None
Save the results of the tool on disk. The file path is
BaseTool.working_directory / {filename}_result.{file_format}.
Args: prefix: The prefix of the filename result.
Parameters:
-
prefix(str, default:'') –The description is missing.
-
file_format(str, default:'hdf5') –The description is missing.
Source code in src/vimseo/tools/base_composite_tool.py
72 73 74 75 | |
set_plot
¶
set_plot(class_name, **options) -> None
Set the type of plot to show the results of this tool.
Parameters:
-
class_name–The name of the plot class.
-
**options–The options of the plot constructor.
Source code in src/vimseo/tools/base_tool.py
264 265 266 267 268 269 270 271 272 273 | |
ModelResult
dataclass
¶
ModelResult(metadata: ToolResultMetadata | None = None)
Bases: BaseResult
A result of a tool (:class:.BaseTool).
This result is the object that flows through a workflow of tools.
It is self-supporting and carries information on how to process it through the
:attr:.ToolResultMetadata.settings. The result can be written on disk in binary format
(pickle) and its metadata can also be written on disk in a readable format
(json).
Attributes¶
metadata
class-attribute
instance-attribute
¶
metadata: ToolResultMetadata | None = None
ToolResultMetadata attached to a result.
Functions¶
from_hdf5
classmethod
¶
from_hdf5(path: str | Path)
Deserialize from a file path.
Source code in src/vimseo/tools/base_result.py
91 92 93 94 95 | |
from_hdf5_buffer
classmethod
¶
from_hdf5_buffer(buffer: IOBase | bytes)
Deserialize from a file-like object or bytes (e.g. Streamlit uploader).
Source code in src/vimseo/tools/base_result.py
97 98 99 100 101 102 103 104 105 | |
save_metadata_to_disk
¶
save_metadata_to_disk(file_path: Path | str = '')
Save metadata to disk in a readable format.
Source code in src/vimseo/tools/base_result.py
117 118 119 120 121 122 123 | |
to_hdf5
¶
to_hdf5(path: str | Path) -> None
Serialize a BaseResult into an HDF5 file.
The file can be explored with an on-line reader, like https://myhdf5.hdfgroup.org/. For more information about hdf5, see HDF5 documentation.
Source code in src/vimseo/tools/base_result.py
69 70 71 72 73 74 75 76 77 78 79 | |
to_hdf5_buffer
¶
to_hdf5_buffer() -> BytesIO
Serialize a BaseResult into an HDF5 buffer.
Source code in src/vimseo/tools/base_result.py
81 82 83 84 85 86 87 88 89 | |
to_pickle
¶
to_pickle(file_path: str | Path)
Save result instance to disk.
Source code in src/vimseo/tools/base_result.py
63 64 65 66 | |