Changes in / [600bea1:cd5e29b] in sasview
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
.gitignore
ra93d6b1 ra93d6b1 13 13 .pydevproject 14 14 .vagrant 15 .idea 16 build 17 dist 18 sasview.egg-info 19 sasview.egg-info 20 15 21 .mplconfig 22 doctrees 23 html 24 build 16 25 17 26 /dist 18 /build27 **/build 19 28 sasview.egg-info 20 29 sasview-install … … 34 43 /docs/sphinx-docs/source/user/perspectives 35 44 45 default_categories.json -
run.py
rf9393dc rf9393dc 104 104 addpath(joinpath(root, 'src')) 105 105 106 # sasmodels on the path 107 addpath(joinpath(root, '../sasmodels/')) 108 106 109 # Import the sasview package from root/sasview as sas.sasview. It would 107 110 # be better to just store the package in src/sas/sasview. -
setup.py
r038ccfe6 r038ccfe6 244 244 model_dir = os.path.join("src", "sas","models") 245 245 246 if os.path.isdir(wrapper_dir):247 for file in os.listdir(wrapper_dir): 248 file_path = os.path.join(wrapper_dir, file)249 os.remove(file_path)250 else:251 os.makedirs(wrapper_dir)252 sys.path.append(os.path.join("src", "sas", "models", "c_extension", "python_wrapper"))253 from wrapping import generate_wrappers254 generate_wrappers(header_dir = includedir, 255 output_dir = model_dir,256 c_wrapper_dir = wrapper_dir)246 #if os.path.isdir(wrapper_dir): 247 # for file in os.listdir(wrapper_dir): 248 # file_path = os.path.join(wrapper_dir, file) 249 # os.remove(file_path) 250 #else: 251 # os.makedirs(wrapper_dir) 252 #sys.path.append(os.path.join("src", "sas", "models", "c_extension", "python_wrapper")) 253 #from wrapping import generate_wrappers 254 #generate_wrappers(header_dir = includedir, 255 # output_dir = model_dir, 256 # c_wrapper_dir = wrapper_dir) 257 257 258 258 IGNORED_FILES = [".svn"] … … 283 283 model_sources = [] 284 284 append_file(file_list=model_sources, dir_path=igordir) 285 append_file(file_list=model_sources, dir_path=c_model_dir)286 append_file(file_list=model_sources, dir_path=wrapper_dir)285 #append_file(file_list=model_sources, dir_path=c_model_dir) 286 #append_file(file_list=model_sources, dir_path=wrapper_dir) 287 287 288 288 smear_sources = [] … … 303 303 304 304 c_models = [ 305 Extension("sas.models.sas_extension.c_models",306 sources=model_sources,307 include_dirs=[308 igordir, includedir, c_model_dir, numpy_incl_path, cephes_dir309 ],310 ),305 #Extension("sas.models.sas_extension.c_models", 306 # sources=model_sources, 307 # include_dirs=[ 308 # igordir, includedir, c_model_dir, numpy_incl_path, cephes_dir 309 # ], 310 #), 311 311 312 312 # Smearer extension … … 340 340 ext_modules.extend(c_models) 341 341 342 packages.append("sas.models") 342 343 # SasView 343 344 … … 350 351 'test/save_states/*', 351 352 'test/upcoming_formats/*', 352 'default_categories.json']353 'default_categories.json'] 353 354 packages.append("sas.sasview") 354 355 -
src/sas/models/dispersion_models.py
rfd5ac0d r0e4e554 154 154 c_models.set_dispersion_weights(self.cdisp, values, weights) 155 155 156 models = {"gaussian":GaussianDispersion, "rectangula ":RectangleDispersion,156 models = {"gaussian":GaussianDispersion, "rectangular":RectangleDispersion, 157 157 "array":ArrayDispersion, "schulz":SchulzDispersion, 158 158 "lognormal":LogNormalDispersion} -
src/sas/perspectives/fitting/basepage.py
r2c8dc19 r2c8dc19 57 57 ## Title to appear on top of the window 58 58 window_caption = "Fit Page " 59 59 60 60 def __init__(self, parent, color='blue', **kwargs): 61 61 """ … … 66 66 #Set window's font size 67 67 self.SetWindowVariant(variant=FONT_VARIANT) 68 68 69 69 self.SetBackgroundColour(color) 70 70 ## parent of the page … … 126 126 self.Npts_fit = None 127 127 self.Npts_total = None 128 self.theory_qmin = None 128 self.theory_qmin = None 129 129 self.theory_qmax = None 130 130 self.theory_qmin_x = None … … 135 135 self.sld_axes = None 136 136 self.multi_factor = None 137 137 138 138 self.disp_cb_dict = {} 139 139 140 140 #self.state = PageState(parent=parent) 141 141 ## dictionary containing list of models 142 142 self.model_list_box = {} 143 143 144 144 ## Data member to store the dispersion object created 145 145 self._disp_obj_dict = {} … … 169 169 self.disp_list = [] 170 170 self.disp_name = "" 171 171 172 172 ## list of orientation parameters 173 173 self.orientation_params = [] 174 174 self.orientation_params_disp = [] 175 # Self.model should ALWAYS be None here. It was set to none above in 175 # Self.model should ALWAYS be None here. It was set to none above in 176 176 # this long init setting. no obvious function call in between setting 177 # and this - commenting out on 4/8/2014 by PDB. Remove once clear 177 # and this - commenting out on 4/8/2014 by PDB. Remove once clear 178 178 # it is pointless. 179 179 # if self.model != None: … … 198 198 ## Create context menu for page 199 199 self.popUpMenu = wx.Menu() 200 200 201 201 id = wx.NewId() 202 202 self._keep = wx.MenuItem(self.popUpMenu, id, "Add bookmark", … … 208 208 wx.EVT_MENU(self, id, self.on_bookmark) 209 209 self.popUpMenu.AppendSeparator() 210 210 211 211 ## Default locations 212 212 self._default_save_location = os.getcwd() … … 214 214 #self.onSave(event=None) 215 215 self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) 216 216 217 217 # bind key event 218 218 self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down) 219 219 220 220 ## create the basic structure of the panel with empty sizer 221 221 self.define_page_structure() 222 222 ## drawing Initial dispersion parameters sizer 223 223 self.set_dispers_sizer() 224 224 225 225 ## layout 226 226 self.set_layout() 227 227 228 228 def set_index_model(self, index): 229 229 """ … … 231 231 """ 232 232 self.index_model = index 233 233 234 234 def create_default_data(self): 235 235 """ … … 248 248 else: 249 249 self._create_default_1d_data() 250 250 251 251 if self.model != None: 252 252 if not self.data.is_data: … … 258 258 self.state.pinhole_smearer = self.pinhole_smearer.GetValue() 259 259 self.state.slit_smearer = self.slit_smearer.GetValue() 260 260 261 261 def _create_default_1d_data(self): 262 262 """ … … 264 264 Only when the page is on theory mode. 265 265 :warning: This data is never plotted. 266 266 267 267 """ 268 268 x = numpy.linspace(start=self.qmin_x, stop=self.qmax_x, … … 274 274 self.data.id = str(self.uid) + " data" 275 275 self.data.group_id = str(self.uid) + " Model1D" 276 276 277 277 def _create_log_1d_data(self): 278 278 """ … … 280 280 Only when the page is on theory mode. 281 281 :warning: This data is never plotted. 282 282 283 283 """ 284 284 if self.qmin_x >= 1.e-10: 285 285 qmin = numpy.log10(self.qmin_x) 286 286 else: 287 qmin = -10. 288 287 qmin = -10. 288 289 289 if self.qmax_x <= 1.e10: 290 290 qmax = numpy.log10(self.qmax_x) 291 291 else: 292 qmax = 10. 293 292 qmax = 10. 293 294 294 x = numpy.logspace(start=qmin, stop=qmax, 295 295 num=self.npts_x, endpoint=True, base=10.0) … … 300 300 self.data.id = str(self.uid) + " data" 301 301 self.data.group_id = str(self.uid) + " Model1D" 302 302 303 303 def _create_default_2d_data(self): 304 304 """ … … 358 358 #xstep = x_size / len(x_bins - 1) 359 359 #ystep = y_size / len(y_bins - 1) 360 360 361 361 self.data.source = Source() 362 362 self.data.data = numpy.ones(len(mask)) … … 381 381 wx.PostEvent(self._manager.parent, PanelOnFocusEvent(panel=self)) 382 382 self.on_tap_focus() 383 383 384 384 def on_tap_focus(self): 385 385 """ … … 397 397 self._manager.menu1.FindItemById(self._manager.id_batchfit) 398 398 batch_menu.Enable(self.batch_on and flag) 399 399 400 400 def set_page_info(self, page_info): 401 401 """ 402 402 set some page important information at once 403 403 """ 404 # THIS METHOD/FUNCTION NO LONGE APPEARS TO BE CALLED. Started up program 404 # THIS METHOD/FUNCTION NO LONGE APPEARS TO BE CALLED. Started up program 405 405 # and started new fit window and PR and Invariant and a fit in fitting 406 406 # but never entered this routine which should be an initialization 407 # routine. Leave for a while but probably something to clean up at 407 # routine. Leave for a while but probably something to clean up at 408 408 # some point? 409 409 # … … 426 426 ## Data member to store the dispersion object created 427 427 self.populate_box(model_dict=self.model_list_box) 428 428 429 429 def onContextMenu(self, event): 430 430 """ … … 433 433 # Skipping the save state functionality for release 0.9.0 434 434 #return 435 435 436 436 pos = event.GetPosition() 437 437 pos = self.ScreenToClient(pos) 438 438 439 439 self.PopupMenu(self.popUpMenu, pos) 440 440 441 441 def onUndo(self, event): 442 442 """ … … 445 445 event = PreviousStateEvent(page=self) 446 446 wx.PostEvent(self.parent, event) 447 447 448 448 def onRedo(self, event): 449 449 """ … … 452 452 event = NextStateEvent(page=self) 453 453 wx.PostEvent(self.parent, event) 454 454 455 455 def define_page_structure(self): 456 456 """ … … 465 465 self.sizer5 = wx.BoxSizer(wx.VERTICAL) 466 466 self.sizer6 = wx.BoxSizer(wx.VERTICAL) 467 467 468 468 self.sizer0.SetMinSize((PANEL_WIDTH, -1)) 469 469 self.sizer1.SetMinSize((PANEL_WIDTH, -1)) … … 473 473 self.sizer5.SetMinSize((PANEL_WIDTH, -1)) 474 474 self.sizer6.SetMinSize((PANEL_WIDTH, -1)) 475 475 476 476 self.vbox.Add(self.sizer0) 477 477 self.vbox.Add(self.sizer1) … … 481 481 self.vbox.Add(self.sizer5) 482 482 self.vbox.Add(self.sizer6) 483 483 484 484 def set_layout(self): 485 485 """ … … 490 490 self.SetSizer(self.vbox) 491 491 self.Centre() 492 492 493 493 def set_owner(self, owner): 494 494 """ 495 495 set owner of fitpage 496 496 497 497 :param owner: the class responsible of plotting 498 498 499 499 """ 500 500 self.event_owner = owner 501 501 self.state.event_owner = owner 502 502 503 503 def get_state(self): 504 504 """ … … 506 506 """ 507 507 return self.state 508 508 509 509 def get_data(self): 510 510 """ … … 512 512 """ 513 513 return self.data 514 514 515 515 def get_data_list(self): 516 516 """ … … 518 518 """ 519 519 return self.data_list 520 520 521 521 def set_manager(self, manager): 522 522 """ 523 523 set panel manager 524 524 525 525 :param manager: instance of plugin fitting 526 526 527 527 """ 528 528 self._manager = manager 529 529 self.state.manager = manager 530 530 531 531 def populate_box(self, model_dict): 532 532 """ 533 533 Store list of model 534 534 535 535 :param model_dict: dictionary containing list of models 536 536 537 537 """ 538 538 self.model_list_box = model_dict 539 539 self.state.model_list_box = self.model_list_box 540 540 self.initialize_combox() 541 541 542 542 def set_model_dictionary(self, model_dict): 543 543 """ … … 551 551 """ 552 552 put default value in the combobox 553 """ 553 """ 554 554 ## fill combox box 555 555 if self.model_list_box is None: … … 560 560 ## These are called for first time by formfactor_combo_init 561 561 ## itself called from fitpanel only. If we find that I'm wrong and 562 ## we DO need to initialize somehow here - do it by a call to 563 ## formfactor_combo_init 562 ## we DO need to initialize somehow here - do it by a call to 563 ## formfactor_combo_init 564 564 ## self.formfator_combo_init() 565 ## BUT NOT HERE -- make it last line of this 565 ## BUT NOT HERE -- make it last line of this 566 566 ## method so that structure box is populated before _show_comboox_helper 567 567 ## is called. Otherwise wx will complain mightily:-) … … 575 575 # self.model_list_box["Shapes"]) 576 576 self._populate_box(self.structurebox, 577 self.model_list_box["Structure Factors"])577 self.model_list_box["Structure Factors"]) 578 578 self.structurebox.Insert("None", 0, None) 579 579 self.structurebox.SetSelection(0) … … 582 582 self.structurebox.Disable() 583 583 self.text2.Disable() 584 584 585 585 if self.model.__class__ in self.model_list_box["P(Q)*S(Q)"]: 586 586 self.structurebox.Show() … … 589 589 self.text2.Enable() 590 590 591 591 592 592 def set_dispers_sizer(self): 593 593 """ … … 601 601 #---------------------------------------------------- 602 602 self.disable_disp = wx.RadioButton(self, -1, 'Off', (10, 10), 603 style=wx.RB_GROUP)603 style=wx.RB_GROUP) 604 604 self.enable_disp = wx.RadioButton(self, -1, 'On', (10, 30)) 605 605 # best size for MAC and PC … … 614 614 id=self.disp_help_bt.GetId()) 615 615 self.disp_help_bt.SetToolTipString("Helps for Polydispersion.") 616 616 617 617 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 618 id=self.disable_disp.GetId())618 id=self.disable_disp.GetId()) 619 619 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 620 id=self.enable_disp.GetId())620 id=self.enable_disp.GetId()) 621 621 #MAC needs SetValue 622 622 self.disable_disp.SetValue(True) … … 630 630 sizer_dispersion.Add((25, 20)) 631 631 sizer_dispersion.Add(self.disp_help_bt) 632 632 633 633 ## fill a sizer for dispersion 634 634 boxsizer1.Add(sizer_dispersion, 0, 635 wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE,636 635 wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 636 border=5) 637 637 self.sizer4_4 = wx.GridBagSizer(6, 5) 638 638 … … 643 643 self.sizer4.Layout() 644 644 self.Layout() 645 645 646 646 self.Refresh() 647 647 ## saving the state of enable dispersity button … … 649 649 self.state.disable_disp = self.disable_disp.GetValue() 650 650 self.SetupScrolling() 651 651 652 652 def onResetModel(self, event): 653 653 """ … … 667 667 previous_state = self.saved_states[name] 668 668 ## reset state of checkbox,textcrtl and regular parameters value 669 669 670 670 self.reset_page(previous_state) 671 671 self.state.m_name = self.m_name 672 672 self.Show(True) 673 673 674 674 def on_preview(self, event): 675 675 """ … … 680 680 # get the report dialog 681 681 self.state.report(images, canvases) 682 682 683 683 def on_save(self, event): 684 684 """ … … 693 693 self._manager.parent._default_save_location 694 694 dlg = wx.FileDialog(self, "Choose a file", self._default_save_location, 695 self.window_caption, "*.fitv", wx.SAVE)695 self.window_caption, "*.fitv", wx.SAVE) 696 696 697 697 if dlg.ShowModal() == wx.ID_OK: 698 698 path = dlg.GetPath() 699 699 self._default_save_location = os.path.dirname(path) 700 self._manager.parent._default_save_location = 701 self._default_save_location700 self._manager.parent._default_save_location =\ 701 self._default_save_location 702 702 else: 703 703 return None … … 709 709 self._manager.save_fit_state(filepath=fName, fitstate=new_state) 710 710 return new_state 711 711 712 712 def on_copy(self, event): 713 713 """ … … 726 726 wx.CallAfter(self.get_copy) 727 727 728 728 729 729 def on_paste(self, event): 730 730 """ … … 738 738 # messages depending on the flag 739 739 #self._copy_info(True) 740 740 741 741 def _copy_info(self, flag): 742 742 """ 743 743 Send event dpemding on flag 744 744 745 745 : Param flag: flag that distinguish event 746 746 """ … … 758 758 # inform msg to wx 759 759 wx.PostEvent(self._manager.parent, 760 761 760 StatusEvent(status=msg, info=infor)) 761 762 762 def _get_time_stamp(self): 763 763 """ … … 769 769 current_date = str(month) + "/" + str(day) + "/" + str(year) 770 770 return current_time, current_date 771 771 772 772 def on_bookmark(self, event): 773 773 """ … … 788 788 name += "bookmarked at %s on %s" % (current_time, current_date) 789 789 self.saved_states[name] = new_state 790 790 791 791 ## Add item in the context menu 792 792 msg = "Model saved at %s on %s" % (current_time, current_date) … … 794 794 msg += " Saved! right click on this page to retrieve this model" 795 795 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 796 796 797 797 id = wx.NewId() 798 798 self.popUpMenu.Append(id, name, str(msg)) … … 802 802 hint=str(msg), 803 803 handler=self._back_to_bookmark)) 804 804 805 805 def _back_to_bookmark(self, event): 806 806 """ … … 810 810 self.onResetModel(event) 811 811 self._draw_model() 812 812 813 813 def onSetFocus(self, evt): 814 814 """ … … 817 817 """ 818 818 return 819 819 820 820 def read_file(self, path): 821 821 """ 822 822 Read two columns file 823 823 824 824 :param path: the path to the file to read 825 825 826 826 """ 827 827 try: … … 856 856 """ 857 857 return self.state.clone() 858 858 859 859 def save_current_state(self): 860 860 """ … … 866 866 self.state.disp_list = copy.deepcopy(self.disp_list) 867 867 self.state.model = self.model.clone() 868 868 869 869 #model combobox: complex code because of mac's silent error 870 870 if self.structurebox != None: … … 885 885 self.state.categorycombobox = self.categorybox.\ 886 886 GetString(cb_select) 887 887 888 888 self.state.enable2D = copy.deepcopy(self.enable2D) 889 889 self.state.values = copy.deepcopy(self.values) … … 902 902 self.state.enable_disp = self.enable_disp.GetValue() 903 903 self.state.disable_disp = self.disable_disp.GetValue() 904 904 905 905 self.state.smearer = copy.deepcopy(self.current_smearer) 906 906 if hasattr(self, "enable_smearer"): … … 917 917 self.state.dxw = copy.deepcopy(self.dxw) 918 918 self.state.slit_smearer = copy.deepcopy(self.slit_smearer.GetValue()) 919 919 920 920 if len(self._disp_obj_dict) > 0: 921 921 for k, v in self._disp_obj_dict.iteritems(): … … 926 926 ## save plotting range 927 927 self._save_plotting_range() 928 928 929 929 self.state.orientation_params = [] 930 930 self.state.orientation_params_disp = [] … … 941 941 self._copy_parameters_state(self.orientation_params_disp, 942 942 self.state.orientation_params_disp) 943 943 944 944 self._copy_parameters_state(self.parameters, self.state.parameters) 945 945 self._copy_parameters_state(self.fittable_param, … … 948 948 #save chisqr 949 949 self.state.tcChi = self.tcChi.GetValue() 950 950 951 951 def save_current_state_fit(self): 952 952 """ … … 958 958 self.state.disp_list = copy.deepcopy(self.disp_list) 959 959 self.state.model = self.model.clone() 960 960 961 961 self.state.enable2D = copy.deepcopy(self.enable2D) 962 962 self.state.values = copy.deepcopy(self.values) … … 964 964 ## save data 965 965 self.state.data = copy.deepcopy(self.data) 966 966 967 967 if hasattr(self, "enable_disp"): 968 968 self.state.enable_disp = self.enable_disp.GetValue() 969 969 self.state.disable_disp = self.disable_disp.GetValue() 970 970 971 971 self.state.smearer = copy.deepcopy(self.current_smearer) 972 972 if hasattr(self, "enable_smearer"): … … 975 975 self.state.disable_smearer = \ 976 976 copy.deepcopy(self.disable_smearer.GetValue()) 977 977 978 978 self.state.pinhole_smearer = \ 979 979 copy.deepcopy(self.pinhole_smearer.GetValue()) … … 998 998 for k, v in self._disp_obj_dict.iteritems(): 999 999 self.state._disp_obj_dict[k] = v 1000 1000 1001 1001 self.state.values = copy.deepcopy(self.values) 1002 1002 self.state.weights = copy.deepcopy(self.weights) 1003 1003 1004 1004 ## save plotting range 1005 1005 self._save_plotting_range() 1006 1006 1007 1007 ## save checkbutton state and txtcrtl values 1008 1008 self._copy_parameters_state(self.orientation_params, 1009 self.state.orientation_params)1009 self.state.orientation_params) 1010 1010 self._copy_parameters_state(self.orientation_params_disp, 1011 self.state.orientation_params_disp)1011 self.state.orientation_params_disp) 1012 1012 self._copy_parameters_state(self.parameters, self.state.parameters) 1013 1013 self._copy_parameters_state(self.fittable_param, 1014 self.state.fittable_param)1014 self.state.fittable_param) 1015 1015 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 1016 1016 1017 1017 def check_invalid_panel(self): 1018 1018 """ … … 1025 1025 wx.MessageBox(msg, 'Info') 1026 1026 return True 1027 1027 1028 1028 def set_model_state(self, state): 1029 1029 """ … … 1032 1032 self.disp_cb_dict = state.disp_cb_dict 1033 1033 self.disp_list = state.disp_list 1034 1034 1035 1035 ## set the state of the radio box 1036 1036 #self.shape_rbutton.SetValue(state.shape_rbutton) … … 1038 1038 #self.struct_rbutton.SetValue(state.struct_rbutton) 1039 1039 #self.plugin_rbutton.SetValue(state.plugin_rbutton) 1040 1040 1041 1041 ## fill model combobox 1042 1042 self._show_combox_helper() … … 1052 1052 category_pos = int(ind_cat) 1053 1053 break 1054 1054 1055 1055 self.categorybox.Select(category_pos) 1056 1056 try: … … 1064 1064 formfactor_pos = int(ind_form) 1065 1065 break 1066 1066 1067 1067 self.formfactorbox.Select(formfactor_pos) 1068 1068 1069 1069 try: 1070 1070 # to support older version … … 1077 1077 structfactor_pos = int(ind_struct) 1078 1078 break 1079 1079 1080 1080 self.structurebox.SetSelection(structfactor_pos) 1081 1081 1082 1082 if state.multi_factor != None: 1083 1083 self.multifactorbox.SetSelection(state.multi_factor) 1084 1084 1085 1085 ## reset state of checkbox,textcrtl and regular parameters value 1086 1086 self._reset_parameters_state(self.orientation_params_disp, … … 1094 1094 self.enable_disp.SetValue(state.enable_disp) 1095 1095 self.disable_disp.SetValue(state.disable_disp) 1096 1096 1097 1097 if hasattr(self, "disp_box") and self.disp_box != None: 1098 1098 self.disp_box.SetSelection(state.disp_box) … … 1102 1102 1103 1103 self._set_dipers_Param(event=None) 1104 1104 1105 1105 if name == "ArrayDispersion": 1106 1106 1107 1107 for item in self.disp_cb_dict.keys(): 1108 1108 1109 1109 if hasattr(self.disp_cb_dict[item], "SetValue"): 1110 1110 self.disp_cb_dict[item].SetValue(\ 1111 1111 state.disp_cb_dict[item]) 1112 1112 # Create the dispersion objects 1113 from sas.models.dispersion_models import ArrayDispersion 1113 #from sas.models.dispersion_models import ArrayDispersion 1114 from sasmodels.weights import ArrayDispersion 1114 1115 disp_model = ArrayDispersion() 1115 1116 if hasattr(state, "values") and \ … … 1122 1123 else: 1123 1124 self._reset_dispersity() 1124 1125 1125 1126 self._disp_obj_dict[item] = disp_model 1126 1127 # Set the new model as the dispersion object 1127 1128 #for the selected parameter 1128 1129 self.model.set_dispersion(item, disp_model) 1129 1130 1130 1131 self.model._persistency_dict[item] = \ 1131 1132 [state.values, state.weights] 1132 1133 1133 1134 else: 1134 1135 keys = self.model.getParamList() … … 1148 1149 self.pinhole_smearer.SetValue(state.pinhole_smearer) 1149 1150 self.slit_smearer.SetValue(state.slit_smearer) 1150 1151 1151 1152 self.dI_noweight.SetValue(state.dI_noweight) 1152 1153 self.dI_didata.SetValue(state.dI_didata) 1153 1154 self.dI_sqrdata.SetValue(state.dI_sqrdata) 1154 1155 self.dI_idata.SetValue(state.dI_idata) 1155 1156 1156 1157 ## we have two more options for smearing 1157 1158 if self.pinhole_smearer.GetValue(): … … 1159 1160 elif self.slit_smearer.GetValue(): 1160 1161 self.onSlitSmear(event=None) 1161 1162 1162 1163 ## reset state of checkbox,textcrtl and dispersity parameters value 1163 1164 self._reset_parameters_state(self.fittable_param, state.fittable_param) 1164 1165 self._reset_parameters_state(self.fixed_param, state.fixed_param) 1165 1166 1166 1167 ## draw the model with previous parameters value 1167 1168 self._onparamEnter_helper() … … 1171 1172 self._lay_out() 1172 1173 self.Refresh() 1173 1174 1174 1175 def reset_page_helper(self, state): 1175 1176 """ 1176 1177 Use page_state and change the state of existing page 1177 1178 1178 1179 :precondition: the page is already drawn or created 1179 1180 1180 1181 :postcondition: the state of the underlying data change as well as the 1181 1182 state of the graphic interface … … 1203 1204 else: 1204 1205 self.set_data(data) 1205 1206 1206 1207 self.enable2D = state.enable2D 1207 1208 try: … … 1213 1214 self.disp_cb_dict = state.disp_cb_dict 1214 1215 self.disp_list = state.disp_list 1215 1216 1216 1217 ## set the state of the radio box 1217 1218 #self.shape_rbutton.SetValue(state.shape_rbutton) … … 1219 1220 #self.struct_rbutton.SetValue(state.struct_rbutton) 1220 1221 #self.plugin_rbutton.SetValue(state.plugin_rbutton) 1221 1222 1222 1223 ## fill model combobox 1223 1224 self._show_combox_helper() … … 1233 1234 category_pos = int(ind_cat) 1234 1235 break 1235 1236 1236 1237 self.categorybox.Select(category_pos) 1237 1238 self._show_combox(None) … … 1246 1247 formfactor_pos = int(ind_form) 1247 1248 break 1248 1249 1249 1250 self.formfactorbox.Select(formfactor_pos) 1250 1251 1251 1252 try: 1252 1253 # to support older version … … 1259 1260 structfactor_pos = int(ind_struct) 1260 1261 break 1261 1262 1262 1263 self.structurebox.SetSelection(structfactor_pos) 1263 1264 … … 1267 1268 #draw the panel according to the new model parameter 1268 1269 self._on_select_model(event=None) 1269 1270 1270 1271 # take care of 2D button 1271 1272 if data == None and self.model_view.IsEnabled(): … … 1274 1275 else: 1275 1276 self.model_view.SetLabel("1D Mode") 1276 1277 1277 1278 ## set the select all check box to the a given state 1278 1279 self.cb1.SetValue(state.cb1) 1279 1280 1280 1281 ## reset state of checkbox,textcrtl and regular parameters value 1281 1282 self._reset_parameters_state(self.orientation_params_disp, … … 1316 1317 self.dI_sqrdata.SetValue(False) 1317 1318 self.dI_idata.SetValue(False) 1318 1319 1319 1320 ## we have two more options for smearing 1320 1321 if self.pinhole_smearer.GetValue(): … … 1332 1333 self.smear_slit_height.SetValue(str(self.dxl)) 1333 1334 if self.dxw != None: 1334 self.smear_slit_width.SetValue(str(self.dxw)) 1335 self.smear_slit_width.SetValue(str(self.dxw)) 1335 1336 else: 1336 self.smear_slit_width.SetValue('') 1337 self.smear_slit_width.SetValue('') 1337 1338 self.onSlitSmear(event=None) 1338 1339 1339 1340 ## reset state of checkbox,textcrtl and dispersity parameters value 1340 1341 self._reset_parameters_state(self.fittable_param, state.fittable_param) 1341 1342 self._reset_parameters_state(self.fixed_param, state.fixed_param) 1342 1343 1343 1344 ## draw the model with previous parameters value 1344 1345 self._onparamEnter_helper() … … 1347 1348 ## reset context menu items 1348 1349 self._reset_context_menu() 1349 1350 1350 1351 ## set the value of the current state to the state given as parameter 1351 1352 self.state = state.clone() 1352 1353 self.state.m_name = self.m_name 1353 1354 1354 1355 def _reset_page_disp_helper(self, state): 1355 1356 """ … … 1366 1367 self.values = copy.deepcopy(state.values) 1367 1368 self.weights = copy.deepcopy(state.weights) 1368 1369 1369 1370 for key, disp in state._disp_obj_dict.iteritems(): 1370 1371 # From saved file, disp_model can not be sent in model obj. … … 1372 1373 if disp.__class__.__name__ == 'str': 1373 1374 disp_model = None 1374 com_str = "from sas.models.dispersion_models " 1375 #com_str = "from sas.models.dispersion_models " 1376 com_str = "from sasmodels.weights " 1375 1377 com_str += "import %s as disp_func \ndisp_model = disp_func()" 1376 1378 exec com_str % disp … … 1413 1415 except: 1414 1416 logging.error(sys.exc_info()[1]) 1415 1417 1416 1418 # Make sure the check box updated when all checked 1417 1419 if self.cb1.GetValue(): 1418 1420 self.select_all_param(None) 1419 1421 1420 1422 def _selectDlg(self): 1421 1423 """ 1422 open a dialog file to selected the customized dispersity 1424 open a dialog file to selected the customized dispersity 1423 1425 """ 1424 1426 if self.parent != None: … … 1426 1428 self._manager.parent.get_save_location() 1427 1429 dlg = wx.FileDialog(self, "Choose a weight file", 1428 self._default_save_location, "",1429 "*.*", wx.OPEN)1430 self._default_save_location, "", 1431 "*.*", wx.OPEN) 1430 1432 path = None 1431 1433 if dlg.ShowModal() == wx.ID_OK: … … 1445 1447 self.popUpMenu.Append(id, name, msg) 1446 1448 wx.EVT_MENU(self, id, self.onResetModel) 1447 1449 1448 1450 def _reset_plotting_range(self, state): 1449 1451 """ … … 1464 1466 self.state.formfactorcombobox = self.formfactorbox.GetLabel() 1465 1467 self.state.categorycombobox = self.categorybox.GetLabel() 1466 1468 1467 1469 ## post state to fit panel 1468 1470 event = PageInfoEvent(page=self) 1469 1471 wx.PostEvent(self.parent, event) 1470 1472 1471 1473 def _save_plotting_range(self): 1472 1474 """ … … 1476 1478 self.state.qmax = self.qmax_x 1477 1479 self.state.npts = self.npts_x 1478 1480 1479 1481 def _onparamEnter_helper(self): 1480 1482 """ … … 1493 1495 try: 1494 1496 is_modified = self._check_value_enter(self.fittable_param, 1495 1497 is_modified) 1496 1498 is_modified = self._check_value_enter(self.fixed_param, 1497 1499 is_modified) … … 1513 1515 self.qmax_x = tempmax 1514 1516 is_modified = True 1515 1517 1516 1518 if is_2Ddata: 1517 1519 # set mask 1518 1520 is_modified = self._validate_Npts() 1519 1521 1520 1522 else: 1521 1523 self.fitrange = False 1522 1524 1523 1525 if not self.data.is_data: 1524 1526 is_modified = True … … 1540 1542 self.Refresh() 1541 1543 return is_modified 1542 1544 1543 1545 def _update_paramv_on_fit(self): 1544 1546 """ … … 1565 1567 self._check_value_enter(self.parameters, is_modified) 1566 1568 1567 # If qmin and qmax have been modified, update qmin and qmax and 1569 # If qmin and qmax have been modified, update qmin and qmax and 1568 1570 # Here we should check whether the boundaries have been modified. 1569 # If qmin and qmax have been modified, update qmin and qmax and 1571 # If qmin and qmax have been modified, update qmin and qmax and 1570 1572 # set the is_modified flag to True 1571 1573 self.fitrange = self._validate_qrange(self.qmin, self.qmax) … … 1594 1596 qmax=float(self.qmax_x), 1595 1597 enable_smearer=enable_smearer, 1596 draw=False)1598 draw=False) 1597 1599 elif not self._is_2D(): 1598 1600 enable_smearer = not self.disable_smearer.GetValue() … … 1603 1605 qmax=float(self.qmax_x), 1604 1606 enable_smearer=enable_smearer, 1605 draw=False)1607 draw=False) 1606 1608 if self.data != None: 1607 1609 index_data = ((self.qmin_x <= self.data.x) & \ … … 1639 1641 msg += " model or Fitting range is not valid!!! " 1640 1642 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1641 1643 1642 1644 try: 1643 1645 self.save_current_state() 1644 1646 except: 1645 1647 logging.error(sys.exc_info()[1]) 1646 1648 1647 1649 return flag 1648 1650 1649 1651 def _is_modified(self, is_modified): 1650 1652 """ … … 1652 1654 """ 1653 1655 return is_modified 1654 1656 1655 1657 def _reset_parameters_state(self, listtorestore, statelist): 1656 1658 """ … … 1691 1693 item_page[5].Show(item_page_info[5][0]) 1692 1694 item_page[5].SetValue(item_page_info[5][1]) 1693 1695 1694 1696 if item_page[6] != None: 1695 1697 ## show of hide the text crtl for fitting error 1696 1698 item_page[6].Show(item_page_info[6][0]) 1697 1699 item_page[6].SetValue(item_page_info[6][1]) 1698 1700 1699 1701 def _reset_strparam_state(self, listtorestore, statelist): 1700 1702 """ … … 1705 1707 1706 1708 listtorestore = copy.deepcopy(statelist) 1707 1709 1708 1710 for j in range(len(listtorestore)): 1709 1711 item_page = listtorestore[j] 1710 1712 item_page_info = statelist[j] 1711 1713 ##change the state of the check box for simple parameters 1712 1714 1713 1715 if item_page[0] != None: 1714 1716 item_page[0].SetValue(format_number(item_page_info[0], True)) … … 1722 1724 item_page[2].SetValue(selection) 1723 1725 self.model.setParam(param_name, selection) 1724 1726 1725 1727 def _copy_parameters_state(self, listtocopy, statelist): 1726 1728 """ 1727 1729 copy the state of button 1728 1730 1729 1731 :param listtocopy: the list of check button to copy 1730 1732 :param statelist: list of state object to store the current state 1731 1733 1732 1734 """ 1733 1735 if len(listtocopy) == 0: 1734 1736 return 1735 1737 1736 1738 for item in listtocopy: 1737 1739 1738 1740 checkbox_state = None 1739 1741 if item[0] != None: … … 1751 1753 error_value = item[4].GetValue() 1752 1754 error_state = item[4].IsShown() 1753 1755 1754 1756 min_value = None 1755 1757 min_state = None … … 1757 1759 min_value = item[5].GetValue() 1758 1760 min_state = item[5].IsShown() 1759 1761 1760 1762 max_value = None 1761 1763 max_state = None … … 1766 1768 if item[7] != None: 1767 1769 unit = item[7].GetLabel() 1768 1770 1769 1771 statelist.append([checkbox_state, parameter_name, parameter_value, 1770 1772 static_text, [error_state, error_value], 1771 1773 [min_state, min_value], 1772 1774 [max_state, max_value], unit]) 1773 1774 1775 1776 1775 1777 def _draw_model(self, update_chisqr=True, source='model'): 1776 1778 """ … … 1778 1780 The method will use the data member from the model page 1779 1781 to build a call to the fitting perspective manager. 1780 1782 1781 1783 :param chisqr: update chisqr value [bool] 1782 1784 """ 1783 1785 wx.CallAfter(self._draw_model_after, update_chisqr, source) 1784 1786 1785 1787 def _draw_model_after(self, update_chisqr=True, source='model'): 1786 1788 """ … … 1788 1790 The method will use the data member from the model page 1789 1791 to build a call to the fitting perspective manager. 1790 1792 1791 1793 :param chisqr: update chisqr value [bool] 1792 1794 """ … … 1816 1818 source='model', 1817 1819 weight=weight) 1818 1820 1819 1821 def _on_show_sld(self, event=None): 1820 1822 """ … … 1831 1833 sld_data.name = 'SLD' 1832 1834 sld_data.axes = self.sld_axes 1833 self.panel = SLDPanel(self, data=sld_data, axes=self.sld_axes, id= 1835 self.panel = SLDPanel(self, data=sld_data, axes=self.sld_axes, id=-1) 1834 1836 self.panel.ShowModal() 1835 1837 1836 1838 def _set_multfactor_combobox(self, multiplicity=10): 1837 1839 """ … … 1843 1845 self.multifactorbox.Append(str(idx), int(idx)) 1844 1846 self._hide_multfactor_combobox() 1845 1847 1846 1848 def _show_multfactor_combobox(self): 1847 1849 """ … … 1853 1855 if not self.multifactorbox.IsShown(): 1854 1856 self.multifactorbox.Show(True) 1855 1857 1856 1858 def _hide_multfactor_combobox(self): 1857 1859 """ … … 1863 1865 if self.multifactorbox.IsShown(): 1864 1866 self.multifactorbox.Hide() 1865 1867 1866 1868 def formfactor_combo_init(self): 1867 1869 """ … … 1869 1871 """ 1870 1872 self._show_combox(None) 1871 1873 1872 1874 def _show_combox_helper(self): 1873 1875 """ … … 1902 1904 StatusEvent(status=msg, info="error")) 1903 1905 self._populate_box(self.formfactorbox, m_list) 1904 1905 def _on_modify_cat(self, event=None): 1906 1907 def _on_modify_cat(self, event=None): 1906 1908 """ 1907 1909 Called when category manager is opened 1908 1910 """ 1909 self._manager.parent.on_category_panel(event) 1910 1911 self._manager.parent.on_category_panel(event) 1912 1911 1913 def _show_combox(self, event=None): 1912 1914 """ … … 1922 1924 self.Layout() 1923 1925 self.Refresh() 1924 1926 1925 1927 def _populate_box(self, combobox, list): 1926 1928 """ 1927 1929 fill combox box with dict item 1928 1930 1929 1931 :param list: contains item to fill the combox 1930 1932 item must model class … … 1935 1937 name = model.__class__.__name__ 1936 1938 if models.__name__ != "NoStructure": 1937 if hasattr(model, "name"): 1939 if hasattr(model, "oldname"): 1940 name = model.oldname 1941 elif hasattr(model, "name"): 1938 1942 name = model.name 1939 1943 mlist.append((name, models)) 1940 1944 1941 1945 # Sort the models 1942 1946 mlist_sorted = sorted(mlist) … … 1944 1948 combobox.Append(item[0], item[1]) 1945 1949 return 0 1946 1950 1947 1951 def _onQrangeEnter(self, event): 1948 1952 """ 1949 1953 Check validity of value enter in the Q range field 1950 1954 1951 1955 """ 1952 1956 tcrtl = event.GetEventObject() … … 2001 2005 self.create_default_data() 2002 2006 self._draw_model() 2003 2007 2004 2008 def _theory_qrange_enter(self, event): 2005 2009 """ 2006 2010 Check validity of value enter in the Q range field 2007 2011 """ 2008 2012 2009 2013 tcrtl = event.GetEventObject() 2010 2014 #Clear msg if previously shown. … … 2058 2062 self.create_default_data() 2059 2063 self._draw_model() 2060 2064 2061 2065 def _on_select_model_helper(self): 2062 2066 """ … … 2084 2088 self.structurebox.Enable() 2085 2089 self.text2.Enable() 2086 2090 2087 2091 if form_factor != None: 2088 2092 # set multifactor for Mutifunctional models … … 2101 2105 # default value 2102 2106 m_id = 1 2103 2107 2104 2108 self.multi_factor = self.multifactorbox.GetClientData(m_id) 2105 2109 if self.multi_factor == None: … … 2129 2133 self.show_sld_button.Hide() 2130 2134 self.multi_factor = None 2131 2135 2132 2136 s_id = self.structurebox.GetCurrentSelection() 2133 2137 struct_factor = self.structurebox.GetClientData(s_id) 2134 2138 2135 2139 if struct_factor != None: 2136 2140 from sas.models.MultiplicationModel import MultiplicationModel … … 2147 2151 # check if model has magnetic parameters 2148 2152 if len(self.model.magnetic_params) > 0: 2149 self._has_magnetic = True 2153 self._has_magnetic = True 2150 2154 else: 2151 self._has_magnetic = False 2155 self._has_magnetic = False 2152 2156 ## post state to fit panel 2153 2157 self.state.parameters = [] … … 2159 2163 self.on_set_focus(None) 2160 2164 self.Layout() 2161 2165 2162 2166 def _validate_qrange(self, qmin_ctrl, qmax_ctrl): 2163 2167 """ 2164 2168 Verify that the Q range controls have valid values 2165 2169 and that Qmin < Qmax. 2166 2170 2167 2171 :param qmin_ctrl: text control for Qmin 2168 2172 :param qmax_ctrl: text control for Qmax 2169 2173 2170 2174 :return: True is the Q range is value, False otherwise 2171 2175 2172 2176 """ 2173 2177 qmin_validity = check_float(qmin_ctrl) … … 2193 2197 return False 2194 2198 return True 2195 2199 2196 2200 def _validate_Npts(self): 2197 2201 """ … … 2228 2232 self.Npts_fit.SetValue(str(len(index_data[index_data == True]))) 2229 2233 self.fitrange = True 2230 2234 2231 2235 return flag 2232 2236 … … 2263 2267 self.Npts_fit.SetValue(str(len(index_data[index_data == True]))) 2264 2268 self.fitrange = True 2265 2269 2266 2270 return flag 2267 2271 2268 2272 def _check_value_enter(self, list, modified): 2269 2273 """ … … 2287 2291 #try: 2288 2292 name = str(item[1]) 2289 2293 2290 2294 if string.find(name, ".npts") == -1 and \ 2291 2295 string.find(name, ".nsigmas") == -1: … … 2293 2297 param_min = None 2294 2298 param_max = None 2295 2299 2296 2300 ## check minimun value 2297 2301 if item[5] != None and item[5] != "": … … 2302 2306 if numpy.isfinite(param_min): 2303 2307 item[2].SetValue(format_number(param_min)) 2304 2308 2305 2309 item[5].SetBackgroundColour(wx.WHITE) 2306 2310 item[2].SetBackgroundColour(wx.WHITE) 2307 2311 2308 2312 except: 2309 2313 msg = "Wrong fit parameter range entered" … … 2320 2324 if numpy.isfinite(param_max): 2321 2325 item[2].SetValue(format_number(param_max)) 2322 2326 2323 2327 item[6].SetBackgroundColour(wx.WHITE) 2324 2328 item[2].SetBackgroundColour(wx.WHITE) … … 2329 2333 raise ValueError, msg 2330 2334 is_modified = True 2331 2335 2332 2336 if param_min != None and param_max != None: 2333 2337 if not self._validate_qrange(item[5], item[6]): … … 2336 2340 wx.PostEvent(self._manager.parent, 2337 2341 StatusEvent(status=msg)) 2338 2342 2339 2343 if name in self.model.details.keys(): 2340 2344 self.model.details[name][1:3] = param_min, param_max … … 2357 2361 msg = "Wrong Fit parameter value entered " 2358 2362 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2359 2363 2360 2364 return is_modified 2361 2365 2362 2366 def _set_dipers_Param(self, event): 2363 2367 """ … … 2378 2382 2379 2383 self._reset_dispersity() 2380 2384 2381 2385 if self.model == None: 2382 2386 self.model_disp.Hide() … … 2386 2390 if self.enable_disp.GetValue(): 2387 2391 ## layout for model containing no dispersity parameters 2388 2392 2389 2393 self.disp_list = self.model.getDispParamList() 2390 2394 2391 2395 if len(self.disp_list) == 0 and len(self.disp_cb_dict) == 0: 2392 2396 self._layout_sizer_noDipers() … … 2396 2400 else: 2397 2401 self.sizer4_4.Clear(True) 2398 2402 2399 2403 ## post state to fit panel 2400 2404 self.save_current_state() … … 2408 2412 self.Layout() 2409 2413 self.Refresh() 2410 2414 2411 2415 def _layout_sizer_noDipers(self): 2412 2416 """ … … 2418 2422 self.fixed_param = [] 2419 2423 self.orientation_params_disp = [] 2420 2424 2421 2425 self.sizer4_4.Clear(True) 2422 2426 text = "No polydispersity available for this model" … … 2426 2430 self.sizer4_4.Layout() 2427 2431 self.sizer4.Layout() 2428 2432 2429 2433 def _reset_dispersity(self): 2430 2434 """ … … 2439 2443 if item in self.param_toFit: 2440 2444 self.param_toFit.remove(item) 2441 2445 2442 2446 self.fittable_param = [] 2443 2447 self.fixed_param = [] … … 2445 2449 self.values = {} 2446 2450 self.weights = {} 2447 2448 from sas.models.dispersion_models import GaussianDispersion 2451 2452 #from sas.models.dispersion_models import GaussianDispersion 2453 from sasmodels.weights import GaussianDispersion 2449 2454 if len(self.disp_cb_dict) == 0: 2450 2455 self.save_current_state() … … 2457 2462 # Go back to Gaussian model (with 0 pts) 2458 2463 disp_model = GaussianDispersion() 2459 2464 2460 2465 self._disp_obj_dict[p] = disp_model 2461 2466 # Set the new model as the dispersion object … … 2470 2475 self.Layout() 2471 2476 self.Refresh() 2472 2477 2473 2478 def _on_select_Disp(self, event): 2474 2479 """ … … 2483 2488 event = PageInfoEvent(page=self) 2484 2489 wx.PostEvent(self.parent, event) 2485 2490 2486 2491 self.sizer4_4.Layout() 2487 2492 self.sizer4.Layout() 2488 2493 self.SetupScrolling() 2489 2494 2490 2495 def _on_disp_func(self, event=None): 2491 2496 """ 2492 2497 Select a distribution function for the polydispersion 2493 2498 2494 2499 :Param event: ComboBox event 2495 2500 """ … … 2507 2512 disp_name = disp_box.GetValue() 2508 2513 dispersity = disp_box.GetClientData(selection) 2509 2514 2510 2515 #disp_model = GaussianDispersion() 2511 2516 disp_model = dispersity() … … 2525 2530 self.model.set_dispersion(param_name, disp_model) 2526 2531 self.state._disp_obj_dict[name1] = disp_model 2527 2532 2528 2533 value1 = str(format_number(self.model.getParam(name1), True)) 2529 2534 value2 = str(format_number(self.model.getParam(name2))) … … 2553 2558 for item in self.fixed_param: 2554 2559 if item[1] == name2: 2555 item[2].SetValue(value2) 2560 item[2].SetValue(value2) 2556 2561 # Disable Npts for array 2557 2562 if disp_name.lower() == "array": … … 2566 2571 else: 2567 2572 item[2].Enable() 2568 2573 2569 2574 # Make sure the check box updated when all checked 2570 2575 if self.cb1.GetValue(): … … 2587 2592 wx.PostEvent(self._manager.parent, 2588 2593 StatusEvent(status=msg, info="error")) 2589 2594 2590 2595 def _set_array_disp(self, name=None, disp=None): 2591 2596 """ 2592 2597 Set array dispersion 2593 2598 2594 2599 :param name: name of the parameter for the dispersion to be set 2595 2600 :param disp: the polydisperion object … … 2608 2613 self._default_save_location = os.path.dirname(path) 2609 2614 if self._manager != None: 2610 self._manager.parent._default_save_location = 2615 self._manager.parent._default_save_location =\ 2611 2616 self._default_save_location 2612 2617 2613 2618 basename = os.path.basename(path) 2614 2619 values, weights = self.read_file(path) 2615 2620 2616 2621 # If any of the two arrays is empty, notify the user that we won't 2617 2622 # proceed … … 2626 2631 values=values, weights=weights) 2627 2632 return basename 2628 2633 2629 2634 def _set_array_disp_model(self, name=None, disp=None, 2630 2635 values=[], weights=[]): 2631 2636 """ 2632 2637 Set array dispersion model 2633 2638 2634 2639 :param name: name of the parameter for the dispersion to be set 2635 2640 :param disp: the polydisperion object … … 2660 2665 self.state.model._persistency_dict[name.split('.')[0]] = \ 2661 2666 [values, weights] 2662 2667 2663 2668 def _del_array_values(self, name=None): 2664 2669 """ 2665 2670 Reset array dispersion 2666 2671 2667 2672 :param name: name of the parameter for the dispersion to be set 2668 2673 """ … … 2678 2683 except: 2679 2684 logging.error(sys.exc_info()[1]) 2680 2685 2681 2686 def _lay_out(self): 2682 2687 """ 2683 2688 returns self.Layout 2684 2689 2685 2690 :Note: Mac seems to like this better when self. 2686 2691 Layout is called after fitting. … … 2689 2694 self.Layout() 2690 2695 return 2691 2696 2692 2697 def _sleep4sec(self): 2693 2698 """ … … 2698 2703 if ON_MAC == True: 2699 2704 time.sleep(1) 2700 2705 2701 2706 def _find_polyfunc_selection(self, disp_func=None): 2702 2707 """ 2703 2708 FInd Comboox selection from disp_func 2704 2709 2705 2710 :param disp_function: dispersion distr. function 2706 2711 """ … … 2716 2721 except: 2717 2722 return 3 2718 2723 2719 2724 def on_reset_clicked(self, event): 2720 2725 """ … … 2728 2733 flag = False 2729 2734 return 2730 2735 2731 2736 elif self.data.__class__.__name__ == "Data2D": 2732 2737 data_min = 0 … … 2734 2739 y = max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) 2735 2740 self.qmin_x = data_min 2736 self.qmax_x = math.sqrt(x * x + y *y)2741 self.qmax_x = math.sqrt(x*x + y*y) 2737 2742 #self.data.mask = numpy.ones(len(self.data.data),dtype=bool) 2738 2743 # check smearing … … 2744 2749 else: 2745 2750 flag = True 2746 2751 2747 2752 elif self.data == None: 2748 2753 self.qmin_x = _QMIN_DEFAULT … … 2750 2755 self.num_points = _NPTS_DEFAULT 2751 2756 self.state.npts = self.num_points 2752 2757 2753 2758 elif self.data.__class__.__name__ != "Data2D": 2754 2759 self.qmin_x = min(self.data.x) … … 2766 2771 else: 2767 2772 flag = False 2768 2773 2769 2774 if flag == False: 2770 2775 msg = "Cannot Plot :Must enter a number!!! " … … 2783 2788 self.state.qmin = self.qmin_x 2784 2789 self.state.qmax = self.qmax_x 2785 2790 2786 2791 #reset the q range values 2787 2792 self._reset_plotting_range(self.state) 2788 2793 self._draw_model() 2789 2794 2790 2795 def select_log(self, event): 2791 2796 """ … … 2796 2801 """ 2797 2802 Get the images of the plots corresponding this panel for report 2798 2803 2799 2804 : return graphs: list of figures 2800 2805 : Need Move to guiframe … … 2820 2825 # append to the list 2821 2826 graphs.append(item2.figure) 2822 canvases.append(item2.canvas) 2827 canvases.append(item2.canvas) 2823 2828 except: 2824 2829 # Not for control panels … … 2870 2875 :param evt: on Description Button pressed event 2871 2876 """ 2872 2877 2873 2878 if self.model == None: 2874 2879 name = 'index.html' … … 2876 2881 name = self.formfactorbox.GetValue() 2877 2882 2878 msg = 'Model description:\n'2883 msg = 'Model description:\n' 2879 2884 info = "Info" 2880 2885 if self.model != None: 2881 2886 # frame.Destroy() 2882 if str(self.model.description).rstrip().lstrip() == '': 2883 msg += "Sorry, no information is available for this model." 2887 if str(self.model.description).rstrip().lstrip() == '': 2888 msg += "Sorry, no information is available for this model." 2889 else: 2890 msg += self.model.description + '\n' 2891 wx.MessageBox(msg, info) 2884 2892 else: 2885 msg += self.model.description + '\n'2886 wx.MessageBox(msg, info)2887 else:2888 2893 msg += "You must select a model to get information on this" 2889 2894 wx.MessageBox(msg, info) … … 2909 2914 "Magnetic Angle Defintions") 2910 2915 2911 def _on_mag_help(self, event): 2916 def _on_mag_help(self, event): 2912 2917 """ 2913 2918 Bring up Magnetic Angle definition bmp image whenever the ? button … … 2929 2934 "Polarized Beam/Magnetc Help") 2930 2935 2931 def _on_mag_on(self, event): 2936 def _on_mag_on(self, event): 2932 2937 """ 2933 2938 Magnetic Parameters ON/OFF … … 2950 2955 #reset mag value to zero fo safety 2951 2956 self.model.setParam(key, 0.0) 2952 2953 self.Show(False) 2957 2958 self.Show(False) 2954 2959 self.set_model_param_sizer(self.model) 2955 2960 #self._set_sizer_dispersion() … … 2957 2962 self.SetupScrolling() 2958 2963 self.Show(True) 2959 2964 2960 2965 def on_pd_help_clicked(self, event): 2961 2966 """ … … 2967 2972 webbrowser does not pass anything past the # to the browser when it is 2968 2973 running "file:///...." 2969 2974 2970 2975 :param evt: Triggers on clicking ? in polydispersity box 2971 2976 """ … … 2975 2980 _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, 2976 2981 _PageAnchor, "Polydispersity Help") 2977 2982 2978 2983 def on_left_down(self, event): 2979 2984 """ … … 2990 2995 # make event free 2991 2996 event.Skip() 2992 2997 2993 2998 def get_copy(self): 2994 2999 """ … … 2999 3004 self._copy_info(flag) 3000 3005 return flag 3001 3006 3002 3007 def get_copy_params(self): 3003 3008 """ … … 3007 3012 # Do it if params exist 3008 3013 if self.parameters != []: 3009 3014 3010 3015 # go through the parameters 3011 3016 strings = self._get_copy_helper(self.parameters, 3012 3017 self.orientation_params) 3013 3018 content += strings 3014 3019 3015 3020 # go through the fittables 3016 3021 strings = self._get_copy_helper(self.fittable_param, … … 3022 3027 self.orientation_params_disp) 3023 3028 content += strings 3024 3029 3025 3030 # go through the str params 3026 3031 strings = self._get_copy_helper(self.str_parameters, … … 3055 3060 content += param[1] #parameter name 3056 3061 content += tab 3057 content += param[1] +"_err"3062 content += param[1]+"_err" 3058 3063 content += tab 3059 3064 … … 3063 3068 for param in self.parameters: 3064 3069 content += param[2].GetValue() #value 3065 content += 3070 content +=tab 3066 3071 content += param[4].GetValue() #error 3067 content += 3072 content +=tab 3068 3073 3069 3074 return content … … 3101 3106 3102 3107 for index, param in enumerate(self.parameters): 3103 content += param[1].replace('_', 3108 content += param[1].replace('_','\_') #parameter name 3104 3109 content += ' & ' 3105 content += param[1].replace('_', '\_') +"\_err"3106 if index < len(self.parameters) -1:3110 content += param[1].replace('_','\_')+"\_err" 3111 if index < len(self.parameters)-1: 3107 3112 content += ' & ' 3108 3113 content += '\\\\ \\hline' … … 3114 3119 content += ' & ' 3115 3120 content += param[4].GetValue() #parameter error 3116 if index < len(self.parameters) -1:3121 if index < len(self.parameters)-1: 3117 3122 content += ' & ' 3118 3123 content += '\\\\ \\hline' … … 3137 3142 return True 3138 3143 return None 3139 3144 3140 3145 def _get_copy_helper(self, param, orient_param): 3141 3146 """ 3142 3147 Helping get value and name of the params 3143 3148 3144 3149 : param param: parameters 3145 3150 : param orient_param = oritational params … … 3158 3163 except: 3159 3164 logging.error(sys.exc_info()[1]) 3160 3165 3161 3166 # 2D 3162 3167 if self.data.__class__.__name__ == "Data2D": … … 3180 3185 # add to the content 3181 3186 if disfunc != '': 3182 3187 3183 3188 disfunc = ',' + disfunc 3184 3189 # Need to support array func for copy/paste … … 3196 3201 3197 3202 return content 3198 3203 3199 3204 def get_clipboard(self): 3200 3205 """ … … 3216 3221 wx.TheClipboard.Close() 3217 3222 return text 3218 3223 3219 3224 def get_paste(self): 3220 3225 """ … … 3225 3230 self._copy_info(flag) 3226 3231 return flag 3227 3232 3228 3233 def get_paste_params(self, text=''): 3229 3234 """ … … 3254 3259 val = [float(a_val) for a_val in array_values[1:]] 3255 3260 weit = [float(a_weit) for a_weit in array_weights[1:]] 3256 3261 3257 3262 context[name].append(val) 3258 3263 context[name].append(weit) … … 3277 3282 self._get_paste_helper(self.fixed_param, 3278 3283 self.orientation_params_disp, context) 3279 3284 3280 3285 # go through the str params 3281 3286 self._get_paste_helper(self.str_parameters, 3282 3287 self.orientation_params, context) 3283 3288 3284 3289 return True 3285 3290 return None 3286 3291 3287 3292 def _get_paste_helper(self, param, orient_param, content): 3288 3293 """ 3289 3294 Helping set values of the params 3290 3295 3291 3296 : param param: parameters 3292 3297 : param orient_param: oritational params … … 3316 3321 fun_val = self.model.fun_list[content[name][1]] 3317 3322 self.model.setParam(name, fun_val) 3318 3323 3319 3324 value = content[name][1:] 3320 3325 self._paste_poly_help(item, value) … … 3362 3367 if is_true != None: 3363 3368 item[0].SetValue(is_true) 3364 3369 3365 3370 def _paste_poly_help(self, item, value): 3366 3371 """ 3367 3372 Helps get paste for poly function 3368 3373 3369 3374 :param item: Gui param items 3370 3375 :param value: the values for parameter ctrols … … 3406 3411 [self.state.values, 3407 3412 self.state.weights] 3408 3413 3409 3414 except: 3410 3415 logging.error(sys.exc_info()[1]) 3411 3416 print "Error in BasePage._paste_poly_help: %s" % \ 3412 3417 sys.exc_info()[1] 3413 3418 3414 3419 def _set_disp_array_cb(self, item): 3415 3420 """ … … 3425 3430 item[6].SetValue('') 3426 3431 item[6].Enable(False) 3427 3432 3428 3433 def update_pinhole_smear(self): 3429 3434 """ … … 3447 3452 if not os.path.isfile(categorization_file): 3448 3453 categorization_file = CategoryInstaller.get_default_file() 3449 cat_file = open(categorization_file, 'rb') 3454 cat_file = open(categorization_file, 'rb') 3450 3455 self.master_category_dict = json.load(cat_file) 3451 3456 self._regenerate_model_dict() … … 3459 3464 def _regenerate_model_dict(self): 3460 3465 """ 3461 regenerates self.by_model_dict which has each model name as the 3466 regenerates self.by_model_dict which has each model name as the 3462 3467 key and the list of categories belonging to that model 3463 3468 along with the enabled mapping … … 3468 3473 self.by_model_dict[model].append(category) 3469 3474 self.model_enabled_dict[model] = enabled 3470 3475 3471 3476 def _populate_listbox(self): 3472 3477 """ … … 3480 3485 if not uncat_str in cat_list: 3481 3486 cat_list.append(uncat_str) 3482 3487 3483 3488 for category in cat_list: 3484 3489 if category != '': … … 3488 3493 self.categorybox.SetSelection(0) 3489 3494 else: 3490 self.categorybox.SetSelection( \3495 self.categorybox.SetSelection( \ 3491 3496 self.categorybox.GetSelection()) 3492 3497 #self._on_change_cat(None) … … 3508 3513 3509 3514 else: 3510 for (model, 3511 key =lambda name: name[0]):3515 for (model,enabled) in sorted(self.master_category_dict[category], 3516 key = lambda name: name[0]): 3512 3517 if(enabled): 3513 3518 self.model_box.Append(model) … … 3539 3544 hint = "toggle view of model from 1D to 2D or 2D to 1D" 3540 3545 self.model_view.SetToolTipString(hint) 3541 3546 3542 3547 cat_set_box = wx.StaticBox(self, -1, 'Category') 3543 3548 sizer_cat_box = wx.StaticBoxSizer(cat_set_box, wx.HORIZONTAL) 3544 3549 sizer_cat_box.SetMinSize((200, 50)) 3545 3550 self.categorybox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 3546 self.categorybox.SetToolTip( wx.ToolTip("Select a Category/Type"))3551 self.categorybox.SetToolTip( wx.ToolTip("Select a Category/Type") ) 3547 3552 self._populate_listbox() 3548 3553 wx.EVT_COMBOBOX(self.categorybox, -1, self._show_combox) … … 3553 3558 #self.struct_rbutton = wx.RadioButton(self, -1, "Structure Factor ") 3554 3559 #self.plugin_rbutton = wx.RadioButton(self, -1, "Uncategorized") 3555 3560 3556 3561 #self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 3557 3562 # id=self.shape_rbutton.GetId()) … … 3563 3568 # id=self.plugin_rbutton.GetId()) 3564 3569 #MAC needs SetValue 3565 3570 3566 3571 show_cat_button = wx.Button(self, -1, "Modify") 3567 3572 cat_tip = "Modify model categories \n" 3568 3573 cat_tip += "(also accessible from the menu bar)." 3569 show_cat_button.SetToolTip( wx.ToolTip(cat_tip))3574 show_cat_button.SetToolTip( wx.ToolTip(cat_tip) ) 3570 3575 show_cat_button.Bind(wx.EVT_BUTTON, self._on_modify_cat) 3571 3576 sizer_cat_box.Add(self.categorybox, 1, wx.RIGHT, 3) 3572 sizer_cat_box.Add((10, 3577 sizer_cat_box.Add((10,10)) 3573 3578 sizer_cat_box.Add(show_cat_button) 3574 3579 #self.shape_rbutton.SetValue(True) 3575 3580 3576 3581 sizer_radiobutton = wx.GridSizer(2, 2, 5, 5) 3577 3582 #sizer_radiobutton.Add(self.shape_rbutton) 3578 3583 #sizer_radiobutton.Add(self.shape_indep_rbutton) 3579 sizer_radiobutton.Add((5, 3584 sizer_radiobutton.Add((5,5)) 3580 3585 sizer_radiobutton.Add(self.model_view, 1, wx.RIGHT, 5) 3581 3586 #sizer_radiobutton.Add(self.plugin_rbutton) … … 3589 3594 sizer_selection = wx.BoxSizer(wx.HORIZONTAL) 3590 3595 mutifactor_selection = wx.BoxSizer(wx.HORIZONTAL) 3591 3596 3592 3597 self.text1 = wx.StaticText(self, -1, "") 3593 3598 self.text2 = wx.StaticText(self, -1, "P(Q)*S(Q)") … … 3598 3603 3599 3604 self.formfactorbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) 3600 self.formfactorbox.SetToolTip( wx.ToolTip("Select a Model"))3605 self.formfactorbox.SetToolTip( wx.ToolTip("Select a Model") ) 3601 3606 if self.model != None: 3602 3607 self.formfactorbox.SetValue(self.model.name) … … 3612 3617 print "_set_model_sizer_selection: disabled." 3613 3618 #self._set_model_sizer_selection(self.model) 3614 3619 3615 3620 sizer_selection.Add(self.text1) 3616 3621 sizer_selection.Add((10, 5)) … … 3620 3625 sizer_selection.Add((5, 5)) 3621 3626 sizer_selection.Add(self.structurebox) 3622 3627 3623 3628 mutifactor_selection.Add((13, 5)) 3624 3629 mutifactor_selection.Add(self.mutifactor_text) … … 3634 3639 boxsizer1.Add((10, 10)) 3635 3640 boxsizer1.Add(mutifactor_selection) 3636 3641 3637 3642 self._set_multfactor_combobox() 3638 3643 self.multifactorbox.SetSelection(1) … … 3640 3645 sizer.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 3641 3646 sizer.Layout() 3642 3647 3643 3648 def on_smear_helper(self, update=False): 3644 3649 """ 3645 3650 Help for onSmear if implemented 3646 3651 3647 3652 :param update: force or not to update 3648 3653 """ … … 3653 3658 def onSmear(self, event): 3654 3659 """ 3655 Create a smear object if implemented 3660 Create a smear object if implemented 3656 3661 """ 3657 3662 def onPinholeSmear(self, event): -
src/sas/perspectives/fitting/fitpage.py
r098f3d2 r098f3d2 34 34 FitPanel class contains fields allowing to display results when 35 35 fitting a model and one data 36 36 37 37 :note: For Fit to be performed the user should check at least one parameter 38 38 on fit Panel window. … … 44 44 """ 45 45 BasicPage.__init__(self, parent, color=color) 46 46 47 47 ## draw sizer 48 48 self._fill_data_sizer() … … 71 71 self.create_default_data() 72 72 self._manager.frame.Bind(wx.EVT_SET_FOCUS, self.on_set_focus) 73 73 74 74 def enable_fit_button(self): 75 75 """ … … 111 111 self.sizer0.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 112 112 self.sizer0.Layout() 113 113 114 114 def enable_datasource(self): 115 115 """ … … 120 120 else: 121 121 self.dataSource.Enable() 122 122 123 123 def fill_data_combobox(self, data_list): 124 124 """ … … 155 155 if len(data_list) == 1: 156 156 self.dataSource.Disable() 157 157 158 158 def on_select_data(self, event=None): 159 159 """ … … 167 167 data = self.dataSource.GetClientData(pos) 168 168 self.set_data(data) 169 169 170 170 def _on_fit_complete(self): 171 171 """ … … 174 174 self.fit_started = False 175 175 self.set_fitbutton() 176 176 177 177 def _is_2D(self): 178 178 """ 179 179 Check if data_name is Data2D 180 180 181 181 :return: True or False 182 182 183 183 """ 184 184 if self.data.__class__.__name__ == "Data2D" or \ … … 186 186 return True 187 187 return False 188 188 189 189 def _fill_range_sizer(self): 190 190 """ … … 195 195 """ 196 196 is_2Ddata = False 197 197 198 198 # Check if data is 2D 199 199 if self.data.__class__.__name__ == "Data2D" or \ 200 200 self.enable2D: 201 201 is_2Ddata = True 202 202 203 203 title = "Fitting" 204 204 #smear messages & titles … … 217 217 smear_message_slit_height_title = "Slit height[1/A]:" 218 218 smear_message_slit_width_title = "Slit width[1/A]:" 219 219 220 220 self._get_smear_info() 221 221 222 222 #Sizers 223 223 box_description_range = wx.StaticBox(self, -1, str(title)) … … 232 232 sizer_smearer_box = wx.StaticBoxSizer(smear_set_box, wx.HORIZONTAL) 233 233 sizer_smearer_box.SetMinSize((_DATA_BOX_WIDTH, 60)) 234 234 235 235 weighting_set_box = wx.StaticBox(self, -1, \ 236 236 'Set Weighting by Selecting dI Source') … … 267 267 self.dI_idata.Enable(False) 268 268 weighting_box.Add(sizer_weighting) 269 269 270 270 # combobox for smear2d accuracy selection 271 271 self.smear_accuracy = wx.ComboBox(self, -1, size=(50, -1), … … 276 276 self.smear_accuracy.SetToolTipString(\ 277 277 "'Higher' uses more Gaussian points for smearing computation.") 278 278 279 279 wx.EVT_COMBOBOX(self.smear_accuracy, -1, self._on_select_accuracy) 280 280 … … 284 284 self.btFit.Bind(wx.EVT_BUTTON, self._onFit, id=self.btFit.GetId()) 285 285 self.btFit.SetToolTipString("Start fitting.") 286 286 287 287 #General Help button 288 288 self.btFitHelp = wx.Button(self, -1, 'Help') … … 324 324 ## smear 325 325 self.smear_data_left = BGTextCtrl(self, -1, 326 326 size=(_BOX_WIDTH - 25, 20), style=0) 327 327 self.smear_data_left.SetValue(str(self.dq_l)) 328 328 self.smear_data_right = BGTextCtrl(self, -1, 329 329 size=(_BOX_WIDTH - 25, 20), style=0) 330 330 self.smear_data_right.SetValue(str(self.dq_r)) 331 331 … … 359 359 id=self.slit_smearer.GetId()) 360 360 self.disable_smearer.SetValue(True) 361 361 362 362 sizer_smearer.Add(self.disable_smearer, 0, wx.LEFT, 10) 363 363 sizer_smearer.Add(self.enable_smearer) … … 366 366 sizer_smearer.Add(self.btSmearHelp) 367 367 sizer_smearer.Add((10, 10)) 368 368 369 369 # StaticText for chi2, N(for fitting), Npts + Log/linear spacing 370 370 self.tcChi = BGTextCtrl(self, -1, "-", size=(75, 20), style=0) … … 374 374 " Npts : number of points selected for fitting") 375 375 self.Npts_total = ModelTextCtrl(self, -1, 376 377 378 376 size=(_BOX_WIDTH, 20), 377 style=wx.TE_PROCESS_ENTER, 378 text_enter_callback=self._onQrangeEnter) 379 379 self.Npts_total.SetValue(format_number(self.npts_x)) 380 380 self.Npts_total.SetToolTipString(\ 381 381 " Total Npts : total number of data points") 382 382 383 383 # Update and Draw button 384 384 self.draw_button = wx.Button(self, wx.NewId(), 'Compute') … … 386 386 self._onDraw, id=self.draw_button.GetId()) 387 387 self.draw_button.SetToolTipString("Compute and Draw.") 388 389 self.points_sizer = wx.BoxSizer(wx.HORIZONTAL) 388 389 self.points_sizer = wx.BoxSizer(wx.HORIZONTAL) 390 390 self.pointsbox = wx.CheckBox(self, -1, 'Log?', (10, 10)) 391 391 self.pointsbox.SetValue(False) 392 392 self.pointsbox.SetToolTipString("Check mark to use log spaced points") 393 393 wx.EVT_CHECKBOX(self, self.pointsbox.GetId(), self.select_log) 394 394 395 395 self.points_sizer.Add(wx.StaticText(self, -1, 'Npts ')) 396 396 self.points_sizer.Add(self.pointsbox) … … 403 403 smear_message_none, style=wx.ALIGN_LEFT) 404 404 self.smear_description_dqdata = wx.StaticText(self, 405 - 405 -1, smear_message_dqdata, style=wx.ALIGN_LEFT) 406 406 self.smear_description_type = wx.StaticText(self, 407 - 407 -1, "Type:", style=wx.ALIGN_LEFT) 408 408 self.smear_description_accuracy_type = wx.StaticText(self, -1, 409 409 "Accuracy:", style=wx.ALIGN_LEFT) … … 434 434 self.smear_description_slit_width = wx.StaticText(self, -1, 435 435 smear_message_slit_width_title, style=wx.ALIGN_LEFT) 436 436 437 437 #arrange sizers 438 438 self.sizer_set_smearer.Add(sizer_smearer) … … 467 467 self.sizer_new_smear.Add((20, -1)) 468 468 self.sizer_new_smear.Add(self.smear_description_2d_y, 469 0, wx.CENTER, 10 )469 0, wx.CENTER, 10 ) 470 470 self.sizer_new_smear.Add(self.smear_description_pin_max, 471 0, wx.CENTER, 10 )471 0, wx.CENTER, 10 ) 472 472 self.sizer_new_smear.Add(self.smear_description_slit_width, 473 0, wx.CENTER, 10 )473 0, wx.CENTER, 10 ) 474 474 475 475 self.sizer_new_smear.Add(self.smear_pinhole_max, 0, wx.CENTER, 10) 476 476 self.sizer_new_smear.Add(self.smear_slit_width, 0, wx.CENTER, 10) 477 477 self.sizer_new_smear.Add(self.smear_data_right, 0, wx.CENTER, 10) 478 478 479 479 self.sizer_set_smearer.Add(self.smear_message_new_s, 0, wx.CENTER, 10) 480 480 self.sizer_set_smearer.Add(self.smear_message_new_p, 0, wx.CENTER, 10) 481 481 self.sizer_set_smearer.Add((5, 2)) 482 482 self.sizer_set_smearer.Add(self.sizer_new_smear, 0, wx.CENTER, 10) 483 483 484 484 # add all to chi2 sizer 485 485 sizer_smearer_box.Add(self.sizer_set_smearer) … … 488 488 sizer_chi2.Add(weighting_box) 489 489 sizer_chi2.Add((-1, 5)) 490 490 491 491 # hide all smear messages and textctrl 492 492 self._hide_all_smear_info() 493 493 494 494 # get smear_selection 495 495 self.current_smearer = smear_selection(self.data, self.model) … … 512 512 #2D data? default 513 513 is_2Ddata = False 514 514 515 515 #check if it is 2D data 516 516 if self.data.__class__.__name__ == "Data2D" or self.enable2D: 517 517 is_2Ddata = True 518 518 519 519 self.sizer5.Clear(True) 520 520 521 521 self.qmin = ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 522 style=wx.TE_PROCESS_ENTER,523 set_focus_callback=self.qrang_set_focus,524 text_enter_callback=self._onQrangeEnter,525 name='qmin')522 style=wx.TE_PROCESS_ENTER, 523 set_focus_callback=self.qrang_set_focus, 524 text_enter_callback=self._onQrangeEnter, 525 name='qmin') 526 526 self.qmin.SetValue(str(self.qmin_x)) 527 527 q_tip = "Click outside of the axes\n to remove the lines." … … 529 529 qmin_tip += q_tip 530 530 self.qmin.SetToolTipString(qmin_tip) 531 531 532 532 self.qmax = ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 533 style=wx.TE_PROCESS_ENTER,534 set_focus_callback=self.qrang_set_focus,535 text_enter_callback=self._onQrangeEnter,536 name='qmax')533 style=wx.TE_PROCESS_ENTER, 534 set_focus_callback=self.qrang_set_focus, 535 text_enter_callback=self._onQrangeEnter, 536 name='qmax') 537 537 self.qmax.SetValue(str(self.qmax_x)) 538 538 qmax_tip = "Maximum value of Q.\n" … … 547 547 wx_id = wx.NewId() 548 548 self.reset_qrange = wx.Button(self, wx_id, 'Reset') 549 549 550 550 self.reset_qrange.Bind(wx.EVT_BUTTON, self.on_reset_clicked, id=wx_id) 551 551 self.reset_qrange.SetToolTipString("Reset Q range to the default") 552 552 553 553 sizer = wx.GridSizer(5, 5, 2, 6) 554 554 … … 558 558 self.btEditMask.SetToolTipString("Edit Mask.") 559 559 self.EditMask_title = wx.StaticText(self, -1, ' Masking(2D)') 560 560 561 561 sizer.Add(wx.StaticText(self, -1, ' Q range')) 562 562 sizer.Add(wx.StaticText(self, -1, ' Min[1/A]')) … … 598 598 self.sizer5.Layout() 599 599 600 600 601 601 def _set_sizer_dispersion(self): 602 602 """ … … 614 614 ## the user didn't select dispersity display 615 615 return 616 616 617 617 self._reset_dispersity() 618 618 619 619 ## fill a sizer with the combobox to select dispersion type 620 620 model_disp = wx.StaticText(self, -1, 'Function') 621 621 CHECK_STATE = self.cb1.GetValue() 622 import sas.models.dispersion_models 623 self.polydisp = sas.models.dispersion_models.models 622 #import sas.models.dispersion_models 623 #self.polydisp = sas.models.dispersion_models.models 624 import sasmodels.weights 625 self.polydisp = sasmodels.weights.models 624 626 625 627 ix = 0 … … 644 646 self.sizer4_4.Add(self.text_disp_1, (iy, ix), (1, 1), \ 645 647 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 646 648 647 649 ix += 1 648 650 self.text_disp_min = wx.StaticText(self, -1, 'Min') … … 654 656 self.sizer4_4.Add(self.text_disp_max, (iy, ix), (1, 1), 655 657 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 656 658 657 659 ix += 1 658 660 npts = wx.StaticText(self, -1, 'Npts') … … 672 674 self.sizer4_4.Add(model_disp, (iy, ix), (1, 1), 673 675 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 674 676 675 677 self.text_disp_max.Show(True) 676 678 self.text_disp_min.Show(True) … … 692 694 iy += 1 693 695 for p in self.model.dispersion[item].keys(): 694 696 695 697 if p == "width": 696 698 ix = 0 … … 704 706 value = self.model.getParam(name1) 705 707 ctl1 = ModelTextCtrl(self, -1, 706 size=(_BOX_WIDTH / 1.3, 20),707 style=wx.TE_PROCESS_ENTER)708 size=(_BOX_WIDTH / 1.3, 20), 709 style=wx.TE_PROCESS_ENTER) 708 710 ctl1.SetLabel('PD[ratio]') 709 711 poly_text = "Polydispersity (STD/mean) of %s\n" % item … … 725 727 size=(_BOX_WIDTH / 1.3, 20), 726 728 style=0) 727 729 728 730 self.sizer4_4.Add(ctl2, (iy, ix), (1, 1), 729 731 wx.EXPAND | wx.ADJUST_MINSIZE, 0) … … 733 735 ix = 4 734 736 ctl3 = ModelTextCtrl(self, -1, 735 size=(_BOX_WIDTH / 2, 20),736 style=wx.TE_PROCESS_ENTER,737 text_enter_callback=self._onparamRangeEnter)738 737 size=(_BOX_WIDTH / 2, 20), 738 style=wx.TE_PROCESS_ENTER, 739 text_enter_callback=self._onparamRangeEnter) 740 739 741 self.sizer4_4.Add(ctl3, (iy, ix), (1, 1), 740 742 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 741 743 742 744 ix = 5 743 745 ctl4 = ModelTextCtrl(self, -1, 744 size=(_BOX_WIDTH / 2, 20),745 style=wx.TE_PROCESS_ENTER,746 size=(_BOX_WIDTH / 2, 20), 747 style=wx.TE_PROCESS_ENTER, 746 748 text_enter_callback=self._onparamRangeEnter) 747 749 748 750 self.sizer4_4.Add(ctl4, (iy, ix), (1, 1), 749 751 wx.EXPAND | wx.ADJUST_MINSIZE, 0) … … 751 753 ctl3.Show(True) 752 754 ctl4.Show(True) 753 755 754 756 elif p == "npts": 755 757 ix = 6 756 758 value = self.model.getParam(name2) 757 759 Tctl = ModelTextCtrl(self, -1, 758 size=(_BOX_WIDTH / 2.2, 20),759 style=wx.TE_PROCESS_ENTER)760 760 size=(_BOX_WIDTH / 2.2, 20), 761 style=wx.TE_PROCESS_ENTER) 762 761 763 Tctl.SetValue(str(format_number(value))) 762 764 self.sizer4_4.Add(Tctl, (iy, ix), (1, 1), … … 768 770 value = self.model.getParam(name3) 769 771 Tct2 = ModelTextCtrl(self, -1, 770 size=(_BOX_WIDTH / 2.2, 20),771 style=wx.TE_PROCESS_ENTER)772 772 size=(_BOX_WIDTH / 2.2, 20), 773 style=wx.TE_PROCESS_ENTER) 774 773 775 Tct2.SetValue(str(format_number(value))) 774 776 self.sizer4_4.Add(Tct2, (iy, ix), (1, 1), … … 789 791 self.fittable_param.append([cb, name1, ctl1, text2, 790 792 ctl2, ctl3, ctl4, disp_box]) 791 793 792 794 ix = 0 793 795 iy += 1 … … 806 808 name2 = item + ".npts" 807 809 name3 = item + ".nsigmas" 808 810 809 811 if not name1 in self.model.details: 810 812 self.model.details[name1] = ["", None, None] 811 813 812 814 iy += 1 813 815 for p in self.model.dispersion[item].keys(): 814 816 815 817 if p == "width": 816 818 ix = 0 … … 829 831 value = self.model.getParam(name1) 830 832 ctl1 = ModelTextCtrl(self, -1, 831 size=(_BOX_WIDTH / 1.3, 20),832 style=wx.TE_PROCESS_ENTER)833 size=(_BOX_WIDTH / 1.3, 20), 834 style=wx.TE_PROCESS_ENTER) 833 835 poly_tip = "Absolute Sigma for %s." % item 834 836 ctl1.SetToolTipString(poly_tip) … … 844 846 poly_text += "It is the STD (ratio*mean)" 845 847 poly_text += " of the distribution.\n " 846 848 847 849 values.SetToolTipString(poly_text) 848 850 first_orient = False … … 850 852 elif ctl1.IsShown(): 851 853 ctl1.Hide() 852 854 853 855 self.sizer4_4.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 854 856 ## text to show error sign … … 864 866 size=(_BOX_WIDTH / 1.3, 20), 865 867 style=0) 866 868 867 869 self.sizer4_4.Add(ctl2, (iy, ix), (1, 1), 868 870 wx.EXPAND | wx.ADJUST_MINSIZE, 0) … … 874 876 text2.Show(True) 875 877 ctl2.Show(True) 876 878 877 879 ix = 4 878 880 ctl3 = ModelTextCtrl(self, -1, 879 size=(_BOX_WIDTH / 2, 20),880 style=wx.TE_PROCESS_ENTER,881 size=(_BOX_WIDTH / 2, 20), 882 style=wx.TE_PROCESS_ENTER, 881 883 text_enter_callback=self._onparamRangeEnter) 882 884 … … 885 887 886 888 ctl3.Hide() 887 889 888 890 ix = 5 889 891 ctl4 = ModelTextCtrl(self, -1, 890 891 892 size=(_BOX_WIDTH / 2, 20), 893 style=wx.TE_PROCESS_ENTER, 892 894 text_enter_callback=self._onparamRangeEnter) 893 895 self.sizer4_4.Add(ctl4, (iy, ix), (1, 1), 894 896 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 895 897 ctl4.Hide() 896 898 897 899 if self.data.__class__.__name__ == "Data2D" or \ 898 900 self.enable2D: 899 901 ctl3.Show(True) 900 902 ctl4.Show(True) 901 903 902 904 elif p == "npts": 903 905 ix = 6 904 906 value = self.model.getParam(name2) 905 907 Tctl = ModelTextCtrl(self, -1, 906 size=(_BOX_WIDTH / 2.2, 20),907 style=wx.TE_PROCESS_ENTER)908 908 size=(_BOX_WIDTH / 2.2, 20), 909 style=wx.TE_PROCESS_ENTER) 910 909 911 Tctl.SetValue(str(format_number(value))) 910 912 if self.data.__class__.__name__ == "Data2D" or \ … … 924 926 value = self.model.getParam(name3) 925 927 Tct2 = ModelTextCtrl(self, -1, 926 size=(_BOX_WIDTH / 2.2, 20),927 style=wx.TE_PROCESS_ENTER)928 928 size=(_BOX_WIDTH / 2.2, 20), 929 style=wx.TE_PROCESS_ENTER) 930 929 931 Tct2.SetValue(str(format_number(value))) 930 932 if self.data.__class__.__name__ == "Data2D" or \ … … 938 940 self.fixed_param.append([None, name3, Tct2, 939 941 None, None, None, None, None]) 940 942 941 943 self.orientation_params_disp.append([None, name3, 942 944 Tct2, None, None, None, None, None]) … … 955 957 self.orientation_params_disp.append([cb, name1, ctl1, 956 958 text2, ctl2, ctl3, ctl4, disp_box]) 957 959 958 960 if self.data.__class__.__name__ == "Data2D" or \ 959 961 self.enable2D: … … 961 963 else: 962 964 disp_box.Hide() 963 965 964 966 self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) 965 967 966 968 self.state.model = self.model.clone() 967 969 ## save state into … … 996 998 """ 997 999 flag = self._update_paramv_on_fit() 998 1000 999 1001 wx.CallAfter(self._onparamEnter_helper) 1000 1002 if not flag: … … 1002 1004 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1003 1005 return 1004 1006 1005 1007 def _onFit(self, event): 1006 1008 """ … … 1027 1029 StatusEvent(status="Fit: %s" % msg, type="stop")) 1028 1030 return 1029 1031 1030 1032 if len(self.param_toFit) <= 0: 1031 1033 msg = "Select at least one parameter to fit" … … 1034 1036 StatusEvent(status=msg, type="stop")) 1035 1037 return 1036 1038 1037 1039 flag = self._update_paramv_on_fit() 1038 1040 1039 1041 if self.batch_on and not self._is_2D(): 1040 1042 if not self._validate_Npts_1D(): 1041 1043 return 1042 1044 1043 1045 if not flag: 1044 1046 msg = "Fitting range or parameters are invalid" … … 1046 1048 StatusEvent(status=msg, type="stop")) 1047 1049 return 1048 1050 1049 1051 self.select_param(event=None) 1050 1052 … … 1062 1064 self.fit_started = self._manager.onFit(uid=self.uid) 1063 1065 wx.CallAfter(self.set_fitbutton) 1064 1066 1065 1067 def _onFitHelp(self, event): 1066 1068 """ … … 1110 1112 if self.is_mac: 1111 1113 return 1112 1114 1113 1115 if self.fit_started: 1114 1116 label = "Stop" … … 1121 1123 self.btFit.SetForegroundColour(color) 1122 1124 self.btFit.Enable(True) 1123 1125 1124 1126 def get_weight_flag(self): 1125 1127 """ … … 1143 1145 break 1144 1146 return flag 1145 1147 1146 1148 def _StopFit(self, event=None): 1147 1149 """ … … 1153 1155 self._manager._reset_schedule_problem(value=0) 1154 1156 self._on_fit_complete() 1155 1157 1156 1158 def rename_model(self): 1157 1159 """ … … 1160 1162 if self.model is not None: 1161 1163 self.model.name = "M" + str(self.index_model) 1162 1164 1163 1165 def _on_select_model(self, event=None): 1164 1166 """ … … 1192 1194 self.state.pinhole_smearer = self.pinhole_smearer.GetValue() 1193 1195 self.state.slit_smearer = self.slit_smearer.GetValue() 1194 1196 1195 1197 self.state.structurecombobox = self.structurebox.GetLabel() 1196 1198 self.state.formfactorcombobox = self.formfactorbox.GetLabel() … … 1208 1210 self._keep.Enable(not self.batch_on) 1209 1211 self._set_save_flag(True) 1210 1212 1211 1213 # more disables for 2D 1212 1214 self._set_smear_buttons() 1213 1215 1214 1216 try: 1215 1217 # update smearer sizer … … 1225 1227 ## event to post model to fit to fitting plugins 1226 1228 (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() 1227 1229 1228 1230 ## set smearing value whether or not 1229 1231 # the data contain the smearing info … … 1235 1237 caption=self.window_caption, 1236 1238 qmax=float(self.qmax_x)) 1237 1239 1238 1240 self._manager._on_model_panel(evt=evt) 1239 self.mbox_description.SetLabel("Model [ %s ]" 1241 self.mbox_description.SetLabel("Model [ %s ]"% str(self.model.name)) 1240 1242 self.mbox_description.SetForegroundColour(wx.BLUE) 1241 1243 self.state.model = self.model.clone() … … 1270 1272 self.get_paste_params(copy_flag) 1271 1273 wx.CallAfter(self._onDraw, None) 1272 1274 1273 1275 else: 1274 1276 self._draw_model() 1275 1277 1276 1278 if self.batch_on: 1277 1279 self.slit_smearer.Enable(False) … … 1279 1281 self.btEditMask.Disable() 1280 1282 self.EditMask_title.Disable() 1281 1283 1282 1284 self.Show(True) 1283 1285 self.SetupScrolling() 1284 1286 1285 1287 def _onparamEnter(self, event): 1286 1288 """ … … 1325 1327 qmax=float(self.qmax_x), 1326 1328 enable_smearer=enable_smearer, 1327 1329 draw=True) 1328 1330 if flag: 1329 1331 #self.compute_chisqr(smearer= temp_smearer) 1330 1332 1331 1333 ## new state posted 1332 1334 if self.state_change: … … 1343 1345 msg = "Cannot Plot :Must enter a number!!! " 1344 1346 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1345 1347 1346 1348 self.save_current_state() 1347 1349 return 1348 1350 1349 1351 def _onparamRangeEnter(self, event): 1350 1352 """ … … 1369 1371 else: 1370 1372 tcrtl.SetBackgroundColour(wx.WHITE) 1371 1373 1372 1374 #self._undo.Enable(True) 1373 1375 self.save_current_state() … … 1375 1377 wx.PostEvent(self.parent, event) 1376 1378 self.state_change = False 1377 1378 def qrang_set_focus(self, event=None): 1379 1380 def qrang_set_focus(self, event=None): 1379 1381 """ 1380 1382 ON Qrange focus … … 1384 1386 #tcrtl = event.GetEventObject() 1385 1387 self._validate_qrange(self.qmin, self.qmax) 1386 1388 1387 1389 def qrange_click(self, event): 1388 1390 """ … … 1398 1400 d_group_id = self.data.group_id 1399 1401 act_ctrl = event.GetEventObject() 1400 wx.PostEvent(self._manager.parent, 1401 PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id, 1402 wx.PostEvent(self._manager.parent, 1403 PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id, 1402 1404 group_id=d_group_id, leftdown=is_click, 1403 1405 active=act_ctrl)) 1404 1406 1405 1407 def on_qrange_text(self, event): 1406 1408 """ … … 1414 1416 d_id = self.data.id 1415 1417 d_group_id = self.data.group_id 1416 wx.PostEvent(self._manager.parent, 1417 PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id, 1418 group_id=d_group_id, leftdown=False, 1418 wx.PostEvent(self._manager.parent, 1419 PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id, 1420 group_id=d_group_id, leftdown=False, 1419 1421 active=act_ctrl)) 1420 1422 self._validate_qrange(self.qmin, self.qmax) 1421 1422 def on_key(self, event): 1423 1424 def on_key(self, event): 1423 1425 """ 1424 1426 On Key down … … 1431 1433 x_data = float(ctrl.GetValue()) 1432 1434 except: 1433 return 1435 return 1434 1436 key = event.GetKeyCode() 1435 1437 length = len(self.data.x) … … 1448 1450 ctrl.SetValue(str(self.data.x[indx])) 1449 1451 self._validate_qrange(self.qmin, self.qmax) 1450 1452 1451 1453 def _onQrangeEnter(self, event): 1452 1454 """ … … 1509 1511 (self.data.x <= self.qmax_x)) 1510 1512 self.Npts_fit.SetValue(str(len(self.data.x[index_data]))) 1511 1513 1512 1514 self.npts_x = self.Npts_total.GetValue() 1513 1515 self.create_default_data() … … 1517 1519 msg = "Model Error:wrong value entered!!!" 1518 1520 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1519 1521 1520 1522 self._draw_model() 1521 1523 self.save_current_state() … … 1524 1526 self.state_change = False 1525 1527 return 1526 1528 1527 1529 def _clear_Err_on_Fit(self): 1528 1530 """ … … 1554 1556 if item[4] != None and item[4].IsShown(): 1555 1557 item[4].Hide() 1556 1558 1557 1559 if len(self.fittable_param) > 0: 1558 1560 for item in self.fittable_param: … … 1574 1576 item[4].Hide() 1575 1577 return 1576 1578 1577 1579 def _get_defult_custom_smear(self): 1578 1580 """ … … 1588 1590 if self.dx_max == None: 1589 1591 self.dx_max = SMEAR_SIZE_H 1590 1592 1591 1593 def _get_smear_info(self): 1592 1594 """ 1593 1595 Get the smear info from data. 1594 1596 1595 1597 :return: self.smear_type, self.dq_l and self.dq_r, 1596 1598 respectively the type of the smear, dq_min and … … 1623 1625 self.dq_l = data.dx[0] 1624 1626 self.dq_r = data.dx[-1] 1625 1627 1626 1628 # check if it is slit smear and get min max if it is. 1627 1629 elif data.dxl != None or data.dxw != None: … … 1632 1634 self.dq_r = data.dxw[0] 1633 1635 #return self.smear_type,self.dq_l,self.dq_r 1634 1636 1635 1637 def _show_smear_sizer(self): 1636 1638 """ … … 1696 1698 self.smear_description_2d_y.Hide() 1697 1699 self.smear_description_2d.Hide() 1698 1700 1699 1701 self.smear_accuracy.Hide() 1700 1702 self.smear_data_left.Hide() … … 1710 1712 self.smear_message_new_p.Hide() 1711 1713 self.smear_message_new_s.Hide() 1712 1714 1713 1715 def _set_accuracy_list(self): 1714 1716 """ … … 1720 1722 for idx in range(len(list)): 1721 1723 self.smear_accuracy.Append(list[idx], idx) 1722 1724 1723 1725 def _set_fun_box_list(self, fun_box): 1724 1726 """ … … 1741 1743 break 1742 1744 ind += 1 1743 1745 1744 1746 def _on_select_accuracy(self, event): 1745 1747 """ … … 1756 1758 if self.current_smearer != None: 1757 1759 self.current_smearer.set_accuracy(accuracy=\ 1758 self.smear2d_accuracy) 1760 self.smear2d_accuracy) 1759 1761 event.Skip() 1760 1762 … … 1781 1783 # get ready for new event 1782 1784 event.Skip() 1783 1785 1784 1786 def _onMask(self, event): 1785 1787 """ … … 1788 1790 from sas.guiframe.local_perspectives.plotting.masking \ 1789 1791 import MaskPanel as MaskDialog 1790 1792 1791 1793 self.panel = MaskDialog(base=self, data=self.data, id=wx.NewId()) 1792 1794 self.panel.ShowModal() 1793 1795 1794 1796 def _draw_masked_model(self, event): 1795 1797 """ … … 1842 1844 """ 1843 1845 return self.enable2D 1844 1846 1845 1847 def compute_data_set_range(self, data_list): 1846 1848 """ … … 1855 1857 self.npts_data_set += npts 1856 1858 return self.qmin_data_set, self.qmax_data_set, self.npts_data_set 1857 1859 1858 1860 def compute_data_range(self, data): 1859 1861 """ … … 1871 1873 npts = len(data.x) 1872 1874 except: 1873 msg = "Unable to find min/max/length of \n data named %s" 1874 data.filename 1875 msg = "Unable to find min/max/length of \n data named %s"% \ 1876 data.filename 1875 1877 wx.PostEvent(self._manager.parent, StatusEvent(status=msg, 1876 1878 info="error")) 1877 1879 raise ValueError, msg 1878 1880 1879 1881 else: 1880 1882 qmin = 0 … … 1883 1885 y = max(math.fabs(data.ymin), math.fabs(data.ymax)) 1884 1886 except: 1885 msg = "Unable to find min/max of \n data named %s" 1886 data.filename 1887 msg = "Unable to find min/max of \n data named %s"% \ 1888 data.filename 1887 1889 wx.PostEvent(self._manager.parent, StatusEvent(status=msg, 1888 1890 info="error")) … … 1892 1894 npts = len(data.data) 1893 1895 return qmin, qmax, npts 1894 1896 1895 1897 def set_data(self, data): 1896 1898 """ … … 1919 1921 self.graph_id = data.group_id 1920 1922 self.data.group_id = self.graph_id 1921 1923 1922 1924 if self.data is None: 1923 1925 data_name = "" … … 1929 1931 self._set_bookmark_flag(not self.batch_on) 1930 1932 self._keep.Enable(not self.batch_on) 1931 if self.data.is_data: 1933 if self.data.is_data: 1932 1934 self._set_save_flag(True) 1933 1935 self._set_preview_flag(True) … … 1967 1969 self.dI_sqrdata.Enable(True) 1968 1970 self.dI_idata.Enable(True) 1969 1971 1970 1972 self.formfactorbox.Enable() 1971 1973 self.structurebox.Enable() … … 1979 1981 self.btEditMask.Enable() 1980 1982 self.EditMask_title.Enable() 1981 1983 1982 1984 self.Npts_total.SetValue(str(npts)) 1983 1985 #default:number of data points selected to fit … … 1986 1988 self.Npts_total.SetBackgroundColour(\ 1987 1989 self.GetParent().GetBackgroundColour()) 1988 1990 1989 1991 self.Npts_total.Bind(wx.EVT_MOUSE_EVENTS, self._npts_click) 1990 1992 self.pointsbox.Disable() … … 1997 1999 if check_data_validity(data): 1998 2000 self.data_box_description.SetForegroundColour(wx.BLUE) 1999 2001 2000 2002 if self.batch_on: 2001 2003 self.slit_smearer.Enable(False) … … 2031 2033 title=str(self.data.title))) 2032 2034 self._draw_model() 2033 2035 2034 2036 def _npts_click(self, event): 2035 2037 """ … … 2038 2040 """ 2039 2041 pass 2040 2042 2041 2043 def reset_page(self, state, first=False): 2042 2044 """ … … 2045 2047 try: 2046 2048 self.reset_page_helper(state) 2047 2049 2048 2050 self.select_param(event=None) 2049 2051 #Save state_fit … … 2053 2055 msg = "Error: This model state has missing or outdated " 2054 2056 msg += "information.\n" 2055 msg += "%s" 2057 msg += "%s"% (sys.exc_value) 2056 2058 wx.PostEvent(self._manager.parent, 2057 2059 StatusEvent(status=msg, info="error")) 2058 2060 self._lay_out() 2059 2061 self.Refresh() 2060 2062 2061 2063 def get_range(self): 2062 2064 """ … … 2064 2066 """ 2065 2067 return float(self.qmin_x), float(self.qmax_x) 2066 2068 2067 2069 def get_npts2fit(self): 2068 2070 """ 2069 2071 return numbers of data points within qrange 2070 2072 2071 2073 :Note: This is to normalize chisq by Npts of fit 2072 2074 2073 2075 """ 2074 2076 if self.data is None: … … 2095 2097 """ 2096 2098 self.Npts_fit.SetValue(str(self.get_npts2fit())) 2097 2099 2098 2100 def get_chi2(self): 2099 2101 """ … … 2101 2103 """ 2102 2104 return self.tcChi.GetValue() 2103 2105 2104 2106 def onsetValues(self, chisqr, p_name, out, cov): 2105 2107 """ 2106 2108 Build the panel from the fit result 2107 2109 2108 2110 :param chisqr: Value of the goodness of fit metric 2109 2111 :param p_name: the name of parameters 2110 2112 :param out: list of parameter with the best value found during fitting 2111 2113 :param cov: Covariance matrix 2112 2113 """ 2114 2114 2115 """ 2116 2115 2117 # make sure stop button to fit button all the time 2116 2118 self._on_fit_complete() 2117 2119 if out == None or not numpy.isfinite(chisqr): 2118 2120 raise ValueError, "Fit error occured..." 2119 2121 2120 2122 is_modified = False 2121 2123 has_error = False 2122 2124 dispersity = '' 2123 2125 2124 2126 #Hide textctrl boxes of errors. 2125 2127 self._clear_Err_on_Fit() 2126 2128 2127 2129 #Check if chi2 is finite 2128 2130 if chisqr != None and numpy.isfinite(chisqr): … … 2133 2135 else: 2134 2136 self.tcChi.SetValue("-") 2135 2137 2136 2138 #Hide error title 2137 2139 if self.text2_3.IsShown() and not self.is_mac: 2138 2140 self.text2_3.Hide() 2139 2141 2140 2142 try: 2141 2143 if self.enable_disp.GetValue(): … … 2146 2148 dispersity = None 2147 2149 pass 2148 2150 2149 2151 i = 0 2150 2152 #Set the panel when fit result are list … … 2164 2166 val_out = format_number(out[ind], True) 2165 2167 item[2].SetValue(val_out) 2166 2168 2167 2169 if(cov != None and len(cov) == len(out)): 2168 2170 try: … … 2176 2178 except: 2177 2179 pass 2178 2180 2179 2181 if cov[ind] != None: 2180 2182 if numpy.isfinite(float(cov[ind])): 2181 2183 val_err = format_number(cov[ind], True) 2182 2183 2184 2184 item[4].SetForegroundColour(wx.BLACK) 2185 else: 2186 val_err = 'NaN' 2185 2187 item[4].SetForegroundColour(wx.RED) 2186 if not self.is_mac:2187 item[3].Show(True)2188 item[4].Show(True)2189 item[4].SetValue(val_err)2190 has_error = True2188 if not self.is_mac: 2189 item[3].Show(True) 2190 item[4].Show(True) 2191 item[4].SetValue(val_err) 2192 has_error = True 2191 2193 i += 1 2192 2194 else: … … 2198 2200 ## save current state 2199 2201 self.save_current_state() 2200 2202 2201 2203 if not self.is_mac: 2202 2204 self.Layout() … … 2205 2207 #plot model ( when drawing, do not update chisqr value again) 2206 2208 self._draw_model(update_chisqr=False, source='fit') 2207 2209 2208 2210 def onWeighting(self, event): 2209 2211 """ … … 2212 2214 self.weightbt_string = event.GetEventObject().GetLabelText() 2213 2215 self._set_weight() 2214 2216 2215 2217 def _set_weight(self, is_2D=None): 2216 2218 """ … … 2225 2227 is2d=is_2D, 2226 2228 fid=None) 2227 2229 2228 2230 def onPinholeSmear(self, event): 2229 2231 """ 2230 2232 Create a custom pinhole smear object that will change the way residuals 2231 2233 are compute when fitting 2232 2234 2233 2235 :Note: accuracy is given by strings'High','Med', 'Low' FOR 2d, 2234 2236 None for 1D 2235 2237 2236 2238 """ 2237 2239 # Need update param values … … 2254 2256 # hide all silt sizer 2255 2257 self._hide_all_smear_info() 2256 2258 2257 2259 # show relevant slit sizers 2258 2260 self._show_smear_sizer() … … 2260 2262 self.sizer_set_smearer.Layout() 2261 2263 self.Layout() 2262 2264 2263 2265 if event != None: 2264 2266 event.Skip() … … 2267 2269 event = PageInfoEvent(page=self) 2268 2270 wx.PostEvent(self.parent, event) 2269 2271 2270 2272 def _is_changed_pinhole(self): 2271 2273 """ 2272 2274 check if any of pinhole smear is changed 2273 2275 2274 2276 :return: True or False 2275 2277 2276 2278 """ 2277 2279 # get the values 2278 2280 pin_min = self.smear_pinhole_min.GetValue() 2279 2281 pin_max = self.smear_pinhole_max.GetValue() 2280 2282 2281 2283 # Check changes in slit width 2282 2284 try: … … 2286 2288 if self.dx_min != dx_min: 2287 2289 return True 2288 2290 2289 2291 # Check changes in slit heigth 2290 2292 try: … … 2295 2297 return True 2296 2298 return False 2297 2299 2298 2300 def _set_pinhole_smear(self): 2299 2301 """ 2300 2302 Set custom pinhole smear 2301 2303 2302 2304 :return: msg 2303 2305 2304 2306 """ 2305 2307 # copy data … … 2317 2319 data.dxw = None 2318 2320 msg = None 2319 2321 2320 2322 get_pin_min = self.smear_pinhole_min 2321 2323 get_pin_max = self.smear_pinhole_max … … 2371 2373 get_pin_max.SetBackgroundColour("white") 2372 2374 ## set smearing value whether or not the data contain the smearing info 2373 2375 2374 2376 enable_smearer = not self.disable_smearer.GetValue() 2375 2377 self._manager.set_smearer(smearer=self.current_smearer, 2376 2377 2378 2378 fid=self.data.id, 2379 qmin=float(self.qmin_x), 2380 qmax=float(self.qmax_x), 2379 2381 enable_smearer=enable_smearer, 2380 2382 uid=self.uid) 2381 2383 return msg 2382 2384 2383 2385 def update_pinhole_smear(self): 2384 2386 """ 2385 2387 called by kill_focus on pinhole TextCntrl 2386 2388 to update the changes 2387 2389 2388 2390 :return: False when wrong value was entered 2389 2391 2390 2392 """ 2391 2393 # msg default … … 2400 2402 else: 2401 2403 return True 2402 2404 2403 2405 def onSlitSmear(self, event): 2404 2406 """ … … 2423 2425 else: 2424 2426 is_new_slit = True 2425 2427 2426 2428 # if any value is changed 2427 2429 if is_new_slit: 2428 2430 msg = self._set_slit_smear() 2429 2431 2430 2432 # hide all silt sizer 2431 2433 self._hide_all_smear_info() … … 2446 2448 """ 2447 2449 check if any of slit lengths is changed 2448 2450 2449 2451 :return: True or False 2450 2452 2451 2453 """ 2452 2454 # get the values 2453 2455 width = self.smear_slit_width.GetValue() 2454 2456 height = self.smear_slit_height.GetValue() 2455 2457 2456 2458 # check and change the box bg color if it was pink 2457 2459 # but it should be white now … … 2461 2463 if width.lstrip().rstrip() == "": 2462 2464 self.smear_slit_width.SetBackgroundColour(wx.WHITE) 2463 2465 2464 2466 # Check changes in slit width 2465 2467 if width == "": … … 2472 2474 if self.dxw != dxw: 2473 2475 return True 2474 2476 2475 2477 # Check changes in slit heigth 2476 2478 if height == "": … … 2485 2487 2486 2488 return False 2487 2489 2488 2490 def _set_slit_smear(self): 2489 2491 """ 2490 2492 Set custom slit smear 2491 2493 2492 2494 :return: message to inform the user about the validity 2493 2495 of the values entered for slit smear … … 2502 2504 data.dxw = None 2503 2505 msg = None 2504 2506 2505 2507 try: 2506 2508 self.dxl = float(self.smear_slit_height.GetValue()) … … 2527 2529 else: 2528 2530 self.smear_slit_width.SetBackgroundColour(wx.WHITE) 2529 2531 2530 2532 self.current_smearer = smear_selection(data, self.model) 2531 2533 ## set smearing value whether or not the data contain the smearing info 2532 2534 enable_smearer = not self.disable_smearer.GetValue() 2533 2535 self._manager.set_smearer(smearer=self.current_smearer, 2534 2535 2536 2536 fid=self.data.id, 2537 qmin=float(self.qmin_x), 2538 qmax=float(self.qmax_x), 2537 2539 enable_smearer=enable_smearer, 2538 2540 uid=self.uid) 2539 2541 return msg 2540 2542 2541 2543 def update_slit_smear(self): 2542 2544 """ 2543 2545 called by kill_focus on pinhole TextCntrl 2544 2546 to update the changes 2545 2547 2546 2548 :return: False when wrong value was entered 2547 2549 2548 2550 """ 2549 2551 # msg default … … 2559 2561 else: 2560 2562 return True 2561 2563 2562 2564 def onSmear(self, event): 2563 2565 """ … … 2576 2578 self._manager.page_finder[self.uid].add_data(data=self.data) 2577 2579 temp_smearer = self.on_smear_helper() 2578 2580 2579 2581 self.sizer_set_smearer.Layout() 2580 2582 self.Layout() 2581 2583 self._set_weight() 2582 2584 2583 2585 ## set smearing value whether or not the data contain the smearing info 2584 2586 enable_smearer = not self.disable_smearer.GetValue() … … 2590 2592 enable_smearer=enable_smearer, 2591 2593 draw=True) 2592 2594 2593 2595 self.state.enable_smearer = self.enable_smearer.GetValue() 2594 2596 self.state.disable_smearer = self.disable_smearer.GetValue() 2595 2597 self.state.pinhole_smearer = self.pinhole_smearer.GetValue() 2596 2598 self.state.slit_smearer = self.slit_smearer.GetValue() 2597 2599 2598 2600 def on_smear_helper(self, update=False): 2599 2601 """ 2600 2602 Help for onSmear 2601 2603 2602 2604 :param update: force or not to update 2603 2605 """ … … 2611 2613 self._hide_all_smear_info() 2612 2614 data = copy.deepcopy(self.data) 2613 2615 2614 2616 # make sure once more if it is smearer 2615 2617 temp_smearer = smear_selection(data, self.model) … … 2634 2636 self.onSlitSmear(None) 2635 2637 self._show_smear_sizer() 2636 2638 2637 2639 return temp_smearer 2638 2640 2639 2641 def on_complete_chisqr(self, event): 2640 2642 """ … … 2653 2655 except: 2654 2656 pass 2655 2657 2656 2658 def get_all_checked_params(self): 2657 2659 """ … … 2669 2671 self.param_toFit.append(item) 2670 2672 self.save_current_state_fit() 2671 2673 2672 2674 event = PageInfoEvent(page=self) 2673 2675 wx.PostEvent(self.parent, event) … … 2677 2679 param2fit.append(item[1]) 2678 2680 self._manager.set_param2fit(self.uid, param2fit) 2679 2681 2680 2682 def select_all_param(self, event): 2681 2683 """ … … 2711 2713 except: 2712 2714 pass 2713 2715 2714 2716 else: 2715 2717 ## for 1D all parameters except orientation … … 2731 2733 item[0].SetValue(False) 2732 2734 self.param_toFit = [] 2733 2735 2734 2736 self.save_current_state_fit() 2735 2737 2736 2738 if event != None: 2737 2739 #self._undo.Enable(True) … … 2744 2746 param2fit.append(item[1]) 2745 2747 self.parent._manager.set_param2fit(self.uid, param2fit) 2746 2748 2747 2749 def select_param(self, event): 2748 2750 """ … … 2797 2799 else: 2798 2800 self.cb1.SetValue(False) 2799 2801 2800 2802 self.save_current_state_fit() 2801 2803 if event != None: … … 2803 2805 event = PageInfoEvent(page=self) 2804 2806 wx.PostEvent(self.parent, event) 2805 2807 2806 2808 param2fit = [] 2807 2809 for item in self.param_toFit: … … 2809 2811 param2fit.append(item[1]) 2810 2812 self._manager.set_param2fit(self.uid, param2fit) 2811 2813 2812 2814 def set_model_param_sizer(self, model): 2813 2815 """ 2814 2816 Build the panel from the model content 2815 2817 2816 2818 :param model: the model selected in combo box for fitting purpose 2817 2819 2818 2820 """ 2819 2821 self.sizer3.Clear(True) … … 2825 2827 self.orientation_params = [] 2826 2828 self.orientation_params_disp = [] 2827 2829 2828 2830 if model == None: 2829 2831 self.sizer3.Layout() … … 2836 2838 ## save the current model 2837 2839 self.model = model 2838 2840 2839 2841 keys = self.model.getParamList() 2840 2842 2841 2843 #list of dispersion parameters 2842 2844 self.disp_list = self.model.getDispParamList() … … 2894 2896 2895 2897 keys.sort(custom_compare) 2896 2898 2897 2899 iy = 0 2898 2900 ix = 0 … … 2902 2904 self.cb1.SetToolTipString("To check/uncheck all the boxes below.") 2903 2905 self.cb1.SetValue(True) 2904 2906 2905 2907 sizer.Add(self.cb1, (iy, ix), (1, 1), \ 2906 2908 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) … … 2930 2932 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 2931 2933 self.text2_4.Hide() 2932 2934 2933 2935 CHECK_STATE = self.cb1.GetValue() 2934 2936 for item in keys: 2935 2937 2936 2938 if not item in self.disp_list and not item in \ 2937 2939 self.model.orientation_params: 2938 2940 2939 2941 ##prepare a spot to store errors 2940 2942 if not item in self.model.details: 2941 2943 self.model.details[item] = ["", None, None] 2942 2944 2943 2945 iy += 1 2944 2946 ix = 0 … … 2964 2966 else: 2965 2967 fun_box = ModelTextCtrl(self, -1, 2966 size=(_BOX_WIDTH, 20),2968 size=(_BOX_WIDTH, 20), 2967 2969 style=wx.TE_PROCESS_ENTER, name='%s' % item) 2968 2970 fun_box.SetToolTipString(\ … … 2980 2982 #cb.SetValue(True) 2981 2983 wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) 2982 2984 2983 2985 sizer.Add(cb, (iy, ix), (1, 1), 2984 2986 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) … … 2988 2990 value = self.model.getParam(item) 2989 2991 ctl1 = ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 2990 2992 style=wx.TE_PROCESS_ENTER) 2991 2993 ctl1.SetToolTipString(\ 2992 2994 "Hit 'Enter' after typing to update the plot.") … … 3010 3012 ix += 1 3011 3013 ctl3 = ModelTextCtrl(self, -1, 3012 size=(_BOX_WIDTH / 1.9, 20),3013 style=wx.TE_PROCESS_ENTER,3014 size=(_BOX_WIDTH / 1.9, 20), 3015 style=wx.TE_PROCESS_ENTER, 3014 3016 text_enter_callback=self._onparamRangeEnter) 3015 3017 min_bound = self.model.details[item][1] … … 3019 3021 sizer.Add(ctl3, (iy, ix), (1, 1), 3020 3022 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 3021 3023 3022 3024 ix += 1 3023 3025 ctl4 = ModelTextCtrl(self, -1, 3024 size=(_BOX_WIDTH / 1.9, 20),3025 style=wx.TE_PROCESS_ENTER,3026 size=(_BOX_WIDTH / 1.9, 20), 3027 style=wx.TE_PROCESS_ENTER, 3026 3028 text_enter_callback=self._onparamRangeEnter) 3027 3029 max_bound = self.model.details[item][2] … … 3030 3032 sizer.Add(ctl4, (iy, ix), (1, 1), 3031 3033 wx.EXPAND | wx.FIXED_MINSIZE, 0) 3032 3034 3033 3035 ix += 1 3034 3036 # Units … … 3041 3043 sizer.Add(units, (iy, ix), (1, 1), 3042 3044 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 3043 3045 3044 3046 self.parameters.append([cb, item, ctl1, 3045 3047 text2, ctl2, ctl3, ctl4, units]) 3046 3048 3047 3049 iy += 1 3048 3050 sizer.Add((10, 10), (iy, ix), (1, 1), 3049 3051 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 3050 3052 3051 3053 # type can be either Guassian or Array 3052 3054 if len(self.model.dispersion.values()) > 0: … … 3054 3056 else: 3055 3057 type = "Gaussian" 3056 3058 3057 3059 iy += 1 3058 3060 ix = 0 … … 3061 3063 if item in self.model.orientation_params: 3062 3064 orient_angle = wx.StaticText(self, -1, '[For 2D only]:') 3063 mag_on_button = wx.Button(self, -1, "Magnetic ON" )3065 mag_on_button = wx.Button(self, -1, "Magnetic ON" ) 3064 3066 mag_on_button.SetToolTipString("Turn Pol Beam/Mag scatt on/off") 3065 3067 mag_on_button.Bind(wx.EVT_BUTTON, self._on_mag_on) … … 3068 3070 mag_help_button = wx.Button(self, -1, "Mag HELP") 3069 3071 mag_help_button.SetToolTipString("Help on pol beam/mag fitting") 3070 mag_help_button.Bind(wx.EVT_BUTTON, 3072 mag_help_button.Bind(wx.EVT_BUTTON,self._on_mag_help) 3071 3073 mag_angle_help_button.Bind(wx.EVT_BUTTON, \ 3072 3074 self._on_mag_angle_help) … … 3074 3076 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 3075 3077 iy += 1 3076 sizer.Add(mag_on_button, (iy, ix), (1, 1),3077 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)3078 sizer.Add(mag_on_button,(iy, ix ),(1,1), 3079 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 3078 3080 ix += 1 3079 3081 sizer.Add(mag_angle_help_button, (iy, ix), (1, 1), 3080 3082 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 3081 sizer.Add(mag_help_button, (iy, ix + 1), (1, 1),3082 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15)3083 3083 sizer.Add(mag_help_button,(iy, ix + 1),(1,1), 3084 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 3085 3084 3086 #handle the magnetic buttons 3085 3087 #clean this up so that assume mag is off then turn … … 3096 3098 if self.magnetic_on: 3097 3099 mag_on_button.SetLabel("Magnetic OFF") 3098 mag_help_button.Show(True) 3100 mag_help_button.Show(True) 3099 3101 mag_angle_help_button.Show(True) 3100 3102 else: … … 3102 3104 mag_help_button.Show(False) 3103 3105 mag_angle_help_button.Show(False) 3104 3106 3105 3107 if not self.data.__class__.__name__ == "Data2D" and \ 3106 3108 not self.enable2D: … … 3109 3111 orient_angle.Show(True) 3110 3112 break 3111 3113 3112 3114 #For Gaussian only 3113 3115 if type.lower() != "array": … … 3120 3122 if not item in self.model.details: 3121 3123 self.model.details[item] = ["", None, None] 3122 3124 3123 3125 iy += 1 3124 3126 ix = 0 … … 3135 3137 sizer.Add(cb, (iy, ix), (1, 1), 3136 3138 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 3137 3139 3138 3140 ## add parameter value 3139 3141 ix += 1 3140 3142 value = self.model.getParam(item) 3141 3143 ctl1 = ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), 3142 3144 style=wx.TE_PROCESS_ENTER) 3143 3145 ctl1.SetToolTipString(\ 3144 3146 "Hit 'Enter' after typing to update the plot.") … … 3164 3166 3165 3167 ctl2.Hide() 3166 3168 3167 3169 ix += 1 3168 3170 ctl3 = ModelTextCtrl(self, -1, 3169 size=(_BOX_WIDTH / 1.8, 20),3170 style=wx.TE_PROCESS_ENTER,3171 size=(_BOX_WIDTH / 1.8, 20), 3172 style=wx.TE_PROCESS_ENTER, 3171 3173 text_enter_callback=self._onparamRangeEnter) 3172 3174 3173 3175 sizer.Add(ctl3, (iy, ix), (1, 1), 3174 3176 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 3175 3177 ctl3.Hide() 3176 3178 3177 3179 ix += 1 3178 3180 ctl4 = ModelTextCtrl(self, -1, 3179 size=(_BOX_WIDTH / 1.8, 20),3180 style=wx.TE_PROCESS_ENTER,3181 size=(_BOX_WIDTH / 1.8, 20), 3182 style=wx.TE_PROCESS_ENTER, 3181 3183 text_enter_callback=self._onparamRangeEnter) 3182 3184 sizer.Add(ctl4, (iy, ix), (1, 1), 3183 3185 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 3184 3186 3185 3187 ctl4.Hide() 3186 3188 3187 3189 if self.data.__class__.__name__ == "Data2D" or \ 3188 3190 self.enable2D: … … 3192 3194 ctl3.Show(True) 3193 3195 ctl4.Show(True) 3194 3196 3195 3197 ix += 1 3196 3198 # Units … … 3207 3209 else: 3208 3210 units.Hide() 3209 3211 3210 3212 sizer.Add(units, (iy, ix), (1, 1), 3211 3213 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 3212 3214 3213 3215 self.parameters.append([cb, item, ctl1, 3214 3216 text2, ctl2, ctl3, ctl4, units]) 3215 3217 self.orientation_params.append([cb, item, ctl1, 3216 3218 text2, ctl2, ctl3, ctl4, units]) 3217 3219 3218 3220 iy += 1 3219 3221 box_description.SetForegroundColour(wx.BLUE) … … 3251 3253 wx.PostEvent(self._manager.parent, 3252 3254 StatusEvent(status=msg, info=infor)) 3253 3255 3254 3256 def _onModel2D(self, event): 3255 3257 """ … … 3259 3261 self.model_view.SetLabel("Show 1D") 3260 3262 self.enable2D = True 3261 3263 3262 3264 else: 3263 3265 self.model_view.SetLabel("Show 2D") … … 3274 3276 self.SetupScrolling() 3275 3277 self._draw_model() 3276 3278 3277 3279 self.state.enable2D = copy.deepcopy(self.enable2D) 3278 3280 3279 3281 def _set_smear_buttons(self): 3280 3282 """ … … 3290 3292 self.slit_smearer.Enable(True) 3291 3293 self.pinhole_smearer.Enable(True) 3292 3293 3294 3295 3294 3296 class BGTextCtrl(wx.TextCtrl): 3295 3297 """ … … 3302 3304 self.SetEditable(False) 3303 3305 self.SetBackgroundColour(self.GetParent().parent.GetBackgroundColour()) 3304 3306 3305 3307 # Bind to mouse event to avoid text highlighting 3306 3308 # The event will be skipped once the call-back 3307 3309 # is called. 3308 3310 self.Bind(wx.EVT_MOUSE_EVENTS, self._click) 3309 3311 3310 3312 def _click(self, event): 3311 3313 """ -
src/sas/perspectives/fitting/models.py
r415fb82 r415fb82 6 6 import os 7 7 import sys 8 import math 8 9 import os.path 9 10 # Time is needed by the log method … … 12 13 import py_compile 13 14 import shutil 15 from sas.guiframe.events import StatusEvent 14 16 # Explicitly import from the pluginmodel module so that py2exe 15 17 # places it in the distribution. The Model1DPlugin class is used 16 18 # as the base class of plug-in models. 17 19 from sas.models.pluginmodel import Model1DPlugin 20 from sas.models.BaseComponent import BaseComponent 18 21 from sas.guiframe.CategoryInstaller import CategoryInstaller 19 22 23 from sasmodels.sasview_model import make_class 24 20 25 PLUGIN_DIR = 'plugin_models' 21 26 … … 314 319 315 320 # regular model names only 316 base_message = "Unable to load model {0}" 317 try: 318 self.model_name_list = [] 319 from sas.models.SphereModel import SphereModel 320 self.model_dictionary[SphereModel.__name__] = SphereModel 321 # self.shape_list.append(SphereModel) 322 self.multiplication_factor.append(SphereModel) 323 self.model_name_list.append(SphereModel.__name__) 324 except: 325 logging.error(base_message.format(SphereModel.__name__)) 321 self.model_name_list = [] 322 323 #Build list automagically from sasmodels package 324 import pkgutil 325 from importlib import import_module 326 import sasmodels.models 327 for importer,modname,ispkg in pkgutil.iter_modules(sasmodels.models.__path__): 328 if not ispkg: 329 module = import_module('.'+modname,'sasmodels.models') 330 self.model_dictionary[module.oldname] = make_class(module, dtype='single',namestyle='oldname') 331 self.model_name_list.append(module.oldname) 332 333 334 ### NASTY HACK - Comment out most of these lines as models are added to sasmodels. 335 ### Still need the lines that put models into multiplication etc 336 337 try: 338 # # from sas.models.SphereModel import SphereModel 339 # from sasmodels.models import sphere 340 # SphereModel = make_class(sphere, dtype='single',namestyle='oldname') 341 # self.model_dictionary[SphereModel.__name__] = SphereModel 342 # # self.shape_list.append(SphereModel) 343 self.multiplication_factor.append(SphereModel) 344 # self.model_name_list.append(SphereModel.__name__) 345 except: 346 pass 326 347 327 348 try: … … 1068 1089 new_plugins = _findModels(dir) 1069 1090 for name, plug in new_plugins.iteritems(): 1070 for stored_name, _in self.stored_plugins.iteritems():1091 for stored_name, stored_plug in self.stored_plugins.iteritems(): 1071 1092 if name == stored_name: 1072 1093 del self.stored_plugins[name]
Note: See TracChangeset
for help on using the changeset viewer.