### Install PeakUtils from Source Source: https://peakutils.readthedocs.io/en/latest/index.html Use this command to install PeakUtils when building from the source package. ```bash python setup.py install ``` -------------------------------- ### Generate Data with Baseline Source: https://peakutils.readthedocs.io/en/latest/_sources/tutorial_a.rst.txt Create data that includes an additional baseline component by adding a polynomial to the original noisy data. This is used to demonstrate baseline removal. ```python y2 = y + numpy.polyval([0.002,-0.08,5], x) pyplot.figure(figsize=(10,6)) pyplot.plot(x, y2) pyplot.title("Data with baseline") ``` -------------------------------- ### Import Libraries for Peak Detection Source: https://peakutils.readthedocs.io/en/latest/_sources/tutorial_a.rst.txt Import necessary libraries including numpy, peakutils, plotting utilities, and matplotlib for data analysis and visualization. ```python import numpy import peakutils from peakutils.plot import plot as pplot from matplotlib import pyplot %matplotlib inline ``` -------------------------------- ### Import Libraries Source: https://peakutils.readthedocs.io/en/latest/tutorial_a.html Imports necessary libraries for data manipulation, peak detection, plotting, and inline plotting. ```python import numpy import peakutils from peakutils.plot import plot as pplot from matplotlib import pyplot %matplotlib inline ``` -------------------------------- ### Generate Noisy Data from Gaussians Source: https://peakutils.readthedocs.io/en/latest/_sources/tutorial_a.rst.txt Create sample 1D data by combining two Gaussian functions with added random noise. This data is used to demonstrate peak detection. ```python centers = (30.5, 72.3) x = numpy.linspace(0, 120, 121) y = (peakutils.gaussian(x, 5, centers[0], 3) + peakutils.gaussian(x, 7, centers[1], 10) + numpy.random.rand(x.size)) pyplot.figure(figsize=(10,6)) pyplot.plot(x, y) pyplot.title("Data with noise") ``` -------------------------------- ### peakutils.prepare.scale Source: https://peakutils.readthedocs.io/en/latest/reference.html Scales a 1D array to a new specified range. It also returns the original data range, which can be used to revert the scaling if needed. ```APIDOC ## peakutils.prepare.scale ### Description Changes the scale of an array to a new specified range. ### Parameters #### Path Parameters - **x** (ndarray) - Required - 1D array to change the scale (remains unchanged) - **new_range** (tuple(float, float)) - Optional - Desired range of the array. Defaults to (0.0, 1.0). - **eps** (float) - Optional - Numerical precision, to detect degenerate cases (for example, when every value of x is equal). Defaults to 1e-09. ### Returns - **ndarray** - Scaled array - **tuple(float, float)** - Previous data range, allowing a rescale to the old range ``` -------------------------------- ### Add Baseline to Data Source: https://peakutils.readthedocs.io/en/latest/tutorial_a.html Adds a polynomial baseline to the existing noisy data to simulate a more realistic dataset for baseline removal demonstration. ```python y2 = y + numpy.polyval([0.002,-0.08,5], x) pyplot.figure(figsize=(10,6)) pyplot.plot(x, y2) pyplot.title("Data with baseline") ``` -------------------------------- ### Generate Noisy Data Source: https://peakutils.readthedocs.io/en/latest/tutorial_a.html Generates synthetic 1D data from two Gaussian distributions with added random noise for demonstration purposes. ```python centers = (30.5, 72.3) x = numpy.linspace(0, 120, 121) y = (peakutils.gaussian(x, 5, centers[0], 3) + peakutils.gaussian(x, 7, centers[1], 10) + numpy.random.rand(x.size)) pyplot.figure(figsize=(10,6)) pyplot.plot(x, y) pyplot.title("Data with noise") ``` -------------------------------- ### gaussian Source: https://peakutils.readthedocs.io/en/latest/reference.html Computes the value of the Gaussian function at a given point. ```APIDOC ## gaussian ### Description Computes the Gaussian function. ### Parameters #### Path Parameters - **x** (number) - Required - Point to evaluate the Gaussian for. - **ampl** (number) - Required - Amplitude. - **center** (number) - Required - Center. - **dev** (number) - Required - Width. ### Returns - **value** (float) - Value of the specified Gaussian at x. ``` -------------------------------- ### Estimate Peak Indexes Source: https://peakutils.readthedocs.io/en/latest/tutorial_a.html Uses peakutils.indexes to find the approximate indices of peaks in the noisy data. Adjust 'thres' and 'min_dist' for different detection sensitivities. ```python indexes = peakutils.indexes(y, thres=0.5, min_dist=30) print(indexes) print(x[indexes], y[indexes]) pyplot.figure(figsize=(10,6)) pplot(x, y, indexes) pyplot.title('First estimate') ``` -------------------------------- ### Interpolated Peak Values Source: https://peakutils.readthedocs.io/en/latest/tutorial_a.html Prints the interpolated x-coordinates of the detected peaks, providing a more precise location than the initial index estimation. ```python [31 74] [ 31. 74.] [ 5.67608909 7.79403394] ``` -------------------------------- ### Enhance Peak Resolution with Interpolation Source: https://peakutils.readthedocs.io/en/latest/tutorial_a.html Applies interpolation to refine the peak locations, fitting a Gaussian near each detected peak for improved resolution. ```python peaks_x = peakutils.interpolate(x, y, ind=indexes) print(peaks_x) ``` -------------------------------- ### Interpolated Peak X-Coordinates Source: https://peakutils.readthedocs.io/en/latest/tutorial_a.html Prints the precise x-coordinates of the peaks after applying interpolation. ```python [ 30.58270223 72.34348214] ``` -------------------------------- ### gaussian_fit Source: https://peakutils.readthedocs.io/en/latest/reference.html Performs a Gaussian fitting of the specified data. Can return only the center or all parameters. ```APIDOC ## gaussian_fit ### Description Performs a Gaussian fitting of the specified data. ### Parameters #### Path Parameters - **x** (ndarray) - Required - Data on the x axis. - **y** (ndarray) - Required - Data on the y axis. - **center_only** (bool, optional) - If True, returns only the center of the Gaussian for interpolate compatibility. Defaults to True. ### Returns - **parameters** (ndarray or float) - If center_only is False, returns the parameters of the Gaussian that fits the specified data. If center_only is True, returns the center position of the Gaussian. ``` -------------------------------- ### peakutils.baseline.baseline Source: https://peakutils.readthedocs.io/en/latest/reference.html Computes the baseline of a given data by iteratively performing a polynomial fitting. It reduces weights in peak regions to isolate the baseline. ```APIDOC ## peakutils.baseline.baseline ### Description Computes the baseline of a given data. Iteratively performs a polynomial fitting in the data to detect its baseline. At every iteration, the fitting weights on the regions with peaks are reduced to identify the baseline only. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Parameters * **y** (ndarray) - Required - Data to detect the baseline. * **deg** (int) - Optional - Degree of the polynomial that will estimate the data baseline. A low degree may fail to detect all the baseline present, while a high degree may make the data too oscillatory, especially at the edges. (default: 3) * **max_it** (int) - Optional - Maximum number of iterations to perform. (default: 100) * **tol** (float) - Optional - Tolerance to use when comparing the difference between the current fit coefficients and the ones from the last iteration. The iteration procedure will stop when the difference between them is lower than tol. (default: 1e-3) ### Returns * **ndarray** - Array with the baseline amplitude for every original point in y ``` -------------------------------- ### Remove Baseline from Data Source: https://peakutils.readthedocs.io/en/latest/tutorial_a.html Estimates and removes the baseline from the data using peakutils.baseline, which employs iterative polynomial regression. This prepares the data for more accurate peak analysis. ```python base = peakutils.baseline(y2, 2) pyplot.figure(figsize=(10,6)) pyplot.plot(x, y2-base) pyplot.title("Data with baseline removed") ``` -------------------------------- ### peakutils.baseline.envelope Source: https://peakutils.readthedocs.io/en/latest/reference.html Computes the upper envelope of a given data using the baseline function. This function helps in identifying the upper boundary of the data. ```APIDOC ## peakutils.baseline.envelope ### Description Computes the upper envelope of a given data. It is implemented in terms of the baseline function. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Parameters * **y** (ndarray) - Required - Data to detect the baseline. * **deg** (int) - Required - Degree of the polynomial that will estimate the envelope. * **max_it** (int) - Required - Maximum number of iterations to perform. * **tol** (float) - Required - Tolerance to use when comparing the difference between the current fit coefficients and the ones from the last iteration. ### Returns * **ndarray** - Array with the envelope amplitude for every original point in y ``` -------------------------------- ### indexes Source: https://peakutils.readthedocs.io/en/latest/reference.html Finds the numeric index of peaks in a 1D array, with options for thresholding and minimum distance. ```APIDOC ## indexes ### Description Peak detection routine. Finds the numeric index of the peaks in _y_ by taking its first order difference. By using _thres_ and _min_dist_ parameters, it is possible to reduce the number of detected peaks. _y_ must be signed. ### Parameters #### Path Parameters - **y** (ndarray (signed)) - Required - 1D amplitude data to search for peaks. - **thres** (float between [0, 1]) - Optional - Normalized threshold. Only the peaks with amplitude higher than the threshold will be detected. Defaults to 0.3. - **min_dist** (int) - Optional - Minimum distance between each detected peak. The peak with the highest amplitude is preferred to satisfy this constraint. Defaults to 1. - **thres_abs** (boolean) - Optional - If True, the thres value will be interpreted as an absolute value, instead of a normalized threshold. Defaults to False. ### Returns - **indexes** (ndarray) - Array containing the numeric indexes of the peaks that were detected. When using with Pandas DataFrames, iloc should be used to access the values at the returned positions. ``` -------------------------------- ### centroid2 Source: https://peakutils.readthedocs.io/en/latest/reference.html Computes the centroid and standard deviation for the specified data. This version is more complete but may be slower. ```APIDOC ## centroid2 ### Description Computes the centroid for the specified data. Not intended to be used directly for simple centroid calculation. ### Parameters #### Path Parameters - **y** (array_like) - Required - Array whose centroid is to be calculated. - **x** (array_like, optional) - The points at which y is sampled. - **dx** (float, optional) - Default value is 1.0. ### Returns - **centroid** (float) - Centroid of the data. - **sd** (float) - Standard deviation of the data. ``` -------------------------------- ### interpolate Source: https://peakutils.readthedocs.io/en/latest/reference.html Enhances peak resolution by using Gaussian fitting or other functions on the neighborhood of detected peaks. ```APIDOC ## interpolate ### Description Tries to enhance the resolution of the peak detection by using Gaussian fitting, centroid computation or an arbitrary function on the neighborhood of each previously detected peak index. RuntimeErrors raised in the fitting function will be converted to warnings, with the peak being mantained as the original one (in the ind array). ### Parameters #### Path Parameters - **x** (ndarray) - Required - Data on the x dimension. - **y** (ndarray) - Required - Data on the y dimension. - **ind** (ndarray, optional) - Indexes of the previously detected peaks. If None, indexes() will be called with the default parameters. - **width** (int) - Optional - Number of points (before and after) each peak index to pass to _func_ in order to increase the resolution in _x_. Defaults to 10. - **func** (function (x, y)) - Optional - Function that will be called to detect an unique peak in the x,y data. Defaults to gaussian_fit. ### Returns - **adjusted_peak_positions** (ndarray) - Array with the adjusted peak positions (in _x_). ``` -------------------------------- ### centroid Source: https://peakutils.readthedocs.io/en/latest/reference.html Computes the centroid for the specified data. This is a simpler version compared to centroid2. ```APIDOC ## centroid ### Description Computes the centroid for the specified data. Refer to centroid2 for a more complete, albeit slower version. ### Parameters #### Path Parameters - **x** (ndarray) - Required - Data on the x axis. - **y** (ndarray) - Required - Data on the y axis. ### Returns - **centroid** (float) - Centroid of the data. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.