I have a python script NeoprobeApp.py which calls a fitting function in Parameter.py Parameter.py is given below
from scipy import optimize
import numpy as np
class Parameter:
def __init__(self, value):
self.value = value
def set(self, value):
self.value = value
def __call__(self):
return self.value
def fit(function, parameters, y, x = None):
def f(params):
i = 0
for p in parameters:
p.set(params[i])
i += 1
return y - function(x)
if x is None: x = arange(y.shape[0])
p = [param() for param in parameters]
optimize.leastsq(f, p)
I import the fit function successfully from Parameter import fit. However, when I try to initialise my parameters
# Define initial parameters of Gaussian fit
mu = Parameter(0)
sigma = Parameter(20)
height = Parameter(1)
#define Gaussian fit function
def f(angles): return height() * exp(-((angles-mu())/sigma())**2)
fit(f, [mu, sigma, height], n_col_cnts)
I get the error message
Traceback (most recent call last):
File "NeoprobeApp.py", line 228, in OnPlot
mu = Parameter(0)
NameError: global name 'Parameter' is not defined
What am I doing wrong?
importstatement. The error should also be very clear - your script doesn't know anything namedParameter. Any good IDE (for example, vim + pyflakes) would have notified you of this error before running the code. Also, you seem to understand that you need to import yourfitfunction, why do you think theParameterclass is special and doesn't need to be imported?