- Timestamp:
- May 15, 2014 7:08:38 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:
- 4a0dc427
- Parents:
- 4e9f227 (diff), bb1b892 (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:
-
- 3 edited
- 5 moved
Legend:
- Unmodified
- Added
- Removed
-
test/sansdataloader/test/utest_cansas.py
r2e3b055 rac5b69d 5 5 warnings.simplefilter("ignore") 6 6 7 import unittest8 import numpy9 7 import sans.dataloader.readers.cansas_reader as cansas 10 8 from sans.dataloader.loader import Loader … … 12 10 from sans.dataloader.readers.xml_reader import XMLreader 13 11 from sans.dataloader.readers.cansas_reader import Reader 14 from sans.dataloader.readers.cansas_constants import cansasConstants12 from sans.dataloader.readers.cansas_constants import CansasConstants 15 13 16 14 import os … … 18 16 import urllib2 19 17 import StringIO 18 import pylint as pylint 19 import unittest 20 import numpy 20 21 21 22 from lxml import etree 22 23 from xml.dom import minidom 23 24 24 CANSAS_FORMAT = cansasConstants.CANSAS_FORMAT25 CANSAS_NS = cansasConstants.CANSAS_NS25 CANSAS_FORMAT = CansasConstants.CANSAS_FORMAT 26 CANSAS_NS = CansasConstants.CANSAS_NS 26 27 27 28 class cansas_reader(unittest.TestCase): … … 72 73 def test_real_xml(self): 73 74 reader = XMLreader(self.xml_valid, self.schema_1_0) 74 valid = reader.validate XML()75 valid = reader.validate_xml() 75 76 if valid: 76 77 self.assertTrue(valid) … … 101 102 filename = "isis_1_1_write_test.xml" 102 103 xmlreader = XMLreader(self.isis_1_1, self.schema_1_1) 103 valid = xmlreader.validate XML()104 xmlreader.set ProcessingInstructions()104 valid = xmlreader.validate_xml() 105 xmlreader.set_processing_instructions() 105 106 self.assertTrue(valid) 106 107 fo = open(self.isis_1_1) … … 126 127 def test_double_trans_spectra(self): 127 128 xmlreader = XMLreader(self.isis_1_1_doubletrans, self.schema_1_1) 128 self.assertTrue(xmlreader.validate XML())129 self.assertTrue(xmlreader.validate_xml()) 129 130 reader = Loader() 130 131 data = reader.load(self.isis_1_1_doubletrans) … … 146 147 valid = [] 147 148 reader1 = XMLreader(self.xml_valid, self.schema_1_0) 148 self.assertTrue(reader1.validate XML())149 self.assertTrue(reader1.validate_xml()) 149 150 reader2 = XMLreader(self.xml_invalid, self.schema_1_0) 150 self.assertFalse(reader2.validate XML())151 self.assertFalse(reader2.validate_xml()) 151 152 reader3 = XMLreader(self.xml_valid, self.schema_1_1) 152 self.assertFalse(reader3.validate XML())153 self.assertFalse(reader3.validate_xml()) 153 154 reader4 = XMLreader(self.xml_invalid, self.schema_1_1) 154 self.assertFalse(reader4.validate XML())155 self.assertFalse(reader4.validate_xml()) 155 156 reader5 = XMLreader(self.isis_1_0, self.schema_1_0) 156 self.assertTrue(reader5.validate XML())157 self.assertTrue(reader5.validate_xml()) 157 158 reader6 = XMLreader(self.isis_1_1, self.schema_1_1) 158 self.assertTrue(reader6.validate XML())159 self.assertTrue(reader6.validate_xml()) 159 160 reader7 = XMLreader(self.isis_1_1, self.schema_1_0) 160 self.assertFalse(reader7.validate XML())161 self.assertFalse(reader7.validate_xml()) 161 162 162 163 163 164 def test_old_cansas_files(self): 164 165 reader1 = XMLreader(self.cansas1d, self.schema_1_0) 165 self.assertTrue(reader1.validate XML())166 self.assertTrue(reader1.validate_xml()) 166 167 file_loader = Loader() 167 168 file1 = file_loader.load(self.cansas1d) 168 169 reader2 = XMLreader(self.cansas1d_units, self.schema_1_0) 169 self.assertTrue(reader2.validate XML())170 self.assertTrue(reader2.validate_xml()) 170 171 reader3 = XMLreader(self.cansas1d_badunits, self.schema_1_0) 171 self.assertTrue(reader3.validate XML())172 self.assertTrue(reader3.validate_xml()) 172 173 reader4 = XMLreader(self.cansas1d_slit, self.schema_1_0) 173 self.assertTrue(reader4.validate XML())174 self.assertTrue(reader4.validate_xml()) 174 175 175 176 … … 177 178 filename = "isis_1_0_write_test.xml" 178 179 xmlreader = XMLreader(self.isis_1_0, self.schema_1_0) 179 valid = xmlreader.validate XML()180 valid = xmlreader.validate_xml() 180 181 self.assertTrue(valid) 181 182 reader_generic = Loader() … … 191 192 written_data = return_data[0] 192 193 xmlwrite = XMLreader(filename, self.schema_1_0) 193 valid = xmlreader.validate XML()194 valid = xmlreader.validate_xml() 194 195 self.assertTrue(valid) 195 196 self._check_data(written_data) … … 198 199 def test_processing_instructions(self): 199 200 reader = XMLreader(self.isis_1_1, self.schema_1_1) 200 valid = reader.validate XML()201 valid = reader.validate_xml() 201 202 if valid: 202 203 ## find the processing instructions and make into a dictionary 203 dic = self.get ProcessingInstructions(reader)204 dic = self.get_processing_instructions(reader) 204 205 self.assertTrue(dic == {'xml-stylesheet': 'type="text/xsl" href="cansas1d.xsl" '}) 205 206 … … 208 209 209 210 ## take the processing instructions and put them back in 210 xmldoc = self.set ProcessingInstructions(xmldoc, dic)211 xmldoc = self.set_processing_instructions(xmldoc, dic) 211 212 xml_output = xmldoc.toprettyxml() 212 213 213 214 214 def set ProcessingInstructions(self, minidomObject, dic):215 xmlroot = minidom Object.firstChild215 def set_processing_instructions(self, minidom_object, dic): 216 xmlroot = minidom_object.firstChild 216 217 for item in dic: 217 pi = minidom Object.createProcessingInstruction(item, dic[item])218 minidom Object.insertBefore(pi, xmlroot)219 return minidom Object220 221 222 def get ProcessingInstructions(self, XMLreaderObject):218 pi = minidom_object.createProcessingInstruction(item, dic[item]) 219 minidom_object.insertBefore(pi, xmlroot) 220 return minidom_object 221 222 223 def get_processing_instructions(self, xml_reader_object): 223 224 dict = {} 224 pi = XMLreaderObject.xmlroot.getprevious()225 pi = xml_reader_object.xmlroot.getprevious() 225 226 i = 0 226 227 while pi is not None: -
test/park_integration/test/batch_fit.py
r5777106 re3efa6b3 1 2 3 import math4 import numpy5 1 import copy 6 2 import time … … 15 11 16 12 17 18 19 13 def classMapper(classInstance, classFunc, *args): 20 14 """ … … 28 22 29 23 30 31 class BatchScipyFit: 24 class BatchFit: 32 25 """ 33 26 test fit module … … 69 62 model.setParam('cyl_phi.npts', 3) 70 63 model.setParam('cyl_theta.nsigmas', 10) 71 """ for 2 data cyl_theta = 60.0 [deg] cyl_phi= 60.0 [deg]"""64 # for 2 data cyl_theta = 60.0 [deg] cyl_phi= 60.0 [deg] 72 65 fitter.set_model(model, i, self.param_to_fit, 73 66 self.list_of_constraints) … … 84 77 self.list_of_mapper.append(classMapper) 85 78 86 def reset_value(self ):79 def reset_value(self, engine='scipy'): 87 80 """ 88 81 Initialize inputs for the map function … … 93 86 self.list_of_constraints = [] 94 87 self.list_of_mapper = [] 95 engine ="scipy" 96 88 97 89 path = "testdata_line3.txt" 98 90 self._reset_helper(path=path, engine=engine, npts=NPTS) … … 113 105 114 106 115 def test_map_fit(self ):107 def test_map_fit(self, n=0): 116 108 """ 117 """ 118 results = map(classMapper,self.list_of_fitter, self.list_of_function) 119 print len(results) 120 for result in results: 121 print result.fitness, result.stderr, result.pvec 109 """ 110 if n > 0: 111 self._test_process_map_fit(n=n) 112 else: 113 results = map(classMapper,self.list_of_fitter, self.list_of_function) 114 print len(results) 115 for result in results: 116 print result.fitness, result.stderr, result.pvec 122 117 123 118 def test_process_map_fit(self, n=1): … … 144 139 """ 145 140 def setUp(self): 146 self.test = Batch ScipyFit(qmin=None, qmax=None)141 self.test = BatchFit(qmin=None, qmax=None) 147 142 148 143 149 def __test_fit1(self):144 def test_fit1(self): 150 145 """test fit with python built in map function---- full range of each data""" 151 146 self.test.test_map_fit() 152 147 153 def __test_fit2(self):148 def test_fit2(self): 154 149 """test fit with python built in map function---- common range for all data""" 155 150 self.test.set_range(qmin=0.013, qmax=0.05) 156 151 self.test.reset_value() 157 152 self.test.test_map_fit() 153 raise Exception("fail") 158 154 159 155 def test_fit3(self): … … 161 157 self.test.set_range(qmin=None, qmax=None) 162 158 self.test.reset_value() 163 self.test.test_ process_map_fit(n=2)159 self.test.test_map_fit(n=1) 164 160 165 161 def test_fit4(self): … … 167 163 self.test.set_range(qmin=-1, qmax=10) 168 164 self.test.reset_value() 169 self.test.test_ process_map_fit(n=1)165 self.test.test_map_fit(n=3) 170 166 171 167 -
test/park_integration/test/utest_fit_cylinder.py
rda5d8e8 r4e9f227 10 10 from sans.dataloader.loader import Loader 11 11 12 #@unittest.skip("") 12 13 class TestSingleFit(unittest.TestCase): 13 14 """ test single fitting """ … … 33 34 fitter.set_model(self.model,1,self.pars1) 34 35 fitter.select_problem_for_fit(id=1,value=1) 35 return fitter.fit() 36 36 result1, = fitter.fit() 37 37 38 def test_scipy(self):39 """ Simple cylinder model fit (scipy) """40 41 result1, = self._fit("scipy")42 43 38 self.assert_(result1) 44 39 self.assertTrue(len(result1.pvec)>0 or len(result1.pvec)==0 ) 45 40 self.assertTrue(len(result1.stderr)> 0 or len(result1.stderr)==0) 46 41 47 42 self.assertTrue( math.fabs(result1.pvec[0]-400.0)/3.0 < result1.stderr[0] ) 48 43 self.assertTrue( math.fabs(result1.pvec[1]-20.0)/3.0 < result1.stderr[1] ) 49 44 self.assertTrue( math.fabs(result1.pvec[2]-1.0)/3.0 < result1.stderr[2] ) 50 45 self.assertTrue( result1.fitness < 1.0 ) 51 52 46 47 48 def test_scipy(self): 49 """ Simple cylinder model fit (scipy) """ 50 self._fit("scipy") 51 52 53 53 def test_park(self): 54 54 """ Simple cylinder model fit (park) """ 55 #raise NotImplementedError() 56 result1, = self._fit("park") 57 58 self.assert_(result1) 59 self.assertTrue(len(result1.pvec)>0 or len(result1.pvec)==0 ) 60 self.assertTrue(len(result1.stderr)> 0 or len(result1.stderr)==0) 61 62 self.assertTrue( math.fabs(result1.pvec[0]-400.0)/3.0 < result1.stderr[0] ) 63 self.assertTrue( math.fabs(result1.pvec[1]-20.0)/3.0 < result1.stderr[1] ) 64 self.assertTrue( math.fabs(result1.pvec[2]-1.0)/3.0 < result1.stderr[2] ) 65 self.assertTrue( result1.fitness < 1.0 ) 66 67 55 self._fit("park") 56 57 def test_bumps(self): 58 """ Simple cylinder model fit (park) """ 59 self._fit("bumps") 60 61 68 62 69 63 class TestSimultaneousFit(unittest.TestCase): … … 82 76 self.model1.set(scale= 1.0) 83 77 self.model1.set(radius=18) 84 self.model1.set(length= 396)78 self.model1.set(length=200) 85 79 self.model1.set(sldCyl=3e-006, sldSolv=0.0) 86 80 self.model1.set(background=0.0) 87 81 88 82 cyl2 = CylinderModel() 89 83 cyl2.name = "C2" … … 91 85 self.model2.set(scale= 1.0) 92 86 self.model2.set(radius=37) 93 self.model2.set(length= 'C1.length')87 self.model2.set(length=300) 94 88 self.model2.set(sldCyl=3e-006, sldSolv=0.0) 95 89 self.model2.set(background=0.0) 96 97 def _fit(self, name="park"): 90 91 92 def test_constrained_bumps(self): 93 """ Simultaneous cylinder model fit (park) """ 94 self._run_fit(Fit('bumps')) 95 96 #@unittest.skip("") 97 def test_constrained_park(self): 98 """ Simultaneous cylinder model fit (park) """ 99 self._run_fit(Fit('park')) 100 101 def _run_fit(self, fitter): 102 result1, result2 = self._fit(fitter) 103 self.assert_(result1) 104 self.assertTrue(len(result1.pvec)>0) 105 self.assertTrue(len(result1.stderr)>0) 106 107 for n, v, dv in zip(result1.param_list, result1.pvec, result1.stderr): 108 print "%s M1.%s = %s +/- %s"%(fitter._engine.__class__.__name__,n,v,dv) 109 if n == "length": 110 self.assertTrue( math.fabs(v-400.0)/3.0 < dv ) 111 elif n=='radius': 112 self.assertTrue( math.fabs(v-20.0)/3.0 < dv ) 113 elif n=='scale': 114 self.assertTrue( math.fabs(v-1.0)/3.0 < dv ) 115 for n, v, dv in zip(result2.param_list, result2.pvec, result2.stderr): 116 print "%s M2.%s = %s +/- %s"%(fitter._engine.__class__.__name__,n,v,dv) 117 if n=='radius': 118 self.assertTrue( math.fabs(v-40.0)/3.0 < dv ) 119 elif n=='scale': 120 self.assertTrue( math.fabs(v-1.0)/3.0 < dv ) 121 122 def _fit(self, fitter): 98 123 """ return fit result """ 99 fitter = Fit(name)100 124 fitter.set_data(self.data1,1) 101 125 fitter.set_model(self.model1, 1, ['length','radius','scale']) 102 126 103 127 fitter.set_data(self.data2,2) 104 fitter.set_model(self.model2, 2, ['radius','scale']) 128 fitter.set_model(self.model2, 2, ['radius','scale'], 129 constraints=[("length","C1.length")]) 105 130 fitter.select_problem_for_fit(id=1,value=1) 106 131 fitter.select_problem_for_fit(id=2,value=1) 107 132 return fitter.fit() 108 109 110 def test_park2(self): 111 """ Simultaneous cylinder model fit (park) """ 112 raise NotImplementedError() 113 result1,= self._fit('park') 114 self.assert_(result1) 115 self.assertTrue(len(result1.pvec)>=0 ) 116 self.assertTrue(len(result1.stderr)>= 0) 117 118 for par in result1.parameters: 119 if par.name=='C1.length': 120 print par.name, par.value 121 self.assertTrue( math.fabs(par.value-400.0)/3.0 < par.stderr ) 122 elif par.name=='C1.radius': 123 print par.name, par.value 124 self.assertTrue( math.fabs(par.value-20.0)/3.0 < par.stderr ) 125 elif par.name=='C2.radius': 126 print par.name, par.value 127 self.assertTrue( math.fabs(par.value-40.0)/3.0 < par.stderr ) 128 elif par.name=='C1.scale': 129 print par.name, par.value 130 self.assertTrue( math.fabs(par.value-1.0)/3.0 < par.stderr ) 131 elif par.name=='C2.scale': 132 print par.name, par.value 133 self.assertTrue( math.fabs(par.value-1.0)/3.0 < par.stderr ) 134 133 135 134 136 135 if __name__ == '__main__': -
test/park_integration/test/utest_fit_line.py
rda5d8e8 re3efa6b3 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('parameter param1') 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-5 ) 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_bumps_lm(self): 92 self.fit_bumps('lm') 93 94 def test_scipy(self): 95 #print "fitting scipy" 96 self.fit_single('scipy') 97 98 def test_park(self): 99 #print "fitting park" 100 self.fit_single('park') 101 65 102 66 103 def test2(self): … … 93 130 fitter.select_problem_for_fit(id=2,value=0) 94 131 95 try: result1, = fitter.fit( )132 try: result1, = fitter.fit(handler=FitHandler()) 96 133 except RuntimeError,msg: 97 134 assert str(msg)=="No Assembly scheduled for Scipy fitting." … … 99 136 fitter.select_problem_for_fit(id=1,value=1) 100 137 fitter.select_problem_for_fit(id=2,value=1) 101 try: result1, = fitter.fit( )138 try: result1, = fitter.fit(handler=FitHandler()) 102 139 except RuntimeError,msg: 103 140 assert str(msg)=="Scipy can't fit more than a single fit problem at a time." 104 141 else: raise AssertionError,"No error raised for scipy fitting with more than 2 models" 105 142 106 143 #fit with park test 107 144 fitter = Fit('park') … … 112 149 fitter.select_problem_for_fit(id=1,value=1) 113 150 fitter.select_problem_for_fit(id=2,value=1) 114 R1,R2 = fitter.fit( )151 R1,R2 = fitter.fit(handler=FitHandler()) 115 152 116 153 self.assertTrue( math.fabs(R1.pvec[0]-4)/3 <= R1.stderr[0] ) … … 157 194 fitter.select_problem_for_fit(id=2,value=1) 158 195 159 R1,R2 = fitter.fit( )196 R1,R2 = fitter.fit(handler=FitHandler()) 160 197 self.assertTrue( math.fabs(R1.pvec[0]-4.0)/3. <= R1.stderr[0]) 161 198 self.assertTrue( math.fabs(R1.pvec[1]-2.5)/3. <= R1.stderr[1]) … … 188 225 fitter.select_problem_for_fit(id=1,value=1) 189 226 190 result1, = fitter.fit() 227 result1, = fitter.fit(handler=FitHandler()) 228 #print(result1) 191 229 self.assert_(result1) 192 230 … … 194 232 self.assertTrue( math.fabs(result1.pvec[1]-2.5)/3 <= result1.stderr[1]) 195 233 self.assertTrue( result1.fitness/len(data1.x) < 2 ) 196 234 197 235 #fit with park test 198 236 fitter = Fit('park') … … 201 239 fitter.set_data(data2,1,qmin=1,qmax=10) 202 240 fitter.select_problem_for_fit(id=1,value=1) 203 result2, = fitter.fit( )241 result2, = fitter.fit(handler=FitHandler()) 204 242 205 243 self.assert_(result2) … … 213 251 self.assertAlmostEquals( result1.stderr[1],result2.stderr[1] ) 214 252 self.assertTrue( result2.fitness/(len(data2.x)+len(data1.x)) < 2 ) 215 216 253 254 255 if __name__ == "__main__": 256 unittest.main() 217 257 218 -
test/park_integration/test/utest_fit_smeared.py
r6c00702 re3efa6b3 5 5 import unittest 6 6 import math 7 7 8 import numpy 8 9 from sans.fit.AbstractFitEngine import Model … … 21 22 out=Loader().load("cyl_400_20.txt") 22 23 # This data file has not error, add them 23 out.dy = out.y24 #out.dy = out.y 24 25 25 26 fitter = Fit('scipy') … … 28 29 # Receives the type of model for the fitting 29 30 model1 = CylinderModel() 30 model1.setParam('sldCyl', 3.0e-6) 31 model1.setParam('sldSolv', 0.0) 31 model1.setParam("scale", 1.0) 32 model1.setParam("radius",18) 33 model1.setParam("length", 397) 34 model1.setParam("sldCyl",3e-006 ) 35 model1.setParam("sldSolv",0.0 ) 36 model1.setParam("background", 0.0) 32 37 model = Model(model1) 33 model.set(scale=1e-10)34 38 pars1 =['length','radius','scale'] 35 39 fitter.set_model(model,1,pars1) … … 38 42 fitter.select_problem_for_fit(id=1,value=1) 39 43 result1, = fitter.fit() 40 44 #print "result1",result1 45 41 46 self.assert_(result1) 42 self.assertTrue(len(result1.pvec) >0 or len(result1.pvec)==0)43 self.assertTrue(len(result1.stderr) > 0 or len(result1.stderr)==0)47 self.assertTrue(len(result1.pvec) > 0) 48 self.assertTrue(len(result1.stderr) > 0) 44 49 45 50 self.assertTrue( math.fabs(result1.pvec[0]-400.0)/3.0 < result1.stderr[0] ) 46 51 self.assertTrue( math.fabs(result1.pvec[1]-20.0)/3.0 < result1.stderr[1] ) 47 self.assertTrue( math.fabs(result1.pvec[2]- 9.0e-12)/3.0 < result1.stderr[2] )52 self.assertTrue( math.fabs(result1.pvec[2]-1)/3.0 < result1.stderr[2] ) 48 53 self.assertTrue( result1.fitness < 1.0 ) 49 54 55 def test_park_dispersion(self): 56 """ 57 Cylinder fit with dispersion 58 """ 59 self._dispersion(fitter = Fit('park')) 60 61 def test_bumps_dispersion(self): 62 """ 63 Cylinder fit with dispersion 64 """ 65 alg = 'lm' 66 from bumps import fitters 67 fitters.FIT_DEFAULT = alg 68 #fitters.FIT_OPTIONS[alg].options.update(opts) 69 fitters.FIT_OPTIONS[alg].options.update(monitors=[]) 70 self._dispersion(fitter = Fit('bumps')) 71 50 72 def test_scipy_dispersion(self): 51 73 """ 52 74 Cylinder fit with dispersion 53 75 """ 76 self._dispersion(fitter = Fit('scipy')) 77 78 def _dispersion(self, fitter): 54 79 # Load data 55 80 # This data is for a cylinder with … … 60 85 out.dy[i] = math.sqrt(out.y[i]) 61 86 62 # Set up the fit63 fitter = Fit('scipy')64 87 # Receives the type of model for the fitting 65 88 model1 = CylinderModel() 66 model1.setParam('sldCyl', 3.0e-6) 67 model1.setParam('sldSolv', 0.0) 89 model1.setParam("scale", 10.0) 90 model1.setParam("radius",18) 91 model1.setParam("length", 397) 92 model1.setParam("sldCyl",3e-006 ) 93 model1.setParam("sldSolv",0.0 ) 94 model1.setParam("background", 0.0) 68 95 69 96 # Dispersion parameters 70 model1.dispersion['radius']['width'] = 0. 00171 model1.dispersion['radius']['npts'] = 50 72 97 model1.dispersion['radius']['width'] = 0.25 98 model1.dispersion['radius']['npts'] = 50 99 73 100 model = Model(model1) 74 101 75 102 pars1 =['length','radius','scale','radius.width'] 76 103 fitter.set_data(out,1) 77 model.set(scale=1e-10)78 104 fitter.set_model(model,1,pars1) 79 105 fitter.select_problem_for_fit(id=1,value=1) 80 result1, = fitter.fit() 106 #import time; T0 = time.time() 107 result1, = fitter.fit() 108 #print "time",time.time()-T0,fitter._engine.__class__.__name__ 81 109 82 110 self.assert_(result1) 83 self.assertTrue(len(result1.pvec)>0 or len(result1.pvec)==0 ) 84 self.assertTrue(len(result1.stderr)> 0 or len(result1.stderr)==0) 85 86 self.assertTrue( math.fabs(result1.pvec[0]-400.0)/3.0 < result1.stderr[0] ) 87 self.assertTrue( math.fabs(result1.pvec[1]-20.0)/3.0 < result1.stderr[1] ) 88 self.assertTrue( math.fabs(result1.pvec[2]-1.0e-10)/3.0 < result1.stderr[2] ) 89 self.assertTrue( math.fabs(result1.pvec[3]-5.0)/3.0 < result1.stderr[3] ) 111 self.assertTrue(len(result1.pvec)>0) 112 self.assertTrue(len(result1.stderr)>0) 113 114 #print [z for z in zip(result1.param_list,result1.pvec,result1.stderr)] 115 self.assertTrue( math.fabs(result1.pvec[0]-399.8)/3.0 < result1.stderr[0] ) 116 self.assertTrue( math.fabs(result1.pvec[1]-17.5)/3.0 < result1.stderr[1] ) 117 self.assertTrue( math.fabs(result1.pvec[2]-11.1)/3.0 < result1.stderr[2] ) 118 self.assertTrue( math.fabs(result1.pvec[3]-0.276)/3.0 < result1.stderr[3] ) 90 119 self.assertTrue( result1.fitness < 1.0 ) 91 120 … … 98 127 """ 99 128 def setUp(self): 100 print "TEST DONE WITHOUT PROPER OUTPUT CHECK:"101 print " ---> TEST NEEDS TO BE COMPLETED"102 129 data = Loader().load("latex_smeared.xml") 103 130 self.data_res = data[0] … … 105 132 106 133 self.sphere = SphereModel() 134 self.sphere.setParam('background', 0) 107 135 self.sphere.setParam('radius', 5000.0) 108 self.sphere.setParam('scale', 1.0e-13) 109 self.sphere.setParam('radius.npts', 30) 110 self.sphere.setParam('radius.width',500) 111 136 self.sphere.setParam('scale', 0.4) 137 self.sphere.setParam('sldSolv',0) 138 self.sphere.setParam('sldSph',1e-6) 139 #self.sphere.setParam('radius.npts', 30) 140 #self.sphere.setParam('radius.width',50) 141 112 142 def test_reso(self): 113 143 … … 125 155 fitter.set_data(self.data_res,1) 126 156 fitter._engine.fit_arrange_dict[1].data_list[0].smearer = smear 127 print "smear ",smear 157 128 158 # Model: maybe there's a better way to do this. 129 159 # Ideally we should have to create a new model from our sans model. 130 fitter.set_model(Model(self.sphere),1, ['radius','scale' ])160 fitter.set_model(Model(self.sphere),1, ['radius','scale', 'background']) 131 161 132 162 # Why do we have to do this...? 133 163 fitter.select_problem_for_fit(id=1,value=1) 134 164 135 165 # Perform the fit (might take a while) 136 166 result1, = fitter.fit() 137 167 138 # Replace this with proper test once we know what the 139 # result should be 140 print result1.pvec 141 print result1.stderr 142 168 #print "v",result1.pvec 169 #print "dv",result1.stderr 170 #print "chisq(v)",result1.fitness 171 172 self.assertTrue( math.fabs(result1.pvec[0]-5000) < 20 ) 173 self.assertTrue( math.fabs(result1.pvec[1]-0.48) < 0.02 ) 174 self.assertTrue( math.fabs(result1.pvec[2]-0.060) < 0.002 ) 175 176 143 177 def test_slit(self): 144 178 smear = smear_selection(self.data_slit) 145 179 self.assertEqual(smear.__class__.__name__, 'SlitSmearer') 146 180 147 # Fit148 181 fitter = Fit('scipy') 149 182 … … 161 194 result1, = fitter.fit() 162 195 163 # Replace this with proper test once we know what the164 # result should be165 print result1.pvec166 print result1.stderr167 168 169 196 #print "v",result1.pvec 197 #print "dv",result1.stderr 198 #print "chisq(v)",result1.fitness 199 200 self.assertTrue( math.fabs(result1.pvec[0]-2340) < 20 ) 201 self.assertTrue( math.fabs(result1.pvec[1]-0.010) < 0.002 ) 202 170 203 if __name__ == '__main__': 171 204 unittest.main() -
test/park_integration/test/utest_park_scipy.py
r6c00702 re544c84 48 48 self.assertTrue(len(result1.stderr)>= 0) 49 49 50 print "results",list(zip(result1.pvec, result1.stderr))51 self.assertTrue( math.fabs(result1.pvec[0]-6 05)/3.0 <= result1.stderr[0] )52 self.assertTrue( math.fabs(result1.pvec[1]-20. 0)/3.0 <= result1.stderr[1] )53 self.assertTrue( math.fabs(result1.pvec[2]- 1)/3.0 <= result1.stderr[2] )50 #print "results",list(zip(result1.pvec, result1.stderr)) 51 self.assertTrue( math.fabs(result1.pvec[0]-612)/3.0 <= result1.stderr[0] ) 52 self.assertTrue( math.fabs(result1.pvec[1]-20.3)/3.0 <= result1.stderr[1] ) 53 self.assertTrue( math.fabs(result1.pvec[2]-25)/3.0 <= result1.stderr[2] ) 54 54 55 55 self.assertTrue( result1.fitness/len(data.x) < 1.0 ) -
test/park_integration/test/utest_small_test.py
r5777106 r76f132a 5 5 import math 6 6 from sans.fit.Fitting import Fit 7 from DataLoader.loader import Loader7 from sans.dataloader.loader import Loader 8 8 9 9 class testFitModule(unittest.TestCase): … … 18 18 from sans.models.CylinderModel import CylinderModel 19 19 model = CylinderModel() 20 model.setParam('contrast', 1) 21 20 model.setParam('sldCyl', 1) 21 model.setParam('sldSolv', 0) 22 22 23 pars1 =['length','radius','scale'] 23 24 fitter.set_data(out,1) 24 25 model.setParam('scale', 1e-10) 25 26 fitter.set_model(model,1,pars1, constraints=()) 26 fitter.select_problem_for_fit(Uid=1,value=1) 27 result1 = fitter.fit() 28 27 fitter.select_problem_for_fit(id=1,value=1) 28 result1, = fitter.fit() 29 #print result1 30 #print result1.__dict__ 31 29 32 self.assert_(result1) 30 33 self.assertTrue(len(result1.pvec)>0 or len(result1.pvec)==0 ) -
test/run_one.py
r95fb3e8 r76f132a 1 1 #!/usr/bin/env python 2 2 3 import os 3 4 import sys … … 8 9 9 10 run_py = joinpath(dirname(dirname(abspath(__file__))), 'run.py') 10 #print run_py11 11 run = imp.load_source('sasview_run', run_py) 12 12 run.prepare() 13 13 #print "\n".join(sys.path) 14 test_path,test_file = splitpath( sys.argv[1])15 print " test file",sys.argv[1]14 test_path,test_file = splitpath(abspath(sys.argv[1])) 15 print "=== testing:",sys.argv[1] 16 16 #print test_path, test_file 17 17 sys.argv = [sys.argv[0]] … … 20 20 test = imp.load_source('tests',test_file) 21 21 unittest.main(test, testRunner=xmlrunner.XMLTestRunner(output='logs')) 22
Note: See TracChangeset
for help on using the changeset viewer.