cycle_count#

The py_fatigue.py_fatigue module collects all functions related to cycle-counting(s) definition. The main class is CycleCount.

class py_fatigue.cycle_count.cycle_count.CycleCount(count_cycle: np.ndarray[Any, np.dtype[np.float64]], stress_range: np.ndarray[Any, np.dtype[np.float32]], mean_stress: np.ndarray[Any, np.dtype[np.float64]], timestamp: ADT | NDT = datetime.datetime(2024, 9, 5, 12, 37, 46, 241340, tzinfo=datetime.timezone.utc), unit: str = 'MPa', range_bin_lower_bound: float = 0.2, range_bin_width: float = 0.05, _mean_bin_lower_bound: float | None = None, mean_bin_width: float = 10, nr_small_cycles: float = 0, residuals_sequence: np.ndarray[Any, Any] = array([], dtype=float64), _min_max_sequence: np.ndarray[Any, Any] = array([], dtype=float64), lffd_solved: bool = False, mean_stress_corrected: str = 'No', stress_concentration_factor: float = 1.0, name: str | None = None, _time_sequence: np.ndarray | None = None)#

Cycle-counting class.

The class heavily relies on the py_fatigue.rainflow and py_fatigue.histogram modules.

CycleCount instances should be defined from either of the following two class methods:

classmethod from_rainflow(data: dict, timestamp: ADT | NDT = datetime.datetime(2024, 9, 5, 12, 37, 46, 241350, tzinfo=datetime.timezone.utc), round_decimals: int = 4, name: str | None = None, mean_stress_corrected: str = 'No', lffd_solved: bool = False, unit: str = 'MPa') CycleCount#

Create a cycle-counting object from rainflow cycles. :param *args: Positional arguments passed to py_fatigue.rainflow.rainflow. :param **kwargs: Keyword arguments passed to py_fatigue.rainflow.rainflow.

Returns:

A cycle-counting object.

Return type:

CycleCount

classmethod from_timeseries(data: ndarray, time: ndarray | None = None, timestamp: ADT | NDT = datetime.datetime(2024, 9, 5, 12, 37, 46, 241352, tzinfo=datetime.timezone.utc), range_bin_lower_bound: float = 0.2, range_bin_width: float = 0.05, mean_bin_lower_bound: float | None = None, mean_bin_width: float = 10, name: str | None = None, unit: str = 'MPa') CycleCount#

Generate a cycle-count from a timeseries.

Parameters:
  • *args – Positional arguments passed to _build_input_data_from_json.

  • **kwargs – Keyword arguments passed to _build_input_data_from_json.

property mean_bin_lower_bound: float#

The stress values.

Returns:

values

Return type:

np.ndarray

property time_sequence: ndarray#

The sequence of timestamps possibly added.

Returns:

time_sequence

Return type:

np.ndarray

property min_max_sequence: ndarray#

The minimum and maximum of the residuals (half-cycles) sequence.

Returns:

The minimum and maximum of the half-cycles sequence.

Return type:

np.ndarray, shape=(2, )

property residuals: ndarray#

Extracts the residuals, also known as half cycles, from mean-range couples of the cycle-counting object.

Returns:

Array containing mean stresses and stress ranges of the residuals. - residual_mean_stresses = array[:, 0] - residual_stress_ranges = array[:, 1]

Return type:

np.ndarray, shape (n, 2)

property full_cycles: ndarray#

Extracts the full cycles only from mean-range couples.

Returns:

Array containing mean stresses and stress ranges of the full cycles. - full_cycles_mean_stresses = array[:, 0] - full_cycles_stress_ranges = array[:, 1]

Return type:

np.ndarray, shape (n, 2)

property half_cycles: ndarray#

Symlink to residuals

See also

py_fatigue.cycle_count.CycleCount.residuals()

property mean_bin_upper_bound: float#

Returns the upper bound of the mean stress bin edges.

Returns:

The upper bound of the mean stress bins (highest mean bin edge).

Return type:

float

property range_bin_upper_bound: float#

Returns the upper bound of the stress range bins.

Returns:

The upper bound of the stress range bins (highest range bin edge).

