- Timestamp:
- May 5, 2014 9:21:47 AM (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:
- 644ca73
- Parents:
- 6f87cc1 (diff), 0089be3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- test
- Files:
-
- 1 added
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
test/run_one.py
r6fe5100 r5bf0331 9 9 10 10 run_py = joinpath(dirname(dirname(abspath(__file__))), 'run.py') 11 #print run_py12 11 run = imp.load_source('sasview_run', run_py) 13 12 run.prepare() -
test/sansdataloader/test/utest_cansas.py
rea67541 r2e3b055 90 90 self.assertTrue(data.detector[1].distance == 4145.02) 91 91 self.assertTrue(data.process[0].name == "Mantid generated CanSAS1D XML") 92 self.assertTrue(data.meta_data["xmlpreprocess"] ["xml-stylesheet"]!= None)92 self.assertTrue(data.meta_data["xmlpreprocess"] != None) 93 93 94 94 … … 102 102 xmlreader = XMLreader(self.isis_1_1, self.schema_1_1) 103 103 valid = xmlreader.validateXML() 104 xmlreader.setProcessingInstructions() 104 105 self.assertTrue(valid) 106 fo = open(self.isis_1_1) 107 str = fo.read() 105 108 reader_generic = Loader() 106 109 dataloader = reader_generic.load(self.isis_1_1) … … 113 116 self._check_data_1_1(cansasreader[i]) 114 117 reader_generic.save(filename, dataloader[i], None) 115 reader2 = Reader() 116 return_data = reader2.read(filename) 117 data_new = return_data 118 fo = open(filename) 119 str = fo.read() 120 reader2 = Loader() 121 return_data = reader2.load(filename) 118 122 written_data = return_data[0] 119 123 self._check_data(written_data) 120 124 121 125 122 126 def test_double_trans_spectra(self): … … 169 173 self.assertTrue(reader4.validateXML()) 170 174 175 171 176 def test_save_cansas_v1_0(self): 172 177 filename = "isis_1_0_write_test.xml" … … 184 189 reader2 = Reader() 185 190 return_data = reader2.read(filename) 186 data_new = return_data187 191 written_data = return_data[0] 192 xmlwrite = XMLreader(filename, self.schema_1_0) 193 valid = xmlreader.validateXML() 194 self.assertTrue(valid) 188 195 self._check_data(written_data) 189 196 … … 230 237 return dict 231 238 239 232 240 if __name__ == '__main__': 233 241 unittest.main() -
test/park_integration/test/utest_fit_line.py
rda5d8e8 r95d58d3 4 4 """ 5 5 import unittest 6 7 from sans.fit.AbstractFitEngine import Model 6 import math 7 8 from sans.fit.AbstractFitEngine import Model, FitHandler 8 9 from sans.dataloader.loader import Loader 9 10 from sans.fit.Fitting import Fit … … 11 12 from sans.models.Constant import Constant 12 13 13 import math14 14 class testFitModule(unittest.TestCase): 15 15 """ test fitting """ 16 17 def test 1(self):18 """ Fit 1 data (testdata_line.txt)and 1 model(lineModel) """19 #load data 16 17 def test_bad_pars(self): 18 fitter = Fit('bumps') 19 20 20 data = Loader().load("testdata_line.txt") 21 21 data.name = data.filename 22 #Importing the Fit module 23 fitter = Fit('scipy') 22 fitter.set_data(data,1) 23 24 model1 = LineModel() 25 model1.name = "M1" 26 model = Model(model1, data) 27 pars1= ['param1','param2'] 28 try: 29 fitter.set_model(model,1,pars1) 30 except ValueError,exc: 31 #print "ValueError was correctly raised: "+str(msg) 32 assert str(exc).startswith('wrong parameter') 33 else: 34 raise AssertionError("No error raised for scipy fitting with wrong parameters name to fit") 35 36 def fit_single(self, fitter_name, isdream=False): 37 fitter = Fit(fitter_name) 38 39 data = Loader().load("testdata_line.txt") 40 data.name = data.filename 41 fitter.set_data(data,1) 42 24 43 # Receives the type of model for the fitting 25 44 model1 = LineModel() … … 27 46 model = Model(model1,data) 28 47 #fit with scipy test 29 30 pars1= ['param1','param2'] 31 fitter.set_data(data,1) 32 try:fitter.set_model(model,1,pars1) 33 except ValueError,exc: 34 #print "ValueError was correctly raised: "+str(msg) 35 assert str(exc).startswith('wrong parameter') 36 else: raise AssertionError("No error raised for scipy fitting with wrong parameters name to fit") 48 37 49 pars1= ['A','B'] 38 50 fitter.set_model(model,1,pars1) 39 51 fitter.select_problem_for_fit(id=1,value=1) 40 result1, = fitter.fit() 41 42 self.assertTrue( math.fabs(result1.pvec[0]-4)/3 <= result1.stderr[0] ) 43 self.assertTrue( math.fabs(result1.pvec[1]-2.5)/3 <= result1.stderr[1]) 44 self.assertTrue( result1.fitness/len(data.x) < 2 ) 45 46 #fit with park test 47 fitter = Fit('park') 48 fitter.set_data(data,1) 49 fitter.set_model(model,1,pars1) 50 fitter.select_problem_for_fit(id=1,value=1) 51 result2, = fitter.fit() 52 53 self.assert_(result2) 54 self.assertTrue( math.fabs(result2.pvec[0]-4)/3 <= result2.stderr[0] ) 55 self.assertTrue( math.fabs(result2.pvec[1]-2.5)/3 <= result2.stderr[1] ) 56 self.assertTrue( result2.fitness/len(data.x) < 2) 57 # compare fit result result for scipy and park 58 self.assertAlmostEquals( result1.pvec[0], result2.pvec[0] ) 59 self.assertAlmostEquals( result1.pvec[1],result2.pvec[1] ) 60 self.assertAlmostEquals( result1.stderr[0],result2.stderr[0] ) 61 self.assertAlmostEquals( result1.stderr[1],result2.stderr[1] ) 62 self.assertAlmostEquals( result1.fitness, 63 result2.fitness/len(data.x),1 ) 64 52 result1, = fitter.fit(handler=FitHandler()) 53 54 # The target values were generated from the following statements 55 p,s,fx = result1.pvec, result1.stderr, result1.fitness 56 #print "p0,p1,s0,s1,fx_ = %g, %g, %g, %g, %g"%(p[0],p[1],s[0],s[1],fx) 57 p0,p1,s0,s1,fx_ = 3.68353, 2.61004, 0.336186, 0.105244, 1.20189 58 59 if isdream: 60 # Dream is not a minimizer: just check that the fit is within 61 # uncertainty 62 self.assertTrue( abs(p[0]-p0) <= s0 ) 63 self.assertTrue( abs(p[1]-p1) <= s1 ) 64 else: 65 self.assertTrue( abs(p[0]-p0) <= 1e-5 ) 66 self.assertTrue( abs(p[1]-p1) <= 1e-5 ) 67 self.assertTrue( abs(fx-fx_) <= 1e-2 ) 68 69 def fit_bumps(self, alg, **opts): 70 #Importing the Fit module 71 from bumps import fitters 72 fitters.FIT_DEFAULT = alg 73 fitters.FIT_OPTIONS[alg].options.update(opts) 74 fitters.FIT_OPTIONS[alg].options.update(monitors=[]) 75 #print "fitting",alg,opts 76 #kprint "options",fitters.FIT_OPTIONS[alg].__dict__ 77 self.fit_single('bumps', isdream=(alg=='dream')) 78 79 def test_bumps_de(self): 80 self.fit_bumps('de') 81 82 def test_bumps_dream(self): 83 self.fit_bumps('dream', burn=500, steps=100) 84 85 def test_bumps_amoeba(self): 86 self.fit_bumps('amoeba') 87 88 def test_bumps_newton(self): 89 self.fit_bumps('newton') 90 91 def test_scipy(self): 92 #print "fitting scipy" 93 self.fit_single('scipy') 94 95 def test_park(self): 96 #print "fitting park" 97 self.fit_single('park') 98 65 99 66 100 def test2(self): … … 93 127 fitter.select_problem_for_fit(id=2,value=0) 94 128 95 try: result1, = fitter.fit( )129 try: result1, = fitter.fit(handler=FitHandler()) 96 130 except RuntimeError,msg: 97 131 assert str(msg)=="No Assembly scheduled for Scipy fitting." … … 99 133 fitter.select_problem_for_fit(id=1,value=1) 100 134 fitter.select_problem_for_fit(id=2,value=1) 101 try: result1, = fitter.fit( )135 try: result1, = fitter.fit(handler=FitHandler()) 102 136 except RuntimeError,msg: 103 137 assert str(msg)=="Scipy can't fit more than a single fit problem at a time." 104 138 else: raise AssertionError,"No error raised for scipy fitting with more than 2 models" 105 139 106 140 #fit with park test 107 141 fitter = Fit('park') … … 112 146 fitter.select_problem_for_fit(id=1,value=1) 113 147 fitter.select_problem_for_fit(id=2,value=1) 114 R1,R2 = fitter.fit( )148 R1,R2 = fitter.fit(handler=FitHandler()) 115 149 116 150 self.assertTrue( math.fabs(R1.pvec[0]-4)/3 <= R1.stderr[0] ) … … 157 191 fitter.select_problem_for_fit(id=2,value=1) 158 192 159 R1,R2 = fitter.fit( )193 R1,R2 = fitter.fit(handler=FitHandler()) 160 194 self.assertTrue( math.fabs(R1.pvec[0]-4.0)/3. <= R1.stderr[0]) 161 195 self.assertTrue( math.fabs(R1.pvec[1]-2.5)/3. <= R1.stderr[1]) … … 188 222 fitter.select_problem_for_fit(id=1,value=1) 189 223 190 result1, = fitter.fit() 224 result1, = fitter.fit(handler=FitHandler()) 225 #print(result1) 191 226 self.assert_(result1) 192 227 … … 194 229 self.assertTrue( math.fabs(result1.pvec[1]-2.5)/3 <= result1.stderr[1]) 195 230 self.assertTrue( result1.fitness/len(data1.x) < 2 ) 196 231 197 232 #fit with park test 198 233 fitter = Fit('park') … … 201 236 fitter.set_data(data2,1,qmin=1,qmax=10) 202 237 fitter.select_problem_for_fit(id=1,value=1) 203 result2, = fitter.fit( )238 result2, = fitter.fit(handler=FitHandler()) 204 239 205 240 self.assert_(result2) … … 213 248 self.assertAlmostEquals( result1.stderr[1],result2.stderr[1] ) 214 249 self.assertTrue( result2.fitness/(len(data2.x)+len(data1.x)) < 2 ) 215 216 250 251 252 if __name__ == "__main__": 253 unittest.main() 217 254 218
Note: See TracChangeset
for help on using the changeset viewer.