data_conversion module¶
Convert arrays/dict of arrays data¶
-
class
gemseo.utils.data_conversion.
DataConversion
[source]¶ Bases:
object
This class contains static methods that convert: - data dict into numpy array - numpy array into data dict by updating an existing dict
-
FLAT_JAC_SEP
= '!d$_$d!'¶
-
static
array_to_dict
(data_array, data_names, data_sizes)[source]¶ Convert an array into a dict
- Parameters
data_array – the array
data_names – list of names (keys of the resulting dict)
data_sizes – dict of (name, size)
- Returns
a dict
- Return type
dict
-
static
deepcopy_datadict
(data_dict, keys=None)[source]¶ Performs a deepcopy of a data dict treats numpy arrays specially using array.copy() instead of deepcopy
- Parameters
data_dict – data dict to copy
-
static
dict_jac_to_2dmat
(jac_dict, outputs, inputs, data_sizes)[source]¶ Converts a dict of dict sparse format jacobian to a full 2D jacobian
:param jac_dict : the jacobian dict of dict :param inputs: derive outputs wrt inputs :param outputs: outputs to be derived :param data_sizes: dict of (name, size) for names in inputs and outputs
-
static
dict_jac_to_dict
(jac_dict)[source]¶ Converts a full 2D jacobian to a flat dict
:param jac_dict : the jacobian dict of dict
-
static
dict_to_array
(data_dict, data_names)[source]¶ Convert a dict into an array
- Parameters
data_dict – the data dictionary
data_names – the data keys to concatenate
- Returns
an array
- Return type
ndarray
-
static
dict_to_jac_dict
(flat_jac_dict)[source]¶ Converts a flat dict to full 2D jacobian
:param flat_jac_dict : the jacobian dict
-
static
flat_jac_name
(out_name, inpt_name)[source]¶ get the flat jacobian name from the full jacobian name :param out_name: name of output :param inpt_name: name of input
-
static
get_all_inputs
(disciplines, recursive=False)[source]¶ Lists all the inputs of the disciplines Merges the input data from the disicplines grammars
- Parameters
disciplines – the list of disciplines to search
recursive – if True, searches for the inputs of the sub disciplines (when some disciplines are scenarios)
- Returns
the list of input data
-
static
get_all_outputs
(disciplines, recursive=False)[source]¶ Lists all the outputs of the disciplines Merges the output data from the disciplines grammars
- Parameters
disciplines – the list of disciplines to search
recursive – if True, searches for the outputs of the sub disciplines (when some disciplines are scenarios)
- Returns
the list of output data
-
static
jac_2dmat_to_dict
(flat_jac, outputs, inputs, data_sizes)[source]¶ Converts a full 2D jacobian to a dict of dict sparse format
:param flat_jac : the flat 2D jacobian :param inputs: derive outputs wrt inputs :param outputs: outputs to be derived :param data_sizes: dict of (name, size) for names in inputs and outputs
-
static
jac_3dmat_to_dict
(jac, outputs, inputs, data_sizes)[source]¶ Converts a 3D jacobian (list of 2D jacobians) to a dict of dict sparse format.
:param jac : list of 2D jacobians :param inputs: derive outputs wrt inputs :param outputs: outputs to be derived :param data_sizes: dict of (name, size) for names in inputs and outputs
-
static
list_of_dict_to_array
(data_list, data_names, group=None)[source]¶ Convert a list of dict into an array
- Parameters
data_list – the data list
data_names – the data keys to concatenate
group – groupe of keys to concatenate
- Returns
an array
- Return type
ndarray
-
static
update_dict_from_array
(reference_input_data, data_names, values_array)[source]¶ Updates a data dictionary from values array The order of the data in the array follows the order of the data names
- Parameters
reference_input_data – the base input data dict
data_names – the dict keys to be updated
values_array – the data array to update the dictionary
- Returns
the updated data dict
-