Source code for vivyd.data.study
from __future__ import annotations
from .container import Container
from .experiment import Experiment
from dataclasses import dataclass
from typing import Any
from zarr.storage import ZipStore
[docs]
@dataclass(kw_only=True)
class Study(Container):
"""
A class representing a study within the dataset. A study is a collection of
experiments that are related to a specific topic. For example, a study could
be focused on a parameter sweep, thus implying several experiments.
"""
[docs]
def add(self, *obj: Study | Experiment) -> Study:
"""
Add one or more studies to the study.
Parameters
----------
*obj : Study | Experiment
One or more study or experiment objects to add to the study.
Returns
-------
Study
The study with the added contents.
"""
for o in obj:
super().add(o.name, o)
return self
@staticmethod
def _from_dict(data: dict[str, Any], store: ZipStore) -> Study:
new = Study(
name = data["name"],
info = data["info"]
)
for obj in data["contents"]:
match obj["type"]:
case "Study":
new.add(Study._from_dict(obj, store))
case "Experiment":
new.add(Experiment._from_dict(obj, store))
case _:
raise ValueError(f"Unsupported type '{obj['type']}' found in study '{new.name}'. Supported types are 'Study' and 'Experiment'.")
return new