Skip to content

Required Vibration Frequencies

Overview

The RequiredVibrationFrequencies class is a subclass of CalculationRequirement that is used to get the vibration frequencies for a list of objects. This requirement is used to check if the vibration frequencies are present for a list of objects and to get the vibration frequencies for the desired period.

Usage

This requirements needs the name of the desired objects and the frequency names as they are defined in the attributes_def table in the database. We assume that the attribute name must start by the prefix FREQ- in the database, but when asking for the frequencies in this requirement, the prefix should not be used.

Below there is an example of how to instantiate this requirement:

requirement = RequiredVibrationFrequencies(
    frequencies={
        "LAN-LAN-01": ["HSS-RF", "GEN_BRG_RS-CF"],
        "LAN-LAN-02": ["GEN_BRG_RS-CF"]
    }
)

Database Requirements

This requirement expects that the vibration frequencies are defined in the attributes_def table in the database. The attribute name must start by the prefix FREQ-. After these attributes are defined, they must be associated to their respective subcomponent models in the subcomponent_model_attributes table. Finally, to associate the respective frequency to the object (wind turbine) we need an event in the events table that marks the installation or replacement of the component in the wind turbine.

THis structure allows for us to have not only the vibration frequencies for the correct model of gearbox, generator, etc that is installed in the wind turbine, but also have any changes of these frequencies in time (applicable for example when a component is replaced for a new one of a different model).

Class Definition

RequiredVibrationFrequencies(frequencies, optional=False)

Subclass of CalculationRequirement that defines the vibration frequencies that are required for the calculation.

This will check the performance database for the existence of the required frequencies for the wanted objects.

Arguments here are aligned with the arguments from perfdb.vibration.frequencies.get method.

Parameters:

  • frequencies

    (dict[str, list[str]]) –

    Dictionary with the object names as keys and the list of frequencies as values.

    The name of the frequencies must be like the ones in the database, ignoring the "FREQ-" prefix.

    Example: {"CLE-CLE1-01"["HSS-RF", "GEN_BRG_RS-CF"]}

  • optional

    (bool, default: False ) –

    Set to True if this is an optional requirement. by default False

Source code in echo_energycalc/calculation_requirement_vibration_frequencies.py
def __init__(
    self,
    frequencies: dict[str, list[str]],
    optional: bool = False,
) -> None:
    """
    Subclass of CalculationRequirement that defines the vibration frequencies that are required for the calculation.

    This will check the performance database for the existence of the required frequencies for the wanted objects.

    Arguments here are aligned with the arguments from perfdb.vibration.frequencies.get method.

    Parameters
    ----------
    frequencies : dict[str, list[str]]
        Dictionary with the object names as keys and the list of frequencies as values.

        The name of the frequencies must be like the ones in the database, ignoring the "FREQ-" prefix.

        Example: `{"CLE-CLE1-01"["HSS-RF", "GEN_BRG_RS-CF"]}`
    optional : bool, optional
        Set to True if this is an optional requirement. by default False
    """
    super().__init__(optional)

    # check if object_names are valid
    if not isinstance(frequencies, dict):
        raise TypeError(f"frequencies must be a dictionary, not {type(frequencies)}")
    if not all(isinstance(k, str) for k in frequencies):
        raise TypeError("Keys of frequencies must be strings")
    if not all(isinstance(v, list) for v in frequencies.values()):
        raise TypeError("Values of frequencies must be lists")

    self._frequencies = frequencies

checked property

Attribute that defines if the requirement has been checked. It's value will start as False and will be set to True after the check method is called.

Returns:

  • bool

    True if the requirement has been checked.

data property

Attribute used to store the data required for the calculation.

Initially it is None and will be set with the data acquired by the get_data method. The data type will depend on the subclass implementation, but usually it will be a pandas DataFrame or a dictionary.

Returns:

  • Any | None

    Returns the data required for the calculation.

frequencies property

Dictionary with the object names as keys and the list of frequencies as values.

Returns:

  • dict[str, list[str]]

    Dictionary with the object names as keys and the list of frequencies as values.

optional property

Attribute that defines if the requirement is optional.

If optional is True, the requirement is only validated to check if it could exist, not if it is actually present. This is useful for requirements that are not necessary for all calculations, but are useful for some of them.

Returns:

  • bool

    True if the requirement is optional.

check()

Method used to check if all required vibration frequencies are present in the database for each object.

This will raise an error if any of the required vibration frequencies are missing.

Returns:

  • bool

    Returns True if all required vibration frequencies are present in the database for each object.

Source code in echo_energycalc/calculation_requirement_vibration_frequencies.py
def check(self) -> bool:
    """
    Method used to check if all required vibration frequencies are present in the database for each object.

    This will raise an error if any of the required vibration frequencies are missing.

    Returns
    -------
    bool
        Returns True if all required vibration frequencies are present in the database for each object.
    """
    if self.optional:
        return True

    # checking if objects are present in the database
    objs = self._perfdb.objects.instances.get_ids(object_names=list(self.frequencies.keys()))
    if len(objs) != len(self.frequencies):
        wrong_objs = set(self.frequencies.keys()) - set(objs.keys())
        raise ValueError(f"Objects {wrong_objs} are not present in the database")

    # getting the frequencies for later checking
    freq_data: DataFrame = self._perfdb.vibration.frequencies.get(object_names=list(self.frequencies.keys()), reference_date="all")

    # listing all the required frequency names for all objects using a set comprehension that goes through all the frequencies for all objects
    required_freqs = {frequency for freq_list in self.frequencies.values() for frequency in freq_list}
    missing_freqs = required_freqs - set(freq_data.columns)
    if missing_freqs:
        raise ValueError(f"Missing frequencies {missing_freqs} for all objects")
    # keeping only the required frequencies
    freq_data = freq_data[list(required_freqs)].copy()
    # dropping rows with all NA values
    freq_data = freq_data.dropna(how="all", axis=0)

    # checking if all frequencies are present
    for obj, freqs in self.frequencies.items():
        obj_freq_data = freq_data.loc[IndexSlice[obj, :, :, :], :].copy()
        # removing all entire NA columns
        obj_freq_data = obj_freq_data.dropna(axis=1, how="all")

        # finding frequencies not in columns
        missing_freqs = set(freqs) - set(obj_freq_data.columns)
        if missing_freqs:
            raise ValueError(f"Object {obj} is missing frequencies {missing_freqs}")

    # saving data
    self._data: DataFrame = freq_data

    self._checked = True

    return True

get_data(**kwargs)

Method used to get the required vibration frequencies for the desired objects.

This will not do anything other than call the check() method because the check() method already gets the data.

Returns:

  • DataFrame

    DataFrame with index as MultiIndex[object_name, component_type_name, subcomponent_type_name, start_date] and columns as the frequencies. Component model and subcomponent model will also be available in the columns.

    start_date indicates when the frequencies started to be valid.

Source code in echo_energycalc/calculation_requirement_vibration_frequencies.py
def get_data(self, **kwargs) -> DataFrame:  # noqa: ARG002
    """
    Method used to get the required vibration frequencies for the desired objects.

    This will not do anything other than call the check() method because the check() method already gets the data.

    Returns
    -------
    DataFrame
        DataFrame with index as MultiIndex[object_name, component_type_name, subcomponent_type_name, start_date] and columns as the frequencies. Component model and subcomponent model will also be available in the columns.

        start_date indicates when the frequencies started to be valid.
    """
    # in case check() was not called before get_data(), calling it now
    if not self._checked:
        self.check()

    # nothing else needs to be done here because check() already gets the data

    return self.data