Source code for vivyd.data.bundle

from __future__ import annotations

from .container import Container
from .source import Source

from dataclasses import dataclass
from typing import Any
from zarr.storage import ZipStore


[docs] @dataclass(kw_only=True) class Bundle(Container): """ A class representing a bundle, which is a collection of data sources. A bundle can contain other bundles, allowing for a hierarchical organization of data sources. For example, a bundle could represent all the equipment related to wind measurements. Parameters ---------- name : str The name of the bundle. info : dict[str, Any] Additional metadata about the bundle, 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. """
[docs] def add(self, *obj: Bundle | Source) -> Bundle: """ Add one or more bundles or sources to the bundle. Parameters ---------- *obj : Bundle | Source One or more bundles or sources to add to the bundle. Returns ------- Bundle The bundle 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) -> Bundle: new = Bundle( name = data["name"], info = data["info"] ) for obj in data["contents"]: match obj["type"]: case "Bundle": new.add(Bundle._from_dict(obj, store)) case "Source": new.add(Source._from_dict(obj, store)) case _: raise ValueError(f"Unsupported type '{obj['type']}' found in bundle '{new.name}'. Supported types are 'Bundle' and 'Source'.") return new