Coder Social home page Coder Social logo

kfit's Introduction

kfit

kfit - Simple, graphical spectral fitting

kfit is a tool for quick and easy spectral fitting in science and education. It works as a standalone data fitting program for simple tasks, or as an exploratory tool in more complex projects. kfit provides a few commonly used peak shapes in engineering and physics, and will eventually support custom, user-defined models.

Usage

Keyboard shortcuts

Action Shortcut
Fit <Control>f
Reset <Control>r
Import File <Control>o
Export Results <Control>s
Open Settings <Control>p
Add/Remove Gaussian To/From Model g / <Shift>g
Add/Remove Lorentzian To/From Model l / <Shift>l
Add/Remove Pseudo-Voigt To/From Model v / <Shift>v
Add/Remove Line To/From Model n / <Shift>n

Importing Data

CSV files are imported via the pandas.read_csv() method, and a few select parameters for this method can be accessed from the settings window in kfit. Generally, a comma-separated plaintext file with or without a header row and with UTF-8 encoding can be import with no issues. A more robust, interactive file import dialog will be implemented in a future release.

Navigating the Graph Tab

The graph tab uses matplotlib backends for the figure and navigation toolbar. This means you can pan, zoom, adjust settings, and export the plot just as you would with a typical matplotlib plot. If you are not familiar with matplotlib, this documentation page describes how to use the interactive toolbar.

Note that zooming in/out on the graph also changes the range of the fitted data in kfit. This can be a useful way to crop out regions of data you are not interested in fitting. Exported results will adhere to this zoomed range as well. To return to viewing and fitting the full dataset, use the <Control>r shortcut to reset the graph.

Exporting Results

The export method will save two CSV files to the local filesystem:

  1. *.csv

    The original data, total fit, and component curves in the fit.

    x data total_fit [model_component_1] ... [model_component_N]
    ... ... ... ... ... ...
  2. *.params.csv

    The parameters for each model component, e.g. gau1_amplitude, lin1_slope, etc.

    parameter value
    [model_component_1]_[parameter_1]
    [model_component_1]_[parameter_2]
    ...
    [model_component_N]_[parameter]_N

Models

At the moment, kfit uses four stock models from the lmfit package: three peak-like models (Gaussian, Lorentzian, Pseudo-Voigt) and a Linear model. These base models can be added together to create a composite model for the data. In the future, support for more lmfit models and user-defined custom models will be added.

Installation (Linux)

From snapcraft

Get it from the Snap Store

sudo snap install kfit

Instructions for installing snapd for each compatible linux distro:

Snap has been tested on:

  • Ubuntu 18.04 and 19.04 ✔️

  • Debian 10 ✔️

  • Red Hat Enterprise Linux 7 ✔️

  • Fedora 30*

  • OpenSUSE Tumbleweed*

*See #2

From source

Install:

sudo apt install python3-dev python3-pip python3-gi python3-gi-cairo libgirepository1.0-dev gcc libcairo2-dev pkg-config gir1.2-gtk-3.0
git clone [email protected]:rhroberts/kfit.git
cd kfit
pip3 install ./

Run:

./kfit/kfit.py

Dependencies

Python packages

  • lmfit
  • matplotlib
  • pandas
  • numpy
  • pycairo
  • pygobject

Distro packages

  • gcc
  • pkg-config
  • python3-dev
  • python3-pip
  • python3-gi
  • python3-gi-cairo
  • libgirepository1.0-dev
  • libcairo2-dev
  • gir1.2-gtk-3.0

Installation (Windows)

STILL WORKING ON THIS

#3

Contributing

  • Check out NOTES.md for development notes and TODOs

kfit's People

Contributors

rhroberts avatar

Stargazers

Sean Clancy avatar

Watchers

James Cloos avatar  avatar

kfit's Issues

Gtk namespace error when executing kfit.py on Windows 10

I've tested the following with Windows 10 and Anaconda's python3 distribution. After installing conda and opening up a conda prompt:

  • Create a conda env
conda create -n kfit python=3.7
conda activate kfit
  • Install dependencies
conda install numpy matplotlib pandas pycairo
conda install -c conda-forge pygobject
pip install lmfit
  • Download and unzip kfit source code
  • Navigate to the project root
  • Run python kfit/kfit.py

Currently, this produces the following error:

Traceback (most recent call last): File "C:\Users\rhrob\Anaconda3\envs\kfit\lib\site-packages\matplotlib\backends\backend_gtk3.py", line 25, in gi.require_version("Gtk", "3.0") File "C:\Users\rhrob\Anaconda3\envs\kfit\lib\site-packages\gi_init_.py", line 129, in require_version raise ValueError('Namespace %s not available' % namespace) ValueError: Namespace Gtk not available
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "kfit.py", line 7, in from matplotlib.backends.backend_gtk3cairo import ( File "C:\Users\rhrob\Anaconda3\envs\kfit\lib\site-packages\matplotlib\backends\backend_gtk3cairo.py", line 1, in from . import backend_cairo, backend_gtk3 File "C:\Users\rhrob\Anaconda3\envs\kfit\lib\site-packages\matplotlib\backends\backend_gtk3.py", line 29, in raise ImportError from e ImportError

Missing cursor theme on snap installation for Fedora 30 and OpenSUSE Tumbleweed

The snap installs properly on Fedora 30 workstation and OpenSUSE Tumbleweed, but running the snap produces this following error, preventing app execution:

Gdk-Message: 16:35:17.073: Unable to load fleur from the cursor theme
Gdk-Message: 16:35:17.093: Unable to load fleur from the cursor theme
Traceback (most recent call last):
File "/snap/kfit/24/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3.py", line 45, in
cursors.MOVE : Gdk.Cursor.new(Gdk.CursorType.FLEUR),
TypeError: constructor returned NULL

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/snap/kfit/24/share/kfit/kfit.py", line 7, in
from matplotlib.backends.backend_gtk3cairo import (
File "/snap/kfit/24/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3cairo.py", line 1, in
from . import backend_cairo, backend_gtk3
File "/snap/kfit/24/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3.py", line 54, in
raise ImportError(exc)
ImportError: constructor returned NULL

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.