utils#

The py_fatigue.utils module collects all the utility functions and classes.

py_fatigue.utils.inplacify(method: Callable) Callable#

Make a method inplace.

Parameters:

method (Callable) – The method to make inplace.

Returns:

The inplace method.

Return type:

Callable

py_fatigue.utils.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:

tuple

Raises:

TypeError – If fig is not a matplotlib.figure.Figure instance

class py_fatigue.utils.IntInt(mean_bin_nr: int, range_bin_nr: int)#

Represents a pair of integers, namely the number of bins for mean and ranges

Parameters:

NamedTuple (NamedTuple) –

Create new instance of IntInt(mean_bin_nr, range_bin_nr)

mean_bin_nr: int#

Alias for field number 0

range_bin_nr: int#

Alias for field number 1

class py_fatigue.utils.ArrayArray(mean_bin_edges: np.ndarray, range_bin_edges: np.ndarray)#

Represents a pair of arrays, namely the mean and range bin edge values

Parameters:

NamedTuple (NamedTuple) –

Create new instance of ArrayArray(mean_bin_edges, range_bin_edges)

mean_bin_edges: ndarray#

Alias for field number 0

range_bin_edges: ndarray#

Alias for field number 1

class py_fatigue.utils.IntArray(mean_bin_nr: int, range_bin_edges: np.ndarray)#

Represents an integer and an array, namely the number of bins for mean and range bin edge values

Parameters:

NamedTuple (NamedTuple) –

Create new instance of IntArray(mean_bin_nr, range_bin_edges)

mean_bin_nr: int#

Alias for field number 0

range_bin_edges: ndarray#

Alias for field number 1

class py_fatigue.utils.ArrayInt(mean_bin_edges: np.ndarray, range_bin_edges: int)#

Represents an array and an integer, namely the number of bins for range and mean bin edge values

Parameters:

NamedTuple (NamedTuple) –

Create new instance of ArrayInt(mean_bin_edges, range_bin_edges)

mean_bin_edges: ndarray#

Alias for field number 0

range_bin_edges: int#

Alias for field number 1

class py_fatigue.utils.FatigueStress(_counts: ndarray, _values: ndarray, bin_width: float, _bin_lb: float | None = None, _bin_ub: float | None = None)#

Fatigue stress class. Mean stress, range, maximum, and minimum can inherit from this class that defines the following properties:

  • bin_edges: the bin edges for the histogram

  • bin_centers: the bin centers for the histogram

  • full: the full cycles

  • full_counts: the counts of the full cycles

  • half: the half cycles

  • half_counts: the counts of the half cycles

  • bins_idx: the index of the full cycles bins

  • binned_values: the binned full cycles

property bin_lb: float#

The lower bound of the bins. Casting resolves mypy error

property bin_ub: float#

The upper bound of the bins. Casting resolves mypy error

property counts: ndarray#

The number of cycles.

Returns:

counts

Return type:

np.ndarray

property values: ndarray#

The stress values.

Returns:

values

Return type:

np.ndarray

property bin_edges: ndarray#

The bin edges.

Returns:

bin_edges

Return type:

np.ndarray

property bin_centers#

The bin centers.

Returns:

bin_centers

Return type:

np.ndarray

property full#

The full cycles stresses.

Returns:

full

Return type:

np.ndarray

property half#

The half cycles stresses.

Returns:

half

Return type:

np.ndarray

property bins_idx#

The index of the full cycles bins.

Returns:

bins_idx

Return type:

np.ndarray

property binned_values#

The binned full cycles.

Returns:

binned_values

Return type:

np.ndarray

py_fatigue.utils.calc_bin_edges(bin_lb: float, bin_ub: float, bin_width: float) ndarray#

Calculate the bin edges for a fatigue histogram using the given bin width, lower bound and upper bound.

Parameters:
  • bin_lb (float) – Lowest bin edge value

  • bin_ub (float) – Uppest bin edge value

  • bin_width (float) – Bin width

Returns:

Bin edges

Return type:

np.ndarray

py_fatigue.utils.bin_upper_bound(bin_lower_bound: float, bin_width: float, max_val: float) float#

Returns the upper bound of the bin edges, given the lower bound, bin width and maximum value of the array. If the maximum value is not a multiple of the bin width, the upper bound is rounded up to the next multiple of the bin width. Also, if the maximum value is smaller than the lower bound, the upper bound is set to the lower bound.

Parameters:
  • bin_lower_bound (float) – Left edge of the first bin

  • bin_width (float) – Bin width

  • max_val (float) – Maximum value of the array to be binned

Returns:

The upper bound of the bin edges

Return type:

float

py_fatigue.utils.split_full_cycles_and_residuals(count_cycle: ndarray) tuple#

Returns the stress ranges or mean stresses from only the full cycles.

py_fatigue.utils.calc_full_cycles(stress: ndarray, count_cycle: ndarray, debug_mode: bool = False) ndarray#

Returns the stress ranges or mean stresses from only the full cycles.

py_fatigue.utils.calc_half_cycles(stress: ndarray, count_cycle: ndarray, debug_mode: bool = False) ndarray#

Returns the stress ranges or mean stresses from only the half cycles.

py_fatigue.utils.compare(a: Any, b: Any) bool#

Compare two objects.

Parameters:
  • a (Any) –

  • b (Any) –

Returns:

True if the a and b are equal, False otherwise.

Return type:

bool

py_fatigue.utils.split(what: int, by: int)#

Split an integer into a list of integers.

>>> split(5, 2)
[2, 3]
>>> split(20, 7)
[3, 3, 3, 3, 3, 3, 2]
Parameters:
  • what (int) – The integer to split

  • by (int) – The number of integers to split the integer into

Returns:

The list of integers

Return type:

list

class py_fatigue.utils.TypedArray#

Wrapper class for numpy arrays that stores and validates type information. This can be used in place of a numpy array, but when used in a pydantic BaseModel or with pydantic.validate_arguments, its dtype will be coerced at runtime to the declared type.

classmethod validate(val, field)#

Validate the value of the field.

py_fatigue.utils.to_numba_dict(data: dict, key_type: type = <class 'str'>, val_type: type = <class 'float'>) DictType#

Converts a dictionary to a numba typed dict, provided the output key and value types.

Parameters:
  • data (dict) – The dictionary to be converted.

  • key_type (type, optional) – The key type, by default str

  • val_type (type, optional) – The type of the values, by default float

Returns:

The numba typed dictionary.

Return type:

nb.types.DictType

py_fatigue.utils.chunks(lst: list[Any], n: int) Generator[list[Any], None, None]#

Yield successive n-sized chunks from lst.