The BaseAlgorithm class

class pyoma2.algorithms.base.BaseAlgorithm(run_params: T_RunParams | None = None, name: str | None = None, *args: Any, **kwargs: Any)[source]

Bases: Generic[T_RunParams, T_Result, T_Data], ABC

Abstract base class for OMA algorithms.

This class serves as a foundational structure for implementing various OMA algorithms, setting a standard interface and workflow.

result

Stores the results produced by the algorithm. The type of result depends on T_Result.

Type:

Optional[T_Result]

run_params

Holds the parameters necessary to run the algorithm. The type of run parameters depends on T_RunParams.

Type:

Optional[T_RunParams]

name

The name of the algorithm, used for identification and logging.

Type:

Optional[str]

RunParamCls

The class used for instantiating run parameters. Must be a subclass of BaseModel.

Type:

Type[T_RunParams]

ResultCls

The class used for encapsulating the algorithm’s results. Must be a subclass of BaseResult.

Type:

Type[T_Result]

fs

The sampling frequency of the input data.

Type:

Optional[float]

dt

The sampling interval, derived from the sampling frequency.

Type:

Optional[float]

data

The input data for the algorithm. The type of data depends on T_Data.

Type:

Optional[T_Data]

__init__(self, run_params=None, name=None, \*args, \*\*kwargs)[source]

Initializes the algorithm with optional run parameters and a name.

set_run_params(self, run_params)[source]

Sets the run parameters for the algorithm.

_set_result(self, result)[source]

Assigns the result to the algorithm after execution.

_set_data(self, data, fs)[source]

Sets the input data and sampling frequency for the algorithm.

__class_getitem__(cls, item)[source]

Evaluates the types of RunParamCls and ResultCls at runtime.

__init_subclass__(cls, \*\*kwargs)[source]

Ensures that subclasses define RunParamCls and ResultCls.

Warning

The BaseAlgorithm class is not intended for direct instantiation by users. Specific functionalities are provided through its subclasses.

__init__(run_params: T_RunParams | None = None, name: str | None = None, *args: Any, **kwargs: Any)[source]

Initialize the algorithm with optional run parameters and a name.

Parameters:
  • run_params (Optional[T_RunParams], optional) – The parameters required to run the algorithm. If not provided, can be set later.

  • name (Optional[str], optional) – The name of the algorithm. If not provided, defaults to the class name.

  • *args (tuple) – Additional positional arguments.

  • **kwargs (dict) – Additional keyword arguments used to instantiate run parameters if run_params is not provided.

abstract mpe(*args, **kwargs) Any[source]

Abstract method to return the modal parameters extracted by the algorithm.

Parameters:
  • *args (tuple) – Positional arguments.

  • **kwargs (dict) – Keyword arguments.

Returns:

The modal parameters extracted by the algorithm.

Return type:

Any

Raises:
  • NotImplementedError – If the method is not implemented in the subclass.

  • ValueError – If the algorithm has not been run or the result is not set.

Note

Implementing classes should override this method to provide functionality for extracting and returning modal parameters based on the algorithm’s results.

abstract mpe_from_plot(*args, **kwargs) Any[source]

Abstract method to select peaks or modal parameters from plots.

Parameters:
  • *args (tuple) – Positional arguments.

  • **kwargs (dict) – Keyword arguments.

Returns:

The selected peaks or modal parameters.

Return type:

Any

Raises:
  • NotImplementedError – If the method is not implemented in the subclass.

  • ValueError – If the algorithm has not been run or the result is not set.

Note

Implementing classes should provide mechanisms for selecting and returning peaks or modal parameters from graphical plots or visual representations of the data.

abstract run() T_Result[source]

Abstract method to execute the algorithm.

This method must be implemented by all subclasses. It should use the set run_params and input data to perform the modal analysis and save the result in the result attribute.

Returns:

The result of the algorithm execution.

Return type:

T_Result

Raises:

NotImplementedError – If the method is not implemented in the subclass.

Note

Implementing classes should handle the algorithm logic within this method and ensure that the output is an instance of the ResultCls.

set_run_params(run_params: T_RunParams) BaseAlgorithm[source]

Set the run parameters for the algorithm.

Parameters:

run_params (T_RunParams) – The run parameters for the algorithm.

Returns:

Returns the instance with updated run parameters.

Return type:

BaseAlgorithm

Note

This method allows dynamically setting or updating the run parameters for the algorithm after its initialization.