lmfit / lmfit-py

Non-Linear Least Squares Minimization, with flexible Parameter settings, based on scipy.optimize, and with many additional classes and methods for curve fitting.
https://lmfit.github.io/lmfit-py/
Other
1.06k stars 274 forks source link

Allow model opts #950

Closed newville closed 5 months ago

newville commented 5 months ago

Description

This restores the behavior of setting a non-default keyword value for a Model function argument when creating a Model. That is, in 1.3.0,

from lmfit import Model
from lmfit.lineshapes import step

mymodel  = Model(step, form='erf')

could sometimes fail to set the form to erf. This is true in StepModel, for example, as it set the independent variables to ['x'].

The fix here is sort of "belt and suspenders" in that: the form above should normally work in 1.3.0, but now that new default value (held in Model.opts = {'form': 'erf'}) is used, and then any independent variables are set, and then any runtime keyword arguments.

See #947

Not being able to leave well enough alone, I also tweaked Model.__repr__() to use Model._reprsting() and to use long=True by default. With this, for example, the repr for StepModel will always show the form.

This can be squashed-and-merged or the repr string change can be removed.

Type of Changes
Tested on

Python: 3.11.5 | packaged by conda-forge | (main, Aug 27 2023, 03:35:23) [Clang 15.0.7 ]

lmfit: 1.3.0.post2+gcf2626b.d20240407, scipy: 1.12.0, numpy: 1.26.4, asteval: 0.9.32, uncertainties: 3.1.7

Verification

Have you

codecov-commenter commented 5 months ago

Codecov Report

Attention: Patch coverage is 92.30769% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 93.20%. Comparing base (cf2626b) to head (217347e).

Files Patch % Lines
lmfit/model.py 90.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #950 +/- ## ========================================== + Coverage 93.14% 93.20% +0.05% ========================================== Files 10 10 Lines 3762 3765 +3 ========================================== + Hits 3504 3509 +5 + Misses 258 256 -2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

newville commented 5 months ago

@reneeotten I'd like to merge this (or a reviewed version of it) and tag as 1.3.1 over the next week or so. Any objections?

reneeotten commented 5 months ago

@reneeotten I'd like to merge this (or a reviewed version of it) and tag as 1.3.1 over the next week or so. Any objections?

@newville I'll take a look tonight after work.

newville commented 5 months ago

@reneeotten Thanks! I backed up and did a forced push for one commit to address #953. I think this is probably OK to leave as a few separate commits rather than squash-and-merge. Assuming the tests pass, I'll plan on merging in a day or so.
I would then rebase to get #952 (maybe with more tweaks) merged, then call that 1.3.1.

newville commented 5 months ago

OK, merging this...