Return type:

float

property bin_centers: tuple#

Extracts the bin centers from the cycle-counting object.

Returns:

Tuple containing mean stresses and stress ranges of the bin centers. - bin_centers_mean_stresses = tuple[0] - bin_centers_stress_ranges = tuple[1]

Return type:

tuple

property bin_edges: tuple#

Extracts the bin edges from the cycle-counting object.

Returns:

Tuple containing mean stresses and stress ranges of the bin edges. - bin_edges_mean_stresses = tuple[0] - bin_edges_stress_ranges = tuple[1]

Return type:

ht.tuple

property stress_amplitude: ndarray#

Extracts the stress amplitude from the cycle-counting object.

Returns:

Array containing the stress amplitude.

Return type:

np.ndarray

property min_stress: ndarray#

Extracts the min stress from the cycle-counting object.

Returns:

Array containing the min stresses.

Return type:

np.ndarray

property max_stress: ndarray#

Extracts the max stress from the cycle-counting object.

Returns:

Array containing the max stresses.

Return type:

np.ndarray

property statistical_moments: tuple[float, float, float]#

Calculate the spectral moments from the cycle-counting object.

Returns:

Tuple containing the spectral moments. - mean = tuple[0] - coefficient of variance = tuple[1] - skewness = tuple[2]

Return type:

tuple[float, float, float]

as_dict(damage_tolerance_for_binning: float = 0.001, damage_exponent: float = 5.0, round_decimals: int = 4, max_consecutive_zeros: int = 32, legacy_export: bool = False, debug_mode=False) dict#

Convert the cycle-counting object to a dictionary.

Parameters:
  • damage_tolerance_for_binning (float, optional) – Tolerance for large-cycles calculation when binning, by default 0.001

  • damage_exponent (float, optional) – SN curve exponent used to define large cycles. Higher means more conservative, by default 5.0

  • max_consecutive_zeros (int, optional) – maximum number of consecutive zeros before saving a cycle to large cycles array. This quantity is introduced to save storage space, by default 8

  • round_decimals (int, optional) – Number of decimals after comma, by default 4

Returns:

Dictionary containing the following keys: - “hist” - “range_bin_lower_bound” - “range_bin_width” - “mean_bin_lower_bound” - “mean_bin_width” - “nr_small_cycles” - “res_sig” - “res” - “lg_c”

Return type:

dict

See also

py_fatigue.cycle_count.rainflow_binner()

to_df() DataFrame#

Represent the CycleCount instance as a pandas dataframe.

Returns:

dataframe containing relevant fatigue information

Return type:

pd.DataFrame

solve_lffd(solve_mode: str = 'Residuals') CycleCount#

Resolve the LFFD using Marsh et al. (2016) method.

Parameters:

solve_mode (str) – Solve mode. Options are: “Residuals” and “Min-Max”.

Returns:

CycleCount instance with LFFD resolved.

Return type:

CycleCount

resolve_residuals() CycleCount#

Resolve the residuals. It is a symlink to solve_lffd().

Returns:

CycleCount instance with LFFD resolved.

Return type:

CycleCount

See also

solve_lffd()

mean_stress_correction(correction_type: str = 'DNVGL-RP-C203', plot: bool = False, enforce_pulsating_load: bool = False, **kwargs) CycleCount#

Calculates the mean stress correction returning a new CycleCount instance with corrected stress ranges at \(R=\sigma_{min}/\sigma_{max}=0\).

Parameters:
  • correction_type (str, optional) – Type of mean stress correction, by default “DNVGL-RP-C203”

  • plot (bool, optional) – Plot the mean stress corrected history, by default False

  • enforce_pulsating_load (bool, optional) – Choosing to enforce load ratio equals zero prior correction (useful in legacy analyses), by default False

  • correction_types (list) –

    • dnvgl-rp-c203

    • Goodman (not included yet)

  • **kwargs (dict) –

    detail_factorfloat

    See DNVGL-RP-C203, by default 0.8

    yield_strengthfloat

    Yielding stress amplitude

Returns:

CycleCount instance with corrected stress ranges

Return type:

CycleCount

