Changeset a2c1196 in sasview for sansrealspace/src/realspace/test/sim_validation.py
- Timestamp:
- Nov 2, 2007 11:02:35 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:
- 7e845ea
- Parents:
- 8c050c1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansrealspace/src/realspace/test/sim_validation.py
rba1d1e9 ra2c1196 18 18 def __init__(self): 19 19 self.density = 0.1 20 self.canvas = None 21 self.ana = None 20 22 self.create() 21 23 … … 23 25 pass 24 26 25 def run_sim (self, q, density=None):27 def run_sim2D(self, qx, qy, density=None): 26 28 """ 27 29 Calculate the mean and error of the simulation … … 34 36 self.create() 35 37 38 return self.canvas.getIq2DError(qx, qy) 39 40 def run_sim(self, q, density=None): 41 """ 42 Calculate the mean and error of the simulation 43 @param q: q-value to calculate at 44 @param density: point density of simulation 45 #return: mean, error 46 """ 47 if not density == None: 48 self.density = density 49 self.create() 50 36 51 return self.canvas.getIqError(q) 52 53 def run_ana2D(self, qx, qy): 54 """ 55 Return analytical value 56 @param q: q-value to evaluate at [float] 57 @return: analytical output [float] 58 """ 59 return self.ana.runXY([qx, qy]) 37 60 38 61 def run_ana(self, q): … … 227 250 output.close() 228 251 252 def validate_model_2D(validator, q_min, q_max, phi, n_q): 253 """ 254 Validate a model 255 An output file containing a comparison between 256 simulation and the analytical solution will be 257 produced. 258 259 @param validator: validator object 260 @param q_min: minimum q 261 @param q_max: maximum q 262 @param n_q: number of q points 263 @param N: number of times to evaluate each simulation point 264 """ 265 266 q_list = pylab.arange(q_min, q_max*1.0001, (q_max-q_min)/(n_q-1)) 267 268 output = open('%s_d=%g_Iq2D.txt' % (validator.name, validator.density), 'w') 269 output.write("PARS: %s\n" % validator.ana.params) 270 output.write("<q> <ana> <sim> <err>\n") 271 t_0 = time.time() 272 for q in q_list: 273 ana = validator.run_ana2D(q*math.cos(phi), q*math.sin(phi)) 274 sim, err = validator.run_sim2D(q*math.cos(phi), q*math.sin(phi)) 275 print "q=%-g ana=%-g sim=%-g err=%-g diff=%-g (%-g) %s" % (q, ana, sim, err, 276 (sim-ana), sim/ana, str(math.fabs(sim-ana)>err)) 277 output.write("%g %g %g %g\n" % (q, ana, sim, err)) 278 print "Time elapsed: ", time.time()-t_0 279 output.close() 280 229 281 def check_density(validator, q, d_min, d_max, n_d): 230 282 """ … … 257 309 258 310 if __name__ == '__main__': 259 #vali = CoreShellValidator(radius = 15, thickness=5, density = 0.01) 260 #validate_model(vali, q_min=0.001, q_max=1, n_q=50, N=40) 261 311 312 # 2D: Density=5, 71.2 secs for 50 points 313 vali = CoreShellValidator(radius = 15, thickness=5, density = 5.0) 314 #validate_model(vali, q_min=0.001, q_max=1, n_q=50) 315 validate_model_2D(vali, q_min=0.001, q_max=1, phi=1.0, n_q=50) 316 317 # 2D: Density=2, 11.1 secs for 25 points 262 318 #vali = SphereValidator(radius = 20, density = 0.02) 263 #validate_model(vali, q_min=0.001, q_max=0.5, n_q=25, N=20) 264 265 vali = CylinderValidator(radius = 20, length=100, density = 0.1) 266 validate_model(vali, q_min=0.001, q_max=0.5, n_q=25) 267 319 #validate_model(vali, q_min=0.001, q_max=0.5, n_q=25) 320 #vali = SphereValidator(radius = 20, density = 2.0) 321 #validate_model_2D(vali, q_min=0.001, q_max=0.5, phi=1.0, n_q=25) 322 323 # 2D: Density=1, 19.4 secs for 25 points 324 # 2D: Density=0.5, 9.8 secs for 25 points 325 #vali = CylinderValidator(radius = 20, length=100, density = 0.1) 326 #validate_model(vali, q_min=0.001, q_max=0.5, n_q=25) 327 #vali = CylinderValidator(radius = 20, length=100, density = 0.5) 328 #validate_model_2D(vali, q_min=0.001, q_max=0.2, phi=1.0, n_q=25) 329 330 # 2D: Density=0.5, 2.26 secs for 25 points 268 331 #vali = EllipsoidValidator(radius_a = 20, radius_b=15, density = 0.05) 269 332 #validate_model(vali, q_min=0.001, q_max=0.5, n_q=25) 333 #vali = EllipsoidValidator(radius_a = 20, radius_b=15, density = 0.5) 334 #validate_model_2D(vali, q_min=0.001, q_max=0.5, phi=1.0, n_q=25) 270 335 271 336 #vali = HelixValidator(density = 0.05)
Note: See TracChangeset
for help on using the changeset viewer.