mooonpy.tools.math_utils module

class mooonpy.tools.math_utils.MixingRule(style='add')[source]

Bases: object

Initialize the mixing rule with a specific method name.

Parameters:

style – The name of the addition method to use

mooonpy.tools.math_utils.aggregate_fun(fun_name: str, vector: ndarray | list) Number[source]

Apply generic aggregate functions to a vector, similar to the bottom row of a spreadsheet. Modes control values to be ignored in operation, by slicing the vector before the operation.

Note that operating on an empty sclice will return a np.nan.

Currently supported Operators: fun_name must start with one of these substrings
  • sum: Summation

  • avg: Arithmetic mean

  • std: Standard Deviation

Currently supported Modes: if fun_name ends with one of these substrings, the rule is applied

-0: Ignores 0’s -None: Ignores None or nan

Parameters:
  • fun_name (str) – Selection of Function and Mode.

  • vector (list or numpy array) – row or column vector to operate on.

Returns:

Result of operation.

Return type:

Number

Example:
>>> from mooonpy.tools import aggregate_fun
>>> MyVect = [0,1,2]
>>> avg_no0 = aggregate_fun('avg0', MyVect)
1.5
>>> avg_all = aggregate_fun('avg', MyVect)
1.0
mooonpy.tools.math_utils.compute_derivative(xdata: ndarray | list, ydata: ndarray | list) Tuple[ndarray, ndarray, ndarray][source]

Function to compute the 1st and 2nd order central derivatives. Edges are not considered, so trimmed x array is returned.

Parameters:
  • xdata (Array1D) – Array of x values.

  • ydata (Array1D) – Array of y values.

Returns:

Trimmed x, 1st derivative, 2nd derivative

Return type:

Tuple[np.ndarray, np.ndarray, np.ndarray

Todo

make an example image

mooonpy.tools.math_utils.compute_fringe_slope(strain: ndarray, stress: ndarray, min_strain: Number | None = None, max_strain: Number | None = None, direction: str = 'forward') Tuple[ndarray, ndarray][source]

Compute fringe slope

Todo

Most concise writeup and a link to the paper

Parameters:
  • strain (Array1D) – Strain

  • stress (Array1D) – Stress

  • min_strain (Optional(Number)) – Minimum strain, defaults to None to use minimum index

  • max_strain (Optional(Number)) – Maximum strain, defaults to None to use maximum index

  • direction (str) – Direction, Must be ‘forward’ or ‘backward’, flips both vectors, defaults to ‘forward’.

Returns:

Fringe slope X and Y

Return type:

Tuple[np.ndarray, np.ndarray]

mooonpy.tools.math_utils.edge_tan_intersect(x, y, N=1)[source]

Discrete derivative tangent lines at edge(N steps from) Returns analytical intersections between tangent lines

mooonpy.tools.math_utils.find_peaks_and_valleys(xdata: ndarray | list, ydata: ndarray | list, prominence: Number | None = None) Tuple[ndarray, ndarray, ndarray, ndarray][source]

Compute the peaks and valleys of a curve using a specified prominence for cutoff.

Parameters:
  • xdata (Array1D) – Array of x values. Must be increasing monotonically.

  • ydata (Array1D) – Array of y values.

  • prominence (Number or None) – Prominence for cutoff

Returns:

X peaks, Y peaks, X valleys, Y valleys

Return type:

Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]

Todo

make an example image

mooonpy.tools.math_utils.first_value_cross(xdata: ndarray | list, ydata: ndarray | list, cross: Number | None = None)[source]

Find x location of the first time the y data crosses a value of the y data.

Parameters:
  • xdata (Array1D) – X data

  • ydata (Array1D) – Y data

  • cross (Number) – Value to compare against, defaults to None, which uses the mean value of ydata

Returns:

First x location

Return type:

Number

mooonpy.tools.math_utils.gaussian_quad_turn(x, X0, Y0, a, b, s, c, d)[source]

Muzzy Gaussian Quadratic Turn curve for fitting Tg data

mooonpy.tools.math_utils.gaussian_turn(x, X0, Y0, a, b, s)[source]

Muzzy Gaussian Turn curve for fitting Tg data

mooonpy.tools.math_utils.hyperbola(x, X0, Y0, a, b, c)[source]

Patrone Hyperbola fit method

Parameters:
  • x (Array1D) – X data

  • X0 (Number) – center x coordinate

  • Y0 (Number) – center y coordinate

  • a (Number) – slope left of turn

  • b (Number) – slope increase after turn

  • c (Number) – slope curvature parameter