"""Damping-ratio plotting against the operating parameter.
Renders the damping ratio of each tracked mode as a function of the operating
parameter (rotor speed or wind speed), the companion to the Campbell diagram for
assessing stability margins across the operating envelope.
"""
from __future__ import annotations
from typing import TYPE_CHECKING
import plotly.graph_objects as go
if TYPE_CHECKING:
from vane.campbell.builder import CampbellDiagram
__all__ = ["plot_damping"]
[docs]
def plot_damping(diagram: CampbellDiagram, *, as_percent: bool = True) -> go.Figure:
"""Plot damping ratio versus the operating parameter.
Parameters
----------
diagram : CampbellDiagram
The diagram whose tracks are plotted.
as_percent : bool, optional
Plot damping as a percentage (the default) rather than a fraction.
Returns
-------
plotly.graph_objects.Figure
The damping figure, one line per tracked mode.
"""
scale = 100.0 if as_percent else 1.0
figure = go.Figure()
for track in diagram.tracks:
x, _, damping = diagram.track_curve(track)
figure.add_trace(
go.Scatter(
x=x,
y=damping * scale,
mode="lines+markers",
name=track.label.label,
)
)
figure.update_layout(
title="Damping",
xaxis_title=diagram.parameter_name,
yaxis_title="Damping ratio (%)" if as_percent else "Damping ratio (-)",
)
return figure