Skip to content

Plot result

plot_result

Classes

PlotResult dataclass

PlotResult(
    metadata: ToolResultMetadata = ToolResultMetadata(),
    figure: Figure | Figure | None = None,
)

Bases: BaseResult

A plot result.

Attributes
metadata class-attribute instance-attribute
metadata: ToolResultMetadata = field(
    default_factory=ToolResultMetadata
)

ToolResultMetadata attached to a result.

Methods:
from_hdf5 classmethod
from_hdf5(path: str | Path)

Deserialize from a file path.

Source code in src\vimseo\tools\base_result.py
92
93
94
95
96
@classmethod
def from_hdf5(cls, path: str | Path):
    """Deserialize from a file path."""
    with h5py.File(path, "r") as f:
        return cls._from_hdf5_file(f)
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
 98
 99
100
101
102
103
104
105
106
@classmethod
def from_hdf5_buffer(cls, buffer: IOBase | bytes):
    """Deserialize from a file-like object or bytes (e.g. Streamlit uploader)."""
    if isinstance(buffer, bytes):
        buffer = BytesIO(buffer)
    else:
        buffer.seek(0)
    with h5py.File(BytesIO(buffer.read()), "r") as f:
        return cls._from_hdf5_file(f)
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
118
119
120
121
122
123
124
def save_metadata_to_disk(self, file_path: Path | str = ""):
    """Save metadata to disk in a readable format."""
    file_path = Path.cwd() if file_path == "" else Path(file_path)
    with Path(file_path / f"{self.__class__.__name__}_metadata.json").open(
        "w"
    ) as f:
        json.dump(asdict(self.metadata), f, indent=4, ensure_ascii=True)
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
70
71
72
73
74
75
76
77
78
79
80
def to_hdf5(self, 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](https://docs.hdfgroup.org/hdf5/develop/)."""
    with h5py.File(path, "w") as f:
        f.attrs["__class__"] = type(self).__name__
        for fld in fields(self):
            serialize_value(f, fld.name, getattr(self, fld.name))
to_hdf5_buffer
to_hdf5_buffer() -> BytesIO

Serialize a BaseResult into an HDF5 buffer.

Source code in src\vimseo\tools\base_result.py
82
83
84
85
86
87
88
89
90
def to_hdf5_buffer(self) -> BytesIO:
    """Serialize a BaseResult into an HDF5 buffer."""
    bio = BytesIO()
    with h5py.File(bio, "w") as f:
        f.attrs["__class__"] = type(self).__name__
        for fld in fields(self):
            serialize_value(f, fld.name, getattr(self, fld.name))

    return bio
to_pickle
to_pickle(file_path: str | Path)

Save result instance to disk.

Source code in src\vimseo\tools\base_result.py
64
65
66
67
def to_pickle(self, file_path: str | Path):
    """Save result instance to disk."""
    with Path(file_path).open("wb") as f:
        pickle.dump(self, f)