### Fit Polynomial Baseline with Selective Masking (Weights) Source: https://pybaselines.readthedocs.io/en/latest/algorithms/polynomial.html Fit a polynomial baseline by assigning weights to data points, where baseline regions have a weight of 1 and peak regions have a weight of 0. This method is generally faster and simpler than trimming data. ```python weights = np.zeros(len(y)) weights[non_peaks] = 1 # directly create baseline by inputting weights baseline = Baseline(x).poly(y, poly_order=3, weights=weights)[0] # Alternatively, just use numpy: # baseline = np.polynomial.Polynomial.fit(x, y, 3, w=weights)(x) fig, ax = plt.subplots(tight_layout={'pad': 0.2}) data_handle = ax.plot(y) baseline_handle = ax.plot(baseline, '--') masked_y = y.copy() masked_y[~non_peaks] = np.nan masked_handle = ax.plot(masked_y) ax.set_yticks([]) ax.set_xticks([]) ax.legend( (data_handle[0], masked_handle[0], baseline_handle[0]), ('data', 'non-peak regions', 'fit baseline'), frameon=False ) plt.show() ``` -------------------------------- ### Fit Polynomial Baseline with Selective Masking (Trimmed Data) Source: https://pybaselines.readthedocs.io/en/latest/algorithms/polynomial.html Fit a polynomial baseline using only the non-peak regions of the data. Requires `return_coef=True` to obtain coefficients for reconstructing the full baseline. ```python import numpy as np import matplotlib.pyplot as plt from pybaselines.utils import gaussian from pybaselines import Baseline x = np.linspace(1, 1000, 500) signal = ( gaussian(x, 6, 180, 5) + gaussian(x, 8, 350, 10) + gaussian(x, 15, 400, 8) + gaussian(x, 13, 700, 12) + gaussian(x, 9, 800, 10) ) real_baseline = 5 + 15 * np.exp(-x / 400) noise = np.random.default_rng(1).normal(0, 0.2, x.size) y = signal + real_baseline + noise # bitwise "or" (|) and "and" (&) operators for indexing numpy array non_peaks = ( (x < 150) | ((x > 210) & (x < 310)) | ((x > 440) & (x < 650)) | (x > 840) ) x_masked = x[non_peaks] y_masked = y[non_peaks] # fit only the masked x and y _, params = Baseline(x_masked).poly(y_masked, poly_order=3, return_coef=True) # recreate the polynomial using numpy and the full x-data baseline = np.polynomial.Polynomial(params['coef'])(x) # Alternatively, just use numpy: # baseline = np.polynomial.Polynomial.fit(x_masked, y_masked, 3)(x) fig, ax = plt.subplots(tight_layout={'pad': 0.2}) data_handle = ax.plot(y) baseline_handle = ax.plot(baseline, '--') masked_y = y.copy() masked_y[~non_peaks] = np.nan masked_handle = ax.plot(masked_y) ax.set_yticks([]) ax.set_xticks([]) ax.legend( (data_handle[0], masked_handle[0], baseline_handle[0]), ('data', 'non-peak regions', 'fit baseline'), frameon=False ) plt.show() ``` -------------------------------- ### Baseline2D Class Initialization Source: https://pybaselines.readthedocs.io/en/latest/api/Baseline2D.html Initializes the Baseline2D class for 2D baseline correction, allowing configuration of data axes and processing options. ```APIDOC ## Class: pybaselines.Baseline2D ### Description A class for all 2D baseline correction algorithms. Contains all available 2D baseline correction algorithms in pybaselines as methods to allow a single interface for easier usage. ### Parameters - **x_data** (array_like) - Optional - The x-values of the measured data (independent variable for the rows). - **z_data** (array_like) - Optional - The z-values of the measured data (independent variable for the columns). - **check_finite** (bool) - Optional - If True (default), will raise an error if any values in input data are not finite. - **assume_sorted** (bool) - Optional - If False (default), will sort the input x_data and z_data values. - **output_dtype** (type or numpy.dtype) - Optional - The dtype to cast the output array. ``` -------------------------------- ### Smoothing and Optimizing Algorithms Source: https://pybaselines.readthedocs.io/en/latest/api/Baseline2D.html Methods for baseline identification using smoothing and optimization techniques. ```APIDOC ## Smoothing and Optimizing Algorithms ### Description Methods for baseline identification using noise-median smoothing and various optimization strategies. ### Methods - **Baseline2D.noise_median**: Noise-median method. - **Baseline2D.collab_pls**: Collaborative Penalized Least Squares (collab-PLS). - **Baseline2D.adaptive_minmax**: Polynomial fitting with maximum value baseline selection. - **Baseline2D.individual_axes**: One-dimensional baseline correction along rows/columns. ``` -------------------------------- ### Morphological Algorithms Source: https://pybaselines.readthedocs.io/en/latest/api/Baseline2D.html Methods for baseline estimation using morphological transformations. ```APIDOC ## Morphological Algorithms ### Description Methods for estimating baselines using morphological operations. ### Methods - **Baseline2D.mor**: Morphological based (Mor) baseline algorithm. - **Baseline2D.imor**: Improved Morphological based (IMor) baseline algorithm. - **Baseline2D.rolling_ball**: The rolling ball baseline algorithm. - **Baseline2D.tophat**: Estimates the baseline using a top-hat transformation (morphological opening). ``` -------------------------------- ### Baseline Class Initialization Source: https://pybaselines.readthedocs.io/en/latest/api/Baseline.html Initialize the Baseline class for 1D data. This class provides a unified interface for various baseline correction algorithms. ```APIDOC ## Baseline Class ### Description A class for all baseline correction algorithms. Contains all available baseline correction algorithms in pybaselines as methods to allow a single interface for easier usage. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Initialization Parameters - **x_data** (array_like, shape (N,), optional) - The x-values of the measured data. Default is None, which will create an array from -1 to 1 during the first function call with length equal to the input data length. - **check_finite** (bool, optional) - If True (default), will raise an error if any values in input data are not finite. Setting to False will skip the check. Note that errors may occur if check_finite is False and the input data contains non-finite values. - **assume_sorted** (bool, optional) - If False (default), will sort the input x_data values. Otherwise, the input is assumed to be sorted, although it will still be checked to be in ascending order. Note that some methods will raise an error if x_data values are not unique. - **output_dtype** (`type` or `numpy.dtype`, optional) - The dtype to cast the output array. Default is None, which uses the typing of the input data. ### Attributes - **x** (`numpy.ndarray` or `None`) - The x-values for the object. If initialized with None, then x is initialized the first function call to have the same length as the input data and has min and max values of -1 and 1, respectively. - **x_domain** (`numpy.ndarray`) - The minimum and maximum values of x. If x_data is None during initialization, then set to numpy.ndarray([-1, 1]). ### Properties - **banded_solver** (int) - Designates the solver to prefer using for solving banded linear systems. Added in version 1.2.0. An integer between 1 and 4 designating the solver to prefer for solving banded linear systems. Default is 2. - **_pentapy_solver** (int) - The solver if using `pentapy` to solve banded equations. Deprecated since version 1.2: The pentapy_solver property is deprecated and will be removed in version 1.4. Use `banded_solver` instead. ### Request Example None ### Response None ``` -------------------------------- ### Polynomial Algorithms Source: https://pybaselines.readthedocs.io/en/latest/api/Baseline.html Overview of polynomial-based baseline correction algorithms available within the Baseline class. ```APIDOC ## Polynomial Algorithms ### Description These algorithms fit a polynomial to the baseline of the data. ### Endpoints - `Baseline.poly` - `Baseline.modpoly` - `Baseline.imodpoly` - `Baseline.penalized_poly` - `Baseline.loess` - `Baseline.quant_reg` - `Baseline.goldindec` ### Details - **`Baseline.poly`**: Computes a polynomial that fits the baseline of the data. - **`Baseline.modpoly`**: The modified polynomial (ModPoly) baseline algorithm. - **`Baseline.imodpoly`**: The improved modified polynomial (IModPoly) baseline algorithm. - **`Baseline.penalized_poly`**: Fits a polynomial baseline using a non-quadratic cost function. - **`Baseline.loess`**: Locally estimated scatterplot smoothing (LOESS). - **`Baseline.quant_reg`**: Approximates the baseline of the data using quantile regression. - **`Baseline.goldindec`**: Fits a polynomial baseline using a non-quadratic cost function. ### Request Example None ### Response None ``` -------------------------------- ### Spline Algorithms Source: https://pybaselines.readthedocs.io/en/latest/api/Baseline2D.html Methods for baseline estimation using various spline-based regression techniques. ```APIDOC ## Spline Algorithms ### Description Methods for baseline estimation using spline-based models. ### Methods - **Baseline2D.mixture_model**: Mixture model composed of noise and peaks. - **Baseline2D.irsqr**: Iterative Reweighted Spline Quantile Regression (IRSQR). - **Baseline2D.pspline_asls**: Penalized spline version of AsLS. - **Baseline2D.pspline_iasls**: Penalized spline version of IAsLS. - **Baseline2D.pspline_airpls**: Penalized spline version of airPLS. - **Baseline2D.pspline_arpls**: Penalized spline version of arPLS. - **Baseline2D.pspline_iarpls**: Penalized spline version of IarPLS. - **Baseline2D.pspline_psalsa**: Penalized spline version of psalsa. - **Baseline2D.pspline_brpls**: Penalized spline version of brPLS. - **Baseline2D.pspline_lsrpls**: Penalized spline version of LSRPLS. ``` -------------------------------- ### noise_median (Noise Median method) Source: https://pybaselines.readthedocs.io/en/latest/algorithms_2d/smooth_2d.html The noise_median algorithm is a smoothing-based method for baseline correction. The window size is index-based and requires user conversion for data units. ```APIDOC ## noise_median() ### Description Applies the Noise Median method for baseline correction. ### Method `noise_median()` ### Parameters This method does not explicitly list parameters in the provided text, but it is noted that a window size is used. ### Request Example ```json { "data": ["..."], "window_size": "..." } ``` ### Response #### Success Response (200) - **baseline** (array) - The calculated baseline. - **params** (object) - Dictionary of parameters used. #### Response Example ```json { "baseline": ["..."], "params": { "baseline_order": "...", "noise_order": "..." } } ``` ``` -------------------------------- ### 2D Baseline Correction Algorithms Source: https://pybaselines.readthedocs.io/en/latest/api/Baseline2D.html This section covers the different algorithms provided by pybaselines for correcting baselines in 2D data. Each algorithm has specific parameters and use cases. ```APIDOC ## 2D Baseline Correction Algorithms This section details the various algorithms available for 2D baseline correction in the pybaselines library. ### Polynomial Algorithms These algorithms use polynomial fitting for baseline correction. #### `pybaselines.Baseline2D.poly` * **Description**: Fits a polynomial to the baseline. * **Method**: Not specified (likely a function call). * **Endpoint**: Not applicable (function within a library). * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.modpoly` * **Description**: Fits a modified polynomial to the baseline. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.imodpoly` * **Description**: Fits an iteratively modified polynomial to the baseline. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.penalized_poly` * **Description**: Fits a penalized polynomial to the baseline. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.quant_reg` * **Description**: Fits a baseline using quantile regression. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. ### Whittaker Smoothing Algorithms These algorithms use Whittaker smoothing techniques for baseline correction. #### `pybaselines.Baseline2D.asls` * **Description**: Applies the Asymmetric Least Squares smoothing algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.iasls` * **Description**: Applies the Improved Asymmetric Least Squares smoothing algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.airpls` * **Description**: Applies the Adaptive Iteratively Reweighted Penalized Least Squares algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.arpls` * **Description**: Applies the Adaptive Reweighted Penalized Least Squares algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.drpls` * **Description**: Applies the Double Reweighted Penalized Least Squares algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.iarpls` * **Description**: Applies the Improved Adaptive Reweighted Penalized Least Squares algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.aspls` * **Description**: Applies the Adaptive Smooth Penalized Least Squares algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.psalsa` * **Description**: Applies the Penalized Sum of Absolute Errors smoothing algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.brpls` * **Description**: Applies the Baseline Reweighted Penalized Least Squares algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.lsrpls` * **Description**: Applies the Least Squares Reweighted Penalized Least Squares algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. ### Morphological Algorithms These algorithms use morphological operations for baseline correction. #### `pybaselines.Baseline2D.mor` * **Description**: Applies the morphological baseline correction algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.imor` * **Description**: Applies the improved morphological baseline correction algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.rolling_ball` * **Description**: Applies the rolling ball morphological algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.tophat` * **Description**: Applies the tophat morphological algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. ### Spline Algorithms These algorithms use spline fitting for baseline correction. #### `pybaselines.Baseline2D.mixture_model` * **Description**: Fits a baseline using a mixture model with splines. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.irsqr` * **Description**: Fits a baseline using iterative reweighted least squares with splines. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.pspline_asls` * **Description**: Applies the penalized spline asymmetric least squares algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.pspline_iasls` * **Description**: Applies the penalized spline improved asymmetric least squares algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.pspline_airpls` * **Description**: Applies the penalized spline adaptive iteratively reweighted penalized least squares algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.pspline_arpls` * **Description**: Applies the penalized spline adaptive reweighted penalized least squares algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.pspline_iarpls` * **Description**: Applies the penalized spline improved adaptive reweighted penalized least squares algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.pspline_psalsa` * **Description**: Applies the penalized spline penalized sum of absolute errors algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.pspline_brpls` * **Description**: Applies the penalized spline baseline reweighted penalized least squares algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.pspline_lsrpls` * **Description**: Applies the penalized spline least squares reweighted penalized least squares algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. ### Smoothing Algorithms These algorithms use general smoothing techniques for baseline correction. #### `pybaselines.Baseline2D.noise_median` * **Description**: Applies a median filter for noise reduction, which can aid baseline correction. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. ### Optimizing Algorithms These algorithms focus on optimizing the baseline correction process. #### `pybaselines.Baseline2D.collab_pls` * **Description**: Applies a collaborative penalized least squares algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.adaptive_minmax` * **Description**: Applies an adaptive minimum-maximum baseline correction algorithm. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `pybaselines.Baseline2D.individual_axes` * **Description**: Applies baseline correction to individual axes. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. ### Solver Algorithms These algorithms are specific solvers used within the 2D baseline correction framework. #### `Baseline2D.banded_solver` * **Description**: A banded solver for 2D baseline correction problems. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. #### `Baseline2D.pentapy_solver` * **Description**: A pentadiagonal solver, likely for specific types of 2D problems. * **Method**: Not specified. * **Endpoint**: Not applicable. * **Parameters**: Not specified. * **Request Body**: Not applicable. * **Response**: Not specified. ``` -------------------------------- ### Whittaker Smoothing Algorithms Source: https://pybaselines.readthedocs.io/en/latest/api/Baseline.html Overview of Whittaker smoothing-based baseline correction algorithms available within the Baseline class. ```APIDOC ## Whittaker Smoothing Algorithms ### Description These algorithms use Whittaker smoothing techniques for baseline correction. ### Endpoints - `Baseline.asls` - `Baseline.iasls` - `Baseline.airpls` - `Baseline.arpls` - `Baseline.drpls` - `Baseline.iarpls` - `Baseline.aspls` - `Baseline.psalsa` - `Baseline.derpsalsa` - `Baseline.brpls` - `Baseline.lsrpls` ### Details - **`Baseline.asls`**: Fits the baseline using asymmetric least squares (AsLS) fitting. - **`Baseline.iasls`**: Fits the baseline using the improved asymmetric least squares (IAsLS) algorithm. - **`Baseline.airpls`**: Adaptive iteratively reweighted penalized least squares (airPLS) baseline. - **`Baseline.arpls`**: Asymmetrically reweighted penalized least squares smoothing (arPLS). - **`Baseline.drpls`**: Doubly reweighted penalized least squares (drPLS) baseline. - **`Baseline.iarpls`**: Improved asymmetrically reweighted penalized least squares smoothing (IarPLS). - **`Baseline.aspls`**: Adaptive smoothness penalized least squares smoothing (asPLS). - **`Baseline.psalsa`**: Peaked Signal's Asymmetric Least Squares Algorithm (psalsa). - **`Baseline.derpsalsa`**: Derivative Peak-Screening Asymmetric Least Squares Algorithm (derpsalsa). - **`Baseline.brpls`**: Bayesian Reweighted Penalized Least Squares (BrPLS) baseline. - **`Baseline.lsrpls`**: Locally Symmetric Reweighted Penalized Least Squares (LSRPLS). ### Request Example None ### Response None ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.