Changeset d23528ee in sasview for DataLoader/test
- Timestamp:
- Nov 16, 2009 6:47:47 PM (15 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:
- edd166b
- Parents:
- 255306e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/test/utest_invariant.py
r4026380 rd23528ee 3 3 @author Gervaise Alina: unittest imcoplete so far 4 4 """ 5 6 7 5 import unittest 8 6 import numpy, math … … 12 10 13 11 14 class InvariantTest(unittest.TestCase): 12 class TestInvPolySphere(unittest.TestCase): 13 """ 14 Test unsmeared data for invariant computation 15 """ 16 def setUp(self): 17 #Data with no slit smear information 18 data= Loader().load("PolySpheres.txt") 19 self.I = InvariantCalculator( data= data) 20 21 22 def testWrongData(self): 23 """ test receiving Data1D not of type loader""" 24 #compute invariant with smear information 25 from danse.common.plottools.plottables import Data1D 26 data= Data1D(x=[1,2],y=[2,3] ) 27 try: 28 self.assertRaises(ValueError,InvariantCalculator(data)) 29 except ValueError, msg: 30 print "test pass "+ str(msg) 31 else: raise ValueError, "fail to raise exception when expected" 32 33 def testInvariant(self): 34 """ test the invariant value for data without smearing""" 35 self.assertAlmostEquals(self.I.q_star, 7.48959e-5,2) 36 37 def testVolume(self): 38 """ test volume fraction for polysphere""" 39 volume = self.I.get_volume_fraction(contrast=2.6e-6) 40 self.assert_(volume >= 0 and volume <=1) 41 self.assertAlmostEqual(volume ,0.01) 42 43 def testSurface(self): 44 """ test surface for polysphere """ 45 surface = self.I.get_surface(contrast=2.6e-6, porod_const=20) 46 self.assertAlmostEqual(surface,0.01) 47 48 49 class TestInvariantSmear(unittest.TestCase): 50 """ 51 Test smeared data for invariant computation 52 """ 53 def setUp(self): 54 # data with smear info 55 list = Loader().load("latex_smeared.xml") 56 self.data_q_smear = list[0] 57 self.I_q_smear = InvariantCalculator( data= self.data_q_smear) 58 59 self.data_slit_smear = list[1] 60 self.I_slit_smear = InvariantCalculator( data= self.data_slit_smear) 61 62 from sans.models.PowerLawModel import PowerLawModel 63 self.power_law = PowerLawModel() 64 from sans.models.GuinierModel import GuinierModel 65 self.guinier = GuinierModel() 66 67 68 def test_invariant_slit(self): 69 """ test the invariant value for data with slit smear""" 70 self.assertTrue(self.I_slit_smear.q_star>0) 71 self.assertAlmostEquals(self.I_slit_smear.q_star, 4.1539e-4) 72 73 def test_volume_slit_smear(self): 74 """ test volume fraction for data with slit smear""" 75 volume = self.I_slit_smear.get_volume_fraction(contrast=2.6e-6) 76 self.assert_(volume >= 0 and volume <=1) 77 self.assertAlmostEqual(volume ,0.01) 78 79 def test_invariant_slit_low_guinier(self): 80 """ test the invariant with slit smear for data extrapolated low q range using guinier""" 81 q_star_min = self.I_slit_smear.get_qstar_min( data= self.data_slit_smear, 82 model= self.guinier, npts=10) 83 self.assertAlmostEquals(q_star_min, 4.89783e-8) 84 self.assertAlmostEquals(self.I.q_star_min, q_star_min) 85 86 def test_invariant_slit_low_power(self): 87 """ test the invariant with slit smear for data extrapolated low q range using pow_law""" 88 q_star_min = self.I_slit_smear.get_qstar_min( data=self.data_slit_smear, 89 model= self.power_law, npts=10) 90 self.assertFalse(numpy.isfinite(q_star_min)) 91 self.assertEquals(self.I.q_star_min, q_star_min) 92 93 def test_invariant_slit_high_power(self): 94 """ test the invariant with slit smear for data extrapolated high q range using pow_law""" 95 q_star_max = self.I_slit_smear.get_qstar_max( data= self.data_slit_smear, 96 model= self.power_law, npts=10) 97 self.assertFalse(numpy.isfinite(q_star_max)) 98 self.assertEquals(self.I.q_star_max, q_star_max) 99 100 def testSurface(self): 101 """ test volume fraction for data with slit smear""" 102 surface = self.I_q_smear.get_surface(contrast=2.6e-6, porod_const=20) 103 self.assertAlmostEqual(surface,0.01) 104 105 def test_invariant_q(self): 106 """ test the invariant value for data with q smear""" 107 self.assertTrue(self.I_q_smear.q_star>0) 108 self.assertAlmostEquals(self.I_q_smear.q_star, 1.361677e-3) 109 110 def test_invariant_q_low_guinier(self): 111 """ test the invariant with q smear for data extrapolated low q range using guinier""" 112 q_star_min = self.I_slit_smear.get_qstar_min( data= self.data_q_smear, 113 model= self.guinier, npts=10) 114 self.assertAlmostEquals(q_star_min,6.76e-4) 115 self.assertAlmostEquals(self.I.q_star_min, q_star_min) 116 117 def test_invariant_q_low_power(self): 118 """ test the invariant with q smear for data extrapolated low q range using pow_law""" 119 q_star_min = self.I_slit_smear.get_qstar_min( data= self.data_q_smear, 120 model= self.power_law, npts=10) 121 self.assertFalse(numpy.isfinite(q_star_min)) 122 self.assertEquals(self.I.q_star_min, q_star_min) 123 124 def test_invariant_q_high_power(self): 125 """ test the invariant with q smear for data extrapolated high q range using pow_law""" 126 q_star_max = self.I_slit_smear.get_qstar_max( data= self.data_q_smear, 127 model= self.power_law, npts=10) 128 self.assertAlmostEquals(q_star_max,1.2e-4) 129 self.assertEquals(self.I.q_star_max, q_star_max) 130 131 def test_volume_q_smear(self): 132 """ test volume fraction for data with q smear""" 133 volume = self.I_slit_smear.get_volume_fraction(contrast=2.6e-6) 134 self.assert_(volume > 0 and volume <=1) 135 self.assertAlmostEqual(volume ,0.01) 136 137 def testSurface_q_smear(self): 138 """ test surface for data with q smear""" 139 surface = self.I_q_smear.get_surface(contrast=2.6e-6, porod_const=20) 140 self.assertAlmostEqual(surface,0.01) 141 142 143 class ExtrapolationTest(unittest.TestCase): 15 144 16 145 def setUp(self): 17 146 #Data with no slit smear information 18 data0 = Loader().load("PolySpheres.txt") 19 self.I0 = InvariantCalculator( data=data0) 147 self.data= Loader().load("PolySpheres.txt") 148 from sans.models.PowerLawModel import PowerLawModel 149 self.power_law = PowerLawModel() 150 from sans.models.GuinierModel import GuinierModel 151 self.guinier = GuinierModel() 152 self.I = InvariantCalculator( data= self.data) 153 20 154 21 # data with smear info 22 list = Loader().load("latex_smeared.xml") 23 data1= list[0] 24 self.I1= InvariantCalculator( data= data1) 155 def testInvariant(self): 156 """ test the invariant value for data extrapolated""" 157 self.assertAlmostEquals(self.I.q_star, 7.48959e-5) 25 158 26 data2= list[1] 27 self.I2= InvariantCalculator( data= data2) 28 29 def test_invariant(self): 30 """ test the invariant value for data with no slit smear""" 31 self.assertAlmostEquals(self.I0.q_star, 7.48959e-5) 32 self.assertTrue(self.I1.q_star>0) 33 self.assertTrue(self.I2.q_star>0) 159 def testInvariantLowGuinier(self): 160 """ test the invariant value for data extrapolated low range using guinier""" 161 q_star_min = self.I.get_qstar_min( data= self.data, model= self.guinier, npts=10) 162 self.assertAlmostEquals(q_star_min, 4.89783e-8) 163 self.assertAlmostEquals(self.I.q_star_min, q_star_min) 164 165 def testInvariantLowPower(self): 166 """ test the invariant value for data extrapolated low range using pow_law""" 167 q_star_min = self.I.get_qstar_min( data= self.data, model= self.power_law, npts=10) 168 self.assertFalse(numpy.isfinite(q_star_min)) 169 self.assertEquals(self.I.q_star_min, q_star_min) 170 171 def testInvariantHigh(self): 172 """ test the invariant value for data extrapolated high range""" 173 q_star_max = self.I.get_qstar_max( self.data, model=self.power_law, npts=10) 174 self.assertAlmostEquals(q_star_max, 4.066202e-6) 175 self.assertAlmostEquals(self.I0.q_star_max, q_star_max) 34 176 35 def test_computation(self): 36 """ 37 Test identity smearing 38 """ 39 vol = self.I0.get_volume_fraction(contrast=2.6e-6) 40 surface = self.I0.get_surface(contrast=2.6e-6, porod_const=20) 177 def testInvariantTotal(self): 178 """ test the total invariant value for data extrapolated""" 179 self.assertAlmostEquals(self.I.q_star_total, 7.88981e-5) 41 180 42 # TODO: Need to test output values 43 #self.assertAlmostEquals(vol, 0) 44 #self.assertAlmostEquals(surface, 0) 45 vol = self.I1.get_volume_fraction(contrast=5.3e-6) 46 surface = self.I1.get_surface(contrast=5.3e-6, porod_const=20) 47 48 # TODO: Need to test output values 49 #self.assertAlmostEquals(vol, 0) 50 #self.assertAlmostEquals(surface, 0) 51 52 vol = self.I2.get_volume_fraction(contrast=5.3e-6) 53 surface = self.I2.get_surface(contrast=5.3e-6, porod_const=20) 54 55 # TODO: Need to test output values 56 self.assertAlmostEquals(vol, 0) 57 self.assertAlmostEquals(surface, 0) 58 59 60 181 def testVolume(self): 182 """ test volume fraction for data extrapolated""" 183 volume = self.I.get_volume_fraction(contrast=2.6e-6) 184 self.assert_(volume > 0 and volume <=1) 185 self.assertAlmostEqual(volume ,0.01) 186 187 def testSurface(self): 188 """ test surface for data extrapolated""" 189 surface = self.I.get_surface(contrast=2.6e-6, porod_const=20) 190 self.assertAlmostEqual(surface,0.01) 191 61 192 if __name__ == '__main__': 62 193 unittest.main()
Note: See TracChangeset
for help on using the changeset viewer.