Changeset c52f66f in sasview
- Timestamp:
- Mar 29, 2010 7:47:59 PM (15 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
- Location:
- sansmodels/src/sans/models
- Files:
-
- 2 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): -
sansmodels/src/sans/models/test/utest_modelmultiplication.py
rc1e865a rc52f66f 47 47 48 48 for item in self.model.getParamList(): 49 self.assert_(item in list3) 49 if not 'scale' in item: 50 self.assert_(item in list3) 50 51 for item in self.model2.getParamList(): 51 52 #model3 parameters should not include effect_radius* … … 54 55 55 56 ## test set value for parameters and get paramaters 56 self.model3.setParam("scale ", 15)57 self.assertEqual(self.model3.getParam("scale "), 15)57 self.model3.setParam("scale_factor", 15) 58 self.assertEqual(self.model3.getParam("scale_factor"), 15) 58 59 self.model3.setParam("radius", 20) 59 60 self.assertEqual(self.model3.getParam("radius"), 20) 60 61 self.model3.setParam("radius.width", 15) 61 62 self.assertEqual(self.model3.getParam("radius.width"), 15) 63 self.model3.setParam("scale_factor", 15) 64 self.assertEqual(self.model3.getParam("scale_factor"), 15) 65 self.assertEqual(self.model3.getParam("volfraction"), self.model.getParam("scale")) 62 66 63 67 ## Dispersity … … 126 130 127 131 for item in self.model.getParamList(): 128 self.assert_(item in list3) 132 if not 'scale' in item: 133 self.assert_(item in list3) 129 134 for item in self.model2.getParamList(): 130 135 #model3 parameters should not include effect_radius* … … 133 138 134 139 ## test set value for parameters and get paramaters 135 self.model3.setParam("scale ", 15)136 self.assertEqual(self.model3.getParam("scale "), 15)140 self.model3.setParam("scale_factor", 15) 141 self.assertEqual(self.model3.getParam("scale_factor"), 15) 137 142 self.model3.setParam("radius", 20) 138 143 self.assertEqual(self.model3.getParam("radius"), 20) 139 144 self.model3.setParam("radius.width", 15) 140 145 self.assertEqual(self.model3.getParam("radius.width"), 15) 146 self.model3.setParam("scale_factor", 15) 147 self.assertEqual(self.model3.getParam("scale_factor"), 15) 148 self.assertEqual(self.model3.getParam("volfraction"), self.model.getParam("scale")) 141 149 142 150 ## Dispersity … … 204 212 205 213 for item in self.model.getParamList(): 206 self.assert_(item in list3) 214 if not 'scale' in item: 215 self.assert_(item in list3) 207 216 for item in self.model2.getParamList(): 208 217 #model3 parameters should not include effect_radius* … … 211 220 212 221 ## test set value for parameters and get paramaters 213 self.model3.setParam("scale ", 15)214 self.assertEqual(self.model3.getParam("scale "), 15)222 self.model3.setParam("scale_factor", 15) 223 self.assertEqual(self.model3.getParam("scale_factor"), 15) 215 224 self.model3.setParam("radius", 20) 216 225 self.assertEqual(self.model3.getParam("radius"), 20) 217 226 self.model3.setParam("radius.width", 15) 218 227 self.assertEqual(self.model3.getParam("radius.width"), 15) 228 self.model3.setParam("scale_factor", 15) 229 self.assertEqual(self.model3.getParam("scale_factor"), 15) 230 self.assertEqual(self.model3.getParam("volfraction"), self.model.getParam("scale")) 219 231 220 232 ## Dispersity … … 283 295 284 296 for item in self.model.getParamList(): 285 self.assert_(item in list3) 297 if not 'scale' in item: 298 self.assert_(item in list3) 286 299 for item in self.model2.getParamList(): 287 300 #model3 parameters should not include effect_radius* … … 290 303 291 304 ## test set value for parameters and get paramaters 292 self.model3.setParam("scale ", 15)293 self.assertEqual(self.model3.getParam("scale "), 15)305 self.model3.setParam("scale_factor", 15) 306 self.assertEqual(self.model3.getParam("scale_factor"), 15) 294 307 self.model3.setParam("radius", 20) 295 308 self.assertEqual(self.model3.getParam("radius"), 20) 296 309 self.model3.setParam("radius.width", 15) 297 310 self.assertEqual(self.model3.getParam("radius.width"), 15) 311 self.model3.setParam("scale_factor", 15) 312 self.assertEqual(self.model3.getParam("scale_factor"), 15) 313 self.assertEqual(self.model3.getParam("volfraction"), self.model.getParam("scale")) 298 314 299 315 ## Dispersity … … 365 381 366 382 for item in self.model.getParamList(): 367 self.assert_(item in list3) 383 if not 'scale' in item: 384 self.assert_(item in list3) 368 385 for item in self.model2.getParamList(): 369 386 #model3 parameters should not include effect_radius* … … 372 389 373 390 ## test set value for parameters and get paramaters 374 self.model3.setParam("scale ", 15)375 self.assertEqual(self.model3.getParam("scale "), 15)391 self.model3.setParam("scale_factor", 15) 392 self.assertEqual(self.model3.getParam("scale_factor"), 15) 376 393 self.model3.setParam("radius", 20) 377 394 self.assertEqual(self.model3.getParam("radius"), 20) 378 395 self.model3.setParam("radius.width", 15) 379 396 self.assertEqual(self.model3.getParam("radius.width"), 15) 397 self.model3.setParam("scale_factor", 15) 398 self.assertEqual(self.model3.getParam("scale_factor"), 15) 399 self.assertEqual(self.model3.getParam("volfraction"), self.model.getParam("scale")) 380 400 381 401 ## Dispersity … … 443 463 444 464 for item in self.model.getParamList(): 445 self.assert_(item in list3) 465 #model3 parameters should not include scale* 466 if not 'scale' in item: 467 self.assert_(item in list3) 446 468 for item in self.model2.getParamList(): 447 469 #model3 parameters should not include effect_radius* … … 450 472 451 473 ## test set value for parameters and get paramaters 452 self.model3.setParam("scale", 15) 453 self.assertEqual(self.model3.getParam("scale"), 15) 474 #self.model3.setParam("scale", 15) 475 #self.assertEqual(self.model3.getParam("scale"), 15) 476 self.model3.setParam("scale_factor", 0.1) 477 self.assertEqual(self.model3.getParam("scale_factor"), 0.1) 454 478 self.model3.setParam("radius", 20) 455 479 self.assertEqual(self.model3.getParam("radius"), 20) 456 480 self.model3.setParam("radius.width", 15) 457 481 self.assertEqual(self.model3.getParam("radius.width"), 15) 482 self.model3.setParam("scale_factor", 15) 483 self.assertEqual(self.model3.getParam("scale_factor"), 15) 484 self.assertEqual(self.model3.getParam("volfraction"), self.model.getParam("scale")) 458 485 459 486 ## Dispersity … … 521 548 522 549 for item in self.model.getParamList(): 523 self.assert_(item in list3) 550 if not 'scale' in item: 551 self.assert_(item in list3) 524 552 for item in self.model2.getParamList(): 525 553 #model3 parameters should not include effect_radius* … … 528 556 529 557 ## test set value for parameters and get paramaters 530 self.model3.setParam("scale ", 15)531 self.assertEqual(self.model3.getParam("scale "), 15)558 self.model3.setParam("scale_factor", 15) 559 self.assertEqual(self.model3.getParam("scale_factor"), 15) 532 560 self.model3.setParam("radius", 20) 533 561 self.assertEqual(self.model3.getParam("radius"), 20) 534 562 self.model3.setParam("radius.width", 15) 535 563 self.assertEqual(self.model3.getParam("radius.width"), 15) 564 self.model3.setParam("scale_factor", 15) 565 self.assertEqual(self.model3.getParam("scale_factor"), 15) 566 self.assertEqual(self.model3.getParam("volfraction"), self.model.getParam("scale")) 536 567 537 568 ## Dispersity … … 599 630 600 631 for item in self.model.getParamList(): 601 self.assert_(item in list3) 632 if not 'scale' in item: 633 self.assert_(item in list3) 602 634 for item in self.model2.getParamList(): 603 635 #model3 parameters should not include effect_radius* … … 606 638 607 639 ## test set value for parameters and get paramaters 608 self.model3.setParam("scale", 15) 609 self.assertEqual(self.model3.getParam("scale"), 15) 640 #self.model3.setParam("scale", 15) 641 #self.assertEqual(self.model3.getParam("scale"), 15) 642 self.model3.setParam("scale_factor", 15) 643 self.assertEqual(self.model3.getParam("scale_factor"), 15) 610 644 self.model3.setParam("radius", 20) 611 645 self.assertEqual(self.model3.getParam("radius"), 20) 612 646 self.model3.setParam("radius.width", 15) 613 647 self.assertEqual(self.model3.getParam("radius.width"), 15) 648 self.model3.setParam("scale_factor", 15) 649 self.assertEqual(self.model3.getParam("scale_factor"), 15) 650 self.assertEqual(self.model3.getParam("volfraction"), self.model.getParam("scale")) 614 651 615 652 ## Dispersity
Note: See TracChangeset
for help on using the changeset viewer.