Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Peak fit: support lmfit 1.3.1 #716

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .tox.ini.swp
Binary file not shown.
2 changes: 1 addition & 1 deletion conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ requirements:
- extranormal3 >=0.0.3
- renishawWiRE >=0.1.8
- pillow
- lmfit >=1.0.2
- lmfit >=1.3.1
- bottleneck
- pebble
- agilent-format>=0.4.5
Expand Down
7 changes: 3 additions & 4 deletions orangecontrib/spectroscopy/widgets/owpeakfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
ThermalDistributionModelEditor, DoniachModelEditor, ConstantModelEditor, \
LinearModelEditor, QuadraticModelEditor, PolynomialModelEditor, set_default_vary
from orangecontrib.spectroscopy.widgets.peakfit_compute import n_best_fit_parameters, \
best_fit_results, LMFIT_LOADS_KWARGS, pool_initializer, pool_fit, pool_fit2
best_fit_results, pool_initializer, pool_fit, pool_fit2

# number of processes used for computation
N_PROCESSES = None
Expand Down Expand Up @@ -264,8 +264,7 @@ def progress_interrupt(_: float):
raise
concurrent.futures.wait([res], 0.05)
fits = res.result()
model_result[row.id] = ModelResult(model, parameters).loads(fits,
**LMFIT_LOADS_KWARGS)
model_result[row.id] = ModelResult(model, parameters).loads(fits)

progress_interrupt(0)
return orig_data, data, model_result
Expand Down Expand Up @@ -393,7 +392,7 @@ def done():
progress_interrupt(99)

for fit, bpar, fitted, resid in fitsr:
out = ModelResult(model, parameters).loads(fit, **LMFIT_LOADS_KWARGS)
out = ModelResult(model, parameters).loads(fit)
output.append(bpar)
fits.append(fitted)
residuals.append(resid)
Expand Down
13 changes: 2 additions & 11 deletions orangecontrib/spectroscopy/widgets/peakfit_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@
import numpy as np


def constant(x, c=0.0):
return c


# WORKAROUND lmfit's inability to load constant models
# Add this as kwargs to .loads
LMFIT_LOADS_KWARGS = {"funcdefs": {"constant": constant}}


def n_best_fit_parameters(model, params):
"""Number of output parameters for best fit results"""
number_of_peaks = len(model.components)
Expand Down Expand Up @@ -54,7 +45,7 @@ def pool_initializer(model, parameters, x):
# Therefore we need to use loads() and dumps() to transfer it between processes.
global lmfit_model
global lmfit_x
lmfit_model = Model(None).loads(model, **LMFIT_LOADS_KWARGS), parameters
lmfit_model = Model(None).loads(model), parameters
lmfit_x = x


Expand All @@ -73,6 +64,6 @@ def pool_fit(v):


def pool_fit2(v, model, parameters, x):
model = Model(None).loads(model, **LMFIT_LOADS_KWARGS)
model = Model(None).loads(model)
model_result = model.fit(v, params=parameters, x=x)
return model_result.dumps()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def include_documentation(local_dir, install_dir):
'extranormal3 >=0.0.3',
'renishawWiRE>=0.1.8',
'pillow',
'lmfit>=1.0.2',
'lmfit>=1.3.1',
'bottleneck',
'pebble',
'agilent-format>=0.4.5'
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ deps =
oldest: scipy~=1.9.0
oldest: pandas~=1.3.0
oldest: spectral~=0.22.3
oldest: lmfit~=1.0.2
oldest: lmfit==1.3.1
latest: https://github.com/biolab/orange3/archive/refs/heads/master.zip#egg=orange3
latest: https://github.com/biolab/orange-canvas-core/archive/refs/heads/master.zip#egg=orange-canvas-core
latest: https://github.com/biolab/orange-widget-base/archive/refs/heads/master.zip#egg=orange-widget-base
Expand Down
Loading