[02cb31a] | 1 | """ |
---|
| 2 | Unit tests for specific oriented models |
---|
| 3 | @copyright: University of Tennessee, for the DANSE project |
---|
| 4 | """ |
---|
| 5 | |
---|
| 6 | import unittest, math, sys |
---|
| 7 | |
---|
| 8 | # Disable "missing docstring" complaint |
---|
| 9 | # pylint: disable-msg=C0111 |
---|
| 10 | # Disable "too many methods" complaint |
---|
| 11 | # pylint: disable-msg=R0904 |
---|
| 12 | # Disable "could be a function" complaint |
---|
| 13 | # pylint: disable-msg=R0201 |
---|
| 14 | # pylint: disable-msg=W0702 |
---|
| 15 | |
---|
| 16 | try: |
---|
| 17 | import VolumeCanvas |
---|
| 18 | print "Testing local version" |
---|
| 19 | except: |
---|
| 20 | print sys.exc_value |
---|
| 21 | #testing the version that is working on |
---|
| 22 | print "Testing installed version" |
---|
| 23 | import sans.realspace.VolumeCanvas as VolumeCanvas |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | class TestSphere(unittest.TestCase): |
---|
| 27 | """ Tests for oriented (2D) systems """ |
---|
| 28 | |
---|
| 29 | def setUp(self): |
---|
| 30 | """ |
---|
| 31 | Set up canvas |
---|
| 32 | """ |
---|
| 33 | from sans.models.SphereModel import SphereModel |
---|
| 34 | self.model = VolumeCanvas.VolumeCanvas() |
---|
| 35 | |
---|
| 36 | handle = self.model.add('sphere') |
---|
| 37 | |
---|
| 38 | radius = 10 |
---|
| 39 | density = .1 |
---|
| 40 | |
---|
| 41 | ana = SphereModel() |
---|
| 42 | ana.setParam('scale', 1.0) |
---|
| 43 | ana.setParam('contrast', 1.0) |
---|
| 44 | ana.setParam('background', 0.0) |
---|
| 45 | ana.setParam('radius', radius) |
---|
| 46 | self.ana = ana |
---|
| 47 | |
---|
| 48 | self.model.setParam('lores_density', density) |
---|
| 49 | self.model.setParam('%s.radius' % handle, radius) |
---|
| 50 | self.model.setParam('scale' , 1.0) |
---|
| 51 | self.model.setParam('%s.contrast' % handle, 1.0) |
---|
| 52 | self.model.setParam('background' , 0.0) |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | def testdefault(self): |
---|
| 56 | """ Testing sphere """ |
---|
| 57 | # Default orientation |
---|
| 58 | ana_val = self.ana.runXY([0.1, 0.1]) |
---|
| 59 | sim_val = self.model.getIq2D(0.1, 0.1) |
---|
| 60 | self.assert_( math.fabs(sim_val/ana_val-1.0)<0.1 ) |
---|
| 61 | |
---|
[3c75696] | 62 | class TestCylinderAddObject(unittest.TestCase): |
---|
| 63 | """ Tests for oriented (2D) systems """ |
---|
| 64 | |
---|
| 65 | def setUp(self): |
---|
| 66 | """ Set up cylinder model """ |
---|
| 67 | from sans.models.CylinderModel import CylinderModel |
---|
| 68 | radius = 5 |
---|
| 69 | length = 40 |
---|
| 70 | density = 20 |
---|
| 71 | |
---|
| 72 | # Analytical model |
---|
| 73 | self.ana = CylinderModel() |
---|
| 74 | self.ana.setParam('scale', 1.0) |
---|
| 75 | self.ana.setParam('contrast', 1.0) |
---|
| 76 | self.ana.setParam('background', 0.0) |
---|
| 77 | self.ana.setParam('radius', radius) |
---|
| 78 | self.ana.setParam('length', length) |
---|
| 79 | |
---|
| 80 | # Simulation model |
---|
| 81 | self.model = VolumeCanvas.VolumeCanvas() |
---|
| 82 | cyl = VolumeCanvas.CylinderDescriptor() |
---|
| 83 | self.handle = self.model.addObject(cyl) |
---|
| 84 | self.model.setParam('lores_density', density) |
---|
| 85 | self.model.setParam('%s.radius' % self.handle, radius) |
---|
| 86 | self.model.setParam('%s.length' % self.handle, length) |
---|
| 87 | self.model.setParam('scale' , 1.0) |
---|
| 88 | self.model.setParam('%s.contrast' % self.handle, 1.0) |
---|
| 89 | self.model.setParam('background' , 0.0) |
---|
| 90 | |
---|
| 91 | def testalongY(self): |
---|
| 92 | """ Testing cylinder along Y axis """ |
---|
| 93 | self.ana.setParam('cyl_theta', math.pi/2.0) |
---|
| 94 | self.ana.setParam('cyl_phi', math.pi/2.0) |
---|
| 95 | |
---|
| 96 | self.model.setParam('%s.orientation' % self.handle, [0,0,0]) |
---|
| 97 | |
---|
| 98 | ana_val = self.ana.runXY([0.1, 0.2]) |
---|
| 99 | sim_val = self.model.getIq2D(0.1, 0.2) |
---|
| 100 | #print ana_val, sim_val, sim_val/ana_val |
---|
| 101 | |
---|
| 102 | self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) |
---|
| 103 | |
---|
| 104 | |
---|
[02cb31a] | 105 | class TestCylinder(unittest.TestCase): |
---|
| 106 | """ Tests for oriented (2D) systems """ |
---|
| 107 | |
---|
| 108 | def setUp(self): |
---|
| 109 | """ Set up cylinder model """ |
---|
| 110 | from sans.models.CylinderModel import CylinderModel |
---|
| 111 | radius = 5 |
---|
| 112 | length = 40 |
---|
| 113 | density = 20 |
---|
| 114 | |
---|
| 115 | # Analytical model |
---|
| 116 | self.ana = CylinderModel() |
---|
| 117 | self.ana.setParam('scale', 1.0) |
---|
| 118 | self.ana.setParam('contrast', 1.0) |
---|
| 119 | self.ana.setParam('background', 0.0) |
---|
| 120 | self.ana.setParam('radius', radius) |
---|
| 121 | self.ana.setParam('length', length) |
---|
| 122 | |
---|
| 123 | # Simulation model |
---|
| 124 | self.model = VolumeCanvas.VolumeCanvas() |
---|
| 125 | self.handle = self.model.add('cylinder') |
---|
| 126 | self.model.setParam('lores_density', density) |
---|
| 127 | self.model.setParam('%s.radius' % self.handle, radius) |
---|
| 128 | self.model.setParam('%s.length' % self.handle, length) |
---|
| 129 | self.model.setParam('scale' , 1.0) |
---|
| 130 | self.model.setParam('%s.contrast' % self.handle, 1.0) |
---|
| 131 | self.model.setParam('background' , 0.0) |
---|
| 132 | |
---|
| 133 | def testalongY(self): |
---|
| 134 | """ Testing cylinder along Y axis """ |
---|
| 135 | self.ana.setParam('cyl_theta', math.pi/2.0) |
---|
| 136 | self.ana.setParam('cyl_phi', math.pi/2.0) |
---|
| 137 | |
---|
| 138 | self.model.setParam('%s.orientation' % self.handle, [0,0,0]) |
---|
| 139 | |
---|
| 140 | ana_val = self.ana.runXY([0.1, 0.2]) |
---|
[1b0707e1] | 141 | sim_val = self.model.getIq2D(0.1, 0.2) |
---|
[02cb31a] | 142 | #print ana_val, sim_val, sim_val/ana_val |
---|
| 143 | |
---|
| 144 | self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) |
---|
| 145 | |
---|
| 146 | def testalongZ(self): |
---|
| 147 | """ Testing cylinder along Z axis """ |
---|
| 148 | self.ana.setParam('cyl_theta', 0) |
---|
| 149 | self.ana.setParam('cyl_phi', 0) |
---|
| 150 | |
---|
| 151 | self.model.setParam('%s.orientation' % self.handle, [90,0,0]) |
---|
| 152 | |
---|
| 153 | ana_val = self.ana.runXY([0.1, 0.2]) |
---|
[1b0707e1] | 154 | sim_val = self.model.getIq2D(0.1, 0.2) |
---|
[02cb31a] | 155 | #print ana_val, sim_val, sim_val/ana_val |
---|
| 156 | |
---|
| 157 | self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) |
---|
| 158 | |
---|
| 159 | def testalongX(self): |
---|
| 160 | """ Testing cylinder along X axis """ |
---|
| 161 | self.ana.setParam('cyl_theta', 1.57) |
---|
| 162 | self.ana.setParam('cyl_phi', 0) |
---|
| 163 | |
---|
| 164 | self.model.setParam('%s.orientation' % self.handle, [0,0,90]) |
---|
| 165 | |
---|
| 166 | ana_val = self.ana.runXY([0.1, 0.2]) |
---|
[1b0707e1] | 167 | sim_val = self.model.getIq2D(0.1, 0.2) |
---|
[02cb31a] | 168 | #print ana_val, sim_val, sim_val/ana_val |
---|
| 169 | |
---|
| 170 | self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) |
---|
| 171 | |
---|
| 172 | class TestEllipsoid(unittest.TestCase): |
---|
| 173 | """ Tests for oriented (2D) systems """ |
---|
| 174 | |
---|
| 175 | def setUp(self): |
---|
| 176 | """ Set up ellipsoid """ |
---|
| 177 | from sans.models.EllipsoidModel import EllipsoidModel |
---|
| 178 | |
---|
| 179 | radius_a = 60 |
---|
| 180 | radius_b = 10 |
---|
| 181 | density = 30 |
---|
| 182 | |
---|
| 183 | self.ana = EllipsoidModel() |
---|
| 184 | self.ana.setParam('scale', 1.0) |
---|
| 185 | self.ana.setParam('contrast', 1.0) |
---|
| 186 | self.ana.setParam('background', 0.0) |
---|
| 187 | self.ana.setParam('radius_a', radius_a) |
---|
| 188 | self.ana.setParam('radius_b', radius_b) |
---|
[f980d4a] | 189 | # Default orientation is there=1.57, phi=0 |
---|
| 190 | # Radius_a is along the x direction |
---|
[02cb31a] | 191 | |
---|
| 192 | canvas = VolumeCanvas.VolumeCanvas() |
---|
| 193 | canvas.setParam('lores_density', density) |
---|
| 194 | self.handle = canvas.add('ellipsoid') |
---|
| 195 | canvas.setParam('%s.radius_x' % self.handle, radius_a) |
---|
| 196 | canvas.setParam('%s.radius_y' % self.handle, radius_b) |
---|
| 197 | canvas.setParam('%s.radius_z' % self.handle, radius_b) |
---|
| 198 | canvas.setParam('scale' , 1.0) |
---|
| 199 | canvas.setParam('%s.contrast' % self.handle, 1.0) |
---|
| 200 | canvas.setParam('background' , 0.0) |
---|
| 201 | self.canvas = canvas |
---|
| 202 | |
---|
| 203 | def testalongX(self): |
---|
| 204 | """ Testing ellipsoid along X """ |
---|
| 205 | self.ana.setParam('axis_theta', 1.57) |
---|
| 206 | self.ana.setParam('axis_phi', 0) |
---|
| 207 | |
---|
| 208 | self.canvas.setParam('%s.orientation' % self.handle, [0,0,0]) |
---|
| 209 | |
---|
| 210 | ana_val = self.ana.runXY([0.1, 0.2]) |
---|
[1b0707e1] | 211 | sim_val = self.canvas.getIq2D(0.1, 0.2) |
---|
[02cb31a] | 212 | #print ana_val, sim_val, sim_val/ana_val |
---|
| 213 | |
---|
| 214 | self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) |
---|
| 215 | |
---|
| 216 | def testalongZ(self): |
---|
| 217 | """ Testing ellipsoid along Z """ |
---|
| 218 | self.ana.setParam('axis_theta', 0) |
---|
| 219 | self.ana.setParam('axis_phi', 0) |
---|
| 220 | |
---|
| 221 | self.canvas.setParam('%s.orientation' % self.handle, [0,90,0]) |
---|
| 222 | |
---|
| 223 | ana_val = self.ana.runXY([0.1, 0.2]) |
---|
[1b0707e1] | 224 | sim_val = self.canvas.getIq2D(0.1, 0.2) |
---|
[02cb31a] | 225 | #print ana_val, sim_val, sim_val/ana_val |
---|
| 226 | |
---|
| 227 | self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) |
---|
| 228 | |
---|
| 229 | def testalongY(self): |
---|
| 230 | """ Testing ellipsoid along Y """ |
---|
| 231 | self.ana.setParam('axis_theta', math.pi/2.0) |
---|
| 232 | self.ana.setParam('axis_phi', math.pi/2.0) |
---|
| 233 | |
---|
| 234 | self.canvas.setParam('%s.orientation' % self.handle, [0,0,90]) |
---|
| 235 | |
---|
| 236 | ana_val = self.ana.runXY([0.05, 0.15]) |
---|
[1b0707e1] | 237 | sim_val = self.canvas.getIq2D(0.05, 0.15) |
---|
[02cb31a] | 238 | #print ana_val, sim_val, sim_val/ana_val |
---|
| 239 | |
---|
| 240 | try: |
---|
| 241 | self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) |
---|
| 242 | except: |
---|
[a2c1196] | 243 | print "Error", ana_val, sim_val, sim_val/ana_val |
---|
[02cb31a] | 244 | raise sys.exc_type, sys.exc_value |
---|
| 245 | |
---|
| 246 | class TestCoreShell(unittest.TestCase): |
---|
| 247 | """ Tests for oriented (2D) systems """ |
---|
| 248 | |
---|
| 249 | def setUp(self): |
---|
| 250 | """ Set up zero-SLD-average core-shell model """ |
---|
| 251 | from sans.models.CoreShellModel import CoreShellModel |
---|
| 252 | |
---|
| 253 | radius = 15 |
---|
| 254 | thickness = 5 |
---|
| 255 | density = 20 |
---|
| 256 | |
---|
| 257 | core_vol = 4.0/3.0*math.pi*radius*radius*radius |
---|
| 258 | self.outer_radius = radius+thickness |
---|
| 259 | shell_vol = 4.0/3.0*math.pi*self.outer_radius*self.outer_radius*self.outer_radius - core_vol |
---|
| 260 | self.shell_sld = -1.0*core_vol/shell_vol |
---|
| 261 | |
---|
| 262 | self.density = density |
---|
| 263 | |
---|
| 264 | # Core-shell |
---|
| 265 | sphere = CoreShellModel() |
---|
| 266 | # Core radius |
---|
| 267 | sphere.setParam('radius', radius) |
---|
| 268 | # Shell thickness |
---|
| 269 | sphere.setParam('thickness', thickness) |
---|
| 270 | sphere.setParam('core_sld', 1.0) |
---|
| 271 | sphere.setParam('shell_sld', self.shell_sld) |
---|
| 272 | sphere.setParam('solvent_sld', 0.0) |
---|
| 273 | sphere.setParam('background', 0.0) |
---|
| 274 | sphere.setParam('scale', 1.0) |
---|
| 275 | self.ana = sphere |
---|
| 276 | |
---|
| 277 | canvas = VolumeCanvas.VolumeCanvas() |
---|
| 278 | canvas.setParam('lores_density', self.density) |
---|
| 279 | |
---|
| 280 | handle = canvas.add('sphere') |
---|
| 281 | canvas.setParam('%s.radius' % handle, self.outer_radius) |
---|
| 282 | canvas.setParam('%s.contrast' % handle, self.shell_sld) |
---|
| 283 | |
---|
| 284 | handle2 = canvas.add('sphere') |
---|
| 285 | canvas.setParam('%s.radius' % handle2, radius) |
---|
| 286 | canvas.setParam('%s.contrast' % handle2, 1.0) |
---|
| 287 | |
---|
| 288 | canvas.setParam('scale' , 1.0) |
---|
| 289 | canvas.setParam('background' , 0.0) |
---|
| 290 | self.canvas = canvas |
---|
[a2c1196] | 291 | |
---|
[02cb31a] | 292 | def testdefault(self): |
---|
| 293 | """ Testing default core-shell orientation """ |
---|
| 294 | ana_val = self.ana.runXY([0.1, 0.2]) |
---|
[a2c1196] | 295 | sim_val, err = self.canvas.getIq2DError(0.1, 0.2) |
---|
[02cb31a] | 296 | |
---|
| 297 | self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) |
---|
[a2c1196] | 298 | |
---|
| 299 | class TestCoreShellError(unittest.TestCase): |
---|
| 300 | """ Tests for oriented (2D) systems """ |
---|
| 301 | |
---|
| 302 | def setUp(self): |
---|
| 303 | """ Set up zero-SLD-average core-shell model """ |
---|
| 304 | from sans.models.CoreShellModel import CoreShellModel |
---|
| 305 | |
---|
| 306 | radius = 15 |
---|
| 307 | thickness = 5 |
---|
| 308 | density = 5 |
---|
| 309 | |
---|
| 310 | core_vol = 4.0/3.0*math.pi*radius*radius*radius |
---|
| 311 | self.outer_radius = radius+thickness |
---|
| 312 | shell_vol = 4.0/3.0*math.pi*self.outer_radius*self.outer_radius*self.outer_radius - core_vol |
---|
| 313 | self.shell_sld = -1.0*core_vol/shell_vol |
---|
| 314 | |
---|
| 315 | self.density = density |
---|
| 316 | |
---|
| 317 | # Core-shell |
---|
| 318 | sphere = CoreShellModel() |
---|
| 319 | # Core radius |
---|
| 320 | sphere.setParam('radius', radius) |
---|
| 321 | # Shell thickness |
---|
| 322 | sphere.setParam('thickness', thickness) |
---|
| 323 | sphere.setParam('core_sld', 1.0) |
---|
| 324 | sphere.setParam('shell_sld', self.shell_sld) |
---|
| 325 | sphere.setParam('solvent_sld', 0.0) |
---|
| 326 | sphere.setParam('background', 0.0) |
---|
| 327 | sphere.setParam('scale', 1.0) |
---|
| 328 | self.ana = sphere |
---|
| 329 | |
---|
| 330 | canvas = VolumeCanvas.VolumeCanvas() |
---|
| 331 | canvas.setParam('lores_density', self.density) |
---|
| 332 | |
---|
| 333 | handle = canvas.add('sphere') |
---|
| 334 | canvas.setParam('%s.radius' % handle, self.outer_radius) |
---|
| 335 | canvas.setParam('%s.contrast' % handle, self.shell_sld) |
---|
| 336 | |
---|
| 337 | handle2 = canvas.add('sphere') |
---|
| 338 | canvas.setParam('%s.radius' % handle2, radius) |
---|
| 339 | canvas.setParam('%s.contrast' % handle2, 1.0) |
---|
| 340 | |
---|
| 341 | canvas.setParam('scale' , 1.0) |
---|
| 342 | canvas.setParam('background' , 0.0) |
---|
| 343 | self.canvas = canvas |
---|
| 344 | |
---|
| 345 | def testdefault(self): |
---|
| 346 | """ Testing default core-shell orientation """ |
---|
| 347 | ana_val = self.ana.runXY([0.1, 0.2]) |
---|
| 348 | sim_val, err = self.canvas.getIq2DError(0.1, 0.2) |
---|
| 349 | |
---|
| 350 | self.assert_( math.fabs(sim_val-ana_val) < 3.0 * err ) |
---|
[02cb31a] | 351 | |
---|
[f98961f] | 352 | class TestRunMethods(unittest.TestCase): |
---|
| 353 | """ Tests run methods for oriented (2D) systems """ |
---|
| 354 | |
---|
| 355 | def setUp(self): |
---|
| 356 | """ Set up ellipsoid """ |
---|
| 357 | from sans.models.EllipsoidModel import EllipsoidModel |
---|
| 358 | |
---|
| 359 | radius_a = 10 |
---|
| 360 | radius_b = 15 |
---|
[a2c1196] | 361 | density = 5 |
---|
[f98961f] | 362 | |
---|
| 363 | self.ana = EllipsoidModel() |
---|
| 364 | self.ana.setParam('scale', 1.0) |
---|
| 365 | self.ana.setParam('contrast', 1.0) |
---|
| 366 | self.ana.setParam('background', 0.0) |
---|
| 367 | self.ana.setParam('radius_a', radius_a) |
---|
| 368 | self.ana.setParam('radius_b', radius_b) |
---|
| 369 | |
---|
| 370 | |
---|
| 371 | canvas = VolumeCanvas.VolumeCanvas() |
---|
| 372 | canvas.setParam('lores_density', density) |
---|
| 373 | self.handle = canvas.add('ellipsoid') |
---|
| 374 | canvas.setParam('%s.radius_x' % self.handle, radius_a) |
---|
| 375 | canvas.setParam('%s.radius_y' % self.handle, radius_b) |
---|
| 376 | canvas.setParam('%s.radius_z' % self.handle, radius_b) |
---|
| 377 | canvas.setParam('scale' , 1.0) |
---|
| 378 | canvas.setParam('%s.contrast' % self.handle, 1.0) |
---|
| 379 | canvas.setParam('background' , 0.0) |
---|
| 380 | self.canvas = canvas |
---|
| 381 | |
---|
| 382 | self.ana.setParam('axis_theta', 1.57) |
---|
| 383 | self.ana.setParam('axis_phi', 0) |
---|
| 384 | |
---|
| 385 | self.canvas.setParam('%s.orientation' % self.handle, [0,0,0]) |
---|
| 386 | |
---|
| 387 | |
---|
| 388 | def testRunXY_List(self): |
---|
| 389 | """ Testing ellipsoid along X """ |
---|
| 390 | ana_val = self.ana.runXY([0.1, 0.2]) |
---|
| 391 | sim_val = self.canvas.runXY([0.1, 0.2]) |
---|
| 392 | #print ana_val, sim_val, sim_val/ana_val |
---|
| 393 | |
---|
[a2c1196] | 394 | try: |
---|
| 395 | self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) |
---|
| 396 | except: |
---|
| 397 | print "Error", ana_val, sim_val, sim_val/ana_val |
---|
| 398 | raise sys.exc_type, sys.exc_value |
---|
[f98961f] | 399 | |
---|
| 400 | def testRunXY_float(self): |
---|
| 401 | """ Testing ellipsoid along X """ |
---|
| 402 | ana_val = self.ana.runXY(0.1) |
---|
| 403 | sim_val = self.canvas.runXY(0.1) |
---|
| 404 | #print ana_val, sim_val, sim_val/ana_val |
---|
| 405 | |
---|
[a2c1196] | 406 | try: |
---|
| 407 | self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) |
---|
| 408 | except: |
---|
| 409 | print "Error", ana_val, sim_val, sim_val/ana_val |
---|
| 410 | raise sys.exc_type, sys.exc_value |
---|
[f98961f] | 411 | |
---|
| 412 | def testRun_float(self): |
---|
| 413 | """ Testing ellipsoid along X """ |
---|
| 414 | ana_val = self.ana.run(0.1) |
---|
| 415 | sim_val = self.canvas.run(0.1) |
---|
| 416 | #print ana_val, sim_val, sim_val/ana_val |
---|
| 417 | |
---|
[a2c1196] | 418 | try: |
---|
| 419 | self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) |
---|
| 420 | except: |
---|
| 421 | print "Error", ana_val, sim_val, sim_val/ana_val |
---|
| 422 | raise sys.exc_type, sys.exc_value |
---|
[f98961f] | 423 | |
---|
| 424 | def testRun_list(self): |
---|
| 425 | """ Testing ellipsoid along X """ |
---|
| 426 | ana_val = self.ana.run([0.1, 33.0]) |
---|
| 427 | sim_val = self.canvas.run([0.1, 33.0]) |
---|
| 428 | #print ana_val, sim_val, sim_val/ana_val |
---|
| 429 | |
---|
[a2c1196] | 430 | try: |
---|
| 431 | self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) |
---|
| 432 | except: |
---|
| 433 | print "Error", ana_val, sim_val, sim_val/ana_val |
---|
| 434 | raise sys.exc_type, sys.exc_value |
---|
[f98961f] | 435 | |
---|
[883a2ef] | 436 | class TestParamChange(unittest.TestCase): |
---|
| 437 | """ Tests for oriented (2D) systems """ |
---|
| 438 | |
---|
| 439 | def setUp(self): |
---|
| 440 | """ Set up cylinder model """ |
---|
| 441 | from sans.models.CylinderModel import CylinderModel |
---|
| 442 | radius = 5 |
---|
| 443 | length = 40 |
---|
| 444 | density = 20 |
---|
| 445 | |
---|
| 446 | # Analytical model |
---|
| 447 | self.ana = CylinderModel() |
---|
| 448 | self.ana.setParam('scale', 1.0) |
---|
| 449 | self.ana.setParam('contrast', 1.0) |
---|
| 450 | self.ana.setParam('background', 0.0) |
---|
| 451 | self.ana.setParam('radius', radius) |
---|
| 452 | self.ana.setParam('length', length) |
---|
| 453 | self.ana.setParam('cyl_theta', math.pi/2.0) |
---|
| 454 | self.ana.setParam('cyl_phi', math.pi/2.0) |
---|
| 455 | |
---|
| 456 | # Simulation model |
---|
| 457 | self.model = VolumeCanvas.VolumeCanvas() |
---|
| 458 | self.handle = self.model.add('cylinder') |
---|
| 459 | self.model.setParam('lores_density', density) |
---|
| 460 | self.model.setParam('%s.radius' % self.handle, radius) |
---|
| 461 | self.model.setParam('%s.length' % self.handle, length) |
---|
| 462 | self.model.setParam('scale' , 1.0) |
---|
| 463 | self.model.setParam('%s.contrast' % self.handle, 1.0) |
---|
| 464 | self.model.setParam('background' , 0.0) |
---|
| 465 | self.model.setParam('%s.orientation' % self.handle, [0,0,0]) |
---|
| 466 | |
---|
| 467 | def testalongY(self): |
---|
| 468 | """ Test that a parameter change forces the generation |
---|
| 469 | of new space points |
---|
| 470 | """ |
---|
| 471 | ana_val = self.ana.runXY([0.1, 0.2]) |
---|
| 472 | sim_val = self.model.getIq2D(0.1, 0.2) |
---|
| 473 | |
---|
| 474 | self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) |
---|
| 475 | |
---|
| 476 | # Change the radius a re-evaluate |
---|
| 477 | self.ana.setParam('radius', 10) |
---|
| 478 | self.model.setParam('%s.radius' % self.handle, 10) |
---|
| 479 | |
---|
| 480 | ana_val = self.ana.runXY([0.1, 0.2]) |
---|
| 481 | sim_val = self.model.getIq2D(0.1, 0.2) |
---|
| 482 | self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) |
---|
[f98961f] | 483 | |
---|
| 484 | |
---|
[02cb31a] | 485 | if __name__ == '__main__': |
---|
| 486 | unittest.main() |
---|