1 | """ |
---|
2 | Unit tests for fitting module |
---|
3 | """ |
---|
4 | import unittest |
---|
5 | from sans.guitools.plottables import Theory1D |
---|
6 | from sans.guitools.plottables import Data1D |
---|
7 | |
---|
8 | import math |
---|
9 | class testFitModule(unittest.TestCase): |
---|
10 | """ test fitting """ |
---|
11 | |
---|
12 | |
---|
13 | def testfit_11Data_1Model(self): |
---|
14 | """ test fitting for one data and one model park vs scipy""" |
---|
15 | #load data |
---|
16 | from sans.fit.Loader import Load |
---|
17 | load= Load() |
---|
18 | load.set_filename("cyl_testdata.txt") |
---|
19 | load.set_values() |
---|
20 | data1 = Data1D(x=[], y=[],dx=None, dy=None) |
---|
21 | load.load_data(data1) |
---|
22 | |
---|
23 | load.set_filename("testdata_line1.txt") |
---|
24 | load.set_values() |
---|
25 | data2 = Data1D(x=[], y=[],dx=None, dy=None) |
---|
26 | load.load_data(data2) |
---|
27 | |
---|
28 | #Importing the Fit module |
---|
29 | from sans.fit.Fitting import Fit |
---|
30 | fitter= Fit('park') |
---|
31 | |
---|
32 | # Receives the type of model for the fitting |
---|
33 | from sans.models.CylinderModel import CylinderModel |
---|
34 | model1 = CylinderModel() |
---|
35 | #model2 = CylinderModel() |
---|
36 | |
---|
37 | #Do the fit SCIPY |
---|
38 | fitter.set_data(data1,1) |
---|
39 | import math |
---|
40 | pars1={'background':0,'contrast':3*math.pow(10, -6),\ |
---|
41 | 'cyl_phi':1,'cyl_theta':1,'length':400,'radius':20,'scale':1} |
---|
42 | fitter.set_model(model1,"M1",1,pars1) |
---|
43 | |
---|
44 | #fitter.set_data(data2,2) |
---|
45 | #fitter.set_model(model1,"M1",2,pars1) |
---|
46 | |
---|
47 | chisqr1, out1, cov1=fitter.fit() |
---|
48 | print "park",chisqr1, out1, cov1 |
---|
49 | self.assert_(chisqr1) |
---|
50 | |
---|
51 | |
---|
52 | |
---|