.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_documentation_model_loadmodel.py: doc_model_loadmodel.py ====================== .. note:: This example *does* actually work, but running from within sphinx-gallery fails to find symbols saved in the save file. .. code-block:: pytb Traceback (most recent call last): File "/Users/Newville/opt/anaconda3/lib/python3.7/site-packages/sphinx_gallery/gen_rst.py", line 440, in _memory_usage out = func() File "/Users/Newville/opt/anaconda3/lib/python3.7/site-packages/sphinx_gallery/gen_rst.py", line 425, in __call__ exec(self.code, self.globals) File "/Users/Newville/Codes/lmfit-py/examples/documentation/model_loadmodel.py", line 32, in result = model.fit(y, params, x=x) File "/Users/Newville/Codes/lmfit-py/lmfit/model.py", line 1022, in fit output.fit(data=data, weights=weights) File "/Users/Newville/Codes/lmfit-py/lmfit/model.py", line 1369, in fit self.init_fit = self.model.eval(params=self.params, **self.userkws) File "/Users/Newville/Codes/lmfit-py/lmfit/model.py", line 848, in eval return self.func(**self.make_funcargs(params, kwargs)) File "/Users/Newville/Codes/lmfit-py/examples/documentation/model_savemodel.py", line 18, in mysine return amp * np.sin(x*freq + shift) NameError: name 'np' is not defined .. code-block:: default ## import warnings warnings.filterwarnings("ignore") ## # import matplotlib.pyplot as plt import numpy as np from lmfit.model import load_model def mysine(x, amp, freq, shift): return amp * np.sin(x*freq + shift) data = np.loadtxt('sinedata.dat') x = data[:, 0] y = data[:, 1] model = load_model('sinemodel.sav', funcdefs={'mysine': mysine}) params = model.make_params(amp=3, freq=0.52, shift=0) params['shift'].max = 1 params['shift'].min = -1 params['amp'].min = 0.0 result = model.fit(y, params, x=x) print(result.fit_report()) plt.plot(x, y, 'bo') plt.plot(x, result.best_fit, 'r-') plt.show() # .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.008 seconds) .. _sphx_glr_download_examples_documentation_model_loadmodel.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: model_loadmodel.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: model_loadmodel.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_