GithubHelp home page GithubHelp logo

multifit's Introduction

multifit

The goal of Multifit is to provide a convenient way of calculating fits with shared parameters over multiple data sets.

The actual fitting is all done using the iminuit package, and I recommend that you familiarise yourself with their basic tutorial.

Installation

Install from PyPI repository (recommended)

pip install multifit

To install the developement version, clone this repository, cd to its root directory and run

pip install .

Usage

Import the UI class and initialise it with a list containing the paths to the spectrum files.

import multifit.UI as fitUI
paths_to_spectra = ['path/to/spectrum1/spec1.asc', 'path/to/spectrum2/spec2.asc']
UI = fitUI(paths_to_spectra)

Then, either call UI() to run the program with the default configuration, or call the methods in UI manually to have full control over the fit. This will be discussed below.

If the get_input method is called, the program will attempt to read certain arguments from the command line, and prompt the user to enter them if this fails. These are interval: the interval of the data to fit. m_init: approximate values for the peak positions. savename: the location to save the results, with no file extention.

Once the fit is complete, the results are contained in the Minuit object UI.m. See the iminuit documentation for information on how to extract it. Working examples are given in doc/examples/.

The default configuration

In the default configuration, multifit can fit any number of peaks using Gaussian functions on a linear background. The mean and standard deviation of each peak is constant across all spectra. The peak areas and background parameters are fitted independently for each spectrum.

Configuring the fit manually

Each step of the fit, as well as the variables involved, can be accessed through the UI class. The following contains a description of some variables you may want to change. For more details, see doc/reference.md

clik to expand

  • self.function_string : This is a string which, when executed, defines the function to be fitted to the data. The function should take x as the first argument, followed by single parameters to fit. The program does not support array parameters, because the selection of common parameters is name based. The default string is created in make_Gaussian(self). This method may be usefull as a template when creating your own fit functions.

  • self.Chi2: This is the ย ฯ‡2 cost function which is minimised by Migrad. It is defined in make_chi2(self, fit_function: callable) as

self.Chi2 = self.Fit.Chi2(self.interval, fit_function, [*self.listall('A'),'slope','offset'])

You will only want to change the last parameter, which is a list of the parameters to be fitted independently for each spectrum. By default these are the areas of all peaks and the background parameters.

  • self.initial_values: This is a dict containing the initial values for all parameters of the fit. For those parameters which are fitted independantly, that is one value for each spectrum. The default is defined in set_initial_values(self). It is recommended to copy and modify this function to generate custom initial values.

  • self.m attributes: self.m.limits: the limits of the fitted parameters, by default the peak areas are positive. self.m.fixed: can be used to fix the value of fitted parameters. False by default. self.m.values: the current values of the fitted parameters. See the iminuit documentation for more information.

multifit's People

Contributors

johashei avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.