Skip to content

plaid.viewer.models

plaid.viewer.models

Data models for the gdataset viewer.

Contains both immutable dataclasses used by services (SampleRef, ParaviewArtifact) and pydantic models used as FastAPI response payloads.

plaid.viewer.models.SampleRef dataclass

SampleRef(dataset_id, split, sample_id)

Reference to a PLAID sample.

Attributes:

  • dataset_id (str) –

    Identifier of the dataset (typically the dataset directory name for local datasets, or the org/repo id for Hub datasets).

  • split (str | None) –

    Optional split name ("train", "test", ...). None when the dataset is not split.

  • sample_id (str) –

    Identifier of the sample within the split. For disk-backed datasets this is the zero-based index rendered as a string.

plaid.viewer.models.SampleRef.encode

encode()

Return a URL-safe string identifier usable as a route parameter.

Source code in plaid/viewer/models.py
def encode(self) -> str:
    """Return a URL-safe string identifier usable as a route parameter."""
    split = self.split if self.split is not None else "_"
    return f"{self.dataset_id}:{split}:{self.sample_id}"

plaid.viewer.models.SampleRef.decode classmethod

decode(value)

Parse a string produced by :meth:encode.

Source code in plaid/viewer/models.py
@classmethod
def decode(cls, value: str) -> "SampleRef":
    """Parse a string produced by :meth:`encode`."""
    parts = value.split(":")
    if len(parts) != 3:
        raise ValueError(f"Invalid sample reference: {value!r}")
    dataset_id, split, sample_id = parts
    return cls(
        dataset_id=dataset_id,
        split=None if split == "_" else split,
        sample_id=sample_id,
    )

plaid.viewer.models.ParaviewArtifact dataclass

ParaviewArtifact(
    artifact_id,
    cgns_path,
    state_path,
    metadata_path,
    cache_key,
    created,
)

A ParaView-readable artifact produced from a PLAID sample.

For time-dependent samples, cgns_path points to a .cgns.series sidecar file that groups multiple CGNS files into a single time sequence. For single-timestep samples, it points to the single CGNS file directly.

Attributes:

  • artifact_id (str) –

    Stable identifier used in API routes. Derived from the cache key.

  • cgns_path (Path) –

    Path to the file ParaView should open. Either a .cgns.series sidecar (multi-time) or a .cgns file.

  • state_path (Path | None) –

    Optional ParaView state file (.pvsm) providing a reasonable default scene.

  • metadata_path (Path | None) –

    Optional JSON metadata file describing the artifact.

  • cache_key (str) –

    Deterministic SHA256 key over the artifact inputs.

  • created (bool) –

    True if the artifact was newly created, False if it was already present in the cache.

plaid.viewer.models.DatasetInfo

Summary information about an available dataset.

is_streaming distinguishes datasets opened with :func:plaid.storage.init_from_disk (False) from Hugging Face repositories streamed through :func:plaid.storage.init_streaming_from_hub (True). Streamed datasets do not always expose a total sample count and may need to be navigated sequentially through a streaming cursor.

plaid.viewer.models.DatasetDetail

Full detail view of a dataset.

splits maps each split name to its sample count. The count is None for streaming datasets where the total is unknown.

plaid.viewer.models.SampleRefDTO

Serializable form of :class:SampleRef used by the API.

plaid.viewer.models.SampleRefDTO.from_ref classmethod

from_ref(ref)

Build the DTO from a :class:SampleRef.

Source code in plaid/viewer/models.py
@classmethod
def from_ref(cls, ref: SampleRef) -> "SampleRefDTO":
    """Build the DTO from a :class:`SampleRef`."""
    return cls(
        dataset_id=ref.dataset_id,
        split=ref.split,
        sample_id=ref.sample_id,
        encoded=ref.encode(),
    )

plaid.viewer.models.SampleSummary

Minimal metadata describing a PLAID sample.

plaid.viewer.models.ValidationResult

Validation outcome for a PLAID sample.

plaid.viewer.models.ArtifactInfo

Public view of a :class:ParaviewArtifact.

plaid.viewer.models.ViewerUrl

Response model for the viewer-url endpoint.