plaid.storage.common.bridge

Common bridge utilities.

This module provides bridge functions for converting between PLAID samples and storage formats, including flattening/unflattening and sample reconstruction.

Functions

unflatten_path(→ str)

Unflattens a Zarr key by replacing underscores with slashes.

flatten_path(→ str)

Flattens a path key by replacing slashes with underscores.

to_sample_dict(→ dict[float, dict[str, Any]])

Convert variable sample dict to time-based sample dict.

flat_dict_to_sample_dict(→ dict[float, dict[str, Any]])

Convert a flattened sample dict into a time-indexed flat-tree mapping.

to_plaid_sample(→ plaid.containers.sample.Sample)

Convert sample dict to PLAID Sample.

plaid_to_sample_dict(→ dict[str, Any])

Convert PLAID Sample to sample dict.

Module Contents

unflatten_path(key: str) str[source]

Unflattens a Zarr key by replacing underscores with slashes.

Parameters:

key (str) – The flattened key with underscores.

Returns:

The unflattened key with slashes.

Return type:

str

flatten_path(key: str) str[source]

Flattens a path key by replacing slashes with underscores.

Parameters:

key (str) – The path key to flatten.

Returns:

The flattened key with slashes replaced by underscores.

Return type:

str

to_sample_dict(var_sample_dict: dict[str, Any], flat_cst: dict[str, Any], cgns_types: dict[str, str], features: list[str] | None = None) dict[float, dict[str, Any]][source]

Convert variable sample dict to time-based sample dict.

Parameters:
  • var_sample_dict – Variable features dictionary.

  • flat_cst – Constant features dictionary.

  • cgns_types – CGNS types dictionary.

  • features – Optional list of features to include.

Returns:

Time-based sample dictionary.

Return type:

dict

flat_dict_to_sample_dict(flat_dict: dict[str, Any], cgns_types: dict[str, str], features: list[str] | None = None) dict[float, dict[str, Any]][source]

Convert a flattened sample dict into a time-indexed flat-tree mapping.

This function processes a single flattened sample dictionary where keys are feature paths or feature path suffixed with ‘_times’ (holding time interval specs). It splits values and their corresponding time specifications, slices feature arrays per interval and groups features by their sample time into CGNS-style flattened trees.

Parameters:
  • flat_dict – Mapping of flattened feature paths to values or to time specifications (keys ending with ‘_times’). Time specifications must be sequences or arrays reshapeable to (-1, 3) rows of (time, start, end).

  • cgns_types – Mapping from feature path to CGNS node type; used to determine which None-valued features should be preserved.

  • features – Optional list of feature paths to include; if None all features are included.

Returns:

A dict mapping time (float) to a flattened tree dict (path -> array or None).

to_plaid_sample(sample_dict: dict[float, dict[str, Any]], cgns_types: dict[str, str]) plaid.containers.sample.Sample[source]

Convert sample dict to PLAID Sample.

Parameters:
  • sample_dict – Time-based sample dictionary.

  • cgns_types – CGNS types dictionary.

Returns:

The reconstructed PLAID Sample.

Return type:

Sample

plaid_to_sample_dict(sample: plaid.containers.sample.Sample, variable_features: list[str], constant_features: list[str]) dict[str, Any][source]

Convert PLAID Sample to sample dict.

Parameters:
  • sample – The PLAID Sample.

  • variable_features – List of variable feature names.

  • constant_features – List of constant feature names.

Returns:

sample_dict

Return type:

dict[str, Any]