Raises:
  • ValueErrorcorrection_type must be one of correction_types.

  • ValueError – Mean stress correction will not be applied because the initial mean stress array is made of zeros. Set enforce_load_ratio to True to proceed.

  • ValueError – This correction type is not supported.

plot_histogram(plot_type: str = 'min-max', mode: str = 'mountain', bins: int | Sequence[int] = 50, bin_range: ndarray | None = None, normed: bool = False, weights: ndarray | None = None, fig: Figure | None = None, ax: Axes | None = None, dens_func: Callable | None = None, **kwargs: dict) tuple#

Plot the rainflow histogram of the Cycle-counting instance with min and max stress on the x-y axes.

Parameters:
  • plot_type (str) – Type of plot to be generated, default is “min-max”. Possible values are: [“min-max”, “mean-range”]

  • mode ([None | 'mountain' | 'valley' | 'clip']) –

  • are (Possible values) –

    • NoneThe points are plotted as one scatter object, in the

      order in-which they are specified at input

    • ’mountain’The points are sorted/plotted in the order of

      the number of points in their ‘bin’. This means that points in the highest density will be plotted on-top of others. This cleans-up the edges a bit, the points near the edges will overlap

    • ’valley’The reverse order of ‘mountain’. The low density

      bins are plotted on top of the high ones

  • bins (int or array_like or [int, int] or [array, array]) –

    The bin specification, by default 50 bins are used:
    • If int, the number of bins for the two dimensions

      (nx=ny=bins)

    • If array_like, the bin edges for the two dimensions

      (x_edges = y_edges = bins)

    • If [int, int], the number of bins in each dimension

      (n_x, n_y = bins)

    • If [array, array], the bin edges in each dimension

      (x_edges, y_edges = bins)

    • A combination [int, array] or [array, int], where int

      is the number of bins and array is the bin edges

  • bin_range (array_like, shape(2,2), optional) – The leftmost and rightmost edges of the bins along each dimension (if not specified explicitly in the bins parameters): [[x_min, x_max], [y_min, y_max]]. All values outside of this range will be considered outliers and not tallied in the histogram. The default value is None, in which case all values are tallied

  • normed (bool, optional) – If False, returns the number of samples in each bin. If True, returns the bin density bin_count / sample_count / bin_area, default is False.

  • weights (array_like, shape(N,), optional) – An array of values w_i weighing each sample (y_i, x_i). Weights are normalized to 1 if normed is True. If normed is False, the values of the returned histogram are equal to the sum of the weights belonging to the samples falling into each bin. The default is None, which gives each sample equal weight

  • fig (matplotlib.figure.Figure, optional) – a Figure instance to add axes into

  • dens_func (function or callable, optional) – A function that modifies (inputs and returns) the dens values (e.g., np.log10). The default is to not modify the values

  • kwargs (these keyword arguments are all passed on to scatter) –

Returns:

  • figure, paths (() – ~matplotlib.figure.Figure, ~matplotlib.axes.Axes

  • ) – The figure with scatter instance.

plot_residuals_sequence(fig: Figure | None = None, ax: Axes | None = None, **kwargs) Tuple[Figure, Axes]#

Plot the residuals of the stress-strain curve.

Parameters:
  • fig (Optional[matplotlib.figure.Figure], optional) – a Figure instance to add axes into, by default None

  • ax (Optional[matplotlib.axes.Axes], optional) – an Axes instance to add axes into, by default None

Returns:

  • Tuple[ – matplotlib.figure.Figure, matplotlib.axes.Axes

  • ] – The figure with plot instance.

plot_half_cycles_sequence(fig: Figure | None = None, ax: Axes | None = None, **kwargs) Tuple[Figure, Axes]#

A symlink to plot_residuals_sequence.

Parameters:
  • fig (Optional[matplotlib.figure.Figure], optional) – a Figure instance to add axes into, by default None

  • ax (Optional[matplotlib.axes.Axes], optional) – an Axes instance to add axes into, by default None

Returns:

  • Tuple[ – matplotlib.figure.Figure, matplotlib.axes.Axes

  • ] – The figure with plot instance.