Changes in / [a2ccd569:a407a40] in sasview
- Location:
- test
- Files:
-
- 76 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
test/sascalculator/test/utest_sas_gen.py
ref908db rb699768 7 7 import unittest 8 8 from sas.sascalc.calculator import sas_gen 9 from sas.models.SphereModel import SphereModel 9 10 10 11 import numpy … … 17 18 self.sldloader = sas_gen.SLDReader() 18 19 self.pdbloader = sas_gen.PDBReader() 19 self.omfloader = sas_gen.OMFReader() 20 self.omfloader = sas_gen.OMFReader() 21 self.comp = SphereModel() 20 22 21 23 def test_sldreader(self): … … 51 53 self.assertEqual(output.pos_z[0], 0.0) 52 54 55 """ 56 def test_slda_and_run(self): # Works when sld reader uses loadtxt 57 sld_data = self.sldloader.read("sphere697_r30.sld") 58 # Generic computation 59 model = sas_gen.GenSAS() 60 model.setParam('background', 0.0) 61 model.setParam('scale', 1.0) 62 model.setParam('Up_frac_in', 0.5) 63 model.setParam('Up_frac_out', 0.5) 64 model.setParam('Up_theta', 0.0) 65 x = numpy.array([0.01]) 66 y = numpy.array([0.01]) 67 model.set_sld_data(sld_data) 68 out_gen = model.runXY([x, y]) 69 # Analytic computation 70 analy_model = self.comp 71 analy_model.setParam('background', 0.0) 72 analy_model.setParam('scale', 1.0) 73 analy_model.setParam('radius', 30.0) 74 analy_model.setParam('sldSolv', 0.0) 75 analy_model.setParam('sldSph', 6.97e-06) 76 out_analy = analy_model.runXY([0.01, 0.01]) 77 # Comparison 78 self.assertAlmostEqual(out_gen[0], out_analy, 1) 79 """ 53 80 if __name__ == '__main__': 54 81 unittest.main() -
test/sasdataloader/test/utest_smearing.py
ref908db rfc18690 10 10 #from DataLoader.qsmearing import SlitSmearer, QSmearer, smear_selection 11 11 from sas.sascalc.data_util.qsmearing import SlitSmearer, QSmearer, smear_selection 12 from sas.models.SphereModel import SphereModel 12 13 import os.path 13 14 from time import time … … 91 92 for i in range(len(input)): 92 93 self.assertAlmostEqual(answer[i], output[i], 2) 94 95 class smear_test_1Dpinhole(unittest.TestCase): 96 97 def setUp(self): 98 # NIST sample data 99 self.data = Loader().load("CMSphere5.txt") 100 # NIST smeared sphere w/ param values below 101 self.answer = Loader().load("CMSphere5smearsphere.txt") 102 # call spheremodel 103 self.model = SphereModel() 104 # setparams consistent with Igor default 105 self.model.setParam('scale', 1.0) 106 self.model.setParam('background', 0.01) 107 self.model.setParam('radius', 60.0) 108 self.model.setParam('sldSolv', 6.3e-06) 109 self.model.setParam('sldSph', 1.0e-06) 110 111 def test_q(self): 112 """ 113 Compare Pinhole resolution smearing with NIST 114 """ 115 # x values 116 input = numpy.zeros(len(self.data.x)) 117 # set time 118 st1 = time() 119 # cal I w/o smear 120 input = self.model.evalDistribution(self.data.x) 121 # Cal_smear (first call) 122 for i in range(1000): 123 s = QSmearer(self.data, self.model) 124 # stop and record time taken 125 first_call_time = time()-st1 126 # set new time 127 st = time() 128 # cal I w/o smear (this is not neccessary to call but just to be fare 129 input = self.model.evalDistribution(self.data.x) 130 # smear cal (after first call done above) 131 for i in range(1000): 132 output = s(input) 133 134 # record time taken 135 last_call_time = time()-st 136 # compare the ratio of ((NIST_answer-SsanView_answer)/NIST_answer) 137 # If the ratio less than 1%, pass the test 138 for i in range(len(self.data.x)): 139 ratio = math.fabs((self.answer.y[i]-output[i])/self.answer.y[i]) 140 if ratio > 0.006: 141 ratio = 0.006 142 self.assertEqual(math.fabs((self.answer.y[i]-output[i])/ \ 143 self.answer.y[i]), ratio) 144 # print 145 print "\n NIST_time = 10sec:" 146 print "Cal_time(1000 times of first_calls; ) = ", first_call_time 147 print "Cal_time(1000 times of calls) = ", last_call_time 93 148 94 149 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.