- Timestamp:
- Apr 4, 2014 12:44:59 PM (11 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- d44648e
- Parents:
- e6d9703
- Location:
- test
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
test/park_integration/test/test_fit_cylinder.py
r5777106 r6c00702 4 4 """ 5 5 import unittest 6 import math 6 7 7 8 from sans.fit.AbstractFitEngine import Model 8 import math9 9 from sans.fit.Fitting import Fit 10 from DataLoader.loader import Loader10 from sans.dataloader.loader import Loader 11 11 12 12 class TestSingleFit(unittest.TestCase): … … 21 21 self.model.setParam("radius",18) 22 22 self.model.setParam("length", 397) 23 self.model.setParam("contrast",3e-006 ) 23 self.model.setParam("sldCyl",3e-006 ) 24 self.model.setParam("sldSolv",0.0 ) 24 25 self.model.setParam("background", 0.0) 25 26 #select parameters to fit … … 31 32 fitter.set_data(self.data,1) 32 33 fitter.set_model(self.model,1,self.pars1) 33 fitter.select_problem_for_fit( Uid=1,value=1)34 fitter.select_problem_for_fit(id=1,value=1) 34 35 return fitter.fit() 35 36 … … 38 39 """ Simple cylinder model fit (scipy) """ 39 40 40 result1 = self._fit("scipy")41 result1, = self._fit("scipy") 41 42 42 43 self.assert_(result1) … … 52 53 def test_park(self): 53 54 """ Simple cylinder model fit (park) """ 54 result1 = self._fit("park") 55 #raise NotImplementedError() 56 result1, = self._fit("park") 55 57 56 58 self.assert_(result1) … … 81 83 self.model1.set(radius=18) 82 84 self.model1.set(length=396) 83 self.model1.set( contrast=3e-006)85 self.model1.set(sldCyl=3e-006, sldSolv=0.0) 84 86 self.model1.set(background=0.0) 85 87 … … 90 92 self.model2.set(radius=37) 91 93 self.model2.set(length='C1.length') 92 self.model2.set( contrast=3e-006)94 self.model2.set(sldCyl=3e-006, sldSolv=0.0) 93 95 self.model2.set(background=0.0) 94 96 … … 101 103 fitter.set_data(self.data2,2) 102 104 fitter.set_model(self.model2, 2, ['radius','scale']) 103 fitter.select_problem_for_fit( Uid=1,value=1)104 fitter.select_problem_for_fit( Uid=2,value=1)105 fitter.select_problem_for_fit(id=1,value=1) 106 fitter.select_problem_for_fit(id=2,value=1) 105 107 return fitter.fit() 106 108 … … 108 110 def test_park2(self): 109 111 """ Simultaneous cylinder model fit (park) """ 110 111 result1 = self._fit('park')112 #raise NotImplementedError() 113 result1,= self._fit('park') 112 114 self.assert_(result1) 113 115 self.assertTrue(len(result1.pvec)>=0 ) -
test/park_integration/test/test_fit_line.py
r5777106 r6c00702 6 6 7 7 from sans.fit.AbstractFitEngine import Model 8 from sans.dataloader.loader import Loader 9 from sans.fit.Fitting import Fit 10 from sans.models.LineModel import LineModel 11 from sans.models.Constant import Constant 12 8 13 import math 9 14 class testFitModule(unittest.TestCase): … … 13 18 """ Fit 1 data (testdata_line.txt)and 1 model(lineModel) """ 14 19 #load data 15 from DataLoader.loader import Loader16 20 data = Loader().load("testdata_line.txt") 17 21 #Importing the Fit module 18 from sans.fit.Fitting import Fit19 22 fitter = Fit('scipy') 20 23 # Receives the type of model for the fitting 21 from sans.models.LineModel import LineModel22 24 model1 = LineModel() 23 25 model1.name = "M1" 24 model = Model(model1 )26 model = Model(model1,data) 25 27 #fit with scipy test 26 28 … … 28 30 fitter.set_data(data,1) 29 31 try:fitter.set_model(model,1,pars1) 30 except ValueError,msg: 31 print "ValueError was raised: "+str(msg) 32 #assert str(msg)=="wrong paramter %s used to set model %s. Choose\ 33 # parameter name within %s"%('param1', model.model.name,str(model.model.getParamList())) 34 else: raise AssertError,"No error raised for scipy fitting with wrong parameters name to fit" 35 pars1= ['A','B'] 36 fitter.set_model(model,1,pars1) 37 fitter.select_problem_for_fit(id=1,value=1) 38 result1 = fitter.fit() 39 self.assert_(result1) 40 41 self.assertTrue( math.fabs(result1.pvec[0]-4)/3 <= result1.stderr[0] ) 42 self.assertTrue( math.fabs(result1.pvec[1]-2.5)/3 <= result1.stderr[1]) 43 self.assertTrue( result1.fitness/len(data.x) < 2 ) 44 32 except ValueError,exc: 33 #print "ValueError was correctly raised: "+str(msg) 34 assert str(exc).startswith('wrong parameter') 35 else: raise AssertionError("No error raised for scipy fitting with wrong parameters name to fit") 36 pars1= ['A','B'] 37 fitter.set_model(model,1,pars1) 38 fitter.select_problem_for_fit(id=1,value=1) 39 result, = fitter.fit() 40 41 self.assertTrue( math.fabs(result.pvec[0]-4)/3 <= result.stderr[0] ) 42 self.assertTrue( math.fabs(result.pvec[1]-2.5)/3 <= result.stderr[1]) 43 self.assertTrue( result.fitness/len(data.x) < 2 ) 44 45 45 #fit with park test 46 46 fitter = Fit('park') … … 66 66 """ fit 2 data and 2 model with no constrainst""" 67 67 #load data 68 from DataLoader.loader import Loader69 68 l = Loader() 70 69 data1=l.load("testdata_line.txt") … … 73 72 74 73 #Importing the Fit module 75 from sans.fit.Fitting import Fit76 74 fitter = Fit('scipy') 77 75 # Receives the type of model for the fitting 78 from sans.models.LineModel import LineModel79 76 model11 = LineModel() 80 77 model11.name= "M1" … … 93 90 fitter.select_problem_for_fit(id=2,value=0) 94 91 95 try: result1 = fitter.fit()92 try: result1, = fitter.fit() 96 93 except RuntimeError,msg: 97 94 assert str(msg)=="No Assembly scheduled for Scipy fitting." … … 99 96 fitter.select_problem_for_fit(id=1,value=1) 100 97 fitter.select_problem_for_fit(id=2,value=1) 101 try: result1 = fitter.fit()98 try: result1, = fitter.fit() 102 99 except RuntimeError,msg: 103 100 assert str(msg)=="Scipy can't fit more than a single fit problem at a time." … … 123 120 """ fit 2 data and 2 model with 1 constrainst""" 124 121 #load data 125 from DataLoader.loader import Loader126 122 l = Loader() 127 123 data1= l.load("testdata_line.txt") … … 129 125 130 126 # Receives the type of model for the fitting 131 from sans.models.LineModel import LineModel132 127 model11 = LineModel() 133 128 model11.name= "line" … … 135 130 model11.setParam("B",1.0) 136 131 137 from sans.models.Constant import Constant138 132 model22 = Constant() 139 133 model22.name= "cst" … … 151 145 152 146 #Importing the Fit module 153 from sans.fit.Fitting import Fit154 147 fitter = Fit('park') 155 148 fitter.set_data(data1,1) … … 170 163 """ fit 2 data concatenates with limited range of x and one model """ 171 164 #load data 172 from DataLoader.loader import Loader173 165 l = Loader() 174 166 data1 = l.load("testdata_line.txt") … … 177 169 178 170 # Receives the type of model for the fitting 179 from sans.models.LineModel import LineModel180 171 model1 = LineModel() 181 172 model1.name= "M1" … … 187 178 pars1= ['A','B'] 188 179 #Importing the Fit module 189 from sans.fit.Fitting import Fit190 180 fitter = Fit('scipy') 191 181 fitter.set_data(data1,1,qmin=0, qmax=7) … … 194 184 fitter.select_problem_for_fit(id=1,value=1) 195 185 196 result1 = fitter.fit()186 result1, = fitter.fit() 197 187 self.assert_(result1) 198 188 -
test/park_integration/test/test_fit_smeared.py
r5777106 r6c00702 4 4 """ 5 5 import unittest 6 from sans.fit.AbstractFitEngine import Model7 6 import math 8 7 import numpy 8 from sans.fit.AbstractFitEngine import Model 9 9 from sans.fit.Fitting import Fit 10 from DataLoader.loader import Loader 10 from sans.dataloader.loader import Loader 11 from sans.models.qsmearing import smear_selection 12 from sans.models.CylinderModel import CylinderModel 13 from sans.models.SphereModel import SphereModel 11 14 12 15 class testFitModule(unittest.TestCase): … … 24 27 25 28 # Receives the type of model for the fitting 26 from sans.models.CylinderModel import CylinderModel27 29 model1 = CylinderModel() 28 model1.setParam('contrast', 1) 30 model1.setParam('sldCyl', 3.0e-6) 31 model1.setParam('sldSolv', 0.0) 29 32 model = Model(model1) 30 33 model.set(scale=1e-10) … … 33 36 34 37 # What the hell is this line for? 35 fitter.select_problem_for_fit( Uid=1,value=1)36 result1 = fitter.fit()38 fitter.select_problem_for_fit(id=1,value=1) 39 result1, = fitter.fit() 37 40 38 41 self.assert_(result1) … … 60 63 fitter = Fit('scipy') 61 64 # Receives the type of model for the fitting 62 from sans.models.CylinderModel import CylinderModel63 65 model1 = CylinderModel() 64 model1.setParam('contrast', 1) 65 66 model1.setParam('sldCyl', 3.0e-6) 67 model1.setParam('sldSolv', 0.0) 68 66 69 # Dispersion parameters 67 70 model1.dispersion['radius']['width'] = 0.001 … … 74 77 model.set(scale=1e-10) 75 78 fitter.set_model(model,1,pars1) 76 fitter.select_problem_for_fit( Uid=1,value=1)77 result1 = fitter.fit()79 fitter.select_problem_for_fit(id=1,value=1) 80 result1, = fitter.fit() 78 81 79 82 self.assert_(result1) … … 97 100 print "TEST DONE WITHOUT PROPER OUTPUT CHECK:" 98 101 print " ---> TEST NEEDS TO BE COMPLETED" 99 from sans.models.SphereModel import SphereModel100 102 data = Loader().load("latex_smeared.xml") 101 103 self.data_res = data[0] … … 109 111 110 112 def test_reso(self): 111 from DataLoader.qsmearing import smear_selection 112 113 113 114 # Let the data module find out what smearing the 114 115 # data needs … … 123 124 # data for a given fit. 124 125 fitter.set_data(self.data_res,1) 125 fitter._engine.fit ArrangeDict[1].dList[0].smearer = smear126 fitter._engine.fit_arrange_dict[1].data_list[0].smearer = smear 126 127 print "smear ",smear 127 128 # Model: maybe there's a better way to do this. … … 130 131 131 132 # Why do we have to do this...? 132 fitter.select_problem_for_fit( Uid=1,value=1)133 fitter.select_problem_for_fit(id=1,value=1) 133 134 134 135 # Perform the fit (might take a while) 135 result1 = fitter.fit()136 result1, = fitter.fit() 136 137 137 138 # Replace this with proper test once we know what the … … 141 142 142 143 def test_slit(self): 143 from DataLoader.qsmearing import smear_selection144 145 144 smear = smear_selection(self.data_slit) 146 145 self.assertEqual(smear.__class__.__name__, 'SlitSmearer') … … 153 152 # data for a given fit. 154 153 fitter.set_data(self.data_slit,1) 155 fitter._engine.fit ArrangeDict[1].dList[0].smearer = smear156 fitter._engine.fit ArrangeDict[1].dList[0].qmax = 0.003154 fitter._engine.fit_arrange_dict[1].data_list[0].smearer = smear 155 fitter._engine.fit_arrange_dict[1].data_list[0].qmax = 0.003 157 156 158 157 # Model 159 158 fitter.set_model(Model(self.sphere),1, ['radius','scale']) 160 fitter.select_problem_for_fit( Uid=1,value=1)159 fitter.select_problem_for_fit(id=1,value=1) 161 160 162 result1 = fitter.fit()161 result1, = fitter.fit() 163 162 164 163 # Replace this with proper test once we know what the -
test/park_integration/test/test_park_scipy.py
r5777106 r6c00702 4 4 """ 5 5 import unittest 6 import math 6 7 7 8 from sans.guiframe.dataFitting import Data1D 8 9 from sans.fit.AbstractFitEngine import Model,FitData1D 9 import math10 10 from sans.fit.Fitting import Fit 11 from DataLoader.loader import Loader 11 from sans.dataloader.loader import Loader 12 from sans.models.MultiplicationModel import MultiplicationModel 13 from sans.models.CylinderModel import CylinderModel 14 from sans.models.SquareWellStructure import SquareWellStructure 12 15 13 16 class testFitModule(unittest.TestCase): … … 21 24 data = Data1D(x=out.x, y=out.y, dx=out.dx, dy=out.dy) 22 25 # Receives the type of model for the fitting 23 from sans.models.MultiplicationModel import MultiplicationModel24 from sans.models.CylinderModel import CylinderModel25 from sans.models.SquareWellStructure import SquareWellStructure26 26 model1 = MultiplicationModel(CylinderModel(),SquareWellStructure()) 27 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) 28 model1.setParam('sldCyl', 3e-006) 29 model1.setParam('sldSolv', 0.0) 30 model1.setParam('length', 420) 31 model1.setParam('radius', 40) 32 model1.setParam('scale_factor', 2) 32 33 model1.setParam('volfraction', 0.04) 33 34 model1.setParam('welldepth', 1.5) … … 36 37 model = Model(model1) 37 38 38 pars1 =['length','radius','scale ']39 pars1 =['length','radius','scale_factor'] 39 40 fitter = Fit('scipy') 40 41 fitter.set_data(data,1) 41 42 fitter.set_model(model,1,pars1) 42 fitter.select_problem_for_fit( Uid=1,value=1)43 result1 = fitter.fit()44 43 fitter.select_problem_for_fit(id=1,value=1) 44 result1, = fitter.fit() 45 45 46 self.assert_(result1) 46 47 self.assertTrue(len(result1.pvec)>=0 ) 47 48 self.assertTrue(len(result1.stderr)>= 0) 48 49 50 print "results",list(zip(result1.pvec, result1.stderr)) 49 51 self.assertTrue( math.fabs(result1.pvec[0]-605)/3.0 <= result1.stderr[0] ) 50 52 self.assertTrue( math.fabs(result1.pvec[1]-20.0)/3.0 <= result1.stderr[1] ) -
test/pr_inversion/test/test_output.txt
r57986a1 r6c00702 3 3 #alpha=0.0007 4 4 #chi2=836.797 5 #elapsed=0.000 4689695 #elapsed=0.000999928 6 6 #qmin=None 7 7 #qmax=None -
test/run_one.py
rbbd97e5 r6c00702 12 12 #print "\n".join(sys.path) 13 13 test_path,test_file = splitpath(sys.argv[1]) 14 print "test file",sys.argv[1] 14 15 #print test_path, test_file 15 16 sys.argv = [sys.argv[0]] -
test/utest_sansview.py
rbbd97e5 r6c00702 26 26 # COMMAND_SEP = '&' 27 27 28 def run_tests( ):28 def run_tests(dirs=None, all=False): 29 29 test_root = os.path.abspath(os.path.dirname(__file__)) 30 30 run_one_py = os.path.join(test_root, 'run_one.py') … … 35 35 n_failures = 0 36 36 37 for d in os.listdir(test_root):37 for d in (dirs if dirs else os.listdir(test_root)): 38 38 39 39 # Check for modules to be skipped … … 76 76 passed += 1 77 77 print "Result for %s: SUCCESS" % module_name 78 78 79 79 print "\n----------------------------------------------" 80 print "Results by test modules:" 81 print " PASSED: %d" % passed 82 ratio = 100.0*failed/(failed+passed) 83 print " FAILED: %d (%.0f%%)" % (failed,ratio) 84 85 print "Results by tests:" 86 print " Tests run: %d" % n_tests 87 print " Tests failed: %d" % n_failures 88 print " Test errors: %d" % n_errors 80 if n_tests == 0: 81 print "No tests." 82 else: 83 print "Results by test modules:" 84 print " PASSED: %d" % passed 85 ratio = 100.0*failed/(failed+passed) 86 print " FAILED: %d (%.0f%%)" % (failed,ratio) 87 88 print "Results by tests:" 89 print " Tests run: %d" % n_tests 90 print " Tests failed: %d" % n_failures 91 print " Test errors: %d" % n_errors 89 92 print "----------------------------------------------" 90 93 … … 92 95 93 96 if __name__ == '__main__': 94 if run_tests()>0: 97 all = (len(sys.argv) > 1 and sys.argv[1] == '-all') 98 dirs = sys.argv[1:] if not all else sys.argv[2:] 99 if run_tests(dirs=dirs, all=all)>0: 95 100 sys.exit(1) 96 101
Note: See TracChangeset
for help on using the changeset viewer.