passive-radio / interactive-curve-fit

A Python project enables you to fit peaks interactively on GUI. You can visualize your spectrum and fit the optional number of the peaks on GUI using Scipy.optimize.curve_fit method.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

You can visualize your spectrum and fit the optional number of peaks on GUI using Scipy.optimize.curve_fit method.

How to install

pip install interactive-curve-fit==0.0.1

How to use

Try tutorial.py with your spectrum data!

Spectrum data format must be like the table below

some header rows,,,...
x,y1,y2,y3
0,0,2,3
1,1,1,2
2,3,2,3
3,1,2,3
4,0,3,4
5,0,2,1
some footer rows,,,...

Steps to curve-fit

  1. Teach your initial guess of the positions of each peaks roughly to Fitter.

    from interactive_curve_fit import read_data, Guessor, Fitter
    
    data = read_data('out/spectrum.csv', headers=2, sep=',')
    guessor = Guessor(data, background=10, method='drag')
    guess = guessor.guess()

    Initial Guess method

    • mouse-dragging (wrap up peak area by mouse-dragging)
    • click (click the top and the both edges of each peaks)

    Screenshot

    Guessing peak pos interactively Guessing another peak pos Fitting results (by Fitter class) Peak information on terminal

  2. Give your spectrum data and your guess to Fitter.

    fitter = Fitter(data, guess)
    fitter.run(method='gaussian')

    Supported fitting functions

    • gaussian function
    • polynomial function

    Output information includes

    • position (x, y) of each peaks
    • baseline height of the spectrum
    • bandwidth of each peaks with its CI (confidential interval)
  3. Save the fitting results

    fitter.save_data('out/fitting_result.csv')
  4. Other features

    bmp_to_csv converts bmp file to csv file.

    from interactive_curve_fit import bmg_to_csv
    bmp_to_csv('data/line_spectrum.bmp')
    data = read_data('data/line_spectrum.csv')

    Fitter can visualize fitting results

    fitter.plot_fit()
    

    Fitter can also display fitting results on terminal

    fitter.display_results_terminal(ci=2)
    

Supported supectrum file format

  • ascii file(.asc .csv .txt etc..)

  • bmp image(.bmp .jpg .png .jpeg etc..)

    excel sheet files, table of html are planed to be suported in the near future.

Features that are planned to be supported!

  • baseline correlation
  • other fitting functions (e.g. binomical distribution function)
  • automated guessor method using wavelet transform and CNN

About

A Python project enables you to fit peaks interactively on GUI. You can visualize your spectrum and fit the optional number of the peaks on GUI using Scipy.optimize.curve_fit method.

License:MIT License


Languages

Language:Python 100.0%