Changeset 1affe64 in sasview for sansmodels/src


Ignore:
Timestamp:
Sep 11, 2009 8:41:02 AM (15 years ago)
Author:
Jae Cho <jhjcho@…>
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:
9002927
Parents:
c1e865a
Message:

cleaned some codes and added doc.s

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sansmodels/src/sans/models/MultiplicationModel.py

    r8b677ec r1affe64  
    66class MultiplicationModel(BaseComponent): 
    77    """ 
    8         Use for P(Q)*S(Q); function call must be in order of P(Q) and then S(Q). 
    9         Perform multiplication of two models. 
    10         Contains the models parameters combined. 
     8        Use for P(Q)*S(Q); function call must be in the order of P(Q) and then S(Q): 
     9        The model parameters are combined from both models, P(Q) and S(Q), except 'effective_radius' of S(Q) 
     10        which will be calculated from P(Q) via calculate_ER(). 
     11        The polydispersion is applicable only to P(Q), not to S(Q). 
     12        Note: P(Q) refers to 'form factor' model while S(Q) does to 'structure factor'. 
    1113    """ 
    12     def __init__(self, model1, model2 ): 
     14    def __init__(self, p_model, s_model ): 
    1315        BaseComponent.__init__(self) 
    14  
    15         
     16        """ 
     17            @param p_model: form factor, P(Q) 
     18            @param s_model: structure factor, S(Q) 
     19        """ 
     20 
    1621        ## Setting  model name model description 
    1722        self.description="" 
    18         if  model1.name != "NoStructure" and  model2.name != "NoStructure": 
    19              self.name = model1.name +" * "+ model2.name 
    20              self.description= self.name+"\n" 
    21              self.fill_description(model1, model2) 
    22         elif  model2.name != "NoStructure": 
    23             self.name = model2.name 
    24             self.description= model2.description 
    25         else : 
    26             self.name = model1.name 
    27             self.description= model1.description 
     23        self.name = p_model.name +" * "+ s_model.name 
     24        self.description= self.name+"\n" 
     25        self.fill_description(p_model, s_model) 
    2826                         
    29          
    30         self.model1= model1 
    31         self.model2= model2 
     27        ##models  
     28        self.p_model= p_model 
     29        self.s_model= s_model 
    3230         
    3331        
     
    4139        self._set_fixed_params()   
    4240        ## parameters with orientation 
    43         for item in self.model1.orientation_params: 
     41        for item in self.p_model.orientation_params: 
    4442            self.orientation_params.append(item) 
    4543             
    46         for item in self.model2.orientation_params: 
     44        for item in self.s_model.orientation_params: 
    4745            if not item in self.orientation_params: 
    4846                self.orientation_params.append(item) 
     
    5856        obj.details    = copy.deepcopy(self.details) 
    5957        obj.dispersion = copy.deepcopy(self.dispersion) 
    60         obj.model1  = self.model1.clone() 
    61         obj.model2  = self.model2.clone() 
     58        obj.p_model  = self.p_model.clone() 
     59        obj.s_model  = self.s_model.clone() 
    6260         
    6361        return obj 
     
    6765        """ 
    6866           combined the two models dispersions 
    69         """ 
    70         for name , value in self.model1.dispersion.iteritems(): 
    71             self.dispersion[name]= value 
    72              
    73         for name , value in self.model2.dispersion.iteritems(): 
    74             ## All S(Q) has only 'effect_radius' for dispersion which  
    75             #    will not be allowed for now. 
    76             if not name in self.dispersion.keys(): 
    77                 if name != 'effect_radius': 
    78                     self.dispersion[name]= value 
    79  
    80                      
    81                  
    82                  
     67           Polydispersion should not be applied to s_model 
     68        """ 
     69        ##set dispersion only from p_model  
     70        for name , value in self.p_model.dispersion.iteritems(): 
     71            self.dispersion[name]= value                            
     72 
    8373    def _set_params(self): 
    8474        """ 
     
    8676            this model parameters  
    8777        """ 
    88         dia_rad = 0 
    89         for name , value in self.model1.params.iteritems(): 
     78 
     79        for name , value in self.p_model.params.iteritems(): 
    9080            self.params[name]= value 
    9181             
    92         for name , value in self.model2.params.iteritems(): 
    93             if not name in self.params.keys(): 
    94                 #effect_radius is not treated as a parameter anymore. 
    95                 if name != 'effect_radius':  
    96                     self.params[name]= value 
     82        for name , value in self.s_model.params.iteritems(): 
     83            #Remove the effect_radius from the (P*S) model parameters. 
     84            if not name in self.params.keys() and name != 'effect_radius': 
     85                self.params[name]= value 
    9786             
    9887    def _set_details(self): 
     
    10190            this model details  
    10291        """ 
    103         for name ,detail in self.model1.details.iteritems(): 
     92        for name ,detail in self.p_model.details.iteritems(): 
    10493            self.details[name]= detail 
    10594             
    106         for name , detail in self.model2.details.iteritems(): 
    107             if not name in self.details.keys():  
    108                 if name != 'effect_radius':  
    109                     self.details[name]= detail 
     95        for name , detail in self.s_model.details.iteritems(): 
     96            if not name in self.details.keys(): 
     97                self.details[name]= detail 
    11098                 
    11199    def setParam(self, name, value): 
     
    119107        self._setParamHelper( name, value) 
    120108 
    121         if name in self.model1.getParamList(): 
    122             self.model1.setParam( name, value) 
    123  
    124         if name in self.model2.getParamList(): 
    125             self.model2.setParam( name, value) 
     109        if name in self.p_model.getParamList(): 
     110            self.p_model.setParam( name, value) 
     111 
     112        if name in self.s_model.getParamList(): 
     113            self.s_model.setParam( name, value) 
    126114 
    127115        self._setParamHelper( name, value) 
     
    152140    def _set_fixed_params(self): 
    153141        """ 
    154              fill the self.fixed list with the two models fixed list 
    155         """ 
    156         for item in self.model1.fixed: 
     142             fill the self.fixed list with the p_model fixed list 
     143        """ 
     144        for item in self.p_model.fixed: 
    157145            self.fixed.append(item) 
    158         #S(Q) should not have fixed items for P*S for now. 
    159         #for item in self.model2.fixed: 
    160         #    if not item in self.fixed: 
    161         #        self.fixed.append(item) 
    162146 
    163147        self.fixed.sort() 
     
    169153            @return: (DAB value) 
    170154        """ 
    171         #Reset radius of model2 just before the run 
    172         effective_radius = None    
    173         effective_radius = self.model1.calculate_ER() 
    174         if effective_radius !=None:          
    175             self.model2.setParam( 'effect_radius',effective_radius) 
    176          
    177         return self.model1.run(x)*self.model2.run(x) 
    178     
     155 
     156        effective_radius = self.p_model.calculate_ER() 
     157        #Reset the effective_radius of s_model just before the run 
     158        if effective_radius != None and effective_radius != NotImplemented: 
     159            self.s_model.setParam('effect_radius',effective_radius)                        
     160        return self.p_model.run(x)*self.s_model.run(x) 
     161 
    179162    def runXY(self, x = 0.0): 
    180163        """ Evaluate the model 
     
    183166        """ 
    184167         
    185         #Reset radius of model2 just before the run 
    186         effective_radius = None     
    187         effective_radius = self.model1.calculate_ER() 
    188         if effective_radius !=None:          
    189             self.model2.setParam( 'effect_radius',effective_radius) 
    190  
    191         return self.model1.runXY(x)* self.model2.runXY(x) 
    192      
     168        effective_radius = self.p_model.calculate_ER() 
     169        #Reset the effective_radius of s_model just before the run 
     170        if effective_radius != None and effective_radius != NotImplemented: 
     171            self.s_model.setParam('effect_radius',effective_radius)           
     172        return self.p_model.runXY(x)* self.s_model.runXY(x) 
     173 
    193174    def set_dispersion(self, parameter, dispersion): 
    194175        """ 
     
    199180        value= None 
    200181        try: 
    201             if parameter in self.model1.dispersion.keys(): 
    202                 value= self.model1.set_dispersion(parameter, dispersion) 
    203             #There is no dispersion for the structure factors(S(Q)).  
    204             #ToDo: need to decide whether or not the dispersion for S(Q) has to be considered for P*S.   
    205             #elif parameter in self.model2.dispersion.keys(): 
    206             #    if item != 'effect_radius': 
    207             #        value= self.model2.set_dispersion(parameter, dispersion) 
     182            if parameter in self.p_model.dispersion.keys(): 
     183                value= self.p_model.set_dispersion(parameter, dispersion) 
    208184            self._set_dispersion() 
    209185            return value 
     
    211187            raise  
    212188 
    213     def fill_description(self, model1, model2): 
     189    def fill_description(self, p_model, s_model): 
    214190        """ 
    215191            Fill the description for P(Q)*S(Q) 
    216192        """ 
    217193        description = "" 
    218         description += "Note:1) The effect_radius (effective radius) of %s \n"% (model2.name) 
     194        description += "Note:1) The effect_radius (effective radius) of %s \n"% (s_model.name) 
    219195        description +="             is automatically calculated from size parameters (radius...).\n" 
    220196        description += "         2) For non-spherical shape, this approximation is valid \n" 
    221         description += "            only for highly dilute systems. Thus, use it at your own risk.\n" 
    222         description +="See %s description and %s description \n"%( model1.name,model2.name ) 
    223         description += "        for details." 
     197        description += "            only for limited systems. Thus, use it at your own risk.\n" 
     198        description +="See %s description and %s description \n"%( p_model.name, s_model.name ) 
     199        description += "        for details of individual models." 
    224200        self.description += description 
    225201     
Note: See TracChangeset for help on using the changeset viewer.