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