[0f5bc9f] | 1 | """ |
---|
| 2 | Unit tests for dispersion functionality of |
---|
| 3 | C++ model classes |
---|
| 4 | """ |
---|
| 5 | |
---|
| 6 | import unittest, math, numpy |
---|
| 7 | |
---|
| 8 | class TestCylinder(unittest.TestCase): |
---|
| 9 | """ |
---|
| 10 | Testing C++ Cylinder model |
---|
| 11 | """ |
---|
| 12 | def setUp(self): |
---|
| 13 | from sans.models.CylinderModel import CylinderModel |
---|
| 14 | self.model= CylinderModel() |
---|
| 15 | |
---|
| 16 | self.model.setParam('scale', 1.0) |
---|
| 17 | self.model.setParam('radius', 20.0) |
---|
| 18 | self.model.setParam('length', 400.0) |
---|
[18b89c4] | 19 | self.model.setParam('sldCyl', 4.e-6) |
---|
| 20 | self.model.setParam('sldSolv', 1.e-6) |
---|
[0f5bc9f] | 21 | self.model.setParam('background', 0.0) |
---|
| 22 | self.model.setParam('cyl_theta', 0.0) |
---|
| 23 | self.model.setParam('cyl_phi', 0.0) |
---|
| 24 | |
---|
| 25 | def test_simple(self): |
---|
| 26 | self.assertAlmostEqual(self.model.run(0.001), 450.355, 3) |
---|
| 27 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 452.299, 3) |
---|
| 28 | |
---|
| 29 | def test_constant(self): |
---|
| 30 | from sans.models.dispersion_models import DispersionModel |
---|
| 31 | disp = DispersionModel() |
---|
| 32 | self.model.setParam('scale', 10.0) |
---|
| 33 | self.model.set_dispersion('radius', disp) |
---|
| 34 | self.model.dispersion['radius']['width'] = 5.0 |
---|
| 35 | self.model.dispersion['radius']['npts'] = 100 |
---|
[18b89c4] | 36 | self.model.dispersion['radius']['nsigmas'] = 2.5 |
---|
[0f5bc9f] | 37 | |
---|
[dfa8832] | 38 | self.assertAlmostEqual(self.model.run(0.001), 1.021051*4527.47250339, 3) |
---|
| 39 | self.assertAlmostEqual(self.model.runXY([0.001, 0.001]), 1.021048*4546.997777604715, 2) |
---|
[0f5bc9f] | 40 | |
---|
| 41 | def test_gaussian(self): |
---|
| 42 | from sans.models.dispersion_models import GaussianDispersion |
---|
| 43 | disp = GaussianDispersion() |
---|
| 44 | self.model.set_dispersion('radius', disp) |
---|
| 45 | self.model.dispersion['radius']['width'] = 5.0 |
---|
| 46 | self.model.dispersion['radius']['npts'] = 100 |
---|
[18b89c4] | 47 | self.model.dispersion['radius']['nsigmas'] = 2.5 |
---|
[0f5bc9f] | 48 | self.model.setParam('scale', 10.0) |
---|
| 49 | |
---|
[dfa8832] | 50 | self.assertAlmostEqual(self.model.run(0.001), 1.1804794*4723.32213339, 3) |
---|
| 51 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 1.180454*4743.56, 2) |
---|
[0f5bc9f] | 52 | |
---|
[8809e48] | 53 | def test_clone(self): |
---|
| 54 | from sans.models.dispersion_models import GaussianDispersion |
---|
| 55 | disp = GaussianDispersion() |
---|
| 56 | self.model.set_dispersion('radius', disp) |
---|
| 57 | self.model.dispersion['radius']['width'] = 5.0 |
---|
| 58 | self.model.dispersion['radius']['npts'] = 100 |
---|
[18b89c4] | 59 | self.model.dispersion['radius']['nsigmas'] = 2.5 |
---|
[8809e48] | 60 | self.model.setParam('scale', 10.0) |
---|
| 61 | |
---|
| 62 | new_model = self.model.clone() |
---|
[dfa8832] | 63 | self.assertAlmostEqual(new_model.run(0.001), 1.1804794*4723.32213339, 3) |
---|
| 64 | self.assertAlmostEqual(new_model.runXY([0.001,0.001]), 1.180454*4743.56, 2) |
---|
[8809e48] | 65 | |
---|
[ae60f86] | 66 | def test_gaussian_zero(self): |
---|
| 67 | from sans.models.dispersion_models import GaussianDispersion |
---|
| 68 | disp = GaussianDispersion() |
---|
| 69 | self.model.set_dispersion('radius', disp) |
---|
| 70 | self.model.dispersion['radius']['width'] = 0.0 |
---|
| 71 | self.model.dispersion['radius']['npts'] = 100 |
---|
[18b89c4] | 72 | self.model.dispersion['radius']['nsigmas'] = 2.5 |
---|
[ae60f86] | 73 | self.model.setParam('scale', 1.0) |
---|
| 74 | |
---|
| 75 | self.assertAlmostEqual(self.model.run(0.001), 450.355, 3) |
---|
| 76 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 452.299, 3) |
---|
| 77 | |
---|
[0f5bc9f] | 78 | def test_array(self): |
---|
| 79 | """ |
---|
| 80 | Perform complete rotational average and |
---|
| 81 | compare to 1D |
---|
| 82 | """ |
---|
| 83 | from sans.models.dispersion_models import ArrayDispersion |
---|
| 84 | disp_ph = ArrayDispersion() |
---|
| 85 | disp_th = ArrayDispersion() |
---|
| 86 | |
---|
| 87 | values_ph = numpy.zeros(100) |
---|
| 88 | values_th = numpy.zeros(100) |
---|
| 89 | weights = numpy.zeros(100) |
---|
| 90 | for i in range(100): |
---|
[18b89c4] | 91 | values_ph[i]=(360/99.0*i) |
---|
| 92 | values_th[i]=(180/99.0*i) |
---|
[0f5bc9f] | 93 | weights[i]=(1.0) |
---|
| 94 | |
---|
| 95 | disp_ph.set_weights(values_ph, weights) |
---|
| 96 | disp_th.set_weights(values_th, weights) |
---|
| 97 | |
---|
| 98 | self.model.set_dispersion('cyl_theta', disp_th) |
---|
| 99 | self.model.set_dispersion('cyl_phi', disp_ph) |
---|
| 100 | |
---|
| 101 | val_1d = self.model.run(math.sqrt(0.0002)) |
---|
| 102 | val_2d = self.model.runXY([0.01,0.01]) |
---|
| 103 | |
---|
| 104 | self.assertTrue(math.fabs(val_1d-val_2d)/val_1d < 0.02) |
---|
| 105 | |
---|
| 106 | class TestCoreShellCylinder(unittest.TestCase): |
---|
| 107 | """ |
---|
| 108 | Testing C++ Cylinder model |
---|
| 109 | """ |
---|
| 110 | def setUp(self): |
---|
| 111 | from sans.models.CoreShellCylinderModel import CoreShellCylinderModel |
---|
| 112 | self.model= CoreShellCylinderModel() |
---|
| 113 | |
---|
| 114 | self.model.setParam('scale', 1.0) |
---|
| 115 | self.model.setParam('radius', 20.0) |
---|
| 116 | self.model.setParam('thickness', 10.0) |
---|
| 117 | self.model.setParam('length', 400.0) |
---|
| 118 | self.model.setParam('core_sld', 1.e-6) |
---|
| 119 | self.model.setParam('shell_sld', 4.e-6) |
---|
| 120 | self.model.setParam('solvent_sld', 1.e-6) |
---|
| 121 | self.model.setParam('background', 0.0) |
---|
| 122 | self.model.setParam('axis_theta', 0.0) |
---|
| 123 | self.model.setParam('axis_phi', 0.0) |
---|
| 124 | |
---|
| 125 | def test_simple(self): |
---|
| 126 | """ |
---|
| 127 | Test simple 1D and 2D values |
---|
| 128 | Numbers taken from model that passed validation, before |
---|
| 129 | the update to C++ underlying class. |
---|
| 130 | """ |
---|
| 131 | self.assertAlmostEqual(self.model.run(0.001), 353.55013216754583, 3) |
---|
| 132 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 355.25355270620543, 3) |
---|
| 133 | |
---|
| 134 | def test_dispersion(self): |
---|
| 135 | """ |
---|
| 136 | Test with dispersion |
---|
| 137 | """ |
---|
| 138 | from sans.models.DisperseModel import DisperseModel |
---|
| 139 | disp = DisperseModel(self.model, ['radius', 'thickness', 'length'], [5, 2, 50]) |
---|
| 140 | disp.setParam('n_pts', 10) |
---|
| 141 | self.assertAlmostEqual(disp.run(0.001), 358.44062724936009, 3) |
---|
| 142 | self.assertAlmostEqual(disp.runXY([0.001,0.001]), 360.22673635224584, 3) |
---|
| 143 | |
---|
| 144 | def test_new_disp(self): |
---|
| 145 | from sans.models.dispersion_models import GaussianDispersion |
---|
| 146 | disp_rm = GaussianDispersion() |
---|
| 147 | self.model.set_dispersion('radius', disp_rm) |
---|
| 148 | self.model.dispersion['radius']['width'] = 5.0 |
---|
| 149 | self.model.dispersion['radius']['npts'] = 10 |
---|
[18b89c4] | 150 | self.model.dispersion['radius']['nsigmas'] = 2.5 |
---|
[0f5bc9f] | 151 | |
---|
| 152 | disp_rr = GaussianDispersion() |
---|
| 153 | self.model.set_dispersion('thickness', disp_rr) |
---|
| 154 | self.model.dispersion['thickness']['width'] = 2. |
---|
| 155 | self.model.dispersion['thickness']['npts'] = 10 |
---|
[18b89c4] | 156 | self.model.dispersion['thickness']['nsigmas'] = 2.5 |
---|
[0f5bc9f] | 157 | |
---|
| 158 | disp_len = GaussianDispersion() |
---|
| 159 | self.model.set_dispersion('length', disp_len) |
---|
| 160 | self.model.dispersion['length']['width'] = 50.0 |
---|
| 161 | self.model.dispersion['length']['npts'] = 10 |
---|
[18b89c4] | 162 | self.model.dispersion['length']['nsigmas'] = 2.5 |
---|
[0f5bc9f] | 163 | |
---|
[dfa8832] | 164 | self.assertAlmostEqual(self.model.run(0.001), 1.07832610*358.44062724936009, 3) |
---|
| 165 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 1.07844010*360.22673635224584, 3) |
---|
[0f5bc9f] | 166 | |
---|
| 167 | |
---|
| 168 | def test_array(self): |
---|
| 169 | """ |
---|
| 170 | Perform complete rotational average and |
---|
| 171 | compare to 1D |
---|
| 172 | """ |
---|
| 173 | from sans.models.dispersion_models import ArrayDispersion |
---|
| 174 | disp_ph = ArrayDispersion() |
---|
| 175 | disp_th = ArrayDispersion() |
---|
| 176 | |
---|
| 177 | values_ph = numpy.zeros(100) |
---|
| 178 | values_th = numpy.zeros(100) |
---|
| 179 | weights = numpy.zeros(100) |
---|
| 180 | for i in range(100): |
---|
[18b89c4] | 181 | values_ph[i]=(360/99.0*i) |
---|
| 182 | values_th[i]=(180/99.0*i) |
---|
[0f5bc9f] | 183 | weights[i]=(1.0) |
---|
| 184 | |
---|
| 185 | disp_ph.set_weights(values_ph, weights) |
---|
| 186 | disp_th.set_weights(values_th, weights) |
---|
| 187 | |
---|
| 188 | self.model.set_dispersion('axis_theta', disp_th) |
---|
| 189 | self.model.set_dispersion('axis_phi', disp_ph) |
---|
| 190 | |
---|
| 191 | val_1d = self.model.run(math.sqrt(0.0002)) |
---|
| 192 | val_2d = self.model.runXY([0.01,0.01]) |
---|
| 193 | |
---|
| 194 | self.assertTrue(math.fabs(val_1d-val_2d)/val_1d < 0.02) |
---|
| 195 | |
---|
| 196 | |
---|
| 197 | |
---|
| 198 | class TestCoreShell(unittest.TestCase): |
---|
| 199 | """ |
---|
| 200 | Testing C++ Cylinder model |
---|
| 201 | """ |
---|
| 202 | def setUp(self): |
---|
| 203 | from sans.models.CoreShellModel import CoreShellModel |
---|
| 204 | self.model= CoreShellModel() |
---|
| 205 | |
---|
| 206 | self.model.setParam('scale', 1.0) |
---|
| 207 | self.model.setParam('radius', 60.0) |
---|
| 208 | self.model.setParam('thickness', 10.0) |
---|
| 209 | self.model.setParam('core_sld', 1.e-6) |
---|
| 210 | self.model.setParam('shell_sld', 2.e-6) |
---|
| 211 | self.model.setParam('solvent_sld', 3.e-6) |
---|
| 212 | self.model.setParam('background', 0.0) |
---|
| 213 | |
---|
| 214 | def test_simple(self): |
---|
| 215 | """ |
---|
| 216 | Test simple 1D and 2D values |
---|
| 217 | Numbers taken from model that passed validation, before |
---|
| 218 | the update to C++ underlying class. |
---|
| 219 | """ |
---|
| 220 | self.assertAlmostEqual(self.model.run(0.001), 381.27304697150055, 3) |
---|
| 221 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 380.93779156218682, 3) |
---|
| 222 | |
---|
| 223 | def test_dispersion(self): |
---|
| 224 | """ |
---|
| 225 | Test with dispersion |
---|
| 226 | """ |
---|
| 227 | from sans.models.DisperseModel import DisperseModel |
---|
| 228 | disp = DisperseModel(self.model, ['radius', 'thickness'], [10, 2]) |
---|
| 229 | disp.setParam('n_pts', 10) |
---|
| 230 | self.assertAlmostEqual(disp.run(0.001), 407.344127907553, 3) |
---|
| 231 | |
---|
| 232 | def test_new_disp(self): |
---|
| 233 | from sans.models.dispersion_models import GaussianDispersion |
---|
| 234 | disp_rm = GaussianDispersion() |
---|
| 235 | self.model.set_dispersion('radius', disp_rm) |
---|
| 236 | self.model.dispersion['radius']['width'] = 10. |
---|
| 237 | self.model.dispersion['radius']['npts'] = 10 |
---|
[18b89c4] | 238 | self.model.dispersion['radius']['nsigmas'] = 2.5 |
---|
[0f5bc9f] | 239 | |
---|
| 240 | disp_rr = GaussianDispersion() |
---|
| 241 | self.model.set_dispersion('thickness', disp_rr) |
---|
| 242 | self.model.dispersion['thickness']['width'] = 2. |
---|
| 243 | self.model.dispersion['thickness']['npts'] = 10 |
---|
[18b89c4] | 244 | self.model.dispersion['thickness']['nsigmas'] = 2.5 |
---|
[0f5bc9f] | 245 | |
---|
[dfa8832] | 246 | self.assertAlmostEqual(self.model.run(0.001), 1.16747510*407.344127907553, 3) |
---|
[0f5bc9f] | 247 | |
---|
| 248 | |
---|
| 249 | class TestEllipsoid(unittest.TestCase): |
---|
| 250 | """ |
---|
| 251 | Testing C++ Cylinder model |
---|
| 252 | """ |
---|
| 253 | def setUp(self): |
---|
| 254 | from sans.models.EllipsoidModel import EllipsoidModel |
---|
| 255 | self.model= EllipsoidModel() |
---|
| 256 | |
---|
| 257 | self.model.setParam('scale', 1.0) |
---|
| 258 | self.model.setParam('radius_a', 20.0) |
---|
| 259 | self.model.setParam('radius_b', 400.0) |
---|
[18b89c4] | 260 | self.model.setParam('sldEll', 4.e-6) |
---|
| 261 | self.model.setParam('sldSolv', 1.e-6) |
---|
[0f5bc9f] | 262 | self.model.setParam('background', 0.0) |
---|
[18b89c4] | 263 | self.model.setParam('axis_theta', 89.95445) |
---|
[0f5bc9f] | 264 | self.model.setParam('axis_phi', 0.0) |
---|
| 265 | |
---|
| 266 | def test_simple(self): |
---|
| 267 | """ |
---|
| 268 | Test simple 1D and 2D values |
---|
| 269 | Numbers taken from model that passed validation, before |
---|
| 270 | the update to C++ underlying class. |
---|
| 271 | """ |
---|
| 272 | self.assertAlmostEqual(self.model.run(0.001), 11808.842896863147, 3) |
---|
| 273 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 11681.990374929677, 3) |
---|
| 274 | |
---|
| 275 | def test_dispersion(self): |
---|
| 276 | """ |
---|
| 277 | Test with dispersion |
---|
| 278 | """ |
---|
| 279 | from sans.models.DisperseModel import DisperseModel |
---|
| 280 | disp = DisperseModel(self.model, ['radius_a', 'radius_b'], [5, 50]) |
---|
| 281 | disp.setParam('n_pts', 10) |
---|
[18b89c4] | 282 | |
---|
[0f5bc9f] | 283 | self.assertAlmostEqual(disp.run(0.001), 11948.72581312305, 3) |
---|
| 284 | self.assertAlmostEqual(disp.runXY([0.001,0.001]), 11811.972359807551, 3) |
---|
| 285 | |
---|
| 286 | def test_new_disp(self): |
---|
| 287 | from sans.models.dispersion_models import GaussianDispersion |
---|
| 288 | disp_rm = GaussianDispersion() |
---|
| 289 | self.model.set_dispersion('radius_a', disp_rm) |
---|
| 290 | self.model.dispersion['radius_a']['width'] = 5.0 |
---|
| 291 | self.model.dispersion['radius_a']['npts'] = 10 |
---|
[18b89c4] | 292 | self.model.dispersion['radius_a']['nsigmas'] = 2.5 |
---|
[0f5bc9f] | 293 | |
---|
| 294 | disp_rr = GaussianDispersion() |
---|
| 295 | self.model.set_dispersion('radius_b', disp_rr) |
---|
| 296 | self.model.dispersion['radius_b']['width'] = 50. |
---|
| 297 | self.model.dispersion['radius_b']['npts'] = 10 |
---|
[18b89c4] | 298 | self.model.dispersion['radius_b']['nsigmas'] = 2.5 |
---|
[0f5bc9f] | 299 | |
---|
[dfa8832] | 300 | self.assertAlmostEqual(self.model.run(0.001), 1.10650710*11948.72581312305, 3) |
---|
| 301 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 1.105898*11811.972359807551, 2) |
---|
[0f5bc9f] | 302 | |
---|
| 303 | def test_array(self): |
---|
| 304 | """ |
---|
| 305 | Perform complete rotational average and |
---|
| 306 | compare to 1D |
---|
| 307 | """ |
---|
| 308 | from sans.models.dispersion_models import ArrayDispersion |
---|
| 309 | disp_ph = ArrayDispersion() |
---|
| 310 | disp_th = ArrayDispersion() |
---|
| 311 | |
---|
| 312 | values_ph = numpy.zeros(100) |
---|
| 313 | values_th = numpy.zeros(100) |
---|
| 314 | weights = numpy.zeros(100) |
---|
| 315 | for i in range(100): |
---|
[18b89c4] | 316 | values_ph[i]=(360/99.0*i) |
---|
| 317 | values_th[i]=(180/99.0*i) |
---|
[0f5bc9f] | 318 | weights[i]=(1.0) |
---|
| 319 | |
---|
| 320 | disp_ph.set_weights(values_ph, weights) |
---|
| 321 | disp_th.set_weights(values_th, weights) |
---|
| 322 | |
---|
| 323 | self.model.set_dispersion('axis_theta', disp_th) |
---|
| 324 | self.model.set_dispersion('axis_phi', disp_ph) |
---|
| 325 | |
---|
| 326 | val_1d = self.model.run(math.sqrt(0.0002)) |
---|
| 327 | val_2d = self.model.runXY([0.01,0.01]) |
---|
| 328 | |
---|
| 329 | self.assertTrue(math.fabs(val_1d-val_2d)/val_1d < 0.02) |
---|
| 330 | |
---|
| 331 | |
---|
| 332 | |
---|
| 333 | class TestSphere(unittest.TestCase): |
---|
| 334 | """ |
---|
| 335 | Testing C++ Cylinder model |
---|
| 336 | """ |
---|
| 337 | def setUp(self): |
---|
| 338 | from sans.models.SphereModel import SphereModel |
---|
| 339 | self.model= SphereModel() |
---|
| 340 | |
---|
| 341 | self.model.setParam('scale', 1.0) |
---|
| 342 | self.model.setParam('radius', 60.0) |
---|
[18b89c4] | 343 | self.model.setParam('sldSph', 2.0e-06) |
---|
| 344 | self.model.setParam('sldSolv', 1.0e-6) |
---|
[0f5bc9f] | 345 | self.model.setParam('background', 0.0) |
---|
| 346 | |
---|
| 347 | def test_simple(self): |
---|
| 348 | """ |
---|
| 349 | Test simple 1D and 2D values |
---|
| 350 | Numbers taken from model that passed validation, before |
---|
| 351 | the update to C++ underlying class. |
---|
| 352 | """ |
---|
| 353 | self.assertAlmostEqual(self.model.run(0.001), 90412744456148.094, 3) |
---|
[dfa8832] | 354 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 90347660670656.391, 1) |
---|
[0f5bc9f] | 355 | |
---|
| 356 | def test_dispersion(self): |
---|
| 357 | """ |
---|
| 358 | Test with dispersion |
---|
| 359 | """ |
---|
| 360 | from sans.models.DisperseModel import DisperseModel |
---|
| 361 | disp = DisperseModel(self.model, ['radius'], [10]) |
---|
| 362 | disp.setParam('n_pts', 10) |
---|
[dfa8832] | 363 | self.assertAlmostEqual(disp.run(0.001), 96795008379475.25, 1) |
---|
[0f5bc9f] | 364 | |
---|
| 365 | def test_new_disp(self): |
---|
| 366 | from sans.models.dispersion_models import GaussianDispersion |
---|
| 367 | disp_rm = GaussianDispersion() |
---|
| 368 | self.model.set_dispersion('radius', disp_rm) |
---|
| 369 | self.model.dispersion['radius']['width'] = 10.0 |
---|
| 370 | self.model.dispersion['radius']['npts'] = 10 |
---|
[18b89c4] | 371 | self.model.dispersion['radius']['nsigmas'] = 2.5 |
---|
[0f5bc9f] | 372 | |
---|
[dfa8832] | 373 | self.assertAlmostEqual(self.model.run(0.001), 1.19864810*96795008379475.25,3) |
---|
[0f5bc9f] | 374 | |
---|
| 375 | |
---|
| 376 | |
---|
| 377 | class TestEllipticalCylinder(unittest.TestCase): |
---|
| 378 | """ |
---|
| 379 | Testing C++ Cylinder model |
---|
| 380 | """ |
---|
| 381 | def setUp(self): |
---|
| 382 | from sans.models.EllipticalCylinderModel import EllipticalCylinderModel |
---|
| 383 | self.model= EllipticalCylinderModel() |
---|
| 384 | |
---|
| 385 | self.model.setParam('scale', 1.0) |
---|
| 386 | self.model.setParam('r_minor', 20.0) |
---|
| 387 | self.model.setParam('r_ratio', 1.5) |
---|
| 388 | self.model.setParam('length', 400.0) |
---|
[18b89c4] | 389 | self.model.setParam('sldCyl', 4.0e-6) |
---|
| 390 | self.model.setParam('sldSolv', 1.0e-6) |
---|
[0f5bc9f] | 391 | self.model.setParam('background', 0.0) |
---|
[18b89c4] | 392 | self.model.setParam('cyl_theta', 90) |
---|
[0f5bc9f] | 393 | self.model.setParam('cyl_phi', 0.0) |
---|
| 394 | self.model.setParam('cyl_psi', 0.0) |
---|
| 395 | |
---|
| 396 | def test_simple(self): |
---|
| 397 | """ |
---|
| 398 | Test simple 1D and 2D values |
---|
| 399 | Numbers taken from model that passed validation, before |
---|
| 400 | the update to C++ underlying class. |
---|
| 401 | """ |
---|
| 402 | self.assertAlmostEqual(self.model.run(0.001), 675.50440232504991, 3) |
---|
[18b89c4] | 403 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 669.5173937622792, 0) |
---|
[0f5bc9f] | 404 | |
---|
| 405 | def test_dispersion(self): |
---|
| 406 | """ |
---|
| 407 | Test with dispersion |
---|
| 408 | """ |
---|
| 409 | from sans.models.DisperseModel import DisperseModel |
---|
| 410 | disp = DisperseModel(self.model, ['r_minor', 'r_ratio', 'length'], [5, 0.25, 50]) |
---|
| 411 | disp.setParam('n_pts', 10) |
---|
| 412 | self.assertAlmostEqual(disp.run(0.001), 711.18048194151925, 3) |
---|
[18b89c4] | 413 | self.assertAlmostEqual(disp.runXY([0.001,0.001]), 704.63525988095705, 0) |
---|
[0f5bc9f] | 414 | |
---|
| 415 | def test_new_disp(self): |
---|
| 416 | from sans.models.dispersion_models import GaussianDispersion |
---|
| 417 | disp_rm = GaussianDispersion() |
---|
| 418 | self.model.set_dispersion('r_minor', disp_rm) |
---|
| 419 | self.model.dispersion['r_minor']['width'] = 5.0 |
---|
| 420 | self.model.dispersion['r_minor']['npts'] = 10 |
---|
[18b89c4] | 421 | self.model.dispersion['r_minor']['nsigmas'] = 2.5 |
---|
[0f5bc9f] | 422 | |
---|
| 423 | disp_rr = GaussianDispersion() |
---|
| 424 | self.model.set_dispersion('r_ratio', disp_rr) |
---|
| 425 | self.model.dispersion['r_ratio']['width'] = 0.25 |
---|
| 426 | self.model.dispersion['r_ratio']['npts'] = 10 |
---|
[18b89c4] | 427 | self.model.dispersion['r_ratio']['nsigmas'] = 2.5 |
---|
[0f5bc9f] | 428 | |
---|
| 429 | disp_len = GaussianDispersion() |
---|
| 430 | self.model.set_dispersion('length', disp_len) |
---|
| 431 | self.model.dispersion['length']['width'] = 50.0 |
---|
| 432 | self.model.dispersion['length']['npts'] = 10 |
---|
[18b89c4] | 433 | self.model.dispersion['length']['nsigmas'] = 2.5 |
---|
[0f5bc9f] | 434 | |
---|
[dfa8832] | 435 | self.assertAlmostEqual(self.model.run(0.001), 1.23925910*711.18048194151925, 3) |
---|
[18b89c4] | 436 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 1.238955*704.63525988095705, 0) |
---|
[0f5bc9f] | 437 | |
---|
| 438 | |
---|
| 439 | def test_array(self): |
---|
| 440 | """ |
---|
| 441 | Perform complete rotational average and |
---|
| 442 | compare to 1D |
---|
| 443 | """ |
---|
| 444 | from sans.models.dispersion_models import ArrayDispersion |
---|
| 445 | disp_ph = ArrayDispersion() |
---|
| 446 | disp_th = ArrayDispersion() |
---|
| 447 | disp_ps = ArrayDispersion() |
---|
| 448 | |
---|
| 449 | values_ph = numpy.zeros(100) |
---|
| 450 | values_th = numpy.zeros(100) |
---|
| 451 | values_ps = numpy.zeros(100) |
---|
| 452 | weights = numpy.zeros(100) |
---|
| 453 | for i in range(100): |
---|
[18b89c4] | 454 | values_ps[i]=(360/99.0*i) |
---|
| 455 | values_ph[i]=(360/99.0*i) |
---|
| 456 | values_th[i]=(180/99.0*i) |
---|
[0f5bc9f] | 457 | weights[i]=(1.0) |
---|
| 458 | |
---|
| 459 | disp_ph.set_weights(values_ph, weights) |
---|
| 460 | disp_th.set_weights(values_th, weights) |
---|
| 461 | disp_ps.set_weights(values_ps, weights) |
---|
| 462 | |
---|
| 463 | self.model.set_dispersion('cyl_theta', disp_th) |
---|
| 464 | self.model.set_dispersion('cyl_phi', disp_ph) |
---|
| 465 | self.model.set_dispersion('cyl_psi', disp_ps) |
---|
| 466 | |
---|
| 467 | val_1d = self.model.run(math.sqrt(0.0002)) |
---|
| 468 | val_2d = self.model.runXY([0.01,0.01]) |
---|
| 469 | |
---|
| 470 | self.assertTrue(math.fabs(val_1d-val_2d)/val_1d < 0.02) |
---|
| 471 | |
---|
[ae60f86] | 472 | class TestDispModel(unittest.TestCase): |
---|
| 473 | def setUp(self): |
---|
| 474 | from sans.models.CylinderModel import CylinderModel |
---|
| 475 | self.model = CylinderModel() |
---|
| 476 | |
---|
| 477 | |
---|
| 478 | def test_disp_params(self): |
---|
| 479 | |
---|
| 480 | self.assertEqual(self.model.dispersion['radius']['width'], 0.0) |
---|
| 481 | self.model.setParam('radius.width', 5.0) |
---|
| 482 | self.assertEqual(self.model.dispersion['radius']['width'], 5.0) |
---|
| 483 | self.assertEqual(self.model.getParam('radius.width'), 5.0) |
---|
| 484 | self.assertEqual(self.model.dispersion['radius']['type'], 'gaussian') |
---|
[0f5bc9f] | 485 | |
---|
| 486 | |
---|
| 487 | if __name__ == '__main__': |
---|
| 488 | unittest.main() |
---|
| 489 | |
---|