histogram#
The following code is based on the histogram function from the numpy package [4].
- py_fatigue.cycle_count.histogram.make_axes(fig: Figure | None = None, ax: Axes | None = None) Tuple[Figure, Axes] #
Check if a figure and axes are provided, and if not, create them.
- Parameters:
fig (Optional[matplotlib.figure.Figure], optional) – The figure instance, by default None
ax (Optional[matplotlib.axes.Axes], optional) – The axes instance, by default None
- Returns:
The figure and axes instances
- Return type:
- Raises:
TypeError – If fig is not a matplotlib.figure.Figure instance
- py_fatigue.cycle_count.histogram.make_histogram(mean_stress: ndarray, stress_range: ndarray, bins: int | Sequence[int] = 10, bin_range: ndarray | None = None, normed: bool = False, weights: ndarray | None = None) tuple #
Make a scattered-histogram plot.
- Parameters:
stress_range (mean_stress,) – Input data
bins (int or array_like or [int, int] or [array, array], optional) –
- The bin specification:
If int, the number of bins for the two dimensions (nx=ny=bins).
If array_like, the bin edges for the two dimensions (stress_range_edges=mean_stress_edges=bins).
If [int, int], the number of bins in each dimension (n_stress_range, n_mean_stress = bins).
If [array, array], the bin edges in each dimension (stress_range_edges, mean_stress_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):
[[stress_range_min, stress_range_max], [mean_stress_min, mean_stress_max]]
. All values outside of this range will be considered outliers and not tallied in the histogram.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
.weights (array_like, shape(N,), optional) – An array of values
w_i
weighing each sample(stress_range_i, mean_stress_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.
- Returns:
hist (np.ndarray, shape(m,m)) – Histogram matrix.
hist_edges (ArrayArray, (shape(m+1,), shape(m+1,))) – Histogram bin edges.
- py_fatigue.cycle_count.histogram.rainflow_binner(ranges: StressRange, _means: MeanStress | None, damage_tolerance_for_binning: float = 0.001, damage_exponent: float = 5.0, max_consecutive_zeros: int = 12, round_decimals: int = 4, debug_mode: bool = True) dict #
Binning the rainflow cycles into mean-range bins up to a certain stress range which is based on the damage tolerance index. All the cycles beyond such stress range are saved separately for accuracy reasons as “large cycles”.
By default, large cycles are calculated from all the cycles accounting for more than 0.1% of the total damage and that have a discrepancy of more than 0.1% with respect to the damage that would be obtained from the bin center.
- Parameters:
ranges (StressRange) – The stress range object.
_means (Optional[MeanStress], optional) – The mean stress object. If not provided, the mean stress is set to zero.
damage_tolerance_for_binning (float, optional) – tolerance for the damage when binning large cycles separately, by default 1e-3
damage_exponent (float, optional) – exponent for the damage when binning large cycles separately, 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 to round the output, by default 4
debug_mode (bool, optional) – if True, print debug messages, by default False
- Returns:
out_dct – A dictionary with the following keys: - “nr_small_cycles”: number of small cycles - “range_bin_lower_bound”: lower bound of the range bin - “range_bin_width”: width of the range bins - “mean_bin_lower_bound”: lower bound of the mean bin - “mean_bin_width”: width of the mean bins - “hist”: histogram of the rainflow cycles - “lg_c”: large cycles - “res”: residuals - “res_sig”: residuals sequence
- Return type:
See also
- py_fatigue.cycle_count.histogram.binned_rainflow(data: ndarray | list, time: ndarray | list | None = None, range_bin_lower_bound: float = 0.2, range_bin_width: float = 0.05, range_bin_upper_bound: float | None = None, mean_bin_lower_bound: float | None = None, mean_bin_width: float = 10.0, mean_bin_upper_bound: float | None = None, damage_tolerance_for_binning: float = 0.001, max_consetutive_zeros: int = 10, damage_exponent: float = 5.0, round_decimals: int = 4, debug_mode: bool = False)#
Returns the cycle-count of the input data calculated through the rainflow method.
- Parameters:
data (np.ndarray) – time series or residuals sequence
time (Optional[Union[np.ndarray, list]], optional) – sampled times, by default None
range_bin_lower_bound (float, optional) – lower bound of the range bin, by default 0.2
range_bin_width (float, optional) – width of the range bin, by default 0.05
range_bin_upper_bound (Optional[float], optional) – upper bound of the range bin, by default None
mean_bin_lower_bound (Optional[float], optional) – lower bound of the mean bin, by default None
mean_bin_width (float, optional) – width of the mean bin, by default 10
mean_bin_upper_bound (Optional[float], optional) – upper bound of the mean bin, by default None
damage_tolerance_for_binning (float, optional) – tolerance for the damage when binning large cycles separately, by default 1e-3
damage_exponent (float, optional) – exponent for the damage when binning large cycles separately, by default 5.0
round_decimals (int, optional) – number of decimals to round the output, by default 4
debug_mode (bool, optional) – if True, print debug messages, by default False
- Returns:
- if np.ndarray:
- rfsnp.ndarray
rainflow [ampl ampl_mean nr_of_cycle cycle_begin_time cycle_period_time]
- if tuple:
- rfsnp.ndarray
rainflow [ampl ampl_mean nr_of_cycle cycle_begin_time cycle_period_time]
- data[res_tp]numpy.ndarray
the residuals signal
- res_tpnumpy.ndarray
the indices of the residuals signal
- time[res_tp]numpy.ndarray
the time signal for residuals
- Return type:
Union[np.ndarray, tuple]
- Raises:
TypeError – data shall be numpy.ndarray or list
See also
calc_rainflow()
,rainflow_binner()
- py_fatigue.cycle_count.histogram.xy_hist2d(x: FloatArray, y: FloatArray, mode: str = 'mountain', bins: int | Sequence[int] = 10, bin_range: FloatArray | None = None, normed: bool = False, weights: FloatArray | None = None, fig: Figure | None = None, ax: PathCollection | None = None, dens_func: Callable | None = None, **kwargs: dict) tuple #
Make a scattered-histogram plot.
- Parameters:
y (x,) – Input data
marker_size (int) – Size of the markers
mode ([None | 'mountain' | 'valley' | 'clip']) –
- Possible values are:
- 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], optional) –
- The bin specification:
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.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
.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.fig (a figure instance to add.) –
ax (an axes instance to plot into.) –
dens_func (function or callable (default: None)) – A function that modifies (inputs and returns) the dens values (e.g., np.log10). The default is to not modify the values.
x_label (str, optional) – Label for the x-axis
y_label (str, optional) – Label for the y-axis
cbar_label (str, optional) – Label for the colorbar
kwargs (these are all passed on to scatter.) –
- Returns:
figure, paths (() – ~matplotlib.figure.Figure, ~matplotlib.collections.PathCollection
) – The figure with scatter instance.