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.
Install via pip:
pip install xarray-lmfit
Install via conda:
conda install -c conda-forge xarray-lmfit
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)
For more detailed documentation and examples, please visit the documentation.
This project is licensed under the GPL-3.0 License.