plaid.containers.utils

Utility functions for PLAID containers.

Functions

_check_names(names)

Check that names do not contain invalid character /.

_read_index(pyTree, dim)

Read Index Array or Index Range from CGNS.

_read_index_array(pyTree)

Read Index Array from CGNS.

_read_index_range(pyTree, dim)

Read Index Range from CGNS.

get_sample_ids(→ list[int])

Return list of sample ids in a dataset on disk.

get_number_of_samples(→ int)

Return number of samples in a dataset on disk.

get_feature_type_and_details_from(→ tuple[str, ...)

Extract and validate the feature type and its associated metadata from a feature identifier.

check_features_type_homogeneity(→ None)

Check type homogeneity of features, for tabular conversion.

check_features_size_homogeneity(→ int)

Check size homogeneity of features, for tabular conversion.

has_duplicates_feature_ids(feature_identifiers)

Check whether a list of feature identifier contains duplicates.

Module Contents

_check_names(names: str | list[str])[source]

Check that names do not contain invalid character /.

Parameters:

names (Union[str, list[str]]) – The names to check.

Raises:

ValueError – If any name contains the invalid character /.

_read_index(pyTree: list, dim: list[int])[source]

Read Index Array or Index Range from CGNS.

Parameters:
  • pyTree (list) – CGNS node which has a child Index to read

  • dim (list) – dimensions of the coordinates

Returns:

indices

_read_index_array(pyTree: list)[source]

Read Index Array from CGNS.

Parameters:

pyTree (list) – CGNS node which has a child of type IndexArray_t to read

Returns:

indices

_read_index_range(pyTree: list, dim: list[int])[source]

Read Index Range from CGNS.

Parameters:
  • pyTree (list) – CGNS node which has a child of type IndexRange_t to read

  • dim (list[str]) – dimensions of the coordinates

Returns:

indices

get_sample_ids(savedir: str | pathlib.Path) list[int][source]

Return list of sample ids in a dataset on disk.

Parameters:

savedir (Union[str,Path]) – The path to the directory where sample files are stored.

Returns:

List of sample ids.

Return type:

list[int]

get_number_of_samples(savedir: str | pathlib.Path) int[source]

Return number of samples in a dataset on disk.

Parameters:

savedir (Union[str,Path]) – The path to the directory where sample files are stored.

Returns:

number of samples.

Return type:

int

get_feature_type_and_details_from(feature_identifier: plaid.types.FeatureIdentifier) tuple[str, plaid.types.FeatureIdentifier][source]

Extract and validate the feature type and its associated metadata from a feature identifier.

This utility function ensures that the feature_identifier dictionary contains a valid “type” key (e.g., “scalar”, “time_series”, “field”, “node”) and returns the type along with the remaining identifier keys, which are specific to the feature type.

Parameters:

feature_identifier (dict) – A dictionary with a “type” key, and other keys (some optional) depending on the feature type. For example: - {“type”: “scalar”, “name”: “Mach”} - {“type”: “time_series”, “name”: “AOA”} - {“type”: “field”, “name”: “pressure”} - {“type”: “field”, “name”: “pressure”, “time”:0.} - {“type”: “nodes”, “base_name”: “Base_2_2”}

Returns:

A tuple (feature_type, feature_details) where:
  • feature_type is the value of the “type” key (e.g., “scalar”).

  • feature_details is a dictionary of the remaining keys.

Return type:

tuple[str, dict]

Raises:

AssertionError

  • If “type” is missing.

  • If the type is not in AUTHORIZED_FEATURE_TYPES.

  • If any unexpected keys are present for the given type.

check_features_type_homogeneity(feature_identifiers: list[plaid.types.FeatureIdentifier]) None[source]

Check type homogeneity of features, for tabular conversion.

Parameters:

feature_identifiers (list[dict]) – dict with a “type” key, and other keys (some optional) depending on the feature type. For example: - {“type”: “scalar”, “name”: “Mach”} - {“type”: “time_series”, “name”: “AOA”} - {“type”: “field”, “name”: “pressure”}

Raises:

AssertionError – if types are not consistent

check_features_size_homogeneity(feature_identifiers: list[plaid.types.FeatureIdentifier], features: dict[int, list[plaid.types.Feature]]) int[source]

Check size homogeneity of features, for tabular conversion.

Size homogeneity is check through samples for each feature, and through features for each sample. To be converted to tabular data, each sample must have the same number of features and each feature must have the same dimension

Parameters:
  • feature_identifiers (list[dict]) – dict with a “type” key, and other keys (some optional) depending on the feature type. For example: - {“type”: “scalar”, “name”: “Mach”} - {“type”: “time_series”, “name”: “AOA”} - {“type”: “field”, “name”: “pressure”}

  • features (dict) – dict with sample index as keys and one or more features as values.

Returns:

the common feature dimension

Return type:

int

Raises:

AssertionError – if sizes are not consistent

has_duplicates_feature_ids(feature_identifiers: list[plaid.types.FeatureIdentifier])[source]

Check whether a list of feature identifier contains duplicates.

Parameters:

feature_identifiers (list[FeatureIdentifier]) – A list of dictionaries representing feature identifiers.

Returns:

True if a duplicate is found in the list, False otherwise.

Return type:

bool