Changeset 7c8d3093 in sasview for fittingview/src/sans/perspectives
- Timestamp:
- Dec 20, 2011 5:25:39 PM (13 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:
- b025572
- Parents:
- 1352c78
- Location:
- fittingview/src/sans/perspectives/fitting
- Files:
-
- 3 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
fittingview/src/sans/perspectives/fitting/fitting.py
r26e1001 r7c8d3093 211 211 resetf_help += "Otherwise, the same initial param values will be used " 212 212 resetf_help += "for all fittings." 213 self.menu1.AppendCheckItem(self.id_reset_flag, "Chain Fitting [BatchFit Only]", 213 self.menu1.AppendCheckItem(self.id_reset_flag, 214 "Chain Fitting [BatchFit Only]", 214 215 resetf_help) 215 216 wx.EVT_MENU(owner, self.id_reset_flag, self.on_reset_batch_flag) … … 238 239 """ 239 240 id = event.GetId() 240 label = self.edit_m odel_menu.GetLabel(id)241 label = self.edit_menu.GetLabel(id) 241 242 from sans.perspectives.calculator.pyconsole import PyConsole 242 243 filename = os.path.join(models.find_plugins_dir(), label) … … 245 246 self.put_icon(frame) 246 247 frame.Show(True) 247 248 249 def make_sum_model(self, event): 250 """ 251 Edit summodel template and make one 252 """ 253 id = event.GetId() 254 model_list = [] 255 model_manager = models.ModelManager() 256 model_list = model_manager.get_model_name_list() 257 258 from sans.perspectives.fitting.fitting_widgets import TextDialog 259 textdial = TextDialog(None, -1, 'Easy Custom Sum(p1,p2)', model_list) 260 self.put_icon(textdial) 261 if textdial.ShowModal() == wx.ID_OK: 262 try: 263 label = textdial.getText() 264 plug_dir = models.find_plugins_dir() 265 fname = os.path.join(plug_dir, "sum_temp.py") 266 name1 = label[0] 267 name2 = label[1] 268 textdial.write_string(fname, name1, name2) 269 textdial.compile_file(fname) 270 271 page = self.fit_panel.get_current_page() 272 temp = self.fit_panel.reset_pmodel_list() 273 if temp: 274 page.model_list_box = temp 275 current_val = page.formfactorbox.GetValue() 276 pos = page.formfactorbox.GetSelection() 277 page._show_combox_helper() 278 page.formfactorbox.SetSelection(pos) 279 page.formfactorbox.SetValue(current_val) 280 #wx.CallAfter(textdial.delete_file, fname) 281 except: 282 raise 283 if self.parent != None: 284 from sans.guiframe.events import StatusEvent 285 msg= "Easy Custom Sum: Error occurred..." 286 wx.PostEvent(self.parent, StatusEvent(status = msg )) 287 else: 288 raise 289 textdial.Destroy() 290 291 248 292 def set_edit_menu(self, owner): 249 293 """ 250 294 Set list of the edit model menu labels 295 """ 296 id = wx.NewId() 297 self.edit_model_menu.Append(id, 'Easy Custom Sum(p1, p2)', 298 'Sum two models') 299 wx.EVT_MENU(owner, id, self.make_sum_model) 300 e_id = wx.NewId() 301 self.edit_menu =wx.Menu() 302 self.edit_model_menu.AppendMenu(e_id, 303 'Edit Sample File', self.edit_menu) 304 self.set_edit_menu_helper(owner) 305 306 def set_edit_menu_helper(self, owner): 307 """ 308 help for setting list of the edit model menu labels 251 309 """ 252 310 list_fnames = os.listdir(models.find_plugins_dir()) … … 254 312 name = os.path.basename(item) 255 313 toks = os.path.splitext(name) 256 if toks[1]=='.py' and not toks[0]=='__init__': 314 if toks[1]=='.py' and not toks[0] =='__init__' \ 315 and not toks[0] =='sum_temp': 257 316 has_file = False 258 for item in self.edit_m odel_menu.GetMenuItems():259 if name == self.edit_m odel_menu.GetLabel(item.GetId()):317 for item in self.edit_menu.GetMenuItems(): 318 if name == self.edit_menu.GetLabel(item.GetId()): 260 319 has_file = True 261 320 if not has_file: 262 321 id = wx.NewId() 263 self.edit_m odel_menu.Append(id, name)322 self.edit_menu.Append(id, name) 264 323 wx.EVT_MENU(owner, id, self.edit_custom_model) 265 324 has_file = False … … 641 700 642 701 """ 643 if string.find(item, ".")!=-1:644 param_names = re.split("\.",item)645 model_name =param_names[0]702 if string.find(item, ".") != -1: 703 param_names = re.split("\.", item) 704 model_name = param_names[0] 646 705 ##Assume max len is 3; eg., M0.radius.width 647 706 if len(param_names) == 3: 648 param_name =param_names[1]+"."+param_names[2]707 param_name = param_names[1] + "." + param_names[2] 649 708 else: 650 param_name =param_names[1]651 return model_name, param_name709 param_name = param_names[1] 710 return model_name, param_name 652 711 653 712 def set_ftol(self, ftol=None): -
fittingview/src/sans/perspectives/fitting/fitting_widgets.py
r657490af r7c8d3093 12 12 13 13 import wx 14 import sys 15 import os 14 16 from wx.lib.scrolledpanel import ScrolledPanel 15 17 18 #TextDialog size 19 if sys.platform.count("win32") > 0: 20 FONT_VARIANT = 0 21 PNL_WIDTH = 460 22 PNL_HITE = 210 23 else: 24 FONT_VARIANT = 1 25 PNL_WIDTH = 500 26 PNL_HITE = 250 16 27 17 28 MAX_NBR_DATA = 4 … … 156 167 wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 157 168 static_line = wx.StaticLine(self, -1) 158 159 169 self._sizer_txt.Add(self._panel, 0, wx.EXPAND|wx.ALL, 10) 160 170 self._sizer_main.Add(self._sizer_txt, 0, wx.EXPAND|wx.ALL, 10) … … 191 201 self._data_text_ctrl.SetForegroundColour('red') 192 202 203 204 class TextDialog(wx.Dialog): 205 """ 206 Dialog for easy custom sum models 207 """ 208 def __init__(self, parent=None, id=None, title='', model_list=[]): 209 """ 210 Dialog window popup when selecting 'Easy Custom Sum' on the menu 211 """ 212 wx.Dialog.__init__(self, parent=parent, id=id, 213 title=title, size=(PNL_WIDTH, PNL_HITE)) 214 self.parent = parent 215 #Font 216 self.SetWindowVariant(variant=FONT_VARIANT) 217 # default 218 self.model_list = model_list 219 self._build_sizer() 220 self.model1_name = str(self.model1.GetValue()) 221 self.model2_name = str(self.model2.GetValue()) 222 223 def _build_sizer(self): 224 """ 225 Build gui 226 """ 227 _BOX_WIDTH = 195 # combobox width 228 vbox = wx.BoxSizer(wx.VERTICAL) 229 sizer = wx.GridBagSizer(1, 3) 230 sum_description= wx.StaticBox(self, -1, 'Select', 231 size=(PNL_WIDTH-30, 70)) 232 sum_box = wx.StaticBoxSizer(sum_description, wx.VERTICAL) 233 model1_box = wx.BoxSizer(wx.HORIZONTAL) 234 model2_box = wx.BoxSizer(wx.HORIZONTAL) 235 model_vbox = wx.BoxSizer(wx.VERTICAL) 236 self.model1 = wx.ComboBox(self, -1, style=wx.CB_READONLY) 237 wx.EVT_COMBOBOX(self.model1, -1, self.on_model1) 238 self.model1.SetMinSize((_BOX_WIDTH, -1)) 239 self.model1.SetToolTipString("model1") 240 self.model2 = wx.ComboBox(self, -1, style=wx.CB_READONLY) 241 wx.EVT_COMBOBOX(self.model2, -1, self.on_model2) 242 self.model2.SetMinSize((_BOX_WIDTH, -1)) 243 self.model2.SetToolTipString("model2") 244 self._set_model_list() 245 self.model1.SetSelection(0) 246 self.model2.SetSelection(1) 247 # Buttons on the bottom 248 self.static_line_1 = wx.StaticLine(self, -1) 249 self.okButton = wx.Button(self,wx.ID_OK, 'OK', size=(_BOX_WIDTH/2, 25)) 250 self.closeButton = wx.Button(self,wx.ID_CANCEL, 'Cancel', 251 size=(_BOX_WIDTH/2, 25)) 252 # Intro 253 explanation = " custom model = scale_factor * (model1 + model2)\n" 254 model_string = " Model%s (p%s):" 255 vbox.Add(sizer) 256 ix = 0 257 iy = 1 258 sizer.Add(wx.StaticText(self, -1, explanation), (iy, ix), 259 (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 260 model1_box.Add(wx.StaticText(self,-1, model_string% (1, 1)), -1, 0) 261 model1_box.Add((_BOX_WIDTH-35,10)) 262 model1_box.Add(wx.StaticText(self, -1, model_string% (2, 2)), -1, 0) 263 model2_box.Add(self.model1, -1, 0) 264 model2_box.Add((20,10)) 265 model2_box.Add(self.model2, -1, 0) 266 model_vbox.Add(model1_box, -1, 0) 267 model_vbox.Add(model2_box, -1, 0) 268 sum_box.Add(model_vbox, -1, 10) 269 iy += 1 270 ix = 0 271 sizer.Add(sum_box, (iy, ix), 272 (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 273 vbox.Add((10,10)) 274 vbox.Add(self.static_line_1, 0, wx.EXPAND, 10) 275 sizer_button = wx.BoxSizer(wx.HORIZONTAL) 276 sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 277 sizer_button.Add(self.okButton, 0, 278 wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 0) 279 sizer_button.Add(self.closeButton, 0, 280 wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 15) 281 vbox.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 282 self.SetSizer(vbox) 283 self.Centre() 284 285 def _set_model_list(self): 286 """ 287 Set the list of models 288 """ 289 # list of model names 290 list = self.model_list 291 if len(list) > 1: 292 list.sort() 293 for idx in range(len(list)): 294 self.model1.Append(list[idx],idx) 295 self.model2.Append(list[idx],idx) 296 297 def on_model1(self, event): 298 """ 299 Set model1 300 """ 301 event.Skip() 302 self.model1_name = str(self.model1.GetValue()) 303 304 def on_model2(self, event): 305 """ 306 Set model2 307 """ 308 event.Skip() 309 self.model2_name = str(self.model2.GetValue()) 310 311 def getText(self): 312 """ 313 Returns model name string as list 314 """ 315 return [self.model1_name, self.model2_name] 316 317 def write_string(self, fname, name1, name2): 318 """ 319 Write and Save file 320 """ 321 try: 322 out_f = open(fname,'w') 323 except : 324 raise 325 lines = SUM_TEMPLATE.split('\n') 326 for line in lines: 327 if line.count("import %s as P1"): 328 out_f.write(line % (name1, name1) + "\n") 329 elif line.count("import %s as P2"): 330 out_f.write(line % (name2, name2) + "\n") 331 else: 332 out_f.write(line + "\n") 333 out_f.close() 334 335 def compile_file(self, path): 336 """ 337 Compile the file in the path 338 """ 339 try: 340 import py_compile 341 py_compile.compile(file=path, doraise=True) 342 except: 343 type, value, traceback = sys.exc_info() 344 return value 345 346 def delete_file(self, path): 347 """ 348 Delete file in the path 349 """ 350 try: 351 os.remove(path) 352 except: 353 raise 354 355 356 SUM_TEMPLATE = """ 357 # A sample of an experimental model function for Sum(Pmodel1,Pmodel2) 358 import copy 359 from sans.models.pluginmodel import Model1DPlugin 360 # User can change the name of the model (only with single functional model) 361 #P1_model: 362 from sans.models.%s import %s as P1 363 364 #P2_model: 365 from sans.models.%s import %s as P2 366 367 class Model(Model1DPlugin): 368 name = "" 369 def __init__(self): 370 Model1DPlugin.__init__(self, name='') 371 p_model1 = P1() 372 p_model2 = P2() 373 ## Setting model name model description 374 self.description="" 375 self.name = self._get_name(p_model1.name, p_model2.name) 376 self.description = p_model1.name 377 self.description += p_model2.name 378 self.fill_description(p_model1, p_model2) 379 380 ## Define parameters 381 self.params = {} 382 383 ## Parameter details [units, min, max] 384 self.details = {} 385 386 # non-fittable parameters 387 self.non_fittable = p_model1.non_fittable 388 self.non_fittable += p_model2.non_fittable 389 390 ##models 391 self.p_model1= p_model1 392 self.p_model2= p_model2 393 193 394 395 ## dispersion 396 self._set_dispersion() 397 ## Define parameters 398 self._set_params() 399 ## New parameter:Scaling factor 400 self.params['scale_factor'] = 1 401 402 ## Parameter details [units, min, max] 403 self._set_details() 404 self.details['scale_factor'] = ['', None, None] 405 406 407 #list of parameter that can be fitted 408 self._set_fixed_params() 409 ## parameters with orientation 410 for item in self.p_model1.orientation_params: 411 new_item = "p1_" + item 412 if not new_item in self.orientation_params: 413 self.orientation_params.append(new_item) 414 415 for item in self.p_model2.orientation_params: 416 new_item = "p2_" + item 417 if not new_item in self.orientation_params: 418 self.orientation_params.append(new_item) 419 # get multiplicity if model provide it, else 1. 420 try: 421 multiplicity1 = p_model1.multiplicity 422 try: 423 multiplicity2 = p_model2.multiplicity 424 except: 425 multiplicity2 = 1 426 except: 427 multiplicity1 = 1 428 multiplicity2 = 1 429 ## functional multiplicity of the model 430 self.multiplicity1 = multiplicity1 431 self.multiplicity2 = multiplicity2 432 self.multiplicity_info = [] 433 434 def _clone(self, obj): 435 obj.params = copy.deepcopy(self.params) 436 obj.description = copy.deepcopy(self.description) 437 obj.details = copy.deepcopy(self.details) 438 obj.dispersion = copy.deepcopy(self.dispersion) 439 obj.p_model1 = self.p_model1.clone() 440 obj.p_model2 = self.p_model2.clone() 441 #obj = copy.deepcopy(self) 442 return obj 443 444 def _get_name(self, name1, name2): 445 name = self._get_upper_name(name1) 446 name += "+" 447 name += self._get_upper_name(name2) 448 return name 449 450 def _get_upper_name(self, name=None): 451 if name == None: 452 return "" 453 upper_name = "" 454 str_name = str(name) 455 for index in range(len(str_name)): 456 if str_name[index].isupper(): 457 upper_name += str_name[index] 458 return upper_name 459 460 def _set_dispersion(self): 461 ##set dispersion only from p_model 462 for name , value in self.p_model1.dispersion.iteritems(): 463 #if name.lower() not in self.p_model1.orientation_params: 464 new_name = "p1_" + name 465 self.dispersion[new_name]= value 466 for name , value in self.p_model2.dispersion.iteritems(): 467 #if name.lower() not in self.p_model2.orientation_params: 468 new_name = "p2_" + name 469 self.dispersion[new_name]= value 470 471 def function(self, x=0.0): 472 return 0 473 474 def getProfile(self): 475 try: 476 x,y = self.p_model1.getProfile() 477 except: 478 x = None 479 y = None 480 481 return x, y 482 483 def _set_params(self): 484 for name , value in self.p_model1.params.iteritems(): 485 # No 2D-supported 486 #if name not in self.p_model1.orientation_params: 487 new_name = "p1_" + name 488 self.params[new_name]= value 489 490 for name , value in self.p_model2.params.iteritems(): 491 # No 2D-supported 492 #if name not in self.p_model2.orientation_params: 493 new_name = "p2_" + name 494 self.params[new_name]= value 495 496 # Set "scale" as initializing 497 self._set_scale_factor() 498 499 500 def _set_details(self): 501 for name ,detail in self.p_model1.details.iteritems(): 502 new_name = "p1_" + name 503 #if new_name not in self.orientation_params: 504 self.details[new_name]= detail 505 506 for name ,detail in self.p_model2.details.iteritems(): 507 new_name = "p2_" + name 508 #if new_name not in self.orientation_params: 509 self.details[new_name]= detail 510 511 def _set_scale_factor(self): 512 pass 513 514 515 def setParam(self, name, value): 516 # set param to p1+p2 model 517 self._setParamHelper(name, value) 518 519 ## setParam to p model 520 model_pre = name.split('_', 1)[0] 521 new_name = name.split('_', 1)[1] 522 if model_pre == "p1": 523 if new_name in self.p_model1.getParamList(): 524 self.p_model1.setParam(new_name, value) 525 elif model_pre == "p2": 526 if new_name in self.p_model2.getParamList(): 527 self.p_model2.setParam(new_name, value) 528 elif name.lower() == 'scale_factor': 529 self.params['scale_factor'] = value 530 else: 531 raise ValueError, "Model does not contain parameter %s" % name 532 533 def getParam(self, name): 534 # Look for dispersion parameters 535 toks = name.split('.') 536 if len(toks)==2: 537 for item in self.dispersion.keys(): 538 # 2D not supported 539 if item.lower()==toks[0].lower(): 540 for par in self.dispersion[item]: 541 if par.lower() == toks[1].lower(): 542 return self.dispersion[item][par] 543 else: 544 # Look for standard parameter 545 for item in self.params.keys(): 546 if item.lower()==name.lower(): 547 return self.params[item] 548 return 549 #raise ValueError, "Model does not contain parameter %s" % name 550 551 def _setParamHelper(self, name, value): 552 # Look for dispersion parameters 553 toks = name.split('.') 554 if len(toks)== 2: 555 for item in self.dispersion.keys(): 556 if item.lower()== toks[0].lower(): 557 for par in self.dispersion[item]: 558 if par.lower() == toks[1].lower(): 559 self.dispersion[item][par] = value 560 return 561 else: 562 # Look for standard parameter 563 for item in self.params.keys(): 564 if item.lower()== name.lower(): 565 self.params[item] = value 566 return 567 568 raise ValueError, "Model does not contain parameter %s" % name 569 570 571 def _set_fixed_params(self): 572 for item in self.p_model1.fixed: 573 new_item = "p1" + item 574 self.fixed.append(new_item) 575 for item in self.p_model2.fixed: 576 new_item = "p2" + item 577 self.fixed.append(new_item) 578 579 self.fixed.sort() 580 581 582 def run(self, x = 0.0): 583 self._set_scale_factor() 584 return self.params['scale_factor'] * \ 585 (self.p_model1.run(x) + self.p_model2.run(x)) 586 587 def runXY(self, x = 0.0): 588 self._set_scale_factor() 589 return self.params['scale_factor'] * \ 590 (self.p_model1.runXY(x) + self.p_model2.runXY(x)) 591 592 ## Now (May27,10) directly uses the model eval function 593 ## instead of the for-loop in Base Component. 594 def evalDistribution(self, x = []): 595 self._set_scale_factor() 596 return self.params['scale_factor'] * \ 597 (self.p_model1.evalDistribution(x) + \ 598 self.p_model2.evalDistribution(x)) 599 600 def set_dispersion(self, parameter, dispersion): 601 value= None 602 new_pre = parameter.split("_", 1)[0] 603 new_parameter = parameter.split("_", 1)[1] 604 try: 605 if new_pre == 'p1' and \ 606 new_parameter in self.p_model1.dispersion.keys(): 607 value= self.p_model1.set_dispersion(new_parameter, dispersion) 608 if new_pre == 'p2' and \ 609 new_parameter in self.p_model2.dispersion.keys(): 610 value= self.p_model2.set_dispersion(new_parameter, dispersion) 611 self._set_dispersion() 612 return value 613 except: 614 raise 615 616 def fill_description(self, p_model1, p_model2): 617 description = "" 618 description +="This model gives the summation of %s and %s. "% \ 619 ( p_model1.name, p_model2.name ) 620 self.description += description 621 622 if __name__ == "__main__": 623 m1= Model() 624 #m1.setParam("p1_scale", 25) 625 #m1.setParam("p1_length", 1000) 626 #m1.setParam("p2_scale", 100) 627 #m1.setParam("p2_rg", 100) 628 out1 = m1.runXY(0.01) 629 630 m2= Model() 631 #m2.p_model1.setParam("scale", 25) 632 #m2.p_model1.setParam("length", 1000) 633 #m2.p_model2.setParam("scale", 100) 634 #m2.p_model2.setParam("rg", 100) 635 out2 = m2.p_model1.runXY(0.01) + m2.p_model2.runXY(0.01) 636 print out1, " = ", out2 637 if out1 == out2: 638 print "===> Simple Test: Passed!" 639 else: 640 print "===> Simple Test: Failed!" 641 """ 642 643 if __name__ == "__main__": 644 app = wx.PySimpleApp() 645 frame = TextDialog(id=1, model_list=["SphereModel", "CylinderModel"]) 646 frame.Show(True) 647 app.MainLoop() 648 649 -
fittingview/src/sans/perspectives/fitting/models.py
r96814e1 r7c8d3093 226 226 """ 227 227 """ 228 229 228 self.stored_plugins = {} 230 229 self._getModelList() 231 232 230 233 231 def findModels(self): … … 250 248 251 249 """ 250 # regular model names only 251 self.model_name_list = [] 252 252 from sans.models.SphereModel import SphereModel 253 253 self.shape_list.append(SphereModel) 254 254 self.multiplication_factor.append(SphereModel) 255 self.model_name_list.append(SphereModel.__name__) 255 256 256 257 from sans.models.BinaryHSModel import BinaryHSModel 257 258 self.shape_list.append(BinaryHSModel) 259 self.model_name_list.append(BinaryHSModel.__name__) 258 260 259 261 from sans.models.FuzzySphereModel import FuzzySphereModel 260 262 self.shape_list.append(FuzzySphereModel) 261 263 self.multiplication_factor.append(FuzzySphereModel) 264 self.model_name_list.append(FuzzySphereModel.__name__) 262 265 263 266 from sans.models.CoreShellModel import CoreShellModel 264 267 self.shape_list.append(CoreShellModel) 265 268 self.multiplication_factor.append(CoreShellModel) 269 self.model_name_list.append(CoreShellModel.__name__) 266 270 267 271 from sans.models.CoreMultiShellModel import CoreMultiShellModel … … 273 277 self.shape_list.append(VesicleModel) 274 278 self.multiplication_factor.append(VesicleModel) 279 self.model_name_list.append(VesicleModel.__name__) 275 280 276 281 from sans.models.MultiShellModel import MultiShellModel 277 282 self.shape_list.append(MultiShellModel) 278 283 self.multiplication_factor.append(MultiShellModel) 284 self.model_name_list.append(MultiShellModel.__name__) 279 285 280 286 from sans.models.OnionExpShellModel import OnionExpShellModel … … 290 296 from sans.models.PearlNecklaceModel import PearlNecklaceModel 291 297 self.shape_list.append(PearlNecklaceModel) 298 self.model_name_list.append(PearlNecklaceModel.__name__) 292 299 #self.multiplication_factor.append(PearlNecklaceModel) 293 300 … … 295 302 self.shape_list.append(CylinderModel) 296 303 self.multiplication_factor.append(CylinderModel) 304 self.model_name_list.append(CylinderModel.__name__) 297 305 298 306 from sans.models.CoreShellCylinderModel import CoreShellCylinderModel 299 307 self.shape_list.append(CoreShellCylinderModel) 300 308 self.multiplication_factor.append(CoreShellCylinderModel) 309 self.model_name_list.append(CoreShellCylinderModel.__name__) 301 310 302 311 from sans.models.HollowCylinderModel import HollowCylinderModel 303 312 self.shape_list.append(HollowCylinderModel) 304 313 self.multiplication_factor.append(HollowCylinderModel) 314 self.model_name_list.append(HollowCylinderModel.__name__) 305 315 306 316 from sans.models.FlexibleCylinderModel import FlexibleCylinderModel 307 317 self.shape_list.append(FlexibleCylinderModel) 318 self.model_name_list.append(FlexibleCylinderModel.__name__) 308 319 309 320 from sans.models.FlexCylEllipXModel import FlexCylEllipXModel 310 321 self.shape_list.append(FlexCylEllipXModel) 322 self.model_name_list.append(FlexCylEllipXModel.__name__) 311 323 312 324 from sans.models.StackedDisksModel import StackedDisksModel 313 325 self.shape_list.append(StackedDisksModel) 314 326 self.multiplication_factor.append(StackedDisksModel) 327 self.model_name_list.append(StackedDisksModel.__name__) 315 328 316 329 from sans.models.ParallelepipedModel import ParallelepipedModel 317 330 self.shape_list.append(ParallelepipedModel) 318 331 self.multiplication_factor.append(ParallelepipedModel) 332 self.model_name_list.append(ParallelepipedModel.__name__) 319 333 320 334 from sans.models.CSParallelepipedModel import CSParallelepipedModel 321 335 self.shape_list.append(CSParallelepipedModel) 322 336 self.multiplication_factor.append(CSParallelepipedModel) 337 self.model_name_list.append(CSParallelepipedModel.__name__) 323 338 324 339 from sans.models.EllipticalCylinderModel import EllipticalCylinderModel 325 340 self.shape_list.append(EllipticalCylinderModel) 326 341 self.multiplication_factor.append(EllipticalCylinderModel) 342 self.model_name_list.append(EllipticalCylinderModel.__name__) 327 343 328 344 from sans.models.BarBellModel import BarBellModel 329 345 self.shape_list.append(BarBellModel) 346 self.model_name_list.append(BarBellModel.__name__) 330 347 # not implemeted yet! 331 348 #self.multiplication_factor.append(BarBellModel) … … 333 350 from sans.models.CappedCylinderModel import CappedCylinderModel 334 351 self.shape_list.append(CappedCylinderModel) 352 self.model_name_list.append(CappedCylinderModel.__name__) 335 353 # not implemeted yet! 336 354 #self.multiplication_factor.append(CappedCylinderModel) … … 339 357 self.shape_list.append(EllipsoidModel) 340 358 self.multiplication_factor.append(EllipsoidModel) 359 self.model_name_list.append(EllipsoidModel.__name__) 341 360 342 361 from sans.models.CoreShellEllipsoidModel import CoreShellEllipsoidModel 343 362 self.shape_list.append(CoreShellEllipsoidModel) 344 363 self.multiplication_factor.append(CoreShellEllipsoidModel) 364 self.model_name_list.append(CoreShellEllipsoidModel.__name__) 345 365 346 366 from sans.models.TriaxialEllipsoidModel import TriaxialEllipsoidModel 347 367 self.shape_list.append(TriaxialEllipsoidModel) 348 368 self.multiplication_factor.append(TriaxialEllipsoidModel) 369 self.model_name_list.append(TriaxialEllipsoidModel.__name__) 349 370 350 371 from sans.models.LamellarModel import LamellarModel 351 372 self.shape_list.append(LamellarModel) 373 self.model_name_list.append(LamellarModel.__name__) 352 374 353 375 from sans.models.LamellarFFHGModel import LamellarFFHGModel 354 376 self.shape_list.append(LamellarFFHGModel) 377 self.model_name_list.append(LamellarFFHGModel.__name__) 355 378 356 379 from sans.models.LamellarPSModel import LamellarPSModel 357 380 self.shape_list.append(LamellarPSModel) 381 self.model_name_list.append(LamellarPSModel.__name__) 358 382 359 383 from sans.models.LamellarPSHGModel import LamellarPSHGModel 360 384 self.shape_list.append(LamellarPSHGModel) 385 self.model_name_list.append(LamellarPSHGModel.__name__) 361 386 362 387 from sans.models.LamellarPCrystalModel import LamellarPCrystalModel 363 388 self.shape_list.append(LamellarPCrystalModel) 389 self.model_name_list.append(LamellarPCrystalModel.__name__) 364 390 365 391 from sans.models.SCCrystalModel import SCCrystalModel 366 392 self.shape_list.append(SCCrystalModel) 393 self.model_name_list.append(SCCrystalModel.__name__) 367 394 368 395 from sans.models.FCCrystalModel import FCCrystalModel 369 396 self.shape_list.append(FCCrystalModel) 397 self.model_name_list.append(FCCrystalModel.__name__) 370 398 371 399 from sans.models.BCCrystalModel import BCCrystalModel 372 400 self.shape_list.append(BCCrystalModel) 401 self.model_name_list.append(BCCrystalModel.__name__) 373 402 374 403 ## Structure factor 375 404 from sans.models.SquareWellStructure import SquareWellStructure 376 405 self.struct_list.append(SquareWellStructure) 406 self.model_name_list.append(SquareWellStructure.__name__) 377 407 378 408 from sans.models.HardsphereStructure import HardsphereStructure 379 409 self.struct_list.append(HardsphereStructure) 410 self.model_name_list.append(HardsphereStructure.__name__) 380 411 381 412 from sans.models.StickyHSStructure import StickyHSStructure 382 413 self.struct_list.append(StickyHSStructure) 414 self.model_name_list.append(StickyHSStructure.__name__) 383 415 384 416 from sans.models.HayterMSAStructure import HayterMSAStructure 385 417 self.struct_list.append(HayterMSAStructure) 418 self.model_name_list.append(HayterMSAStructure.__name__) 386 419 387 420 ##shape-independent models 388 421 from sans.models.PowerLawAbsModel import PowerLawAbsModel 389 422 self.shape_indep_list.append( PowerLawAbsModel ) 423 self.model_name_list.append(PowerLawAbsModel.__name__) 390 424 391 425 from sans.models.BEPolyelectrolyte import BEPolyelectrolyte 392 426 self.shape_indep_list.append(BEPolyelectrolyte ) 427 self.model_name_list.append(BEPolyelectrolyte.__name__) 393 428 self.form_factor_dict[str(wx.NewId())] = [SphereModel] 394 429 395 430 from sans.models.BroadPeakModel import BroadPeakModel 396 431 self.shape_indep_list.append(BroadPeakModel) 432 self.model_name_list.append(BroadPeakModel.__name__) 397 433 398 434 from sans.models.CorrLengthModel import CorrLengthModel 399 435 self.shape_indep_list.append(CorrLengthModel) 436 self.model_name_list.append(CorrLengthModel.__name__) 400 437 401 438 from sans.models.DABModel import DABModel 402 439 self.shape_indep_list.append(DABModel ) 440 self.model_name_list.append(DABModel.__name__) 403 441 404 442 from sans.models.DebyeModel import DebyeModel 405 443 self.shape_indep_list.append(DebyeModel ) 444 self.model_name_list.append(DebyeModel.__name__) 406 445 407 446 #FractalModel (a c-model)is now being used instead of FractalAbsModel. 408 447 from sans.models.FractalModel import FractalModel 409 448 self.shape_indep_list.append(FractalModel ) 449 self.model_name_list.append(FractalModel.__name__) 410 450 411 451 from sans.models.FractalCoreShellModel import FractalCoreShellModel 412 452 self.shape_indep_list.append(FractalCoreShellModel ) 453 self.model_name_list.append(FractalCoreShellModel.__name__) 413 454 414 455 from sans.models.GaussLorentzGelModel import GaussLorentzGelModel 415 456 self.shape_indep_list.append(GaussLorentzGelModel) 457 self.model_name_list.append(GaussLorentzGelModel.__name__) 416 458 417 459 from sans.models.GuinierModel import GuinierModel 418 460 self.shape_indep_list.append(GuinierModel ) 461 self.model_name_list.append(GuinierModel.__name__) 419 462 420 463 from sans.models.GuinierPorodModel import GuinierPorodModel 421 464 self.shape_indep_list.append(GuinierPorodModel ) 465 self.model_name_list.append(GuinierPorodModel.__name__) 422 466 423 467 from sans.models.LorentzModel import LorentzModel 424 468 self.shape_indep_list.append( LorentzModel) 469 self.model_name_list.append(LorentzModel.__name__) 425 470 426 471 from sans.models.PeakGaussModel import PeakGaussModel 427 472 self.shape_indep_list.append(PeakGaussModel) 473 self.model_name_list.append(PeakGaussModel.__name__) 428 474 429 475 from sans.models.PeakLorentzModel import PeakLorentzModel 430 476 self.shape_indep_list.append(PeakLorentzModel) 477 self.model_name_list.append( PeakLorentzModel.__name__) 431 478 432 479 from sans.models.Poly_GaussCoil import Poly_GaussCoil 433 480 self.shape_indep_list.append(Poly_GaussCoil) 481 self.model_name_list.append(Poly_GaussCoil.__name__) 434 482 435 483 from sans.models.PolymerExclVolume import PolymerExclVolume 436 484 self.shape_indep_list.append(PolymerExclVolume) 485 self.model_name_list.append(PolymerExclVolume.__name__) 437 486 438 487 from sans.models.PorodModel import PorodModel 439 self.shape_indep_list.append(PorodModel ) 488 self.shape_indep_list.append(PorodModel ) 489 self.model_name_list.append(PorodModel.__name__) 440 490 441 491 from sans.models.RPA10Model import RPA10Model … … 445 495 from sans.models.TeubnerStreyModel import TeubnerStreyModel 446 496 self.shape_indep_list.append(TeubnerStreyModel ) 497 self.model_name_list.append(TeubnerStreyModel.__name__) 447 498 448 499 from sans.models.TwoLorentzianModel import TwoLorentzianModel 449 500 self.shape_indep_list.append(TwoLorentzianModel ) 501 self.model_name_list.append(TwoLorentzianModel.__name__) 450 502 451 503 from sans.models.TwoPowerLawModel import TwoPowerLawModel 452 504 self.shape_indep_list.append(TwoPowerLawModel ) 505 self.model_name_list.append(TwoPowerLawModel.__name__) 453 506 454 507 from sans.models.UnifiedPowerRgModel import UnifiedPowerRgModel … … 458 511 from sans.models.LineModel import LineModel 459 512 self.shape_indep_list.append(LineModel) 513 self.model_name_list.append(LineModel.__name__) 460 514 461 515 from sans.models.ReflectivityModel import ReflectivityModel … … 695 749 return self.model_combobox.get_list() 696 750 751 def get_model_name_list(self): 752 """ 753 return regular model name list 754 """ 755 return self.model_name_list 697 756 698 757 … … 730 789 return self.__modelmanager.get_model_list() 731 790 791 def get_model_name_list(self): 792 return self.__modelmanager.get_model_name_list() 793 732 794 733 795 -
fittingview/src/sans/perspectives/fitting/plugin_models/sum_p1_p2.py
r96814e1 r7c8d3093 2 2 import copy 3 3 from sans.models.pluginmodel import Model1DPlugin 4 # User can change the name of the model (only with single functional model) 5 from sans.models.CylinderModel import CylinderModel as P1 6 from sans.models.PolymerExclVolume import PolymerExclVolume as P2 7 8 4 # Possible model names 5 """ 6 BCCrystalModel, BEPolyelectrolyte, BarBellModel, BinaryHSModel, BroadPeakModel, 7 CSParallelepipedModel, CappedCylinderModel, CoreShellCylinderModel, 8 CoreShellEllipsoidModel, CoreShellModel, CorrLengthModel, CylinderModel, 9 DABModel, DebyeModel, EllipsoidModel, EllipticalCylinderModel, FCCrystalModel, 10 FlexCylEllipXModel, FlexibleCylinderModel, FractalCoreShellModel, FractalModel, 11 FuzzySphereModel, GaussLorentzGelModel, GuinierModel, GuinierPorodModel, 12 HardsphereStructure, HayterMSAStructure, HollowCylinderModel, LamellarFFHGModel, 13 LamellarModel, LamellarPCrystalModel, LamellarPSHGModel, LamellarPSModel, 14 LineModel, LorentzModel, MultiShellModel, ParallelepipedModel, PeakGaussModel, 15 PeakLorentzModel, PearlNecklaceModel, Poly_GaussCoil, PolymerExclVolume, 16 PorodModel, PowerLawAbsModel, SCCrystalModel, SphereModel, SquareWellStructure, 17 StackedDisksModel, StickyHSStructure, TeubnerStreyModel, TriaxialEllipsoidModel, 18 TwoLorentzianModel, TwoPowerLawModel, VesicleModel 19 """ 20 ## This is same as the Easy Custom Sum(p1 + p2) 21 # 22 # Custom model = scale_factor * (P1 + P2) 23 # 24 ## User can REPLACE model names below two arrowed lines (two names per line) 25 from sans.models.CylinderModel import CylinderModel as P1 #<======== 26 from sans.models.PolymerExclVolume import PolymerExclVolume as P2 #<======== 27 28 #####DO NOT CHANGE ANYTHING BELOW THIS LINE 29 #####------------------------------------------------------------------------ 9 30 class Model(Model1DPlugin): 10 31 """ … … 23 44 ## Setting model name model description 24 45 self.description="" 25 self.name = "Sum[" + "P1(Cyl)" +", "+ "P2(PEV)" + "]"46 self.name = self._get_name(p_model1.name, p_model2.name) 26 47 self.description = p_model1.name+"\n" 27 48 self.description += p_model2.name+"\n" … … 52 73 ## Parameter details [units, min, max] 53 74 self._set_details() 54 self.details['scale_factor'] = ['', 75 self.details['scale_factor'] = ['', None, None] 55 76 56 77 … … 96 117 return obj 97 118 98 119 def _get_name(self, name1, name2): 120 """ 121 Get combined name from two model names 122 """ 123 name = self._get_upper_name(name1) 124 name += "+" 125 name += self._get_upper_name(name2) 126 return name 127 128 def _get_upper_name(self, name=None): 129 """ 130 Get uppercase string from model name 131 """ 132 if name == None: 133 return "" 134 upper_name = "" 135 str_name = str(name) 136 for index in range(len(str_name)): 137 if str_name[index].isupper(): 138 upper_name += str_name[index] 139 return upper_name 140 99 141 def _set_dispersion(self): 100 142 """ … … 339 381 if __name__ == "__main__": 340 382 m1= Model() 341 m1.setParam("p1_scale", 25)342 m1.setParam("p1_length", 1000)343 m1.setParam("p2_scale", 100)344 m1.setParam("p2_rg", 100)383 #m1.setParam("p1_scale", 25) 384 #m1.setParam("p1_length", 1000) 385 #m1.setParam("p2_scale", 100) 386 #m1.setParam("p2_rg", 100) 345 387 out1 = m1.runXY(0.01) 346 388 347 389 m2= Model() 348 m2.p_model1.setParam("scale", 25)349 m2.p_model1.setParam("length", 1000)350 m2.p_model2.setParam("scale", 100)351 m2.p_model2.setParam("rg", 100)390 #m2.p_model1.setParam("scale", 25) 391 #m2.p_model1.setParam("length", 1000) 392 #m2.p_model2.setParam("scale", 100) 393 #m2.p_model2.setParam("rg", 100) 352 394 out2 = m2.p_model1.runXY(0.01) + m2.p_model2.runXY(0.01) 395 print "Testing at Q = 0.01:" 353 396 print out1, " = ", out2 354 355 397 if out1 == out2: 398 print "===> Simple Test: Passed!" 399 else: 400 print "===> Simple Test: Failed!" -
fittingview/src/sans/perspectives/fitting/plugin_models/testmodel.py
r96814e1 r7c8d3093 7 7 """ 8 8 from sans.models.pluginmodel import Model1DPlugin ##DO NOT CHANGE THIS LINE!!! 9 from math import *##DO NOT CHANGE THIS LINE!!!10 from numpy import *##DO NOT CHANGE THIS LINE!!!9 import math ##DO NOT CHANGE THIS LINE!!! 10 import numpy ##DO NOT CHANGE THIS LINE!!! 11 11 12 12 ##PLEASE READ COMMENTS CAREFULLY !!! COMMENT ARE IN CAPITAL LETTERS AND AFTER ## … … 83 83 ## numpy FUNCTIONS ARE FOR EXPERT USER 84 84 85 return self.params['A']+self.params['B']*cos(2.0*x)+self.params['C']*math.sin(2.0*x) 86 85 return self.params['A']+self.params['B']*math.cos(2.0*x)+self.params['C']*math.sin(2.0*x) 86 87 ## DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!! 88 if __name__ == "__main__": 89 m= Model() 90 out1 = m.runXY(0.0) 91 out2 = m.runXY(0.01) 92 isfine1 = numpy.isfinite(out1) 93 isfine2 = numpy.isfinite(out2) 94 print "Testing the value at Q = 0.0:" 95 print out1, " : finite? ", isfine1 96 print "Testing the value at Q = 0.01:" 97 print out2, " : finite? ", isfine2 98 if isfine1 and isfine2: 99 print "===> Simple Test: Passed!" 100 else: 101 print "===> Simple Test: Failed!" -
fittingview/src/sans/perspectives/fitting/plugin_models/testmodel_2.py
r96814e1 r7c8d3093 133 133 result = 1 ## <----- 134 134 else: ## <----- 135 result = sin(poly)/poly ## <-----135 result = math.sin(poly)/poly ## <----- 136 136 137 137 #Re-scale ## <----- … … 139 139 140 140 return result ## MODIFY ONLY RESULT. DON'T DELETE RETURN!!!! 141 141 142 ## DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!! 143 if __name__ == "__main__": 144 m= Model() 145 out1 = m.runXY(0.0) 146 out2 = m.runXY(0.01) 147 isfine1 = numpy.isfinite(out1) 148 isfine2 = numpy.isfinite(out2) 149 print "Testing the value at Q = 0.0:" 150 print out1, " : finite? ", isfine1 151 print "Testing the value at Q = 0.01:" 152 print out2, " : finite? ", isfine2 153 if isfine1 and isfine2: 154 print "===> Simple Test: Passed!" 155 else: 156 print "===> Simple Test: Failed!"
Note: See TracChangeset
for help on using the changeset viewer.