Changeset 6b8399b in sasview for sansmodels
- Timestamp:
- Mar 26, 2008 1:49:05 PM (17 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 6cfe703
- Parents:
- f629e346
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/test/utest_nonshape.py
rf629e346 r6b8399b 36 36 self.assertEqual(self.model.run(0.0), 2.0) 37 37 self.assertEqual(self.model.run(2.0), 2.0*math.exp(-(1.0*2.0)**2/3.0)) 38 self.assertEqual(self.model.runXY(2.0), 2.0*math.exp(-(1.0*2.0)**2/3.0)) 38 39 39 40 def test2D(self): … … 79 80 value = self._func(2.0, 3.0) 80 81 self.assertEqual(self.model.run(3.0), value) 82 self.assertEqual(self.model.runXY(3.0), value) 81 83 82 84 def test2D(self): … … 118 120 value = self._func(50.0, 1.0, 0.001, 2.0) 119 121 self.assertEqual(self.model.run(2.0), value) 122 self.assertEqual(self.model.runXY(2.0), value) 120 123 121 124 # User enter zero as a value of x … … 162 165 self.assertEqual(self.model.run(0.0), 101.0) 163 166 self.assertEqual(self.model.run(2.0), self._func(100.0, 50.0, 1.0, 2.0)) 167 self.assertEqual(self.model.runXY(2.0), self._func(100.0, 50.0, 1.0, 2.0)) 164 168 165 169 def test2D(self): … … 201 205 from sans.models.DABModel import DABModel 202 206 self.model= DABModel() 203 204 def test1D(self): 205 self.model.setParam('scale', 10.0) 206 self.model.setParam('Length', 40.0) 207 self.model.setParam('background', 0.0) 208 209 self.assertEqual(self.model.run(0.0), 10.0) 210 self.assertEqual(self.model.run(2.0), self._func(10.0, 40.0, 0.0, 2.0)) 211 212 def test2D(self): 213 self.model.setParam('scale', 10.0) 214 self.model.setParam('Length', 40.0) 215 self.model.setParam('background', 0.0) 216 217 value = self._func(10.0, 40.0, 0.0, 1.0)*self._func(10.0, 40.0, 0.0, 2.0) 218 self.assertEqual(self.model.runXY([1.0,2.0]), value) 219 220 def test2Dphi(self): 221 self.model.setParam('scale', 10.0) 222 self.model.setParam('Length', 40.0) 223 self.model.setParam('background', 0.0) 224 225 x = 1.0 226 y = 2.0 227 r = math.sqrt(x**2 + y**2) 228 phi = math.atan2(y, x) 229 230 value = self._func(10.0, 40.0, 0.0, x)*self._func(10.0, 40.0, 0.0, y) 207 self.scale = 10.0 208 self.length = 40.0 209 self.back = 1.0 210 211 self.model.setParam('scale', self.scale) 212 self.model.setParam('Length', self.length) 213 self.model.setParam('background', self.back) 214 215 def test1D(self): 216 217 self.assertEqual(self.model.run(0.0), self.scale+self.back) 218 self.assertEqual(self.model.run(2.0), self._func(self.scale, self.length, self.back, 2.0)) 219 self.assertEqual(self.model.runXY(2.0), self._func(self.scale, self.length, self.back, 2.0)) 220 221 def test2D(self): 222 value = self._func(self.scale, self.length, self.back, 1.0)*self._func(self.scale, self.length, self.back, 2.0) 223 self.assertEqual(self.model.runXY([1.0,2.0]), value) 224 225 def test2Dphi(self): 226 x = 1.0 227 y = 2.0 228 r = math.sqrt(x**2 + y**2) 229 phi = math.atan2(y, x) 230 231 value = self._func(self.scale, self.length, self.back, x)*self._func(self.scale, self.length, self.back, y) 231 232 self.assertAlmostEquals(self.model.run([r, phi]), value,1) 232 233 … … 257 258 #self.assertEqual(self.model.run(0.0), 1.0) 258 259 self.assertEqual(self.model.run(2.0), self._func(math.exp(-6), 4.0, 1.0, 2.0)) 260 self.assertEqual(self.model.runXY(2.0), self._func(math.exp(-6), 4.0, 1.0, 2.0)) 259 261 260 262 def testlimit(self): … … 323 325 self.assertEqual(self.model.run(0.0), 10.1) 324 326 self.assertEqual(self.model.run(2.0), self._func(0.1,-30.0,5000.0,0.1,2.0)) 327 self.assertEqual(self.model.runXY(2.0), self._func(0.1,-30.0,5000.0,0.1,2.0)) 325 328 326 329 def test2D(self): … … 409 412 410 413 self.assertEqual(self.model.run(q), self._func(q)) 414 self.assertEqual(self.model.runXY(q), self._func(q)) 411 415 412 416 def test2D(self): … … 438 442 from sans.models.FractalModel import FractalModel 439 443 self.model= FractalModel() 440 441 def test1D(self): 442 r0 = 5.0 443 sldp = 2.0e-6 444 sldm = 6.35e-6 445 phi = 0.05 446 Df = 2 447 corr = 100.0 448 bck = 1.0 449 450 x = 0.001 451 452 self.model.setParam('scale', phi) 453 self.model.setParam('Radius', r0) 454 self.model.setParam('fractal_dim',Df) 455 self.model.setParam('corr_length', corr) 456 self.model.setParam('block_sld', sldp) 457 self.model.setParam('solvent_sld', sldm) 458 self.model.setParam('background', bck) 444 self.r0 = 5.0 445 self.sldp = 2.0e-6 446 self.sldm = 6.35e-6 447 self.phi = 0.05 448 self.Df = 2 449 self.corr = 100.0 450 self.bck = 1.0 451 452 self.model.setParam('scale', self.phi) 453 self.model.setParam('Radius', self.r0) 454 self.model.setParam('fractal_dim',self.Df) 455 self.model.setParam('corr_length', self.corr) 456 self.model.setParam('block_sld', self.sldp) 457 self.model.setParam('solvent_sld', self.sldm) 458 self.model.setParam('background', self.bck) 459 460 def _func(self, x): 461 r0 = self.r0 462 sldp = self.sldp 463 sldm = self.sldm 464 phi = self.phi 465 Df = self.Df 466 corr = self.corr 467 bck = self.bck 459 468 460 469 pq = 1.0e8*phi*4.0/3.0*math.pi*r0*r0*r0*(sldp-sldm)*(sldp-sldm)*math.pow((3*(math.sin(x*r0) - x*r0*math.cos(x*r0))/math.pow((x*r0),3)),2); … … 463 472 sq /= math.pow((x*r0),Df) * math.pow((1.0 + 1.0/(x*corr)/(x*corr)),((Df-1.0)/2.0)); 464 473 sq += 1.0; 465 466 self.assertAlmostEqual(self.model._scatterRanDom(x),pq, 8 ) 467 474 475 self.assertAlmostEqual(self.model._scatterRanDom(x), pq, 8 ) 468 476 self.assertEqual(self.model._Block(x),sq ) 469 477 470 self.assertEqual(self.model.run(x), pq*sq+bck) 478 return sq*pq+bck 479 480 def test1D(self): 481 x = 0.001 482 483 iq = self._func(x) 484 self.assertEqual(self.model.run(x), iq) 485 self.assertEqual(self.model.runXY(x), iq) 486 487 def test2D(self): 488 x = 1.0 489 y = 2.0 490 r = math.sqrt(x**2 + y**2) 491 phi = math.atan2(y, x) 492 iq_x = self._func(x) 493 iq_y = self._func(y) 494 495 self.assertEqual(self.model.run([r, phi]), iq_x*iq_y) 496 self.assertEqual(self.model.runXY([x,y]), iq_x*iq_y) 471 497 472 498 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.