Skip to content

Validation case result

validation_case_result

Classes

ValidationCaseResult dataclass

ValidationCaseResult(
    metadata: ToolResultMetadata = ToolResultMetadata(),
    element_wise_metrics: IODataset | None = None,
    integrated_metrics: (
        Mapping[str, Mapping[str, float]] | None
    ) = None,
    stochastic_point_results: Sequence[
        ValidationPointResult
    ] = (),
)

Bases: BaseResult

The result of a validation case.

Attributes
integrated_metrics class-attribute instance-attribute
integrated_metrics: (
    Mapping[str, Mapping[str, float]] | None
) = None

A dictionary mapping variable names and metric names to integrated metric values corresponding the each validation point (i.e. each sample of the reference data).

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

ToolResultMetadata attached to a result.

Methods:
add_averaged_point
add_averaged_point(
    src_group_name: str,
    dataset: Dataset,
    data: dict[str, list],
    output_group_name: str,
)

Average validation point data and add to case dictionary.

Source code in src\vimseo\tools\validation_case\validation_case_result.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def add_averaged_point(
    self,
    src_group_name: str,
    dataset: Dataset,
    data: dict[str, list],
    output_group_name: str,
):
    """Average validation point data and add to case dictionary."""
    group_data = dataset.get_view(group_names=[src_group_name]).copy()
    group_data.columns = group_data.get_columns(as_tuple=False)
    group_data = group_data.mean().to_dict()
    for name, value in group_data.items():
        data[
            f"{name}{GROUP_SEPARATORS[0]}{output_group_name}{GROUP_SEPARATORS[1]}"
        ].append(value)
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)
get_common_values
get_common_values(data_list: Sequence[list]) -> list

Get the common values across all lists in data_list.

Source code in src\vimseo\tools\validation_case\validation_case_result.py
56
57
58
59
60
61
def get_common_values(self, data_list: Sequence[list]) -> list:
    """Get the common values across all lists in data_list."""
    common_values = set(data_list[0])
    for data in data_list[1:]:
        common_values.intersection_update(data)
    return sorted(common_values)
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)

Functions: