utils#
- py_fatigue.cycle_count.utils.solve_lffd(x: Any) Any | CycleCount #
Solve the low-frequency fatigue dynamics of a cycle count or return the object as is.
- Parameters:
x (Any) – The object to evaluate. If it is a
CycleCount
instance, the low-frequency fatigue dynamics is solved. Otherwise, the object is returned as is.- Returns:
The object evaluated
- Return type:
Any
- py_fatigue.cycle_count.utils.aggregate_cc(df: pd.DataFrame, aggr_by: str, save_residuals: bool = False) pd.DataFrame | tuple[pd.DataFrame, DefaultDict[str, DefaultDict[str, list[float]]]] #
Aggregate a pandas dataframe by time window. The pandas dataframe must have a DatetimeIndex and at least one column whose name starts with ‘CC_’ containing
CycleCount
instances, e.g.,# DateTimeIndex
CC_CycleCount-name-1
CC_CycleCount-name-2
CC_CycleCount-name-3
CC_…
2018-01-01 00:00:00
CycleCount-name-1 (01 Jan 2018, 00:00)
CycleCount-name-2 (01 Jan 2018, 00:00)
CycleCount-name-3 (01 Jan 2018, 00:00)
…
2018-01-01 01:00:00
CycleCount-name-1 (01 Jan 2018, 01:00)
CycleCount-name-2 (01 Jan 2018, 01:00)
CycleCount-name-3 (01 Jan 2018, 01:00)
…
2018-01-01 02:00:00
CycleCount-name-1 (01 Jan 2018, 02:00)
CycleCount-name-2 (01 Jan 2018, 02:00)
CycleCount-name-3 (01 Jan 2018, 02:00)
…
⋮
⋮
⋮
⋮
⋱
The function performs the following workflow:
Perform initial checks on the input pandas dataframe
Build the aggregation dictionary
Aggregate the dataframe by time window, i.e. the aggregated CycleCounts
Retrieve the low-frequency fatigue dynamics on the aggregated dataframe
Save the residuals sequences of each aggregated CycleCount
- Parameters:
df (pd.DataFrame) – The dataframe to cluster
aggr_by (str) – The time window to cluster the dataframe by. It must be a valid pandas date offset frequency string or ‘all’. For all the frequency string aliases offered by pandas, see: pandas-timeseries.html#dateoffset-objects.
save_residuals (bool, optional) – If True, the residuals sequences of each aggregated CycleCount are saved
- Returns:
The aggregated dataframe and the residuals sequences of each aggregated
- Return type:
- py_fatigue.cycle_count.utils.plot_aggregated_residuals(res_dct: dict[str, DefaultDict[str, DefaultDict[str, list[float]]]], plt_prmtr: str, minor_grid: bool = True) tuple #
Plot the aggregated residuals sequences. T
- Parameters:
res_dct (dict[str, DefaultDict[str, DefaultDict[str, list[float]]]]) – The residuals sequences of each aggregated CycleCount as returned by
aggregate_cc()
.plt_prmtr (str) – The parameter to plot.
labels (Collection[str]) – The labels of the aggregated CycleCounts.
minor_grid (bool, optional) – Whether to plot the minor grid, by default True
- Returns:
- Return type:
tuple[plt.figure.Figure, plt.axes.Axes]
- py_fatigue.cycle_count.utils.calc_aggregated_damage(df: pd.DataFrame, sn: dict[str, SNCurve] | DefaultDict[str, SNCurve] | list[SNCurve] | SNCurve) pd.DataFrame #
Calculate the damage of each aggregated CycleCount. This function needs the output of
aggregate_cc()
.- Parameters:
df (pd.DataFrame) – The aggregated CycleCount as returned by
aggregate_cc()
.sn (DefaultDict[str, SNCurve]) – The S-N curves of each aggregated CycleCount.
- Returns:
The damage of each aggregated CycleCount as a multi-indexed dataframe.
- Return type:
pd.DataFrame