gemseo / core / data_converters

Hide inherited members

pydantic module

Data values to NumPy arrays and vice versa from a PydanticGrammar.

class gemseo.core.data_converters.pydantic.PydanticGrammarDataConverter(grammar)[source]

Bases: BaseDataConverter[PydanticGrammar]

Data values to NumPy arrays and vice versa from a PydanticGrammar.

Parameters:

grammar (T) – The grammar providing the data types used for the conversions.

compute_names_to_sizes(names, data)

Compute a mapping from data names to data value sizes.

See also

get_value_size().

Parameters:
  • data (Data) – The data structure.

  • names (Iterable[str]) – The data names.

Returns:

The mapping from the data names to the data sizes.

Return type:

dict[str, int]

compute_names_to_slices(names, data, names_to_sizes=mappingproxy({}))

Compute a mapping from data names to data value slices.

The slices are relative to a NumPy array concatenating the data values associated with these data names.

Parameters:
  • data (Data) – The data structure.

  • names (Iterable[str]) – The data names.

  • names_to_sizes (Mapping[str, int]) –

    The mapping from the data names to the data sizes. If empty, it will be computed.

    By default it is set to {}.

Returns:

The mapping from the data names to the data slices of the expected concatenated NumPy array. and the size of this array.

Return type:

tuple[dict[str, slice], int]

convert_array_to_data(array, names_to_slices)

Convert a NumPy array to a data structure.

Parameters:
  • array (NumberArray) – The NumPy array to slice.

  • names_to_slices (Mapping[str, slice]) – The mapping from the data names to the array slices.

Returns:

The mapping from the data names to the array slices.

Return type:

dict[str, ValueType]

convert_array_to_value(name, array)

Convert a NumPy array to a data value.

Parameters:
  • name (str) – The data name.

  • array (NumberArray) – The NumPy array to convert.

Returns:

The data value.

Return type:

ValueType

convert_data_to_array(names, data)

Convert a part of a data structure to a NumPy array.

Parameters:
  • data (Data) – The data structure.

  • names (Iterable[str]) – The data names which values will be concatenated.

Returns:

The concatenated NumPy array.

Return type:

NumberArray

convert_value_to_array(name, value)

Convert a data value to a NumPy array.

Parameters:
  • name (str) – The data name.

  • value (ValueType) – The data value.

Returns:

The NumPy array.

Return type:

NumberArray

classmethod get_value_size(name, value)

Return the size of a data value.

The size is typically what is returned by ndarray.size or len(list). The size of a number is 1.

Parameters:
  • name (str) – The data name.

  • value (ValueType) – The data value to get the size from.

Returns:

The size.

Return type:

int

is_continuous(name)

Check that a data item has a type that can differentiate.

Parameters:

name (str) – The name of the data item.

Returns:

Whether the data item can differentiate.

Return type:

bool

is_numeric(name)

Check that a data item is numeric.

Parameters:

name (str) – The name of the data item.

Returns:

Whether the data item is numeric.

Return type:

bool