- Timestamp:
- Jan 11, 2010 6:44:59 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:
- 3082632
- Parents:
- 885857e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Invariant/test/utest_data_handling.py
r46d50ca r6939bd4 9 9 """ 10 10 import unittest 11 import numpy 11 import numpy, math 12 12 from DataLoader.loader import Loader 13 13 from DataLoader.data_info import Data1D … … 53 53 # Test results 54 54 self.assertTrue(math.fabs(a-1.0)<0.05) 55 self.assertTrue(math.fabs(b)<0. 05)55 self.assertTrue(math.fabs(b)<0.1) 56 56 57 57 … … 101 101 102 102 103 class TestGuinierExtrapolation(unittest.TestCase): 104 """ 105 Generate a Guinier distribution and verify that the extrapolation 106 produce the correct ditribution. 107 """ 108 109 def setUp(self): 110 """ 111 Generate a Guinier distribution. After extrapolating, we will 112 verify that we obtain the scale and rg parameters 113 """ 114 self.scale = 1.5 115 self.rg = 70.0 116 x = numpy.arange(0.0001, 0.1, 0.0001) 117 y = numpy.asarray([self.scale * math.exp( -(q*self.rg)**2 / 3.0 ) for q in x]) 118 dy = y*.1 119 self.data = Data1D(x=x, y=y, dy=dy) 120 121 def test_low_q(self): 122 """ 123 Invariant with low-Q extrapolation 124 """ 125 # Create invariant object. Background and scale left as defaults. 126 inv = invariant.InvariantCalculator(data=self.data) 127 # Set the extrapolation parameters for the low-Q range 128 inv.set_extrapolation(range='low', npts=20, function='guinier') 129 130 self.assertEqual(inv._low_extrapolation_npts, 20) 131 self.assertEqual(inv._low_extrapolation_function.__name__, 'guinier') 132 133 # Data boundaries for fiiting 134 qmin = inv._data.x[0] 135 qmax = inv._data.x[inv._low_extrapolation_npts - 1] 136 137 # Extrapolate the low-Q data 138 a, b = inv._fit(function=inv._low_extrapolation_function, 139 qmin=qmin, 140 qmax=qmax, 141 power=inv._low_extrapolation_power) 142 self.assertAlmostEqual(self.scale, a, 6) 143 self.assertAlmostEqual(self.rg, b, 6) 144 145 146 class TestPowerLawExtrapolation(unittest.TestCase): 147 """ 148 Generate a power law distribution and verify that the extrapolation 149 produce the correct ditribution. 150 """ 151 152 def setUp(self): 153 """ 154 Generate a power law distribution. After extrapolating, we will 155 verify that we obtain the scale and m parameters 156 """ 157 self.scale = 1.5 158 self.m = 3.0 159 x = numpy.arange(0.0001, 0.1, 0.0001) 160 y = numpy.asarray([self.scale * math.pow(q ,-1.0*self.m) for q in x]) 161 dy = y*.1 162 self.data = Data1D(x=x, y=y, dy=dy) 163 164 def test_low_q(self): 165 """ 166 Invariant with low-Q extrapolation 167 """ 168 # Create invariant object. Background and scale left as defaults. 169 inv = invariant.InvariantCalculator(data=self.data) 170 # Set the extrapolation parameters for the low-Q range 171 inv.set_extrapolation(range='low', npts=20, function='power_law') 172 173 self.assertEqual(inv._low_extrapolation_npts, 20) 174 self.assertEqual(inv._low_extrapolation_function.__name__, 'power_law') 175 176 # Data boundaries for fitting 177 qmin = inv._data.x[0] 178 qmax = inv._data.x[inv._low_extrapolation_npts - 1] 179 180 # Extrapolate the low-Q data 181 a, b = inv._fit(function=inv._low_extrapolation_function, 182 qmin=qmin, 183 qmax=qmax, 184 power=inv._low_extrapolation_power) 185 186 self.assertAlmostEqual(self.scale, a, 6) 187 self.assertAlmostEqual(self.m, b, 6) 188
Note: See TracChangeset
for help on using the changeset viewer.