Druckansicht der Internetadresse:

Faculty of Biology, Chemistry & Earth Sciences

Biochemistry: Lab Prof. Dr. Andreas Möglich – Sensory Photoreceptors

Print page

Fit-o-mat

Download

Use these links to obtain Fit-o-mat, cf. below for installation instructions and program requirements.

  • Python source code - the best option to run Fit-o-mat on Windows, Linux and OS X platforms [v0.669]
  • Windows binary - for people daunted by having to install Python, we supply a precompiled, stand-alone version (be warned, the file is humongous) [v0.669]

For more features, download the latest version of the program [v0.680].

Alternatively, visit the GitHub project page. For the legacy version 0.510, use these links [py] [binary].

Manual

Fit-o-mat written and © by Andreas Möglich 2017-2019, Universität Bayreuth, Germany
andreasmoeglichuni-bayreuthde
Möglich, A. (2018) An open-source, cross-platform resource for nonlinear least-squares curve fitting. J Chem Educ 95(12), 2273-2278, doi: 10.1021/acs.jchemed.8b00649 [doi]

General remarks

Purpose & audience

Fit-o-mat is an all-purpose, open-source, cross-platform program for nonlinear least-squares data fitting. The software is written in Python 3 and resorts to the Python libraries NumPy and SciPy for numerical methods, and to matplotlib for visualization. The program is operated via a graphical user interface implemented in PyQt5. In a nutshell, Fit-o-mat provides a front-end to data-fitting algorithms implemented in Python and thereby strives to unlock their application for a broad audience, including people less versed in computer programming.

The intended target audience for Fit-o-mat is anybody interested in nonlinear least-squares analysis, specifically but not limited to students, teachers and researchers in the life sciences. As a case in point, we have been using the program in the classroom and for preparing figures for publication.

Gallery

A few examples of graphics prepared with Fit-o-mat (in a matter of minutes only).

Disclaimer

The program is released under the GNU General Public License version 3.0 or later. Hence, it can be freely used and distributed as long as it is unmodified. Use at your own responsibility, the author cannot be held responsible for any data loss etc. If you encounter bugs, try to reproduce, save program state right before bug occurs (cf. below) and send to andreasmoeglichuni-bayreuthde. Feature requests and illustrations for the figure gallery may also be sent to the same address.

If you employ Fit-o-mat in a publication, please acknowledge use:
Möglich, A. (2018) An open-source, cross-platform resource for nonlinear least-squares curve fitting. J Chem Educ 95(12), 2273-2278 [doi]

Features

Fit-o-mat attempts to meet these objectives:

  • open-source, cross-platform, Python-based architecture
  • free to copy, free to share, facilitate data exchange
  • least-squares fitting to arbitrary target functions, including discontinuous and numerical functions
  • flexible online modification of fit parameters and function
  • global fit of multiple data sets and functions
  • publication-quality graphics in various formats
  • tutorial mode to aid teaching
  • enthuse people for Python

Installation

