spectrochempy.find_peaksο
- find_peaks(dataset, height=None, window_length=3, threshold=None, distance=None, prominence=None, width=None, wlen=None, rel_height=0.5, plateau_size=None, use_coord=True)[source]ο
Find and analyze peaks in spectroscopic data with advanced filtering options.
This function extends scipy.signal.find_peaks by adding spectroscopy-specific features like coordinate system awareness and unit handling. It performs peak detection through local maxima analysis and supports various filtering criteria to identify significant peaks.
- Parameters:
dataset (NDDataset) β Input dataset containing spectral data. Must be 1D or 2D with len(X.y) == 1.
height (float or array-like, optional) β Minimum and/or maximum peak height criteria. Can be specified as: - Single value for minimum height - Tuple (min, max) for height range - Array matching x for position-dependent criteria
window_length (int, default: 3) β Window size for peak interpolation. Must be odd. Larger values provide smoother interpolation but may miss narrow peaks.
threshold (float or array-like, optional) β Minimum height difference between peak and neighboring points. Useful for filtering out noise-related peaks.
distance (float, optional) β Minimum separation between peaks. Peaks closer than this are filtered based on their prominence.
prominence (float or array-like, optional) β Required prominence (height above surrounding baseline) of peaks.
width (float or array-like, optional) β Required width of peaks. Interpreted as coordinate units if use_coord=True, otherwise as number of points.
wlen (int or float, optional) β Window length for prominence calculation. Affects computation speed for large datasets.
rel_height (float, default: 0.5) β Relative height for width calculation (0-1 range).
plateau_size (float or array-like, optional) β Required size of peak plateau (flat top).
use_coord (bool, default: True) β Whether to use coordinate system units instead of array indices.
- Returns:
peaks (NDDataset) β Dataset containing identified peaks with interpolated positions and heights.
properties (dict) β Peak properties including heights, widths, prominences, and more. All values use appropriate units when use_coord=True.
Notes
Peak positions are refined using quadratic interpolation when window_length > 1
The function handles units automatically when use_coord=True
For noisy data, consider preprocessing with smoothing functions
Examples
Basic peak finding with height threshold: >>> dataset = scp.read(βirdata/nh4y-activation.spgβ) >>> X = dataset[0, 1800.0:1300.0] >>> peaks, props = X.find_peaks(height=1.5)
Find well-separated peaks with minimum width: >>> peaks, props = X.find_peaks(distance=50.0, width=10.0)
Complex filtering with multiple criteria: >>> peaks, props = X.find_peaks( β¦ height=1.5, β¦ distance=50.0, β¦ prominence=0.5, β¦ width=20.0 β¦ )