summaryrefslogtreecommitdiff
path: root/silx/math/fit
diff options
context:
space:
mode:
Diffstat (limited to 'silx/math/fit')
-rw-r--r--silx/math/fit/bgtheories.py8
-rw-r--r--silx/math/fit/fitmanager.py16
-rw-r--r--silx/math/fit/fittheories.py34
-rw-r--r--silx/math/fit/functions.pyx4
-rw-r--r--silx/math/fit/leastsq.py30
-rw-r--r--silx/math/fit/test/test_fit.py8
-rw-r--r--silx/math/fit/test/test_fitmanager.py12
7 files changed, 56 insertions, 56 deletions
diff --git a/silx/math/fit/bgtheories.py b/silx/math/fit/bgtheories.py
index ccb556e..631c43e 100644
--- a/silx/math/fit/bgtheories.py
+++ b/silx/math/fit/bgtheories.py
@@ -1,7 +1,7 @@
# coding: utf-8
#/*##########################################################################
#
-# Copyright (c) 2004-2019 European Synchrotron Radiation Facility
+# Copyright (c) 2004-2020 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -281,7 +281,7 @@ def estimate_strip(x, y):
"""
estimated_par = [CONFIG["StripWidth"],
CONFIG["StripIterations"]]
- constraints = numpy.zeros((len(estimated_par), 3), numpy.float)
+ constraints = numpy.zeros((len(estimated_par), 3), numpy.float64)
# code = 3: FIXED
constraints[0][0] = 3
constraints[1][0] = 3
@@ -295,7 +295,7 @@ def estimate_snip(x, y):
set constraints to FIXED.
"""
estimated_par = [CONFIG["SnipWidth"]]
- constraints = numpy.zeros((len(estimated_par), 3), numpy.float)
+ constraints = numpy.zeros((len(estimated_par), 3), numpy.float64)
# code = 3: FIXED
constraints[0][0] = 3
return estimated_par, constraints
@@ -321,7 +321,7 @@ def estimate_poly(x, y, deg=2):
CONFIG["StripWidth"],
CONFIG["StripIterations"])
pcoeffs = numpy.polyfit(x, y, deg)
- cons = numpy.zeros((deg + 1, 3), numpy.float)
+ cons = numpy.zeros((deg + 1, 3), numpy.float64)
return pcoeffs, cons
diff --git a/silx/math/fit/fitmanager.py b/silx/math/fit/fitmanager.py
index 2dc63a1..b60e073 100644
--- a/silx/math/fit/fitmanager.py
+++ b/silx/math/fit/fitmanager.py
@@ -727,12 +727,12 @@ class FitManager(object):
:param xmax: Upper value of x values to use for fitting
"""
if y is None:
- self.xdata0 = numpy.array([], numpy.float)
- self.ydata0 = numpy.array([], numpy.float)
- # self.sigmay0 = numpy.array([], numpy.float)
- self.xdata = numpy.array([], numpy.float)
- self.ydata = numpy.array([], numpy.float)
- # self.sigmay = numpy.array([], numpy.float)
+ self.xdata0 = numpy.array([], numpy.float64)
+ self.ydata0 = numpy.array([], numpy.float64)
+ # self.sigmay0 = numpy.array([], numpy.float64)
+ self.xdata = numpy.array([], numpy.float64)
+ self.ydata = numpy.array([], numpy.float64)
+ # self.sigmay = numpy.array([], numpy.float64)
else:
self.ydata0 = numpy.array(y)
@@ -886,7 +886,7 @@ class FitManager(object):
:return: Output of the fit function with ``x`` as input and ``pars``
as fit parameters.
"""
- result = numpy.zeros(numpy.shape(x), numpy.float)
+ result = numpy.zeros(numpy.shape(x), numpy.float64)
if self.selectedbg is not None:
bg_pars_list = self.bgtheories[self.selectedbg].parameters
@@ -1036,7 +1036,7 @@ def test():
from . import bgtheories
# Create synthetic data with a sum of gaussian functions
- x = numpy.arange(1000).astype(numpy.float)
+ x = numpy.arange(1000).astype(numpy.float64)
p = [1000, 100., 250,
255, 690., 45,
diff --git a/silx/math/fit/fittheories.py b/silx/math/fit/fittheories.py
index f733d1a..6b19a38 100644
--- a/silx/math/fit/fittheories.py
+++ b/silx/math/fit/fittheories.py
@@ -213,7 +213,7 @@ class FitTheories(object):
"""
pcoeffs = numpy.polyfit(x, y, n)
- constraints = numpy.zeros((n + 1, 3), numpy.float)
+ constraints = numpy.zeros((n + 1, 3), numpy.float64)
return pcoeffs, constraints
def estimate_quadratic(self, x, y):
@@ -298,7 +298,7 @@ class FitTheories(object):
:return: List of peak indices
"""
# add padding
- ysearch = numpy.ones((len(y) + 2 * fwhm,), numpy.float)
+ ysearch = numpy.ones((len(y) + 2 * fwhm,), numpy.float64)
ysearch[0:fwhm] = y[0]
ysearch[-1:-fwhm - 1:-1] = y[len(y)-1]
ysearch[fwhm:fwhm + len(y)] = y[:]
@@ -389,7 +389,7 @@ class FitTheories(object):
xw = x
yw = y - bg
- cons = numpy.zeros((len(param), 3), numpy.float)
+ cons = numpy.zeros((len(param), 3), numpy.float64)
# peak height must be positive
cons[0:len(param):3, 0] = CPOSITIVE
@@ -405,10 +405,10 @@ class FitTheories(object):
shape = [max(1, int(x)) for x in (param[1:len(param):3])]
cons[1:len(param):3, 1] = min(xw) * numpy.ones(
shape,
- numpy.float)
+ numpy.float64)
cons[1:len(param):3, 2] = max(xw) * numpy.ones(
shape,
- numpy.float)
+ numpy.float64)
# ensure fwhm is positive
cons[2:len(param):3, 0] = CPOSITIVE
@@ -420,7 +420,7 @@ class FitTheories(object):
full_output=True)
# set final constraints based on config parameters
- cons = numpy.zeros((len(fittedpar), 3), numpy.float)
+ cons = numpy.zeros((len(fittedpar), 3), numpy.float64)
peak_index = 0
for i in range(len(peaks)):
# Setup height area constrains
@@ -524,7 +524,7 @@ class FitTheories(object):
# get the number of found peaks
npeaks = len(fittedpar) // 3
estimated_parameters = []
- estimated_constraints = numpy.zeros((4 * npeaks, 3), numpy.float)
+ estimated_constraints = numpy.zeros((4 * npeaks, 3), numpy.float64)
for i in range(npeaks):
for j in range(3):
estimated_parameters.append(fittedpar[3 * i + j])
@@ -579,7 +579,7 @@ class FitTheories(object):
fittedpar, cons = self.estimate_height_position_fwhm(x, y)
npeaks = len(fittedpar) // 3
newpar = []
- newcons = numpy.zeros((4 * npeaks, 3), numpy.float)
+ newcons = numpy.zeros((4 * npeaks, 3), numpy.float64)
# find out related parameters proper index
if not self.config['NoConstraintsFlag']:
if self.config['SameFwhmFlag']:
@@ -640,7 +640,7 @@ class FitTheories(object):
fittedpar, cons = self.estimate_height_position_fwhm(x, y)
npeaks = len(fittedpar) // 3
newpar = []
- newcons = numpy.zeros((5 * npeaks, 3), numpy.float)
+ newcons = numpy.zeros((5 * npeaks, 3), numpy.float64)
# find out related parameters proper index
if not self.config['NoConstraintsFlag']:
if self.config['SameFwhmFlag']:
@@ -741,7 +741,7 @@ class FitTheories(object):
fittedpar, cons = self.estimate_height_position_fwhm(x, y)
npeaks = len(fittedpar) // 3
newpar = []
- newcons = numpy.zeros((8 * npeaks, 3), numpy.float)
+ newcons = numpy.zeros((8 * npeaks, 3), numpy.float64)
main_peak = 0
# find out related parameters proper index
if not self.config['NoConstraintsFlag']:
@@ -841,7 +841,7 @@ class FitTheories(object):
newcons[8 * i + 7, 1] = self.config['MinStepTailHeightRatio']
newcons[8 * i + 7, 2] = self.config['MaxStepTailHeightRatio']
# if self.config['NoConstraintsFlag'] == 1:
- # newcons=numpy.zeros((8*npeaks, 3),numpy.float)
+ # newcons=numpy.zeros((8*npeaks, 3),numpy.float64)
if npeaks > 0:
if g_term:
if self.config['PositiveHeightAreaFlag']:
@@ -931,7 +931,7 @@ class FitTheories(object):
self.config["FwhmPoints"] * (x[1] - x[0])] # fwhm: default value
# Setup constrains
- newcons = numpy.zeros((3, 3), numpy.float)
+ newcons = numpy.zeros((3, 3), numpy.float64)
if not self.config['NoConstraintsFlag']:
# Setup height constrains
if self.config['PositiveHeightAreaFlag']:
@@ -983,7 +983,7 @@ class FitTheories(object):
position = (xx[0] + xx[-1]) / 2.0
fwhm = xx[-1] - xx[0]
largest = [height, position, fwhm, beamfwhm]
- cons = numpy.zeros((4, 3), numpy.float)
+ cons = numpy.zeros((4, 3), numpy.float64)
# Setup constrains
if not self.config['NoConstraintsFlag']:
# Setup height constrains
@@ -1056,7 +1056,7 @@ class FitTheories(object):
x[len(x)//2], # center: middle of x range
self.config["FwhmPoints"] * (x[1] - x[0])] # fwhm: default value
- newcons = numpy.zeros((3, 3), numpy.float)
+ newcons = numpy.zeros((3, 3), numpy.float64)
# Setup constrains
if not self.config['NoConstraintsFlag']:
# Setup height constraints
@@ -1123,7 +1123,7 @@ class FitTheories(object):
npeaks = len(peaks)
if not npeaks:
fittedpar = []
- cons = numpy.zeros((len(fittedpar), 3), numpy.float)
+ cons = numpy.zeros((len(fittedpar), 3), numpy.float64)
return fittedpar, cons
fittedpar = [0.0, 0.0, 0.0, 0.0, 0.0]
@@ -1153,7 +1153,7 @@ class FitTheories(object):
fittedpar[4] = search_fwhm
# setup constraints
- cons = numpy.zeros((5, 3), numpy.float)
+ cons = numpy.zeros((5, 3), numpy.float64)
cons[0, 0] = CFIXED # the number of gaussians
if npeaks == 1:
cons[1, 0] = CFIXED # the delta between peaks
@@ -1337,7 +1337,7 @@ function, parameters list, configuration function and description.
def test(a):
from silx.math.fit import fitmanager
- x = numpy.arange(1000).astype(numpy.float)
+ x = numpy.arange(1000).astype(numpy.float64)
p = [1500, 100., 50.0,
1500, 700., 50.0]
y_synthetic = functions.sum_gauss(x, *p) + 1
diff --git a/silx/math/fit/functions.pyx b/silx/math/fit/functions.pyx
index ebbc37b..1f78563 100644
--- a/silx/math/fit/functions.pyx
+++ b/silx/math/fit/functions.pyx
@@ -1,6 +1,6 @@
# coding: utf-8
#/*##########################################################################
-# Copyright (C) 2016-2018 European Synchrotron Radiation Facility
+# Copyright (C) 2016-2020 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -977,7 +977,7 @@ def periodic_gauss(x, *pars):
raise IndexError("No parameters specified. " +
"At least 5 parameters are required.")
- newpars = numpy.zeros((pars[0], 3), numpy.float)
+ newpars = numpy.zeros((pars[0], 3), numpy.float64)
for i in range(int(pars[0])):
newpars[i, 0] = pars[2]
newpars[i, 1] = pars[3] + i * pars[1]
diff --git a/silx/math/fit/leastsq.py b/silx/math/fit/leastsq.py
index 8c87d6b..3df1a35 100644
--- a/silx/math/fit/leastsq.py
+++ b/silx/math/fit/leastsq.py
@@ -1,7 +1,7 @@
# coding: utf-8
# /*##########################################################################
#
-# Copyright (c) 2004-2017 European Synchrotron Radiation Facility
+# Copyright (c) 2004-2020 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -132,7 +132,7 @@ def leastsq(model, xdata, ydata, p0, sigma=None,
calculating the numerical derivatives (for model_deriv=None).
Normally the actual step length will be sqrt(epsfcn)*x
Original Gefit module was using epsfcn 1.0e-5 while default value
- is now numpy.finfo(numpy.float).eps as in scipy
+ is now numpy.finfo(numpy.float64).eps as in scipy
:type epsfcn: *optional*, float
:param deltachi: float
@@ -205,7 +205,7 @@ def leastsq(model, xdata, ydata, p0, sigma=None,
if sigma is not None:
sigma = numpy.asarray_chkfinite(sigma)
else:
- sigma = numpy.ones((ydata.shape), dtype=numpy.float)
+ sigma = numpy.ones((ydata.shape), dtype=numpy.float64)
ydata.shape = -1
sigma.shape = -1
else:
@@ -215,7 +215,7 @@ def leastsq(model, xdata, ydata, p0, sigma=None,
if sigma is not None:
sigma = numpy.asarray(sigma)
else:
- sigma = numpy.ones((ydata.shape), dtype=numpy.float)
+ sigma = numpy.ones((ydata.shape), dtype=numpy.float64)
sigma.shape = -1
# get rid of NaN in input data
idx = numpy.isfinite(ydata)
@@ -289,9 +289,9 @@ def leastsq(model, xdata, ydata, p0, sigma=None,
nparameters = len(parameters)
if epsfcn is None:
- epsfcn = numpy.finfo(numpy.float).eps
+ epsfcn = numpy.finfo(numpy.float64).eps
else:
- epsfcn = max(epsfcn, numpy.finfo(numpy.float).eps)
+ epsfcn = max(epsfcn, numpy.finfo(numpy.float64).eps)
# check if constraints have been passed as text
constrained_fit = False
@@ -383,7 +383,7 @@ def leastsq(model, xdata, ydata, p0, sigma=None,
newpar = fitparam + deltapar [0]
else:
newpar = parameters.__copy__()
- pwork = numpy.zeros(deltapar.shape, numpy.float)
+ pwork = numpy.zeros(deltapar.shape, numpy.float64)
for i in range(n_free):
if constraints is None:
pwork [0] [i] = fitparam [i] + deltapar [0] [i]
@@ -567,7 +567,7 @@ def chisq_alpha_beta(model, parameters, x, y, weight, constraints=None,
calculating the numerical derivatives (for model_deriv=None).
Normally the actual step length will be sqrt(epsfcn)*x
Original Gefit module was using epsfcn 1.0e-10 while default value
- is now numpy.finfo(numpy.float).eps as in scipy
+ is now numpy.finfo(numpy.float64).eps as in scipy
:type epsfcn: *optional*, float
:param left_derivative:
@@ -595,9 +595,9 @@ def chisq_alpha_beta(model, parameters, x, y, weight, constraints=None,
Sequence with the indices of the original parameters considered in the calculations.
"""
if epsfcn is None:
- epsfcn = numpy.finfo(numpy.float).eps
+ epsfcn = numpy.finfo(numpy.float64).eps
else:
- epsfcn = max(epsfcn, numpy.finfo(numpy.float).eps)
+ epsfcn = max(epsfcn, numpy.finfo(numpy.float64).eps)
#nr0, nc = data.shape
n_param = len(parameters)
if constraints is None:
@@ -644,9 +644,9 @@ def chisq_alpha_beta(model, parameters, x, y, weight, constraints=None,
print("Initial value = %f" % parameters[i])
print("Limits are %f and %f" % (pmin, pmax))
print("Parameter will be kept at its starting value")
- fitparam = numpy.array(fitparam, numpy.float)
- alpha = numpy.zeros((n_free, n_free), numpy.float)
- beta = numpy.zeros((1, n_free), numpy.float)
+ fitparam = numpy.array(fitparam, numpy.float64)
+ alpha = numpy.zeros((n_free, n_free), numpy.float64)
+ beta = numpy.zeros((1, n_free), numpy.float64)
#delta = (fitparam + numpy.equal(fitparam, 0.0)) * 0.00001
delta = (fitparam + numpy.equal(fitparam, 0.0)) * numpy.sqrt(epsfcn)
nr = y.size
@@ -803,7 +803,7 @@ def _get_sigma_parameters(parameters, sigma0, constraints):
if constraints is None:
return sigma0
n_free = 0
- sigma_par = numpy.zeros(parameters.shape, numpy.float)
+ sigma_par = numpy.zeros(parameters.shape, numpy.float64)
for i in range(len(constraints)):
if constraints[i][0] == CFREE:
sigma_par [i] = sigma0[n_free]
@@ -860,7 +860,7 @@ def main(argv=None):
return numpy.exp(x * numpy.less(abs(x), 250)) -\
1.0 * numpy.greater_equal(abs(x), 250)
- xx = numpy.arange(npoints, dtype=numpy.float)
+ xx = numpy.arange(npoints, dtype=numpy.float64)
yy = gauss(xx, *[10.5, 2, 1000.0, 20., 15])
sy = numpy.sqrt(abs(yy))
parameters = [0.0, 1.0, 900.0, 25., 10]
diff --git a/silx/math/fit/test/test_fit.py b/silx/math/fit/test/test_fit.py
index 372d6cb..3fdf394 100644
--- a/silx/math/fit/test/test_fit.py
+++ b/silx/math/fit/test/test_fit.py
@@ -1,6 +1,6 @@
# coding: utf-8
# /*##########################################################################
-# Copyright (C) 2016 European Synchrotron Radiation Facility
+# Copyright (C) 2016-2020 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -57,7 +57,7 @@ class Test_leastsq(unittest.TestCase):
self.my_exp = myexp
def gauss(x, *params):
- params = numpy.array(params, copy=False, dtype=numpy.float)
+ params = numpy.array(params, copy=False, dtype=numpy.float64)
result = params[0] + params[1] * x
for i in range(2, len(params), 3):
p = params[i:(i+3)]
@@ -69,7 +69,7 @@ class Test_leastsq(unittest.TestCase):
def gauss_derivative(x, params, idx):
if idx == 0:
- return numpy.ones(len(x), numpy.float)
+ return numpy.ones(len(x), numpy.float64)
if idx == 1:
return x
gaussian_peak = (idx - 2) // 3
@@ -140,7 +140,7 @@ class Test_leastsq(unittest.TestCase):
parameters_actual = [10.5, 2, 10000.0, 20., 150, 5000, 900., 300]
x = numpy.arange(10000.)
y = self.gauss(x, *parameters_actual)
- delta = numpy.sqrt(numpy.finfo(numpy.float).eps)
+ delta = numpy.sqrt(numpy.finfo(numpy.float64).eps)
for i in range(len(parameters_actual)):
p = parameters_actual * 1
if p[i] == 0:
diff --git a/silx/math/fit/test/test_fitmanager.py b/silx/math/fit/test/test_fitmanager.py
index 7a643cb..acac242 100644
--- a/silx/math/fit/test/test_fitmanager.py
+++ b/silx/math/fit/test/test_fitmanager.py
@@ -125,7 +125,7 @@ class TestFitmanager(ParametricTestCase):
"""Test fit manager on synthetic data using a gaussian function
and a linear background"""
# Create synthetic data with a sum of gaussian functions
- x = numpy.arange(1000).astype(numpy.float)
+ x = numpy.arange(1000).astype(numpy.float64)
p = [1000, 100., 250,
255, 650., 45,
@@ -186,7 +186,7 @@ class TestFitmanager(ParametricTestCase):
"""Test FitManager using a custom fit function defined in an external
file and imported with FitManager.loadtheories"""
# Create synthetic data with a sum of gaussian functions
- x = numpy.arange(100).astype(numpy.float)
+ x = numpy.arange(100).astype(numpy.float64)
# a, b, c are the fit parameters
# d is a known scaling parameter that is set using configure()
@@ -233,7 +233,7 @@ class TestFitmanager(ParametricTestCase):
"""Test FitManager using a custom fit function defined in an external
file and imported with FitManager.loadtheories (legacy PyMca format)"""
# Create synthetic data with a sum of gaussian functions
- x = numpy.arange(100).astype(numpy.float)
+ x = numpy.arange(100).astype(numpy.float64)
# a, b, c are the fit parameters
# d is a known scaling parameter that is set using configure()
@@ -279,7 +279,7 @@ class TestFitmanager(ParametricTestCase):
"""Test FitManager using a custom fit function imported with
FitManager.addtheory"""
# Create synthetic data with a sum of gaussian functions
- x = numpy.arange(100).astype(numpy.float)
+ x = numpy.arange(100).astype(numpy.float64)
# a, b, c are the fit parameters
# d is a known scaling parameter that is set using configure()
@@ -369,7 +369,7 @@ class TestFitmanager(ParametricTestCase):
for theory_name, theory_fun in (('Step Down', sum_stepdown),
('Step Up', sum_stepup)):
# Create synthetic data with a sum of gaussian functions
- x = numpy.arange(1000).astype(numpy.float)
+ x = numpy.arange(1000).astype(numpy.float64)
# ('Height', 'Position', 'FWHM')
p = [1000, 439, 250]
@@ -407,7 +407,7 @@ def cubic(x, a, b, c, d):
class TestPolynomials(unittest.TestCase):
"""Test polynomial fit theories and fit background"""
def setUp(self):
- self.x = numpy.arange(100).astype(numpy.float)
+ self.x = numpy.arange(100).astype(numpy.float64)
def testQuadraticBg(self):
gaussian_params = [100, 45, 8]