Source code for vivyd.data.experiment
from __future__ import annotations
from .container import Container
from .bundle import Bundle
from dataclasses import dataclass
from datetime import datetime
from typing import Any
from zarr.storage import ZipStore
[docs]
@dataclass(kw_only=True)
class Experiment(Container):
"""
A class representing an experiment within a study. An experiment is a
specific run of data acquisition. Simply said, an experiment corresponds to
time the experiment hits the "start" button. An experiment can contain one
or more bundles collecting data from different sources.
Parameters
----------
name : str
The name of the experiment.
date : datetime
The date and time when the experiment was conducted.
info : dict[str, Any]
Additional metadata about the experiment, such as experimental conditions,
measurement techniques, etc. This is a flexible field that can hold any
relevant information that does not fit into the predefined fields.
"""
date: datetime
[docs]
def add(self, *bundle: Bundle) -> Experiment:
"""
Add one or more bundles to the experiment.
Parameters
----------
*bundle : Bundle
One or more bundle objects to add to the experiment.
Returns
-------
Experiment
The experiment with the added bundles.
"""
for b in bundle:
super().add(b.name, b)
return self
@property
def __dict__(self) -> dict[str, Any]:
return {
**super().__dict__,
"date": self.date.isoformat()
}
@staticmethod
def _from_dict(data: dict[str, Any], store: ZipStore) -> Experiment:
new = Experiment(
name = data["name"],
info = data["info"],
date = datetime.fromisoformat(data["date"]),
)
for bdl in data["contents"]:
new.add(Bundle._from_dict(bdl, store))
return new