This repository contains code for fitting Lorentzian curves with different types of baseline function. The Lorentzian curve is a common model used in numerous scientific domains to characterize spectral lines, resonances, and other phenomena exhibiting a distinctive peak shape. The inclusion of various baseline functions enables users to account for and model the underlying background signal inherent in experimental data, which may vary due to factors such as noise, drift or systematic effects.
The Lorentzian function
where
To use this code, follow these steps:
- Clone the repository
git clone https://github.com/PreethaSaha/Lorentzian-Fit-kit.git
- Navigate to the project directory
cd Lorentzian-Fit-kit
- Install the required dependencies
pip install -r requirements.txt
Currently the types of baseline include and the respective codes are linked below:
The above codes are designed to find a true Loretzian peak/dip and also handle noisy data by easily customisable parameters.
import csv
import numpy as np
a=np.genfromtxt('test3-2.csv',delimiter=',')
wavelength=a[:,0]
intensity=a[:,1]
from LorentzFit_cubic import cubic_lorentzian, initial_params, fit_lorentzian_cubic
Yfit, params, covar, perr, r2 = fit_lorentzian_cubic(wavelength, intensity, plot=True, plot_path=None)
The input data should contain two columns of equal length: one for the independent variable X (e.g., wavelength, frequency) and another for the corresponding dependent variable Y (e.g., intensity, amplitude).
Note that the code assumes an input data consisting of a minimum 20 (X,Y) datapoints.
The script prints the parameters of the fitted Lorentzian curve:
This project is licensed under the MIT License - see the LICENSE file for details.