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