Skip to content

Croissant

rddac.load and rddac.add_view are the two entry points to the Croissant manifest. Both are re-exported at the top level (rddac.load, rddac.add_view); the implementation lives in rddac.croissant.

rddac.load

load(source: str | Path | None = None, data_dir: str | Path | None = DEFAULT_DATA_DIR) -> mlc.Dataset

Return an :class:mlcroissant.Dataset for the RDDAC manifest.

Local-first, URL-fallback resolution — see :func:resolve_source. When data_dir points at a directory that contains files referenced by the manifest (e.g. zips written by rddac download), mlcroissant is told to use those local copies instead of refetching from DaRUS.

Pass data_dir=None to opt out of local-file discovery and force mlcroissant to download via its own cache.

Source code in rddac/croissant.py
def load(
    source: str | Path | None = None,
    data_dir: str | Path | None = DEFAULT_DATA_DIR,
) -> mlc.Dataset:
    """Return an :class:`mlcroissant.Dataset` for the RDDAC manifest.

    Local-first, URL-fallback resolution — see :func:`resolve_source`. When
    ``data_dir`` points at a directory that contains files referenced by the
    manifest (e.g. zips written by ``rddac download``), `mlcroissant` is told
    to use those local copies instead of refetching from DaRUS.

    Pass ``data_dir=None`` to opt out of local-file discovery and force
    `mlcroissant` to download via its own cache.
    """
    return _ddacs_croissant.load(source, data_dir, spec=RDDAC_SPEC)

rddac.add_view

add_view(ds: mlc.Dataset, name: str, fields: dict[str, FieldSpec]) -> mlc.Dataset

Add a custom RecordSet to a loaded dataset and rewire it in place.

Each fields entry references a manifest field by name. Bare ids resolve to field-map (the h5 source); qualified ids of the form "<record-set>/<field>" can pull from any other RecordSet, e.g. "process-parameters/sheet_metal_thickness":

  • "name": "field_id" — whole field-map field
  • "name": ("field_id", None | int | list[int]) — explicit, with optional timestep slicing
  • "name": "process-parameters/<column>" — CSV column from the index

Timestep slicing is only valid on field-map sources. The published manifest on DaRUS is untouched — only the in-memory representation grows. ds is mutated in place and returned for optional chaining.

Source code in ddacs/croissant.py
def add_view(
    ds: mlc.Dataset,
    name: str,
    fields: dict[str, FieldSpec],
) -> mlc.Dataset:
    """Add a custom RecordSet to a loaded dataset and rewire it in place.

    Each ``fields`` entry references a manifest field by name. Bare ids
    resolve to ``field-map`` (the h5 source); qualified ids of the form
    ``"<record-set>/<field>"`` can pull from any other RecordSet, e.g.
    ``"process-parameters/sheet_metal_thickness"``:

    - ``"name": "field_id"``                            — whole field-map field
    - ``"name": ("field_id", None | int | list[int])``   — explicit, with optional timestep slicing
    - ``"name": "process-parameters/<column>"``          — CSV column from the index

    Timestep slicing is only valid on field-map sources. The published
    manifest on DaRUS is untouched — only the in-memory representation
    grows. ``ds`` is mutated in place and returned for optional chaining.
    """
    jsonld = _load_jsonld_dict(ds.jsonld)
    jsonld.setdefault("recordSet", []).append(_build_record_set(jsonld, name, fields))
    rebuilt = mlc.Dataset(jsonld=jsonld, mapping=ds.mapping)
    ds.metadata = rebuilt.metadata
    ds.operations = rebuilt.operations
    # Persist the mutated dict so subsequent add_view calls accumulate
    # instead of clobbering each other.
    ds.jsonld = jsonld
    return ds

Module reference

Croissant manifest access for RDDAC — thin wrappers over :mod:ddacs.croissant.

The machinery lives in the ddacs package (shared with the DDACS simulation dataset); everything here just injects :data:rddac.spec.RDDAC_SPEC so the manifest resolution targets the RDDAC dataset. The manifest conventions (field-map RecordSet, process-parameters join on index) are identical between the datasets, so add_view & friends pass through as-is.

metadata_url()

Return the DaRUS download URL for the published RDDAC metadata.json.

Resolved via the DaRUS API (numeric file id — DaRUS has no per-file persistent ids) and cached for the process lifetime.

Source code in rddac/croissant.py
def metadata_url() -> str:
    """Return the DaRUS download URL for the published RDDAC ``metadata.json``.

    Resolved via the DaRUS API (numeric file id — DaRUS has no per-file
    persistent ids) and cached for the process lifetime.
    """
    return _ddacs_croissant.metadata_url(RDDAC_SPEC)

resolve_source(source=None, data_dir=None)

Return the source string (path or URL) that :func:load would use.

Resolution order
  1. source if given (local path or HTTP(S) URL).
  2. <data_dir>/metadata.json if it exists locally.
  3. The DaRUS download URL from :func:metadata_url.
Source code in rddac/croissant.py
def resolve_source(source: str | Path | None = None, data_dir: str | Path | None = None) -> str:
    """Return the source string (path or URL) that :func:`load` would use.

    Resolution order:
        1. ``source`` if given (local path or HTTP(S) URL).
        2. ``<data_dir>/metadata.json`` if it exists locally.
        3. The DaRUS download URL from :func:`metadata_url`.
    """
    return _ddacs_croissant.resolve_source(source, data_dir, spec=RDDAC_SPEC)

field_map(dataset)

Map each HDF5 field name in the field-map RecordSet to its mlc Field.

Source code in ddacs/croissant.py
def field_map(dataset: mlc.Dataset) -> dict[str, Any]:
    """Map each HDF5 field name in the field-map RecordSet to its mlc Field."""
    rs = _record_set(dataset, FIELD_MAP_RECORD_SET)
    if rs is None:
        return {}
    return {f.name: f for f in rs.fields}

process_parameters_descriptions(dataset)

Map each process_parameters column to its human-readable description.

Pulled directly from the process-parameters RecordSet in the manifest.

Source code in ddacs/croissant.py
def process_parameters_descriptions(dataset: mlc.Dataset) -> dict[str, str]:
    """Map each process_parameters column to its human-readable description.

    Pulled directly from the ``process-parameters`` RecordSet in the manifest.
    """
    rs = _record_set(dataset, "process-parameters")
    if rs is None:
        return {}
    return {f.name: (f.description or "") for f in rs.fields}

dataset_name(dataset)

Source code in ddacs/croissant.py
def dataset_name(dataset: mlc.Dataset) -> str:
    return dataset.metadata.name or ""

rddac.croissant.METADATA_URL mirrors the DDACS constant of the same name, but is a lazy module attribute: DaRUS assigns no per-file persistent ids, so the numeric file id behind the download URL is resolved through the DaRUS API on first access (see metadata_url above) and cached for the process lifetime.