Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

kmnhan/xarray-lmfit

Repository files navigation

xarray-lmfit

Documentation Status pre-commit.ci status 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: This package is not affiliated with the xarray or lmfit projects. Any issue that arises from using this package should be reported to the xarray-lmfit issue tracker, not to the xarray or lmfit projects.

Installation

Install via pip:

pip install xarray-lmfit

Or build from source by cloning the repository:

git clone https://github.com/kmnhan/xarray-lmfit.git
cd xarray-lmfit
pip install .

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.

Releases

No releases published

Packages

No packages published

Languages