Skip to content

kmnhan/xarray-lmfit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

4b0b6b2 · Mar 10, 2025

History

36 Commits
Feb 25, 2025
Mar 10, 2025
Mar 10, 2025
Feb 26, 2025
Feb 25, 2025
Feb 23, 2025
Mar 5, 2025
Mar 5, 2025
Mar 10, 2025
Feb 23, 2025
Mar 10, 2025
Mar 10, 2025
Mar 10, 2025

Repository files navigation

xarray-lmfit

Supported Python Versions PyPi Conda Version Workflow Status Documentation Status pre-commit.ci status codecov Ruff

xarray-lmfit is a Python package that bridges the power of xarray for handling multi-dimensional labeled arrays with the flexible fitting capabilities of lmfit.

With xarray-lmfit, lmfit models can be fit to xarray Datasets and DataArrays, automatically propagating across multiple dimensions. The fit results are stored as xarray Datasets, retaining the original coordinates and dimensions of the input data.

Disclaimer: Please note that this package is independent and not affiliated with the xarray or lmfit projects. If you encounter any issues, please report them on the xarray-lmfit issue tracker.

Installation

Install via pip:

pip install xarray-lmfit

Install via conda:

conda install -c conda-forge xarray-lmfit

Usage

Below is a basic example to demonstrate how to use xarray-lmfit:

import xarray as xr
import numpy as np
from lmfit.models import GaussianModel

import xarray_lmfit as xlm

# Create an example dataset
x = np.linspace(0, 10, 100)
y = 3.0 * np.exp(-((x - 5) ** 2) / (2 * 1.0**2)) + np.random.normal(0, 0.1, x.size)
data = xr.DataArray(y, dims="x", coords={"x": x})

# Define the model to be used
model = GaussianModel()

# Perform the fit
result = data.xlm.modelfit("x", model=model)

Documentation

For more detailed documentation and examples, please visit the documentation.

License

This project is licensed under the GPL-3.0 License.