1
votes
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()

Traceback (most recent call last):

File "C:\Users\MUHAMMAD ALI QURESHI\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2910, in run_code exec(code_obj, self.user_global_ns, self.user_ns)

File "", line 4, in from lmfit.model import load_model

File "C:\Users\MUHAMMAD ALI QURESHI\Anaconda3\lib\site-packages\lmfit__init__.py", line 39, in from .confidence import conf_interval, conf_interval2d

File "C:\Users\MUHAMMAD ALI QURESHI\Anaconda3\lib\site-packages\lmfit\confidence.py", line 10, in from .minimizer import MinimizerException

File "C:\Users\MUHAMMAD ALI QURESHI\Anaconda3\lib\site-packages\lmfit\minimizer.py", line 34, in import uncertainties

File "C:\Users\MUHAMMAD ALI QURESHI\Anaconda3\lib\site-packages\uncertainties__init__.py", line 224, in from .core import *

File "C:\Users\MUHAMMAD ALI QURESHI\Anaconda3\lib\site-packages\uncertainties\core.py", line 2889 POSITIVE_DECIMAL_UNSIGNED_OR_NON_FINITE = ur'((\d*)(.\d*)?|nan|NAN|inf|INF)' ^ SyntaxError: invalid syntax

1
Please provide a full traceback for the error. It appears that the import of uncertainties is failing, but there isn't enough here to know why (invalid syntax might suggest a Python version problem). Try a simple import uncertainties and import uncertainties.core (like, just type those at the Python prompt) and investigate or report the full traceback. - M Newville
i really dont know whats happening. I also try different program related to lmfit but the same error arises. - Zewo
File "<ipython-input-13-6df3e4b517ba>", line 1, in <module> import uncertainties File "C:\Users\MUHAMMAD ALI QURESHI\Anaconda3\lib\site-packages\uncertainties_init_.py", line 224, in <module> from .core import * File "C:\Users\MUHAMMAD ALI QURESHI\Anaconda3\lib\site-packages\uncertainties\core.py", line 2889 POSITIVE_DECIMAL_UNSIGNED_OR_NON_FINITE = ur'((\d*)(\.\d*)?|nan|NAN|inf|INF)' ^ SyntaxError: invalid syntax - Zewo
i cant figure out what is the actual problem . the uncertainty package or the python version problem. - Zewo
i also tried the import lmfit in the Ipython console and the same error exists - Zewo

1 Answers

0
votes

I think you need to re-install uncertainties. It looks like the code you have is using Python2 syntax.

I believe that uncertainties needs to (automatically) use the 2to3 tool on installation -- it looks like some part of that didn't work for you.

It should work to do:

C:\.....\Anaconda3\Scripts\pip.exe install --force-reinstall uncertainties