[48882d1] | 1 | """ |
---|
[d831626] | 2 | test Data, Model , fucntor classes of AbstractFittingModule |
---|
[48882d1] | 3 | """ |
---|
| 4 | import unittest |
---|
| 5 | from sans.guitools.plottables import Theory1D |
---|
| 6 | from sans.guitools.plottables import Data1D |
---|
| 7 | from sans.fit.AbstractFitEngine import Data, Model |
---|
| 8 | from sans.fit.AbstractFitEngine import sansAssembly |
---|
| 9 | import math |
---|
| 10 | class testFitModule(unittest.TestCase): |
---|
| 11 | """ test fitting """ |
---|
| 12 | |
---|
| 13 | def test_Data(self): |
---|
[d831626] | 14 | """ test Data""" |
---|
[48882d1] | 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 | data11 = Data1D(x=[], y=[],dx=None, dy=None) |
---|
| 21 | load.load_data(data11) |
---|
| 22 | |
---|
| 23 | #Importing the Fit module |
---|
| 24 | from sans.fit.Fitting import Fit |
---|
| 25 | fitter= Fit('scipy') |
---|
| 26 | |
---|
| 27 | # Receives the type of model for the fitting |
---|
| 28 | from sans.guitools.LineModel import LineModel |
---|
| 29 | model1 = LineModel() |
---|
| 30 | data1=Data(sans_data=data11) |
---|
| 31 | model =Model(model1) |
---|
| 32 | #Do the fit SCIPY0.007778 1.78E+14 13335629 |
---|
| 33 | v=[0.007778,0.023333,0.031111,0.038889,0.046667,0.054444] |
---|
| 34 | for i in range(len(v)): |
---|
| 35 | self.assertEquals(data1.x[i],v[i]) |
---|
| 36 | #fitter.set_data_assembly(data1,1) |
---|
| 37 | #fitter.set_model_assembly(model,"M1",1,['A','B']) |
---|
| 38 | def test_Model(self): |
---|
[d831626] | 39 | """ test Model""" |
---|
[48882d1] | 40 | #load data |
---|
| 41 | from sans.fit.Loader import Load |
---|
| 42 | load= Load() |
---|
| 43 | load.set_filename("cyl_testdata.txt") |
---|
| 44 | load.set_values() |
---|
| 45 | data11 = Data1D(x=[], y=[],dx=None, dy=None) |
---|
| 46 | load.load_data(data11) |
---|
| 47 | |
---|
| 48 | #Importing the Fit module |
---|
| 49 | from sans.fit.Fitting import Fit |
---|
| 50 | fitter= Fit('scipy') |
---|
| 51 | |
---|
| 52 | # Receives the type of model for the fitting |
---|
| 53 | from sans.models.CylinderModel import CylinderModel |
---|
| 54 | model1 = CylinderModel() |
---|
| 55 | data1=Data(sans_data=data11) |
---|
| 56 | model =Model(model1) |
---|
| 57 | for item in data1.x: |
---|
| 58 | self.assertEquals(model.eval(item),model.model.run(item)) |
---|
| 59 | p=[0.0, 3.0000000000000001e-006, 1.0, 1.0, 400.0, 20.0, 1.0] |
---|
| 60 | model.setParams(p) |
---|
| 61 | res=[] |
---|
| 62 | for i in range(len(data1.x)): |
---|
| 63 | res.append((data1.y[i]-model.eval(data1.x[i]))/data1.dy[i]) |
---|
| 64 | self.assertEquals(model.eval(data1.x[i]),model.model.run(data1.x[i])) |
---|
| 65 | print res |
---|
| 66 | def test_funtor(self): |
---|
| 67 | """ test functor""" |
---|
| 68 | #load data |
---|
| 69 | from sans.fit.Loader import Load |
---|
| 70 | load= Load() |
---|
| 71 | load.set_filename("cyl_testdata.txt") |
---|
| 72 | load.set_values() |
---|
| 73 | data11 = Data1D(x=[], y=[],dx=None, dy=None) |
---|
| 74 | load.load_data(data11) |
---|
| 75 | |
---|
| 76 | #Importing the Fit module |
---|
| 77 | from sans.fit.Fitting import Fit |
---|
| 78 | fitter= Fit('scipy') |
---|
| 79 | |
---|
| 80 | # Receives the type of model for the fitting |
---|
| 81 | from sans.models.CylinderModel import CylinderModel |
---|
| 82 | model1 = CylinderModel() |
---|
| 83 | data1=Data(sans_data=data11) |
---|
| 84 | model =Model(model1) |
---|
| 85 | functor= sansAssembly(model,data1) |
---|
| 86 | for item in data1.x: |
---|
| 87 | self.assertEquals(model.eval(item),model.model.run(item)) |
---|
| 88 | p=[0.0, 3.0000000000000001e-006, 1.0, 1.0, 400.0, 20.0, 1.0] |
---|
| 89 | model.setParams(p) |
---|
| 90 | res=[] |
---|
| 91 | for i in range(len(data1.x)): |
---|
| 92 | res.append((data1.y[i]-model.eval(data1.x[i]))/data1.dy[i]) |
---|
| 93 | self.assertEquals(model.eval(data1.x[i]),model.model.run(data1.x[i])) |
---|
| 94 | f=functor(p) |
---|
| 95 | |
---|
| 96 | for i in range(len(res)): |
---|
| 97 | self.assertEquals(res[i],f[i]) |
---|
| 98 | |
---|