[c9636f7] | 1 | """ |
---|
| 2 | Unit tests for specific models |
---|
| 3 | @author: Gervaise Alina / UTK |
---|
| 4 | """ |
---|
[ec38f27] | 5 | #This test replaces the older utests for multiplicationModel. Aug. 31, 2009. JC |
---|
[c9636f7] | 6 | import unittest, numpy,math |
---|
[ec38f27] | 7 | ### P*S with sphere model |
---|
| 8 | class TestsphereSuareW(unittest.TestCase): |
---|
| 9 | """ |
---|
| 10 | Unit tests for SphereModel(Q) * SquareWellStructure(Q) |
---|
| 11 | """ |
---|
| 12 | def setUp(self): |
---|
| 13 | from sans.models.SphereModel import SphereModel |
---|
| 14 | from sans.models.SquareWellStructure import SquareWellStructure |
---|
| 15 | from sans.models.DiamCylFunc import DiamCylFunc |
---|
| 16 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
[c9636f7] | 17 | |
---|
[ec38f27] | 18 | self.model = SphereModel() |
---|
| 19 | self.model2 = SquareWellStructure() |
---|
| 20 | self.model3 = MultiplicationModel(self.model, self.model2) |
---|
| 21 | self.modelD = DiamCylFunc() |
---|
| 22 | |
---|
| 23 | #Radius of model1.calculate_ER should be equal to the output/2 of DiamFunctions |
---|
[b22748b] | 24 | def test_multplication_radius(self): |
---|
[ec38f27] | 25 | """ |
---|
| 26 | test multiplication model (check the effective radius & the output |
---|
| 27 | of the multiplication) |
---|
| 28 | """ |
---|
| 29 | self.model.setParam("radius", 60) |
---|
| 30 | modelDrun = 60 |
---|
| 31 | self.model2.setParam("volfraction", 0.2) |
---|
| 32 | self.model2.setParam("effect_radius", modelDrun ) |
---|
| 33 | |
---|
| 34 | #Compare new method with old method |
---|
| 35 | self.assertEqual(self.model3.run(0.1), self.model.run(0.1)*self.model2.run(0.1)) |
---|
| 36 | |
---|
| 37 | #Compare radius from two different calculations. Note: modelD.run(0.0) is DIAMETER |
---|
| 38 | self.assertEqual(self.model.calculate_ER(), modelDrun) |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | def testMultiplicationParam(self): |
---|
| 42 | """ Test Multiplication (check the setparameters and the run & runXY w/ array dispersion)""" |
---|
| 43 | ## test details dictionary |
---|
| 44 | |
---|
| 45 | ## test parameters list |
---|
| 46 | list3= self.model3.getParamList() |
---|
| 47 | |
---|
| 48 | for item in self.model.getParamList(): |
---|
| 49 | self.assert_(item in list3) |
---|
| 50 | for item in self.model2.getParamList(): |
---|
| 51 | #model3 parameters should not include effect_radius* |
---|
| 52 | if not 'effect_radius' in item: |
---|
| 53 | self.assert_(item in list3) |
---|
| 54 | |
---|
| 55 | ## test set value for parameters and get paramaters |
---|
| 56 | self.model3.setParam("scale", 15) |
---|
| 57 | self.assertEqual(self.model3.getParam("scale"), 15) |
---|
| 58 | self.model3.setParam("radius", 20) |
---|
| 59 | self.assertEqual(self.model3.getParam("radius"), 20) |
---|
| 60 | self.model3.setParam("radius.width", 15) |
---|
| 61 | self.assertEqual(self.model3.getParam("radius.width"), 15) |
---|
| 62 | |
---|
| 63 | ## Dispersity |
---|
| 64 | list3= self.model3.getDispParamList() |
---|
| 65 | self.assertEqual(list3, ['radius.npts', 'radius.nsigmas', 'radius.width']) |
---|
| 66 | |
---|
| 67 | from sans.models.dispersion_models import ArrayDispersion |
---|
| 68 | disp_th = ArrayDispersion() |
---|
| 69 | |
---|
| 70 | values_th = numpy.zeros(100) |
---|
| 71 | weights = numpy.zeros(100) |
---|
| 72 | for i in range(100): |
---|
| 73 | values_th[i]=(math.pi/99.0*i) |
---|
| 74 | weights[i]=(1.0) |
---|
| 75 | |
---|
| 76 | disp_th.set_weights(values_th, weights) |
---|
| 77 | |
---|
| 78 | self.model3.set_dispersion('radius', disp_th) |
---|
| 79 | |
---|
| 80 | val_1d = self.model3.run(math.sqrt(0.0002)) |
---|
| 81 | val_2d = self.model3.runXY([0.01,0.01]) |
---|
| 82 | |
---|
| 83 | self.assertTrue(math.fabs(val_1d-val_2d)/val_1d < 0.02) |
---|
| 84 | model4= self.model3.clone() |
---|
| 85 | self.assertEqual(model4.getParam("radius"), 20) |
---|
| 86 | |
---|
| 87 | class TestsphereHardS(unittest.TestCase): |
---|
| 88 | """ |
---|
| 89 | Unit tests for SphereModel(Q) * HardsphereStructure(Q) |
---|
| 90 | """ |
---|
| 91 | def setUp(self): |
---|
| 92 | from sans.models.SphereModel import SphereModel |
---|
[b22748b] | 93 | from sans.models.HardsphereStructure import HardsphereStructure |
---|
| 94 | from sans.models.DiamCylFunc import DiamCylFunc |
---|
[ec38f27] | 95 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
| 96 | |
---|
| 97 | self.model = SphereModel() |
---|
| 98 | self.model2 = HardsphereStructure() |
---|
| 99 | self.model3 = MultiplicationModel(self.model, self.model2) |
---|
| 100 | self.modelD = DiamCylFunc() |
---|
| 101 | |
---|
| 102 | #Radius of model1.calculate_ER should be equal to the output/2 of DiamFunctions |
---|
| 103 | def test_multplication_radius(self): |
---|
| 104 | """ |
---|
| 105 | test multiplication model (check the effective radius & the output |
---|
| 106 | of the multiplication) |
---|
| 107 | """ |
---|
| 108 | self.model.setParam("radius", 60) |
---|
| 109 | modelDrun = 60 |
---|
| 110 | self.model2.setParam("volfraction", 0.2) |
---|
| 111 | self.model2.setParam("effect_radius", modelDrun ) |
---|
| 112 | |
---|
| 113 | #Compare new method with old method |
---|
| 114 | self.assertEqual(self.model3.run(0.1), self.model.run(0.1)*self.model2.run(0.1)) |
---|
| 115 | |
---|
| 116 | #Compare radius from two different calculations. Note: modelD.run(0.0) is DIAMETER |
---|
| 117 | self.assertEqual(self.model.calculate_ER(), modelDrun) |
---|
[24415e9] | 118 | |
---|
[ec38f27] | 119 | |
---|
| 120 | def testMultiplicationParam(self): |
---|
| 121 | """ Test Multiplication (check the parameters)""" |
---|
| 122 | ## test details dictionary |
---|
| 123 | |
---|
| 124 | ## test parameters list |
---|
| 125 | list3= self.model3.getParamList() |
---|
| 126 | |
---|
| 127 | for item in self.model.getParamList(): |
---|
| 128 | self.assert_(item in list3) |
---|
| 129 | for item in self.model2.getParamList(): |
---|
| 130 | #model3 parameters should not include effect_radius* |
---|
| 131 | if not 'effect_radius' in item: |
---|
| 132 | self.assert_(item in list3) |
---|
| 133 | |
---|
| 134 | ## test set value for parameters and get paramaters |
---|
| 135 | self.model3.setParam("scale", 15) |
---|
| 136 | self.assertEqual(self.model3.getParam("scale"), 15) |
---|
| 137 | self.model3.setParam("radius", 20) |
---|
| 138 | self.assertEqual(self.model3.getParam("radius"), 20) |
---|
| 139 | self.model3.setParam("radius.width", 15) |
---|
| 140 | self.assertEqual(self.model3.getParam("radius.width"), 15) |
---|
| 141 | |
---|
| 142 | ## Dispersity |
---|
| 143 | list3= self.model3.getDispParamList() |
---|
| 144 | self.assertEqual(list3, ['radius.npts', 'radius.nsigmas', 'radius.width']) |
---|
| 145 | |
---|
| 146 | from sans.models.dispersion_models import ArrayDispersion |
---|
| 147 | disp_th = ArrayDispersion() |
---|
| 148 | |
---|
| 149 | values_th = numpy.zeros(100) |
---|
| 150 | weights = numpy.zeros(100) |
---|
| 151 | for i in range(100): |
---|
| 152 | values_th[i]=(math.pi/99.0*i) |
---|
| 153 | weights[i]=(1.0) |
---|
[b22748b] | 154 | |
---|
[ec38f27] | 155 | disp_th.set_weights(values_th, weights) |
---|
| 156 | |
---|
| 157 | self.model3.set_dispersion('radius', disp_th) |
---|
| 158 | |
---|
| 159 | val_1d = self.model3.run(math.sqrt(0.0002)) |
---|
| 160 | val_2d = self.model3.runXY([0.01,0.01]) |
---|
| 161 | |
---|
| 162 | self.assertTrue(math.fabs(val_1d-val_2d)/val_1d < 0.02) |
---|
| 163 | model4= self.model3.clone() |
---|
| 164 | self.assertEqual(model4.getParam("radius"), 20) |
---|
| 165 | class TestsphereSHS(unittest.TestCase): |
---|
| 166 | """ |
---|
| 167 | Unit tests for SphereModel(Q) * StickyHSStructure(Q) |
---|
| 168 | """ |
---|
| 169 | def setUp(self): |
---|
[8cfdd5e] | 170 | from sans.models.SphereModel import SphereModel |
---|
[ec38f27] | 171 | from sans.models.StickyHSStructure import StickyHSStructure |
---|
| 172 | from sans.models.DiamCylFunc import DiamCylFunc |
---|
| 173 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
| 174 | |
---|
| 175 | self.model = SphereModel() |
---|
| 176 | self.model2 = StickyHSStructure() |
---|
| 177 | self.model3 = MultiplicationModel(self.model, self.model2) |
---|
| 178 | self.modelD = DiamCylFunc() |
---|
| 179 | |
---|
| 180 | #Radius of model1.calculate_ER should be equal to the output/2 of DiamFunctions |
---|
| 181 | def test_multplication_radius(self): |
---|
| 182 | """ |
---|
| 183 | test multiplication model (check the effective radius & the output |
---|
| 184 | of the multiplication) |
---|
| 185 | """ |
---|
| 186 | self.model.setParam("radius", 60) |
---|
| 187 | modelDrun = 60 |
---|
| 188 | self.model2.setParam("volfraction", 0.2) |
---|
| 189 | self.model2.setParam("effect_radius", modelDrun ) |
---|
| 190 | |
---|
| 191 | #Compare new method with old method |
---|
| 192 | self.assertEqual(self.model3.run(0.1), self.model.run(0.1)*self.model2.run(0.1)) |
---|
| 193 | |
---|
| 194 | #Compare radius from two different calculations. Note: modelD.run(0.0) is DIAMETER |
---|
| 195 | self.assertEqual(self.model.calculate_ER(), modelDrun) |
---|
[c9636f7] | 196 | |
---|
[ec38f27] | 197 | |
---|
| 198 | def testMultiplicationParam(self): |
---|
| 199 | """ Test Multiplication (check the parameters)""" |
---|
| 200 | ## test details dictionary |
---|
| 201 | |
---|
[c9636f7] | 202 | ## test parameters list |
---|
| 203 | list3= self.model3.getParamList() |
---|
[ec38f27] | 204 | |
---|
| 205 | for item in self.model.getParamList(): |
---|
[c9636f7] | 206 | self.assert_(item in list3) |
---|
| 207 | for item in self.model2.getParamList(): |
---|
[ec38f27] | 208 | #model3 parameters should not include effect_radius* |
---|
| 209 | if not 'effect_radius' in item: |
---|
| 210 | self.assert_(item in list3) |
---|
[c9636f7] | 211 | |
---|
| 212 | ## test set value for parameters and get paramaters |
---|
| 213 | self.model3.setParam("scale", 15) |
---|
| 214 | self.assertEqual(self.model3.getParam("scale"), 15) |
---|
| 215 | self.model3.setParam("radius", 20) |
---|
| 216 | self.assertEqual(self.model3.getParam("radius"), 20) |
---|
| 217 | self.model3.setParam("radius.width", 15) |
---|
| 218 | self.assertEqual(self.model3.getParam("radius.width"), 15) |
---|
| 219 | |
---|
| 220 | ## Dispersity |
---|
| 221 | list3= self.model3.getDispParamList() |
---|
| 222 | self.assertEqual(list3, ['radius.npts', 'radius.nsigmas', 'radius.width']) |
---|
| 223 | |
---|
| 224 | from sans.models.dispersion_models import ArrayDispersion |
---|
| 225 | disp_th = ArrayDispersion() |
---|
| 226 | |
---|
| 227 | values_th = numpy.zeros(100) |
---|
| 228 | weights = numpy.zeros(100) |
---|
| 229 | for i in range(100): |
---|
| 230 | values_th[i]=(math.pi/99.0*i) |
---|
| 231 | weights[i]=(1.0) |
---|
| 232 | |
---|
| 233 | disp_th.set_weights(values_th, weights) |
---|
| 234 | |
---|
| 235 | self.model3.set_dispersion('radius', disp_th) |
---|
| 236 | |
---|
| 237 | val_1d = self.model3.run(math.sqrt(0.0002)) |
---|
| 238 | val_2d = self.model3.runXY([0.01,0.01]) |
---|
| 239 | |
---|
| 240 | self.assertTrue(math.fabs(val_1d-val_2d)/val_1d < 0.02) |
---|
| 241 | model4= self.model3.clone() |
---|
| 242 | self.assertEqual(model4.getParam("radius"), 20) |
---|
| 243 | |
---|
[ec38f27] | 244 | class TestsphereHayterM(unittest.TestCase): |
---|
| 245 | """ |
---|
| 246 | Unit tests for SphereModel(Q) * HayterMSAStructure(Q) |
---|
| 247 | """ |
---|
| 248 | def setUp(self): |
---|
| 249 | from sans.models.SphereModel import SphereModel |
---|
| 250 | from sans.models.HayterMSAStructure import HayterMSAStructure |
---|
| 251 | from sans.models.DiamCylFunc import DiamCylFunc |
---|
| 252 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
| 253 | |
---|
| 254 | self.model = SphereModel() |
---|
| 255 | self.model2 = HayterMSAStructure() |
---|
| 256 | self.model3 = MultiplicationModel(self.model, self.model2) |
---|
| 257 | self.modelD = DiamCylFunc() |
---|
| 258 | |
---|
| 259 | #Radius of model1.calculate_ER should be equal to the output/2 of DiamFunctions |
---|
| 260 | def test_multplication_radius(self): |
---|
| 261 | """ |
---|
| 262 | test multiplication model (check the effective radius & the output |
---|
| 263 | of the multiplication) |
---|
| 264 | """ |
---|
| 265 | self.model.setParam("radius", 60) |
---|
| 266 | modelDrun = 60 |
---|
| 267 | self.model2.setParam("volfraction", 0.2) |
---|
| 268 | self.model2.setParam("effect_radius", modelDrun ) |
---|
| 269 | |
---|
| 270 | #Compare new method with old method |
---|
| 271 | self.assertEqual(self.model3.run(0.1), self.model.run(0.1)*self.model2.run(0.1)) |
---|
| 272 | |
---|
| 273 | #Compare radius from two different calculations. Note: modelD.run(0.0) is DIAMETER |
---|
| 274 | self.assertEqual(self.model.calculate_ER(), modelDrun) |
---|
| 275 | |
---|
| 276 | |
---|
| 277 | def testMultiplicationParam(self): |
---|
| 278 | """ Test Multiplication (check the parameters)""" |
---|
| 279 | ## test details dictionary |
---|
| 280 | |
---|
| 281 | ## test parameters list |
---|
| 282 | list3= self.model3.getParamList() |
---|
| 283 | |
---|
| 284 | for item in self.model.getParamList(): |
---|
| 285 | self.assert_(item in list3) |
---|
| 286 | for item in self.model2.getParamList(): |
---|
| 287 | #model3 parameters should not include effect_radius* |
---|
| 288 | if not 'effect_radius' in item: |
---|
| 289 | self.assert_(item in list3) |
---|
| 290 | |
---|
| 291 | ## test set value for parameters and get paramaters |
---|
| 292 | self.model3.setParam("scale", 15) |
---|
| 293 | self.assertEqual(self.model3.getParam("scale"), 15) |
---|
| 294 | self.model3.setParam("radius", 20) |
---|
| 295 | self.assertEqual(self.model3.getParam("radius"), 20) |
---|
| 296 | self.model3.setParam("radius.width", 15) |
---|
| 297 | self.assertEqual(self.model3.getParam("radius.width"), 15) |
---|
| 298 | |
---|
| 299 | ## Dispersity |
---|
| 300 | list3= self.model3.getDispParamList() |
---|
| 301 | self.assertEqual(list3, ['radius.npts', 'radius.nsigmas', 'radius.width']) |
---|
| 302 | |
---|
| 303 | from sans.models.dispersion_models import ArrayDispersion |
---|
| 304 | disp_th = ArrayDispersion() |
---|
| 305 | |
---|
| 306 | values_th = numpy.zeros(100) |
---|
| 307 | weights = numpy.zeros(100) |
---|
| 308 | for i in range(100): |
---|
| 309 | values_th[i]=(math.pi/99.0*i) |
---|
| 310 | weights[i]=(1.0) |
---|
| 311 | |
---|
| 312 | disp_th.set_weights(values_th, weights) |
---|
| 313 | |
---|
| 314 | self.model3.set_dispersion('radius', disp_th) |
---|
| 315 | |
---|
| 316 | val_1d = self.model3.run(math.sqrt(0.0002)) |
---|
| 317 | val_2d = self.model3.runXY([0.01,0.01]) |
---|
| 318 | |
---|
| 319 | self.assertTrue(math.fabs(val_1d-val_2d)/val_1d < 0.02) |
---|
| 320 | |
---|
| 321 | model4= self.model3.clone() |
---|
| 322 | self.assertEqual(model4.getParam("radius"), 20) |
---|
| 323 | |
---|
| 324 | ### P*S with cylinder model |
---|
| 325 | class TestcylinderSuareW(unittest.TestCase): |
---|
| 326 | """ |
---|
| 327 | Unit tests for CylinderModel(Q) * SquareWellStructure(Q) |
---|
| 328 | """ |
---|
| 329 | def setUp(self): |
---|
| 330 | from sans.models.CylinderModel import CylinderModel |
---|
| 331 | from sans.models.SquareWellStructure import SquareWellStructure |
---|
| 332 | from sans.models.DiamCylFunc import DiamCylFunc |
---|
| 333 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
| 334 | |
---|
| 335 | self.model = CylinderModel() |
---|
| 336 | self.model2 = SquareWellStructure() |
---|
| 337 | self.model3 = MultiplicationModel(self.model, self.model2) |
---|
| 338 | self.modelD = DiamCylFunc() |
---|
| 339 | |
---|
| 340 | #Radius of model1.calculate_ER should be equal to the output/2 of DiamFunctions |
---|
| 341 | def test_multplication_radius(self): |
---|
| 342 | """ |
---|
| 343 | test multiplication model (check the effective radius & the output |
---|
| 344 | of the multiplication) |
---|
| 345 | """ |
---|
| 346 | self.model.setParam("radius", 60) |
---|
| 347 | self.modelD.setParam("radius", 60) |
---|
| 348 | modelDrun = self.modelD.run(0.1)/2 |
---|
| 349 | self.model2.setParam("volfraction", 0.2) |
---|
| 350 | self.model2.setParam("effect_radius", modelDrun) |
---|
| 351 | |
---|
| 352 | #Compare new method with old method |
---|
| 353 | self.assertEqual(self.model3.run(0.1), self.model.run(0.1)*self.model2.run(0.1)) |
---|
| 354 | |
---|
| 355 | #Compare radius from two different calculations. Note: modelD.run(0.0) is DIAMETER |
---|
| 356 | self.assertEqual(self.model.calculate_ER(), modelDrun) |
---|
| 357 | |
---|
| 358 | |
---|
| 359 | def testMultiplicationParam(self): |
---|
| 360 | """ Test Multiplication (check the setparameters and the run & runXY w/ array dispersion)""" |
---|
| 361 | ## test details dictionary |
---|
| 362 | |
---|
| 363 | ## test parameters list |
---|
| 364 | list3= self.model3.getParamList() |
---|
| 365 | |
---|
| 366 | for item in self.model.getParamList(): |
---|
| 367 | self.assert_(item in list3) |
---|
| 368 | for item in self.model2.getParamList(): |
---|
| 369 | #model3 parameters should not include effect_radius* |
---|
| 370 | if not 'effect_radius' in item: |
---|
| 371 | self.assert_(item in list3) |
---|
| 372 | |
---|
| 373 | ## test set value for parameters and get paramaters |
---|
| 374 | self.model3.setParam("scale", 15) |
---|
| 375 | self.assertEqual(self.model3.getParam("scale"), 15) |
---|
| 376 | self.model3.setParam("radius", 20) |
---|
| 377 | self.assertEqual(self.model3.getParam("radius"), 20) |
---|
| 378 | self.model3.setParam("radius.width", 15) |
---|
| 379 | self.assertEqual(self.model3.getParam("radius.width"), 15) |
---|
| 380 | |
---|
| 381 | ## Dispersity |
---|
| 382 | list3= self.model3.getDispParamList() |
---|
| 383 | self.assertEqual(list3, ['radius.npts', 'radius.nsigmas', 'radius.width', 'length.npts', \ |
---|
| 384 | 'length.nsigmas', 'length.width', 'cyl_theta.npts', 'cyl_theta.nsigmas', 'cyl_theta.width',\ |
---|
| 385 | 'cyl_phi.npts', 'cyl_phi.nsigmas', 'cyl_phi.width']) |
---|
| 386 | |
---|
| 387 | from sans.models.dispersion_models import ArrayDispersion |
---|
| 388 | disp_th = ArrayDispersion() |
---|
| 389 | |
---|
| 390 | values_th = numpy.zeros(100) |
---|
| 391 | weights = numpy.zeros(100) |
---|
| 392 | for i in range(100): |
---|
| 393 | values_th[i]=(math.pi/99.0*i) |
---|
| 394 | weights[i]=(1.0) |
---|
| 395 | |
---|
| 396 | disp_th.set_weights(values_th, weights) |
---|
| 397 | |
---|
| 398 | self.model3.set_dispersion('radius', disp_th) |
---|
| 399 | |
---|
| 400 | model4= self.model3.clone() |
---|
| 401 | self.assertEqual(model4.getParam("radius"), 20) |
---|
| 402 | |
---|
| 403 | class TestcylinderHardS(unittest.TestCase): |
---|
| 404 | """ |
---|
| 405 | Unit tests for CylinderModel(Q) * HardsphereStructure(Q) |
---|
| 406 | """ |
---|
| 407 | def setUp(self): |
---|
| 408 | from sans.models.CylinderModel import CylinderModel |
---|
| 409 | from sans.models.HardsphereStructure import HardsphereStructure |
---|
| 410 | from sans.models.DiamCylFunc import DiamCylFunc |
---|
| 411 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
| 412 | |
---|
| 413 | self.model = CylinderModel() |
---|
| 414 | self.model2 = HardsphereStructure() |
---|
| 415 | self.model3 = MultiplicationModel(self.model, self.model2) |
---|
| 416 | self.modelD = DiamCylFunc() |
---|
| 417 | |
---|
| 418 | #Radius of model1.calculate_ER should be equal to the output/2 of DiamFunctions |
---|
| 419 | def test_multplication_radius(self): |
---|
| 420 | """ |
---|
| 421 | test multiplication model (check the effective radius & the output |
---|
| 422 | of the multiplication) |
---|
| 423 | """ |
---|
| 424 | self.model.setParam("radius", 60) |
---|
| 425 | self.modelD.setParam("radius", 60) |
---|
| 426 | modelDrun = self.modelD.run(0.1)/2 |
---|
| 427 | self.model2.setParam("volfraction", 0.2) |
---|
| 428 | self.model2.setParam("effect_radius", modelDrun ) |
---|
| 429 | |
---|
| 430 | #Compare new method with old method |
---|
| 431 | self.assertEqual(self.model3.run(0.1), self.model.run(0.1)*self.model2.run(0.1)) |
---|
| 432 | |
---|
| 433 | #Compare radius from two different calculations. Note: modelD.run(0.0) is DIAMETER |
---|
| 434 | self.assertEqual(self.model.calculate_ER(), modelDrun) |
---|
| 435 | |
---|
| 436 | |
---|
| 437 | def testMultiplicationParam(self): |
---|
| 438 | """ Test Multiplication """ |
---|
| 439 | ## test details dictionary |
---|
| 440 | |
---|
| 441 | ## test parameters list |
---|
| 442 | list3= self.model3.getParamList() |
---|
| 443 | |
---|
| 444 | for item in self.model.getParamList(): |
---|
| 445 | self.assert_(item in list3) |
---|
| 446 | for item in self.model2.getParamList(): |
---|
| 447 | #model3 parameters should not include effect_radius* |
---|
| 448 | if not 'effect_radius' in item: |
---|
| 449 | self.assert_(item in list3) |
---|
| 450 | |
---|
| 451 | ## test set value for parameters and get paramaters |
---|
| 452 | self.model3.setParam("scale", 15) |
---|
| 453 | self.assertEqual(self.model3.getParam("scale"), 15) |
---|
| 454 | self.model3.setParam("radius", 20) |
---|
| 455 | self.assertEqual(self.model3.getParam("radius"), 20) |
---|
| 456 | self.model3.setParam("radius.width", 15) |
---|
| 457 | self.assertEqual(self.model3.getParam("radius.width"), 15) |
---|
| 458 | |
---|
| 459 | ## Dispersity |
---|
| 460 | list3= self.model3.getDispParamList() |
---|
| 461 | self.assertEqual(list3, ['radius.npts', 'radius.nsigmas', 'radius.width', 'length.npts', \ |
---|
| 462 | 'length.nsigmas', 'length.width', 'cyl_theta.npts', 'cyl_theta.nsigmas', 'cyl_theta.width',\ |
---|
| 463 | 'cyl_phi.npts', 'cyl_phi.nsigmas', 'cyl_phi.width']) |
---|
| 464 | |
---|
| 465 | from sans.models.dispersion_models import ArrayDispersion |
---|
| 466 | disp_th = ArrayDispersion() |
---|
| 467 | |
---|
| 468 | values_th = numpy.zeros(100) |
---|
| 469 | weights = numpy.zeros(100) |
---|
| 470 | for i in range(100): |
---|
| 471 | values_th[i]=(math.pi/99.0*i) |
---|
| 472 | weights[i]=(1.0) |
---|
| 473 | |
---|
| 474 | disp_th.set_weights(values_th, weights) |
---|
| 475 | |
---|
| 476 | self.model3.set_dispersion('radius', disp_th) |
---|
| 477 | |
---|
| 478 | |
---|
| 479 | model4= self.model3.clone() |
---|
| 480 | self.assertEqual(model4.getParam("radius"), 20) |
---|
| 481 | class TestcylinderSHS(unittest.TestCase): |
---|
| 482 | """ |
---|
| 483 | Unit tests for SphereModel(Q) * StickyHSStructure(Q) |
---|
| 484 | """ |
---|
| 485 | def setUp(self): |
---|
| 486 | from sans.models.CylinderModel import CylinderModel |
---|
| 487 | from sans.models.StickyHSStructure import StickyHSStructure |
---|
| 488 | from sans.models.DiamCylFunc import DiamCylFunc |
---|
| 489 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
| 490 | |
---|
| 491 | self.model = CylinderModel() |
---|
| 492 | self.model2 = StickyHSStructure() |
---|
| 493 | self.model3 = MultiplicationModel(self.model, self.model2) |
---|
| 494 | self.modelD = DiamCylFunc() |
---|
| 495 | |
---|
| 496 | #Radius of model1.calculate_ER should be equal to the output/2 of DiamFunctions |
---|
| 497 | def test_multplication_radius(self): |
---|
| 498 | """ |
---|
| 499 | test multiplication model (check the effective radius & the output |
---|
| 500 | of the multiplication) |
---|
| 501 | """ |
---|
| 502 | self.model.setParam("radius", 60) |
---|
| 503 | self.modelD.setParam("radius", 60) |
---|
| 504 | modelDrun = self.modelD.run(0.1)/2 |
---|
| 505 | self.model2.setParam("volfraction", 0.2) |
---|
| 506 | self.model2.setParam("effect_radius", modelDrun ) |
---|
| 507 | |
---|
| 508 | #Compare new method with old method |
---|
| 509 | self.assertEqual(self.model3.run(0.1), self.model.run(0.1)*self.model2.run(0.1)) |
---|
| 510 | |
---|
| 511 | #Compare radius from two different calculations. Note: modelD.run(0.0) is DIAMETER |
---|
| 512 | self.assertEqual(self.model.calculate_ER(), modelDrun) |
---|
| 513 | |
---|
| 514 | |
---|
| 515 | def testMultiplicationParam(self): |
---|
| 516 | """ Test Multiplication (check the parameters)""" |
---|
| 517 | ## test details dictionary |
---|
| 518 | |
---|
| 519 | ## test parameters list |
---|
| 520 | list3= self.model3.getParamList() |
---|
| 521 | |
---|
| 522 | for item in self.model.getParamList(): |
---|
| 523 | self.assert_(item in list3) |
---|
| 524 | for item in self.model2.getParamList(): |
---|
| 525 | #model3 parameters should not include effect_radius* |
---|
| 526 | if not 'effect_radius' in item: |
---|
| 527 | self.assert_(item in list3) |
---|
| 528 | |
---|
| 529 | ## test set value for parameters and get paramaters |
---|
| 530 | self.model3.setParam("scale", 15) |
---|
| 531 | self.assertEqual(self.model3.getParam("scale"), 15) |
---|
| 532 | self.model3.setParam("radius", 20) |
---|
| 533 | self.assertEqual(self.model3.getParam("radius"), 20) |
---|
| 534 | self.model3.setParam("radius.width", 15) |
---|
| 535 | self.assertEqual(self.model3.getParam("radius.width"), 15) |
---|
| 536 | |
---|
| 537 | ## Dispersity |
---|
| 538 | list3= self.model3.getDispParamList() |
---|
| 539 | self.assertEqual(list3, ['radius.npts', 'radius.nsigmas', 'radius.width', 'length.npts', \ |
---|
| 540 | 'length.nsigmas', 'length.width', 'cyl_theta.npts', 'cyl_theta.nsigmas', 'cyl_theta.width',\ |
---|
| 541 | 'cyl_phi.npts', 'cyl_phi.nsigmas', 'cyl_phi.width']) |
---|
| 542 | |
---|
| 543 | from sans.models.dispersion_models import ArrayDispersion |
---|
| 544 | disp_th = ArrayDispersion() |
---|
| 545 | |
---|
| 546 | values_th = numpy.zeros(100) |
---|
| 547 | weights = numpy.zeros(100) |
---|
| 548 | for i in range(100): |
---|
| 549 | values_th[i]=(math.pi/99.0*i) |
---|
| 550 | weights[i]=(1.0) |
---|
| 551 | |
---|
| 552 | disp_th.set_weights(values_th, weights) |
---|
| 553 | |
---|
| 554 | self.model3.set_dispersion('radius', disp_th) |
---|
| 555 | |
---|
| 556 | model4= self.model3.clone() |
---|
| 557 | self.assertEqual(model4.getParam("radius"), 20) |
---|
| 558 | |
---|
| 559 | class TestcylinderHayterM(unittest.TestCase): |
---|
| 560 | """ |
---|
| 561 | Unit tests for SphereModel(Q) * HayterMSAStructure(Q) |
---|
| 562 | """ |
---|
| 563 | def setUp(self): |
---|
| 564 | from sans.models.CylinderModel import CylinderModel |
---|
| 565 | from sans.models.HayterMSAStructure import HayterMSAStructure |
---|
| 566 | from sans.models.DiamCylFunc import DiamCylFunc |
---|
| 567 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
| 568 | |
---|
| 569 | self.model = CylinderModel() |
---|
| 570 | self.model2 = HayterMSAStructure() |
---|
| 571 | self.model3 = MultiplicationModel(self.model, self.model2) |
---|
| 572 | self.modelD = DiamCylFunc() |
---|
| 573 | |
---|
| 574 | #Radius of model1.calculate_ER should be equal to the output/2 of DiamFunctions |
---|
| 575 | def test_multplication_radius(self): |
---|
| 576 | """ |
---|
| 577 | test multiplication model (check the effective radius & the output |
---|
| 578 | of the multiplication) |
---|
| 579 | """ |
---|
| 580 | self.model.setParam("radius", 60) |
---|
| 581 | self.modelD.setParam("radius", 60) |
---|
| 582 | modelDrun = self.modelD.run(0.1)/2 |
---|
| 583 | self.model2.setParam("volfraction", 0.2) |
---|
| 584 | self.model2.setParam("effect_radius", modelDrun ) |
---|
| 585 | |
---|
| 586 | #Compare new method with old method |
---|
| 587 | self.assertEqual(self.model3.run(0.1), self.model.run(0.1)*self.model2.run(0.1)) |
---|
| 588 | |
---|
| 589 | #Compare radius from two different calculations. Note: modelD.run(0.0) is DIAMETER |
---|
| 590 | self.assertEqual(self.model.calculate_ER(), modelDrun) |
---|
| 591 | |
---|
| 592 | |
---|
| 593 | def testMultiplicationParam(self): |
---|
| 594 | """ Test Multiplication (check the parameters)""" |
---|
| 595 | ## test details dictionary |
---|
| 596 | |
---|
| 597 | ## test parameters list |
---|
| 598 | list3= self.model3.getParamList() |
---|
| 599 | |
---|
| 600 | for item in self.model.getParamList(): |
---|
| 601 | self.assert_(item in list3) |
---|
| 602 | for item in self.model2.getParamList(): |
---|
| 603 | #model3 parameters should not include effect_radius* |
---|
| 604 | if not 'effect_radius' in item: |
---|
| 605 | self.assert_(item in list3) |
---|
| 606 | |
---|
| 607 | ## test set value for parameters and get paramaters |
---|
| 608 | self.model3.setParam("scale", 15) |
---|
| 609 | self.assertEqual(self.model3.getParam("scale"), 15) |
---|
| 610 | self.model3.setParam("radius", 20) |
---|
| 611 | self.assertEqual(self.model3.getParam("radius"), 20) |
---|
| 612 | self.model3.setParam("radius.width", 15) |
---|
| 613 | self.assertEqual(self.model3.getParam("radius.width"), 15) |
---|
| 614 | |
---|
| 615 | ## Dispersity |
---|
| 616 | list3= self.model3.getDispParamList() |
---|
| 617 | self.assertEqual(list3, ['radius.npts', 'radius.nsigmas', 'radius.width', 'length.npts', \ |
---|
| 618 | 'length.nsigmas', 'length.width', 'cyl_theta.npts', 'cyl_theta.nsigmas', 'cyl_theta.width',\ |
---|
| 619 | 'cyl_phi.npts', 'cyl_phi.nsigmas', 'cyl_phi.width']) |
---|
| 620 | |
---|
| 621 | from sans.models.dispersion_models import ArrayDispersion |
---|
| 622 | disp_th = ArrayDispersion() |
---|
| 623 | |
---|
| 624 | values_th = numpy.zeros(100) |
---|
| 625 | weights = numpy.zeros(100) |
---|
| 626 | for i in range(100): |
---|
| 627 | values_th[i]=(math.pi/99.0*i) |
---|
| 628 | weights[i]=(1.0) |
---|
| 629 | |
---|
| 630 | disp_th.set_weights(values_th, weights) |
---|
| 631 | |
---|
| 632 | self.model3.set_dispersion('radius', disp_th) |
---|
| 633 | |
---|
| 634 | model4= self.model3.clone() |
---|
| 635 | self.assertEqual(model4.getParam("radius"), 20) |
---|
| 636 | |
---|
| 637 | |
---|
[c9636f7] | 638 | if __name__ == '__main__': |
---|
| 639 | unittest.main() |
---|