gemseo / wrappers / matlab

matlab_data_processor module

Definition of Matlab data processor.

Overview

The class and functions in this module enables to manipulate data from and toward the Matlab workspace. It also enables to read and write Matlab data file (.mat).

Classes:

MatlabDataProcessor()

A Matlab data processor.

Functions:

array2double(data_array)

Turn a ndarray into a matlab.double.

convert_array_from_matlab(data)

Convert dict of matlab.output to dict of ndarray.

convert_array_to_matlab(data)

Convert gems dict of ndarray to dict of matlab.double.

double2array(matlab_double)

Turn a matlab double into ndarray.

load_matlab_file(file_path)

Read .mat file and convert it to usable format for Matlab.

save_matlab_file(dict_to_save[, file_path])

Create a .mat file from dict of ndarray.

class gemseo.wrappers.matlab.matlab_data_processor.MatlabDataProcessor[source]

Bases: gemseo.core.data_processor.DataProcessor

A Matlab data processor.

Convert GEMSEO format to Matlab format.

Examples

>>> # Build a new instance
>>> proc = MatlabDataProcessor()
>>> # initial python data
>>> d = {"x": array([2]), "y": array([2j], dtype="complex")}
>>> # process data to matlab format
>>> res = proc.pre_process_data(d)
>>> print(res)
>>>
>>> # initial data in matlab format
>>> d = {"y": double([2, 3]), "x": double([2j], is_complex=True)}
>>> # process to Python format
>>> res = proc.post_process_data(d)
>>> print(res)

Methods:

post_process_data(data)

Transform the output data from Matlab to GEMSEO.

pre_process_data(data)

Transform data from GEMSEO to Matlab.

post_process_data(data)[source]

Transform the output data from Matlab to GEMSEO.

Parameters

data (Mapping[str, matlab.double]) – The data with matlab arrays.

Returns

The data with numpy arrays.

Return type

Mapping[str, ndarray]

pre_process_data(data)[source]

Transform data from GEMSEO to Matlab.

The function takes a dict of ndarray and return a dict of matlab.double.

Parameters

data (Mapping[str, ndarray]) – The input data.

Returns

The data with matlab array types.

Return type

Mapping[str, matlab.double]

gemseo.wrappers.matlab.matlab_data_processor.array2double(data_array)[source]

Turn a ndarray into a matlab.double.

Parameters

data_array – The numpy array to be converted.

Returns

The matlab.double value.

gemseo.wrappers.matlab.matlab_data_processor.convert_array_from_matlab(data)[source]

Convert dict of matlab.output to dict of ndarray.

Parameters

data (Mapping[str, matlab.double]) – The dict of matlab.double.

Returns

The dict of ndarray.

Return type

Mapping[str, ndarray]

gemseo.wrappers.matlab.matlab_data_processor.convert_array_to_matlab(data)[source]

Convert gems dict of ndarray to dict of matlab.double.

Parameters

data (Mapping[str, ndarray]) – The dict of ndarray.

Returns

The dict of matlab.double.

Return type

Mapping[str, matlab.double]

gemseo.wrappers.matlab.matlab_data_processor.double2array(matlab_double)[source]

Turn a matlab double into ndarray.

Parameters

matlab_double (matlab.double) – The matlab.double values.

Returns

The array of values.

Return type

ndarray

gemseo.wrappers.matlab.matlab_data_processor.load_matlab_file(file_path)[source]

Read .mat file and convert it to usable format for Matlab.

Parameters

file_path (Union[str, Path]) – The path to a .mat file.

Returns

The dict of matlab.double.

Return type

Mapping[str, matlab.double]

gemseo.wrappers.matlab.matlab_data_processor.save_matlab_file(dict_to_save, file_path='output_dict', *args, **kwargs)[source]

Create a .mat file from dict of ndarray.

Parameters
  • dict_to_save (dict) – The dict of ndarray to be saved.

  • file_path (Union[str, pathlib.Path]) –

    The path where to sabe the file.

    By default it is set to output_dict.

  • *args (bool) – The list of scipy.io.savemat options.

  • **kwargs (bool) – The dict of scipy.io.savemat options.

Raises

ValueError – If the saved dictionary is nor composed of ndarray only.

Return type

None