mooonpy.tools.signals module

mooonpy.tools.signals.butter_lowpass(xdata: ndarray | list | None, ydata: ndarray | list, wn: Number | str = 'PSD', quadrant: str = 'msr', order: Number = 2) Tuple[ndarray, Number, str][source]

Call butterworth low-pass filter with Quadrant Mirroring padding. The original image region is returned fully filtered.

Cutoff frequency may be input as a number, or can be chosen using an optimizer style

If the quadrant is ‘msr’ the lowest residual low and high data_extension is used, or the quadrants are specified with a comma separated string of ‘2,3’ for left and right extension.

Parameters:
  • xdata (Array1D) – Array of x values. Only used for PSD optimization

  • ydata (Array1D) – Y data to filter.

  • wn (Number) – Normalized Cutoff frequency, defaults to 0.1.

  • quadrant (str) – Quadrants, defaults to ‘msr’ optimization.

  • order (Number) – Order of filter, defaults to 2

Returns:

Filtered data, wn used, qm string used

mooonpy.tools.signals.compute_PSD(xdata: ndarray | list, ydata: ndarray | list) Tuple[ndarray | list, ndarray | list][source]

Compute the Power Spectral Density (PSD) with the X-values being the normalized frequencies.

Returns the normalized frequencies (Omega N / Wn) and power spectral density (PSD) as a tuple of arrays.

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

  • ydata (Array1D) – Array of y values.

Returns:

wn’s, PDS’s

Return type:

Tuple(Array1D, Array1D)

mooonpy.tools.signals.data_extension(xdata: ndarray | list, ydata: ndarray | list, lo: Number = 1, hi: Number = 1) Tuple[ndarray, ndarray, int, int][source]

Function to extend data at the “lo” and “hi” end. This function assumes xdata is increasing and ydata is the dependent variable. This function replaces the usage of scipy’s “signal.filtfilt” or “signal.sosfiltfilt” padtype=<’odd’ or ‘even’ or ‘const’ or None>, with greater functionality.

For example the padtype=<’odd’ or ‘even’ or ‘const’ or None> implementation assumes that the padding on the “lo X-end” will be the same as the padding that should be used on the “hi X-end”, however for stress-strain data, this is usually not the case.

lo/hi integer meanings can be thought of as quadrant numbers for “lo” and have the same meaning for “hi”, but at the tail end of the data. For example:

  • 1 = means shut off data mirroring

  • 2 = means mirror data (lo=mirrored into quadrant 2)

  • 3 = means apply 180-degree rotation (lo=mirrored into quadrant 3)

  • 4 = means flip the Y-data and append at the end of the Y-data

Parameters:
  • xdata (Array1D) – X data

  • ydata (Array1D) – Y data

  • lo (Number) – Left side quadrant setting, defaults to 1.

  • hi (Number) – Right side quadrant setting, defaults to 1.

Returns:

Extended data as X / Y, and lo_trim / hi_trim slicing index to access original data within the extension.

Return type:

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

Todo

Make example images

mooonpy.tools.signals.determine_mirroring_locations(xdata: ndarray | list | None, ydata: ndarray | list, wn: Number | str = 'PSD', order: Number = 2) Tuple[int, int][source]

Compare 4 mirror images at both ends of dataset. The combination with the lowest residual^2 after filtering is returned.

Parameters:
  • xdata (Array1D) – X data

  • ydata (Array1D) – Y data

  • wn (Number or str) – Normalized Cutoff frequency, defaults to ‘PSD’ optimization.

  • order (Number) – Order of filter, defaults to 2

Returns:

Lowest residual and Highest residual.

Return type:

Tuple(int, int)

mooonpy.tools.signals.power_to_db(power: ndarray | list, ref_power: Number = 1) ndarray[source]

Convert power to decibels (dB).

Parameters:
  • power (Array1D) – Power to convert.

  • ref_power (Number) – Reference power.

Returns:

Converted power.

Return type:

Array1D

mooonpy.tools.signals.sparse_eye_diff(m, d, format='csc')[source]
mooonpy.tools.signals.whitt_smooth(ydata, order, lambda_)[source]