Changeset c52f66f in sasview for sansmodels/src/sans/models/MultiplicationModel.py
- Timestamp:
- Mar 29, 2010 7:47:59 PM (14 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:
- 6546e4b
- Parents:
- 277fad8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/MultiplicationModel.py
rfe9c19b4 rc52f66f 7 7 """ 8 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(). 9 The model parameters are combined from both models, P(Q) and S(Q), except 1) 'effect_radius' of S(Q) 10 which will be calculated from P(Q) via calculate_ER(), 11 and 2) 'scale' in P model which is synchronized w/ volfraction in S 12 then P*S is multiplied by a new param, 'scale_factor'. 11 13 The polydispersion is applicable only to P(Q), not to S(Q). 12 14 Note: P(Q) refers to 'form factor' model while S(Q) does to 'structure factor'. … … 24 26 self.description= self.name+"\n" 25 27 self.fill_description(p_model, s_model) 26 28 29 ## Define parameters 30 self.params = {} 31 32 ## Parameter details [units, min, max] 33 self.details = {} 34 27 35 ##models 28 36 self.p_model= p_model … … 34 42 ## Define parameters 35 43 self._set_params() 44 ## New parameter:Scaling factor 45 self.params['scale_factor'] = 1 46 36 47 ## Parameter details [units, min, max] 37 48 self._set_details() 49 self.details['scale_factor'] = ['', None, None] 50 38 51 #list of parameter that can be fitted 39 52 self._set_fixed_params() … … 78 91 79 92 for name , value in self.p_model.params.iteritems(): 80 self.params[name]= value 93 if not name in self.params.keys() and name != 'scale': 94 self.params[name]= value 81 95 82 96 for name , value in self.s_model.params.iteritems(): … … 84 98 if not name in self.params.keys() and name != 'effect_radius': 85 99 self.params[name]= value 100 101 # Set "scale and effec_radius to P and S model as initializing 102 # since run P*S comes from P and S separately. 103 self._set_scale_factor() 104 self._set_effect_radius() 86 105 87 106 def _set_details(self): … … 91 110 """ 92 111 for name ,detail in self.p_model.details.iteritems(): 93 self.details[name]= detail 112 if name != 'scale': 113 self.details[name]= detail 94 114 95 115 for name , detail in self.s_model.details.iteritems(): 96 if not name in self.details.keys() :116 if not name in self.details.keys() or name != 'effect_radius': 97 117 self.details[name]= detail 118 119 def _set_scale_factor(self): 120 """ 121 Set scale=volfraction to P model 122 """ 123 value = self.params['volfraction'] 124 if value != None: 125 self.p_model.setParam( 'scale', value) 126 127 128 def _set_effect_radius(self): 129 """ 130 Set effective radius to S(Q) model 131 """ 132 effective_radius = self.p_model.calculate_ER() 133 #Reset the effective_radius of s_model just before the run 134 if effective_radius != None and effective_radius != NotImplemented: 135 self.s_model.setParam('effect_radius',effective_radius) 98 136 99 137 def setParam(self, name, value): … … 104 142 @param value: value of the parameter 105 143 """ 106 144 # set param to P*S model 107 145 self._setParamHelper( name, value) 108 109 if name in self.p_model.getParamList(): 146 147 ## setParam to p model 148 # set 'scale' in P(Q) equal to volfraction 149 if name == 'volfraction': 150 self._set_scale_factor() 151 elif name in self.p_model.getParamList(): 110 152 self.p_model.setParam( name, value) 111 153 154 ## setParam to s model 155 # This is a little bit abundant: Todo: find better way 156 self._set_effect_radius() 112 157 if name in self.s_model.getParamList(): 113 158 self.s_model.setParam( name, value) 114 115 self._setParamHelper( name, value) 159 160 161 #self._setParamHelper( name, value) 116 162 117 163 def _setParamHelper(self, name, value): … … 153 199 @return: (DAB value) 154 200 """ 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) 201 # set effective radius and scaling factor before run 202 self._set_effect_radius() 203 self._set_scale_factor() 204 return self.params['scale_factor']*self.p_model.run(x)*self.s_model.run(x) 161 205 162 206 def runXY(self, x = 0.0): … … 164 208 @param x: input q-value (float or [float, float] as [qx, qy]) 165 209 @return: DAB value 166 """ 167 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) 210 """ 211 # set effective radius and scaling factor before run 212 self._set_effect_radius() 213 self._set_scale_factor() 214 return self.params['scale_factor']*self.p_model.runXY(x)* self.s_model.runXY(x) 173 215 174 216 def set_dispersion(self, parameter, dispersion):
Note: See TracChangeset
for help on using the changeset viewer.