Algebraic Functions

pycube.algebra.equations.par_equation()

Treat signals of the input h5 file by a list of equations generating new signals written to the output h5 file.

An equation is given by a string in the form:

[result_signal] = sin([input_signal1]) + cos([group1/input_signal2]) * 1.234

where square brackets mark signal names (including their path if applicable).

Attention: With square brackets serving as signal name delimiters and round brackets serving as function delimiters, no use of bracket is possible within signal names!

Set one equation string to “help” to get a list of available functions and constants.

Cube Parameters:
  • task_source (str): name of the source task, with h5 file with the signals in the subfolder ‘results’

  • task_target (str, optional): name of the target task, defaults to current task

  • equations (list[str]): list of equation strings

  • units (list[str], optional): list of corresponding result units

  • parallel (bool, optional): if True, h5 files are treated in parallel, defaults to True

Function Help:
  • fft: Calculate amplitude spectrum of x by FFT with amplitude-preserving

    normalization to peak amplitude. Segments of x are windowed and averaged to reduce noise. The spectrum is one-sided for real-valued input. The inner bins are doubled to preserve the amplitude, except for the DC bin and the Nyquist bin (if nperseg is even).

    • Parameter explanation:
      • x: Time data input

      • nperseg: Length per time sequence segment

      • percent_overlap: percent overlap of segments. Defaults to 50.

      • window: Type of window, see scipy.signal.windows.get_window for details.

        Defaults to ‘hann’.

      • zero_padding_factor: Factor by which to increase nperseg for zero-padding,

        defaults to 1 (no zero-padding)

      • detrend: Detrend method, either ‘constant’ (subtract mean) or None

        (no detrending), defaults to ‘constant’

      • average: Method to average spectra of segments, either ‘mean’, ‘median’,

        ‘rms’ or ‘peak_hold’, defaults to ‘peak_hold’

      • output: amplitude spectrum of x

    See Also

    numpy.fft : For definition of the DFT and conventions used.

pycube.algebra.doe.par_doe(user_function=None)

Generate a doe design matrix, specified by a design parameter dict.

The design matrix is stored into csv and xlsx files.

Currently supported designs patterns are:

  • full factorial test design

For more information see: https://github.com/tirthajyoti/doepy/blob/master/docs/index.rst

The values that define the design matrix are specified as a model parameter dict:

model_parameter = {
    'Param1' (str): [value_1, value_2, ...] (float),
    'Param2' (str): [value_1, value_2, ...] (float),
    'Param3' (str): [value_1, value_2, ...] (float),
    ...,
}

There is a user function available to manipulate or overload the design matrix.

The functional body looks as follows:

external_design_matrix_name = "my_external_matrix.xlsx"

def user_function(
        source_path: Path | str,
        df: pf.DataFrame
):

    global external_design_matrix_name

    if external_design_matrix_name:
        source_path = Path(source_path)
        df = filetools.load_data_as_dataframe(
            source_path / external_design_matrix_name
        )

    # This section is used for the manipulation of the dataframe
    # It must be adapted to the specific requirements of the experiment
    # As an example: remove all entries for Param1 * Param3 <= 333.
    for index, row in df.iterrows():
        if row['Param1'] * row['Param3'] <= 333:
            df.drop(index, inplace=True)

    return df

The resulting design matrix is a Pandas dataframe looks as follows:

Param1;Param2;Param3
1.0;1.0;1.0
2.0;1.0;1.0
3.0;1.0;1.0
1.0;2.0;1.0
2.0;2.0;1.0
3.0;2.0;1.0
...;...;...
...

The dataframe is written as csv and xlsx file into the target directory

Cube Parameters:
  • task_source (str): name of the source task with an external design matrix files

  • task_target (str, optional): name of the target task, defaults to current task

  • target_filename (str): name of the final design matrix file

  • model_parameter (dict): dict with design parameter to create the design matrix