Ignore:
Timestamp:
Nov 2, 2007 11:02:35 AM (17 years ago)
Author:
Mathieu Doucet <doucetm@…>
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
Message:

Added 2D (oriented systems) error estimation, tests and validation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sansrealspace/src/realspace/test/sim_validation.py

    rba1d1e9 ra2c1196  
    1818    def __init__(self): 
    1919        self.density = 0.1 
     20        self.canvas  = None 
     21        self.ana     = None 
    2022        self.create() 
    2123         
     
    2325        pass 
    2426          
    25     def run_sim(self, q, density=None): 
     27    def run_sim2D(self, qx, qy, density=None): 
    2628        """ 
    2729            Calculate the mean and error of the simulation 
     
    3436            self.create() 
    3537         
     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         
    3651        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])  
    3760          
    3861    def run_ana(self, q): 
     
    227250    output.close() 
    228251        
     252def 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        
    229281def check_density(validator, q, d_min, d_max, n_d):  
    230282    """ 
     
    257309     
    258310if __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 
    262318    #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 
    268331    #vali = EllipsoidValidator(radius_a = 20, radius_b=15, density = 0.05) 
    269332    #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) 
    270335     
    271336    #vali = HelixValidator(density = 0.05) 
Note: See TracChangeset for help on using the changeset viewer.