Repository: lmfit/lmfit-py

Issue:
Model.make_params() sometimes ignores set a parameter with a prefix
#### Description
<!-- Provide a short description of the issue, describe the expected outcome, and give the actual result -->

This issue was shown  in #892 

###### A Minimal, Complete, and Verifiable example
<!-- see, for example, https://stackoverflow.com/help/mcve on how to do this -->

```
from lmfit.models import GaussianModel

mod = GausssiaModel(prefix='g1_')

# this works
mod.make_params(amplitude=1, center=2000, sigma=20) 

# this fails
mod.make_params(g1_amplitude=1, g1_center=2000, g1_sigma=20) 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/..../lmfit-py/lmfit/model.py", line 703, in make_params
    setpar(par, kwargs[basename])
KeyError: 'amplitude'
```

Note that if a composite model was created, the `g1_amplitude` variation would work and be required


###### Fit report:
<!-- paste the *full* fit report here  -->



###### Error message:
<!-- If any, paste the *full* error message inside a code block (starting from line Traceback) -->


The error is shown in #892, but repeated here:

```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/..../lmfit-py/lmfit/model.py", line 703, in make_params
    setpar(par, kwargs[basename])
KeyError: 'amplitude'
```


###### Version information
<!-- Generate version information with this command in the Python shell and copy the output here:
import sys, lmfit, numpy, scipy, asteval, uncertainties
print(f"Python: {sys.version}\n\nlmfit: {lmfit.__version__}, scipy: {scipy.__version__}, numpy: {numpy.__version__},"
      f"asteval: {asteval.__version__}, uncertainties: {uncertainties.__version__}")
-->

Latest.

###### Link(s)
<!-- If you started a discussion on the lmfit mailing list, discussion page, or Stack Overflow, please provide the relevant link(s) -->

#892


Discussion:

Resolving patch:
diff --git a/lmfit/model.py b/lmfit/model.py
--- a/lmfit/model.py
+++ b/lmfit/model.py
@@ -700,7 +700,7 @@ def setpar(par, val):
             if basename in kwargs:
                 setpar(par, kwargs[basename])
             if name in kwargs:
-                setpar(par, kwargs[basename])
+                setpar(par, kwargs[name])
             params.add(par)
             if verbose:
                 print(f' - Adding parameter "{name}"')


Test patch:
diff --git a/tests/test_model.py b/tests/test_model.py
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -10,10 +10,10 @@
 from scipy import __version__ as scipy_version
 
 import lmfit
-from lmfit import Model, models
+from lmfit import Model, Parameters, models
 from lmfit.lineshapes import gaussian, lorentzian
 from lmfit.model import get_reducer, propagate_err
-from lmfit.models import PseudoVoigtModel
+from lmfit.models import GaussianModel, PseudoVoigtModel
 
 
 @pytest.fixture()
@@ -339,6 +339,36 @@ def func_default_value(a, b, c=10):
     assert_allclose(mod.def_vals['c'], 10)
 
 
+def test_make_params_withprefixs():
+    # tests Github Issue #893
+    gmod1 = GaussianModel(prefix='p1_')
+    gmod2 = GaussianModel(prefix='p2_')
+
+    model = gmod1 + gmod2
+
+    pars_1a = gmod1.make_params(p1_amplitude=10, p1_center=600, p1_sigma=3)
+    pars_1b = gmod1.make_params(amplitude=10, center=600, sigma=3)
+
+    pars_2a = gmod2.make_params(p2_amplitude=30, p2_center=730, p2_sigma=4)
+    pars_2b = gmod2.make_params(amplitude=30, center=730, sigma=4)
+
+    pars_a = Parameters()
+    pars_a.update(pars_1a)
+    pars_a.update(pars_2a)
+
+    pars_b = Parameters()
+    pars_b.update(pars_1b)
+    pars_b.update(pars_2b)
+
+    pars_c = model.make_params()
+
+    for pname in ('p1_amplitude', 'p1_center', 'p1_sigma',
+                  'p2_amplitude', 'p2_center', 'p2_sigma'):
+        assert pname in pars_a
+        assert pname in pars_b
+        assert pname in pars_c
+
+
 def test__parse_params_forbidden_variable_names():
     """Tests for _parse_params function using invalid variable names."""