autom8qc.qaqc.peak

ScipyPeakTest

Class

class autom8qc.qaqc.peak.ScipyPeakTest(width=None, height=None, threshold=None, distance=None, prominence=None, only_positive=True)

Bases: autom8qc.qaqc.base.QAQCTest

This class implements a peak-detection algorithm by using the Python package scipy. The algorithm checks the peak properties to detect them.

Important

The test ignores the time-index and considers only the values

Parameters
  • NAME (str) – Name of the test

  • DESCRIPTION (str) – Description of the test

  • CATEGORY (str) – Category of the test

  • SUPPORTED_STRUCTURES (tuple or BaseStructure) – Supported data structures (e.g., Series)

  • parameters (ParameterList) – Supported parameters (default: None)

Supported parameters:
  • width (float): Required width of peaks in samples

  • height (float): is used to specify the minimum height that a peak should have in order to be identified;

  • threshold (float): Is the required vertical distance between a peak and its neighboring, very useful in the case of noisy functions where we want to avoid selecting peaks from the noise;

  • distance (float): is the required minimum horizontal distance between neighboring peaks; it can be really useful in cases where we have some knowledge about the periodicity of the peaks.

  • prominence (float): Required prominence of peaks. The prominence of a peak measures how much the peak stands out due to its intrinsic height and its location relative to other peaks. A low isolated peak can be more prominent than one that is higher but is an otherwise unremarkable member of a tall range.

  • only_positive (bool): Checks only for positive values (default: True)

SUPPORTED_STRUCTURES

alias of autom8qc.core.structures.Series

perform(series)

Performs the test and returns the probabilities.

Raises

InvalidType – If structure is not supported

Parameters

series (pd.Series) – Time series

Returns

Probabilities (0=Peak, 1=No peak)

Return type

pd.Series

static supported_parameters()

Returns the supported parameters.

Returns

Supported parameters

Return type

ParameterList

Example

# Generate sample data
import numpy as np
import pandas as pd
np.random.seed(42)
mu, sigma = 50, 1.5
values = np.random.normal(mu, sigma, 500)
values[42] = 55
values[275] = 42
index = pd.date_range(start="1/1/2021", periods=500, freq="min")
series = pd.Series(values, index=index)

# Perform test
from autom8qc.qaqc.peak import ScipyPeakTest
test = ScipyPeakTest(prominence=7.5, only_positive=False)
test.plot(series=series, series_name="Example")

Visualization

../_images/ScipyPeakTest.svg