Karlsruhe Fit Environment 2 (kafe2)

2.11.0 · active · verified Tue Apr 14

kafe2 (Karlsruhe Fit Environment 2) is an open-source Python package (current version 2.11.0) for likelihood-based parameter estimation and elementary data analysis. Primarily used for fitting models to measured data and visualizing results, it provides a user-friendly interface for state-of-the-art statistical methods, relying on established numerical and optimization libraries like NumPy and SciPy. The library aims to offer an easy-to-use and performance-optimized pipeline for data analysis, including parameter confidence intervals and publication-quality plots. It typically sees a few releases per year.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a simple linear fit to x-y data with errors, using kafe2's simplified functional interface. It defines data, performs the fit, and then visualizes the results.

import kafe2
import numpy as np
import matplotlib.pyplot as plt

# 1. Define your data
x_data = np.array([1.0, 2.0, 3.0, 4.0])
y_data = np.array([2.3, 4.2, 7.5, 9.4])

# 2. Perform a fit using the simplified functional interface
# A 'line' model is used by default if not specified explicitly.
fit_object = kafe2.xy_fit(
    "line",
    x_data,
    y_data,
    x_error=0.1, 
    y_error=[0.40, 0.45, 0.40, 0.25] # Point-wise y errors
)

# 3. Plot the results
plot_object = kafe2.plot(fit_object, x_label="$t$ [s]", y_label="$h$ [m]")
plt.show()

view raw JSON →