source: sasview/park_integration/test/test_fit_cylinder.py @ 671d14e1

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 671d14e1 was ca6d914, checked in by Gervaise Alina <gervyh@…>, 16 years ago

some bugs fixed

  • Property mode set to 100644
File size: 1.9 KB
Line 
1"""
2    Unit tests for fitting module
3"""
4import unittest
5from sans.guitools.plottables import Theory1D
6from sans.guitools.plottables import Data1D
7from sans.fit.AbstractFitEngine import Data, Model
8import math
9class testFitModule(unittest.TestCase):
10    """ test fitting """
11    def test1(self):
12        """ Fit 1 data (cyl_testdata.txt)and 1 model(CylinderModel)  """
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        #Importing the Fit module
21        from sans.fit.Fitting import Fit
22        fitter = Fit('scipy')
23        # Receives the type of model for the fitting
24        from sans.models.CylinderModel import CylinderModel
25        model1  = CylinderModel()
26        model1.setParam('contrast',1)
27        data = Data(sans_data=data1 )
28        model = Model(model1)
29       
30        pars1 =['length','radius','scale']
31        fitter.set_data(data,1)
32        model.model.setParam('scale',10)
33        fitter.set_model(model,"M1",1,pars1)
34        result1 = fitter.fit()
35        print "test scipy result:",result1.stderr,result1.pvec,result1.fitness
36        self.assert_(result1)
37        self.assertTrue(len(result1.pvec)>0 or len(result1.pvec)==0 )
38        self.assertTrue(len(result1.stderr)> 0 or len(result1.stderr)==0)
39        self.assertAlmostEquals( result1.pvec[0],0 )
40        self.assertAlmostEquals( result1.pvec[1],3*math.pow(10,-6) )
41        self.assertAlmostEquals( result1.pvec[2] , 1 )
42        self.assertAlmostEquals( result1.pvec[3] , 1 )
43        self.assertAlmostEquals( result1.pvec[4] , 400 )
44        self.assertAlmostEquals( result1.pvec[5] , 20 )
45        self.assertAlmostEquals ( result1.pvec[6] , 1 )
46        self.assertTrue( result1.fitness/43 < 2 )
47       
48       
Note: See TracBrowser for help on using the repository browser.