Changeset f98961f in sasview for sansrealspace/src
- Timestamp:
- Sep 28, 2007 10:48:09 AM (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:
- 3c75696
- Parents:
- 1b0707e1
- Location:
- sansrealspace/src/realspace
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sansrealspace/src/realspace/VolumeCanvas.py
rba1d1e9 rf98961f 8 8 from sansModeling.geoshapespy import geoshapespy 9 9 10 import os.path 10 import os.path, math 11 11 12 12 class ShapeDescriptor: … … 23 23 self.params = {} 24 24 self.params["center"] = [0, 0, 0] 25 # Orientation are angular offsets in degrees with respect to X, Y, Z 25 26 self.params["orientation"] = [0, 0, 0] 26 27 # Default to lores shape … … 72 73 """ 73 74 Descriptor for a cylinder 75 Orientation: Default cylinder is along Y 74 76 """ 75 77 def __init__(self): … … 478 480 """ 479 481 Returns the value of I(q) for a given q-value 480 @param q: q-value [float] 481 @return: I(q) [float] 482 """ 483 #TODO: The right simulation function should be 484 # called according to the type of input we get. 485 # For now, only a q length is supported. 486 return getIq(q) 482 @param q: q-value ([float] or [list]) ([A-1] or [[A-1], [rad]]) 483 @return: I(q) [float] [cm-1] 484 """ 485 # Check for 1D q length 486 if q.__class__.__name__ == 'int' \ 487 or q.__class__.__name__ == 'float': 488 return self.getIq(q) 489 # Check for 2D q-value 490 elif q.__class__.__name__ == 'list': 491 # Compute (Qx, Qy) from (Q, phi) 492 # Phi is in radian and Q-values are in A-1 493 qx = q[0]*math.cos(q[1]) 494 qy = q[0]*math.sin(q[1]) 495 return self.getIq2D(qx, qy) 496 # Through an exception if it's not a 497 # type we recognize 498 else: 499 raise ValueError, "run(q): bad type for q" 500 501 def runXY(self, q = 0): 502 """ 503 Standard run command for the canvas. 504 Redirects to the correct method 505 according to the input type. 506 @param q: q-value [float] or [list] [A-1] 507 @return: I(q) [float] [cm-1] 508 """ 509 # Check for 1D q length 510 if q.__class__.__name__ == 'int' \ 511 or q.__class__.__name__ == 'float': 512 return self.getIq(q) 513 # Check for 2D q-value 514 elif q.__class__.__name__ == 'list': 515 return self.getIq2D(q[0], q[1]) 516 # Through an exception if it's not a 517 # type we recognize 518 else: 519 raise ValueError, "runXY(q): bad type for q" 520 521 522 def getIq2D(self, qx, qy): 523 """ 524 Returns simulate I(q) for given q_x and q_y values. 525 @param qx: q_x [A-1] 526 @param qy: q_y [A-1] 527 @return: I(q) [cm-1] 528 """ 529 # To find a complete example of the correct call order: 530 # In LORES2, in actionclass.py, method CalculateAction._get_iq() 531 532 # If there are not shapes, do nothing 533 if len(self.shapes) == 0: 534 self.hasPr = False 535 return 0 536 537 # generate space filling points from shape list 538 self.createVolumeFromList() 539 540 self.points = pointsmodelpy.new_point3dvec() 541 542 pointsmodelpy.complexmodel_add(self.complex_model, 543 self.lores_model, "LORES") 544 for shape in self.shapes: 545 if self.shapes[shape].params['is_lores'] == False: 546 pointsmodelpy.complexmodel_add(self.complex_model, 547 self.shapes[shape].shapeObject, "PDB") 548 549 #pointsmodelpy.get_lorespoints(self.lores_model, self.points) 550 self.npts = pointsmodelpy.get_complexpoints(self.complex_model, self.points) 551 552 norm = 1.0e8/self.params['lores_density']*self.params['scale'] 553 #return norm*pointsmodelpy.get_lores_i(self.lores_model, q) 554 return norm*pointsmodelpy.get_complex_iq_2D(self.complex_model, self.points, qx, qy)\ 555 + self.params['background'] 556 487 557 488 558 def getIq(self, q): -
sansrealspace/src/realspace/test/utest_oriented.py
r1b0707e1 rf98961f 254 254 self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 255 255 256 class TestRunMethods(unittest.TestCase): 257 """ Tests run methods for oriented (2D) systems """ 258 259 def setUp(self): 260 """ Set up ellipsoid """ 261 from sans.models.EllipsoidModel import EllipsoidModel 262 263 radius_a = 10 264 radius_b = 15 265 density = 1 266 267 self.ana = EllipsoidModel() 268 self.ana.setParam('scale', 1.0) 269 self.ana.setParam('contrast', 1.0) 270 self.ana.setParam('background', 0.0) 271 self.ana.setParam('radius_a', radius_a) 272 self.ana.setParam('radius_b', radius_b) 273 274 275 canvas = VolumeCanvas.VolumeCanvas() 276 canvas.setParam('lores_density', density) 277 self.handle = canvas.add('ellipsoid') 278 canvas.setParam('%s.radius_x' % self.handle, radius_a) 279 canvas.setParam('%s.radius_y' % self.handle, radius_b) 280 canvas.setParam('%s.radius_z' % self.handle, radius_b) 281 canvas.setParam('scale' , 1.0) 282 canvas.setParam('%s.contrast' % self.handle, 1.0) 283 canvas.setParam('background' , 0.0) 284 self.canvas = canvas 285 286 self.ana.setParam('axis_theta', 1.57) 287 self.ana.setParam('axis_phi', 0) 288 289 self.canvas.setParam('%s.orientation' % self.handle, [0,0,0]) 290 291 292 def testRunXY_List(self): 293 """ Testing ellipsoid along X """ 294 ana_val = self.ana.runXY([0.1, 0.2]) 295 sim_val = self.canvas.runXY([0.1, 0.2]) 296 #print ana_val, sim_val, sim_val/ana_val 297 298 self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 299 300 def testRunXY_float(self): 301 """ Testing ellipsoid along X """ 302 ana_val = self.ana.runXY(0.1) 303 sim_val = self.canvas.runXY(0.1) 304 #print ana_val, sim_val, sim_val/ana_val 305 306 self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 307 308 def testRun_float(self): 309 """ Testing ellipsoid along X """ 310 ana_val = self.ana.run(0.1) 311 sim_val = self.canvas.run(0.1) 312 #print ana_val, sim_val, sim_val/ana_val 313 314 self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 315 316 def testRun_list(self): 317 """ Testing ellipsoid along X """ 318 ana_val = self.ana.run([0.1, 33.0]) 319 sim_val = self.canvas.run([0.1, 33.0]) 320 #print ana_val, sim_val, sim_val/ana_val 321 322 self.assert_( math.fabs(sim_val/ana_val-1.0)<0.05 ) 323 324 325 326 256 327 if __name__ == '__main__': 257 328 unittest.main()
Note: See TracChangeset
for help on using the changeset viewer.