Fit-o-mat requires a working Python 3 installation and the following modules, all of which are pretty standard: PyQt5, sys, glob, functools, copy, ast, time, os, webbrowser, matplotlib, xlrd, xlsxwriter, numpy, scipy. To install Python 3, the following information may be helpful.

  • Windows - we recommend WinPython as it already includes the above required modules
  • Linux - modern Linux distributions should come with Python 3 or offer the option to install it. Similarly, missing modules can be installed as well.
  • Mac OS X - Fit-o-mat runs on Mac OS X but the installation of PyQt5 is challenging. Assuming you have a working installation of Python 3, you should first try installing the PyQt5 wheel by issuing this command:
    python3 -m pip install PyQt5
    Ideally, you are good to go now. However, failing that, people have had success with Homebrew. (Sorry, don't possess a current Mac, can only provide minimal support here.)

The actual Fit-o-mat program is a Python script named fit-o-mat.py. Copy this script as well as the accompanying file folders to a desired directory. Run the Python program. (Under Linux/OS X, the script assumes that the Python 3 interpreter is located at /usr/bin/python3.) If installation has been successful, a program window should now appear that depending upon operating system looks approximately like this.
On Linux/OS X platforms, the graphical user interface may appear overly small (depending on screen resolution). In this case, you can try to start the program with the following command line argument:

./fit-o-mat.py -font 14
This argument sets the base font size of the user interface, and one may try different values here. Note that the command line argument will have no effect on Windows platforms.

Tutorials

How to learn using Fit-o-mat? One option certainly is to go through this manual but arguably the best way to learn using (and liking) Fit-o-mat is to actually try it out. In this spirit, Fit-o-mat comes with several tutorial files that can be executed via the 'Open State' button located in the bottom right corner of the program window (or, by pressing Ctrl-O).

Credits

Kudos to my research group at Universität Bayreuth for patience, comments, inspiration, testing, beta-testing and (rather painful) alpha-testing. Thanks to my old pals Max2, Marvin, Falko et al. at Humboldt-Universität zu Berlin for hooking me up with Python (used to be a camelid before). Thanks to Nischal Karki and Vincent Emann, and Drs. Christian Kambach, Jochen Reinstein, David Richter, Dagmar Wachten, Michael Weyand, and Brian Zoltowski for stimulating discussion and motivation.

Feature reference

Main window

The program window is divided into two halves, with the left showing one of five tabs and the right displaying main and residuals plots. The usage of the five tabs is detailed below. The right part of the window allows to set limits and scale (linear or log) for the x any y axes; the checkboxes turn on/off automatic zoom to current data/curve during program usage. Left-click in the main graph area allows interactive zoom to desired regions of the plot; right button unzooms to previous view. Middle button (or, left double-click) toggles on/off a mouse cursor. Use Ctrl key and mousewheel to set magnification of plot.

The very bottom of the program window contains a status bar that displays messages in case of problems during program usage. Watch this space to become aware of (and hopefully solve) any problems. At the right edge of the status bar, buttons are available for saving and loading the current state (or, session) of the program; for controlling the magnification of on-screen display; and for accessing advanced program options (under development). Fit-o-mat responds to a number of keyboard shortcuts as follows: Ctrl-O and Ctrl-S for opening and saving state files, respectively; Ctrl-P for exporting graphics; Ctrl-I for importing data files; Ctrl-F for fitting data; Ctrl-+ and Ctrl-- for setting plot magnification; F1 key for help; F2 for plot preview.

Data tab

The purpose of this tab is to import data, and to optionally reduce and transform them.

  • Open file - data files in Excel and text format (tab-, comma-, or whitespace-delimited) are supported. Once a file has been loaded, the below table is populated. In case of Excel files with several sheets, a pertinent selector dialog is displayed. Data rows in the table can be selected by mouse or keyboard. Cells can be edited by double-clicking on them or just typing new contents. By left-clicking on the table header, the role of a given data column can be specified, i.e. none, x and y values and errors, or data labels. Right click on the table header allows sorting of the table based on the selected column. Via Ctrl+left click on the column header, the data column can be transformed. To this end, enter a formula in the dialog where individual columns in the data sheet can be accessed via C1, C2, etc. For example, clicking on column 1 and then entering 'C1 = C1 - 1' subtracts 1 from each value in column 1.
  • Replace comma - Certain countries use the comma character (,) to delimit decimal numbers but Fit-o-mat expects decimal numbers with a period delimiter (.). Use this button, to replace all commata in data table with periods.
  • Transpose? - Check this box to transpose data sheet, i.e. swap columns and rows.
  • Error options - Choose between using no errors, individual data errors in specified column (or, none if column is not assigned), constant error and proportional error.
  • Data reduction - Data can be reduced by skipping or averaging n data points. The option 'mvavg' calculates a moving average over n consecutive data points, and the option 'log' logarithmically reduces number of data points to target number (approximately).
  • Data transform - Formulas can be entered to transform the x and y values. For example, entering 'x = y' and 'y = x' swaps x and y. Likewise, 'x = x + 5' shifts data in x by 5.
  • Import data - The currently selected data rows are imported with the current settings for error, data reduction and transform. When applying the reduction and transformation steps, data errors will be propagated.
  • Import data series - This function iteratively imports data sets starting with the currently selected y column and then continuing for all (unassigned) columns to the right of this initial column. To speed up graphics, display of data is switched to line graphics with no markers. Other than that, the comments for the 'Import data' function apply.

Fit tab

The purpose of this tab is to fit the data.

  • Function selector - The top-most drop-down menu allows to select fitting functions. These are actual text files that (by default) reside in the 'functions' subdirectory. Once a fit function has been selected, the parameter and formula fields and the parameter table are updated, and the new function is plotted over the current x interval.
  • Parameter field - Use this field to specify which parameters the fit formula is using. Note that the independent variable is always assumed to be 'x' and the return variable is always assumed to be 'y'. Hence, 'x' and 'y' need not be specified here.
  • Formula field - This field contains the current fit formula which can be edited at will. The entry field turns red if a fit function throws an error when it is plotted. Entering new formula may prove somewhat of a challenge to new users -- best start from an existing function file and modify as desired.
  • Save fit function - The current fit formula and parameter values can be saved to file.
  • Apply fit function - Use this button to apply a previously edited fit function. If a fit function has been chosen via the drop-down selector, it has been applied already and this button need not be clicked.
  • Parameter table - Use checkboxes to restrain parameters to set values or to optimize them during fit. Entry fields hold current parameter values. Adjacent column shows asymptotic standard errors from last fit. (Note that these errors are calculated a posteriori, i.e. based on estimates of the uncertainties for the individual data points. The final column reports a priori errors, provided uncertainties for the individual data points were defined. If in doubt, read up or use the regular a posteriori errors to be on the safe side.)
  • Fit data - Nonlinear least-squares optimization is performed for the currently selected data sets and curves, cf. Objects tab. If the data contain x errors, optimization is done by orthogonal distance regression (odr), otherwise by Levenberg-Marquardt (lm). Fitted parameters are updated in the parameter table as are curve and residuals in the plot. If start parameters are ill-chosen, the fit may not converge to the global minimum but be trapped in a local minimum. If so, try adjusting start parameters, either manually or by using the 'Grid search' or 'Random search' options, and fit again.
  • Grid search - Starting from the current set of parameters, Fit-o-mat tries to find better agreement between data and fit by systematic variation of parameters in a grid-like fashion. A progress window pops up that provides information on the process and allows to terminate the procedure. Note that this function does not perform an actual fit of the data, but rather it is ideally used to determine suitable start parameters for a subsequent least-squares fit.
  • Random search - Starting from the current set of parameters, Fit-o-mat tries to find better agreement between data and fit by random variation of parameters. A progress window pops up that provides information on the process and allows to terminate the procedure. Note that this function does not perform an actual fit of the data, but rather it is ideally used to determine suitable start parameters for a subsequent least-squares fit.
  • Reset parameters - Upon loading or saving a fit function (cf. above), the current function parameters are stored in memory. Use this function, to revert to the previously saved parameter values. (Useful when a fit has not converged.)
  • Fit results - The bottom text field displays information on the last fit.

Global tab

This tab allows global fitting of several data sets to one or several functions.

  • Data sets and curves - Each line in the table represents one data set and the fit function associated with this data set. Use checkbox to control whether the respective data set is considered for global fitting. Use drop-down selection to choose which function the particular data set is fitted to within the global fitting process. (Fit functions need to be specified in the Fit tab beforehand. Use the Objects tab to create additional functions for global fitting.) The final column of the table lists the parameters of the selected fit function.
  • Parameters Local / Global - This table collates the parameters in all currently selected fit functions. Parameter names which occur in several fit functions are fitted globally and are highlighted in bold blue. Use the checkboxes to fix individual parameter and to set start values for the global fit. The final two columns report a posteriori and a priori confidence intervals for the fitted parameters. Use the buttons to start global fit or to restore global fit parameters to their original values.
  • Global fit results - The bottom text field displays information on the last global fit.

Results tab

This tab lists the current data and fit function values.

  • Main table - Once data has been imported, a table with the data and error values is displayed. After fitting, columns with the fitted function values and residuals are added.
  • Export results - The content of the data table and the current graph can be exported as an HTML file with embedded SVG. Use this function to document your work. Alternatively, export these data to Excel (if you must).

Objects tab

This tab grants access to the organization and the appearance of data, curve, residuals and extra graphics objects.

  • Data sets - Each line in the table represents one data set. Use checkbox to control visibility, radiobutton to set active data set and the two entry fields to control z order and name of the data set. Note that curves are always fitted to the currently active data set. The 'Conf' button opens a pop-up menu that allows to alter the appearance of the data set. 'Copy' creates an identical copy of the data set, and 'Del' deletes the data set (unless it is the last remaining data set).
  • Curves - Each line in the table represents one curve. Use checkbox to control visibility, radiobutton to set active curve and the two entry fields to control z order and name of the curve. Note that the currently active curve is used for fitting; for plotting, the curve is evaluated over the currently set x range. The 'Conf' button opens a pop-up menu that allows to alter the appearance of the curve. 'Copy' creates an identical copy of the curve, and 'Del' deletes the curve (unless it is the last remaining curve).
  • Extras - You can add lines, geometric shapes, text labels or annotations to the plot. Resultant objects will then appear as entries in the table. Use checkbox to control visibility and the two entry fields to control z order and name of the object. The 'Conf' button opens a pop-up menu that allows to alter the appearance of the object. 'Copy' creates an identical copy of the object, and 'Del' deletes the object.
  • Residuals - Each line in the table represents one residuals object, with the first line being the zero line in the residuals plot. Use checkbox to control visibility, and the two entry fields to control z order and name of the residuals. Note that the currently active residuals object is paired to the currently active data set. The 'Conf' button opens a pop-up menu that allows to alter the appearance of the residuals.

Graphics tab

This tab is used to adjust and export graphics. It's arguably easier to try out and see what these settings are doing than reading the below, but just in case, here we go:

  • x and y labels - Set text, color, size, style and font of axes labels. Use third row to control angle, horizontal and vertical alignment, and position along axis of label.
  • Axes - Control visibility, color, width and line style of axes.
  • Arrows - Draw arrowheads for x and y axes. Set colors, length and width of arrowheads. The settings 'ind.' and 'off.' control the shape and the offset of the arrowhead, respectively.
  • Tick labels - Control position of axes ticks. Use 'auto' to automatically assign them, or the text box to manually determine where and which labels are displayed. The x axis also has the additional option 'Use labels' to show custom labels contained in the current data set (if any). Also, control angle, size, color, style and font of tick labels.
  • Ticks - Control visibility, position, color, width and length of tick marks.
  • Grid - Control visibility, color, width and line style of x and y grid. Also, determine whether grid is shown in front or behind data.
  • Legend - Control visibility, placement, face and edge color, border width and shadow of legend. Configure color, size, style and font of legend entries.
  • Figure - The first line sets figure and canvas color. The second line sets the width and height of exported graphics (in inches). The button 'Use screen' updates the entry fields with the dimensions currently seen on screen. The third row controls the padding around the graph; use these settings if graphics are cut off in exported files.
  • Miscellaneous graphics settings - Draw your graphics in xkcd style (works great in the class room). Draw an outline and/or shadow for your data and curves.
  • Preview - Display a preview of the current plot as it looks when exported.
  • Export graphics - Save the current plot and residuals graphics in PDF, SVG and PS vector formats, or as a PNG bitmap. Advanced users may save the current graphics as a Python script that generates these graphics (useful for further modification of plot graphics).
  • Open style - Apply style settings to the current plot.
  • Save style - Save current graphics settings as a style. Generate and share your own style files.


Webmaster: Univ.Prof.Dr. Andreas Möglich

Facebook Twitter Youtube-Kanal Instagram Blog Contact