Extra1 - Tips and Tricks 1

In this example file we will dive a bit more into pyOMA2 functionalities. Check out the documentation to get a full description of the various classes, functions, attributes, method and arguments (https://pyoma.readthedocs.io/en/main/).

To start the analysis we need to have the data loaded as an array with shape (Ndat, Nchannels), where Ndat is the number of datapoints (i.e. sampling frequency * period of acquisition), and Nchannels is the number of sensors/channels.

import os
import sys
import numpy as np
# Add the directory we execute the script from to path:
sys.path.insert(0, os.path.realpath('__file__'))

# import the necessary functions and classes
from pyoma2.functions.gen import example_data
from pyoma2.setup.single import SingleSetup
from pyoma2.algorithms.data.run_params import EFDDRunParams, SSIRunParams
from pyoma2.algorithms.fdd import FSDD
from pyoma2.algorithms.ssi import SSI
from pyoma2.functions.plot import plot_mac_matrix, plot_mode_complexity
from pyoma2.functions.gen import save_to_file, load_from_file

# generate example data and results
data, ground_truth = example_data()

# Create an instance of the setup class
simp_5dof = SingleSetup(data, fs=100)

Once we have created the instance of the setup class we have access to a series of methods (and attributes) that let us inspect the data: - The data attribute stores the input data. - The fs attribute stores the sampling frequency. - The dt attribute stores the sampling interval. - The algorithms attribute stores the algorithms associated with the setup. - The plot_STFT() method is used to plot the Short-Time Fourier Transform (STFT) magnitude spectrogram for the specified channels, useful to get a graphical feedback regarding the time invariance of the data. - The plot_ch_info() method plots information for the specified channels, including time history, normalized auto-correlation, power spectral density (PSD), probability density function, and normal probability plot, useful to get a feedback regarding the quality of the data. - The plot_data() method plots the time histories of the data channels in a subplot format.

Moreover we have access to some methods useful to pre-process the data at hand: - The decimate_data() method decimates the data. - The detrend_data() method detrends the data. - The filter_data() method applies a Butterworth filter to the data. - The rollback() method restores the data and sampling frequency to their initial state.

# Decimate the data
simp_5dof.decimate_data(q=2)

Once we´re done with the pre-processing we can start with the analysis.

The next step is the initialisation of the desired OMA algorithms that will be added to the setup instance.

The parameters required to run each algorithm can be passed one by one to the algorithm instance or in group through the run_params argument.

# Import FSDD run parameters (default values) and print out as dictionary
fsdd_runpar = EFDDRunParams()
dict(fsdd_runpar)
# Do the same for SSI, changing some of the default arguments
ssi_runpar = SSIRunParams(method="cov", br=20, ordmax=50, calc_unc=True, step=2)
dict(ssi_runpar)
# Initialise the algorithms
fsdd = FSDD(name="FSDD", run_params=fsdd_runpar)
# Equivalent to
fsdd1 = FSDD(name="FSDD1")

ssicov = SSIcov(name="SSIcov", run_params=ssi_runpar)
# Equivalent to
ssicov1 = SSIcov(name="SSIcov1", method="cov", br=20, ordmax=50, calc_unc=True, step=2)

The run_params attribute of the algorithm instance let us inspect the parameters passed and overwrite/update them if needed.

# Inspect the parameters passed
print("SSI run parameters: ", ssicov.run_params)

# Overwrite/update run parameters for an algorithm
fsdd.run_params = FSDD.RunParamCls(nxseg=2048, method_SD="per", pov=0.5)
print("")
print("FSDD run parameters: ", fsdd.run_params)

With the new release we have moved some of the parameters that were actually used for the mpe() and mpe_from_plot() methods to a specialised class MPEParams.

Now the algorithms can be added to the setup instance and executed collectively or by name.

# Add algorithms to the class
simp_5dof.add_algorithms(fsdd, ssicov)

# to check which algorithms have been added, we can call the algorithms attribute
simp_5dof.algorithms
# run all
simp_5dof.run_all()
# or run by name
# simp_5dof.run_by_name("SSIcov", "FSDD")

Once the algorithms have been run, we gain access to plotting options such as: - The plot_CMIF() method for the FDD family of classes, which shows the plot of the singular values of the Spectral Density matrix. - The plot_stab() method for the SSI family of classes, which shows the stabilisation of the identified poles for increasing model order.

SSI algorithms have also access to the plot_freqvsdamp() method which shows the frequency-damping cluster diagram.

ssicov.plot_freqvsdamp()

Color Schemes for Stabilization Plots

The stabilization plots (plot_stab() and plot_freqvsdamp()) now support different color schemes to improve accessibility and readability. By default, the plots use the original green/red colors, but you can select from several alternatives:

Available Color Schemes:

  • 'default': Green/red colors (original scheme)

  • 'classic': Blue/orange colors (colorblind-friendly)

  • 'high_contrast': Black/gray colors (excellent for B&W printing)

  • 'viridis': Colors from the viridis colormap (scientific publication friendly)

Usage Examples:

# Default colors (green/red)
ssicov.plot_stab()

# Colorblind-friendly blue/orange colors
ssicov.plot_stab(color_scheme='classic')

# High contrast for B&W printing
ssicov.plot_stab(color_scheme='high_contrast')

# Scientific publication colors
ssicov.plot_freqvsdamp(color_scheme='viridis')

The color_scheme parameter is available for both SSI and pLSCF algorithms in their plot_stab() and plot_freqvsdamp() methods.