Changeset 3c75696 in sasview
- Timestamp:
- Oct 18, 2007 1:36:17 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:
- 8c050c1
- Parents:
- f98961f
- Location:
- sansrealspace/src/realspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sansrealspace/src/realspace/VolumeCanvas.py
rf98961f r3c75696 214 214 self.hasPr = False 215 215 216 def addObject(self, shapeDesc, id = None): 217 """ 218 Adds a real-space object to the canvas. 219 220 @param shapeDesc: object to add to the canvas [ShapeDescriptor] 221 @param id: string handle for the object [string] [optional] 222 @return: string handle for the object 223 """ 224 # If the handle is not provided, create one 225 if id == None: 226 id = shapeDesc.params["type"]+str(self.shapecount) 227 228 # Self the order number 229 shapeDesc.params['order'] = self.shapecount 230 # Store the shape in a dictionary entry associated 231 # with the handle 232 self.shapes[id] = shapeDesc 233 self.shapecount += 1 234 235 #model changed, need to recalculate P(r) 236 self.hasPr = False 237 238 return id 239 240 216 241 def add(self, shape, id = None): 217 242 """ 243 The intend of this method is to eventually be able to use it 244 as a factory for the canvas and unify the simulation with the 245 analytical solutions. For instance, if one adds a cylinder and 246 it is the only shape on the canvas, the analytical solution 247 could be called. If multiple shapes are involved, then 248 simulation has to be performed. 249 218 250 @param shape: name of the object to add to the canvas [string] 219 251 @param id: string handle for the object [string] [optional] -
sansrealspace/src/realspace/test/simulation_stimuli.py
rba1d1e9 r3c75696 160 160 except: 161 161 report.log = "GetIq: bad value for Iq "+str(value) 162 163 report.trace = "I(q) = %g" % value 164 return canvas, report 165 166 class GetIq2DStimulus(Stimulus): 167 """Calculate I(q)""" 168 169 frequency = 1.0 170 171 def __call__(self, canvas): 172 report = generator.StimulusReport(tag=self.name) 173 174 # Check that a float is returned 175 # Validation testing will be done elsewhere 176 value = canvas.getIq2D(0.01,0.01) 177 178 # Check that it is in the list of objects 179 try: 180 float(value) 181 report.passed = 1 182 except: 183 report.log = "GetIq2D: bad value for Iq "+str(value) 162 184 163 185 report.trace = "I(q) = %g" % value -
sansrealspace/src/realspace/test/utest_oriented.py
rf98961f r3c75696 59 59 sim_val = self.model.getIq2D(0.1, 0.1) 60 60 self.assert_( math.fabs(sim_val/ana_val-1.0)<0.1 ) 61 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 61 104 62 105 class TestCylinder(unittest.TestCase):
Note: See TracChangeset
for help on using the changeset viewer.