source: sasview/park_integration/test/test_park_scipy.py @ 9f7a1c1

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 9f7a1c1 was 8a6d4af, checked in by Gervaise Alina <gervyh@…>, 15 years ago

change fitData1D for test_park_scipy

  • Property mode set to 100644
File size: 2.0 KB
Line 
1"""
2    Unit tests for fitting module
3    @author: G. Alina
4"""
5import unittest
6
7from sans.guiframe.dataFitting import Data1D
8from sans.fit.AbstractFitEngine import Model,FitData1D
9import math
10from sans.fit.Fitting import Fit
11from DataLoader.loader import Loader
12
13class testFitModule(unittest.TestCase):
14    """ test fitting """
15   
16       
17    def test_scipy(self):
18        """ Simple cylinder model fit (scipy)  """
19       
20        out=Loader().load("cyl_400_20.txt")
21        data = Data1D(x=out.x, y=out.y, dx=out.dx, dy=out.dy)
22        # Receives the type of model for the fitting
23        from sans.models.MultiplicationModel import MultiplicationModel
24        from sans.models.CylinderModel import CylinderModel
25        from sans.models.SquareWellStructure import SquareWellStructure
26        model1  =  MultiplicationModel(CylinderModel(),SquareWellStructure())
27        model1.setParam('background', 0.0)
28        model1.setParam('contrast', 3e-006)
29        model1.setParam('length', 600)
30        model1.setParam('radius', 20)
31        model1.setParam('scale', 10)
32        model1.setParam('volfraction', 0.04)
33        model1.setParam('welldepth', 1.5)
34        model1.setParam('wellwidth', 1.2)
35     
36        model = Model(model1)
37   
38        pars1 =['length','radius','scale']
39        fitter = Fit('scipy')
40        fitter.set_data(data,1)
41        fitter.set_model(model,1,pars1)
42        fitter.select_problem_for_fit(Uid=1,value=1)
43        result1 = fitter.fit()
44     
45        self.assert_(result1)
46        self.assertTrue(len(result1.pvec)>=0 )
47        self.assertTrue(len(result1.stderr)>= 0)
48       
49        self.assertTrue( math.fabs(result1.pvec[0]-605)/3.0 <= result1.stderr[0] )
50        self.assertTrue( math.fabs(result1.pvec[1]-20.0)/3.0  <= result1.stderr[1] )
51        self.assertTrue( math.fabs(result1.pvec[2]-1)/3.0 <= result1.stderr[2] )
52       
53        self.assertTrue( result1.fitness/len(data.x) < 1.0 )
54       
55       
56if __name__ == '__main__':
57    unittest.main() 
Note: See TracBrowser for help on using the repository browser.