Changeset f668101 in sasview for src/sas/sasgui/perspectives/fitting/basepage.py
- Timestamp:
- Dec 7, 2016 9:16:33 AM (7 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- c6728e1
- Parents:
- 1cad8a4 (diff), 5231948 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/basepage.py
r55db501 rf668101 19 19 20 20 from sas.sasgui.guiframe.panel_base import PanelBase 21 from sas.sasgui.guiframe.utils import format_number, check_float, IdList, check_int 21 from sas.sasgui.guiframe.utils import format_number, check_float, IdList, \ 22 check_int 22 23 from sas.sasgui.guiframe.events import PanelOnFocusEvent 23 24 from sas.sasgui.guiframe.events import StatusEvent … … 42 43 _QMAX_DEFAULT = 0.5 43 44 _NPTS_DEFAULT = 50 44 # Control panel width45 # Control panel width 45 46 if sys.platform.count("win32") > 0: 46 47 PANEL_WIDTH = 450 … … 57 58 This class provide general structure of fitpanel page 58 59 """ 59 # #Internal name for the AUI manager60 # Internal name for the AUI manager 60 61 window_name = "Fit Page" 61 # #Title to appear on top of the window62 # Title to appear on top of the window 62 63 window_caption = "Fit Page " 63 64 … … 75 76 PanelBase.__init__(self, parent) 76 77 self.SetupScrolling() 77 # Set window's font size78 # Set window's font size 78 79 self.SetWindowVariant(variant=FONT_VARIANT) 79 80 self.SetBackgroundColour(color) 80 81 81 82 self._ids = iter(self._id_pool) 82 # #parent of the page83 # parent of the page 83 84 self.parent = parent 84 # #manager is the fitting plugin85 # #owner of the page (fitting plugin)85 # manager is the fitting plugin 86 # owner of the page (fitting plugin) 86 87 self.event_owner = None 87 # #current model88 # current model 88 89 self.model = None 89 90 self.m_name = None 90 91 self.index_model = None 91 92 self.panel = None 92 # #data93 # data 93 94 self.data = None 94 # list of available data95 # list of available data 95 96 self.data_list = [] 96 97 self.mask = None 97 98 self.uid = wx.NewId() 98 99 self.graph_id = None 99 # Q range for data set100 # Q range for data set 100 101 self.qmin_data_set = numpy.inf 101 102 self.qmax_data_set = None 102 103 self.npts_data_set = 0 103 # #Q range104 # Q range 104 105 self.qmin = None 105 106 self.qmax = None … … 107 108 self.qmin_x = _QMIN_DEFAULT 108 109 self.npts_x = _NPTS_DEFAULT 109 # #total number of point: float110 # total number of point: float 110 111 self.npts = None 111 112 self.num_points = None 112 # #smear default113 # smear default 113 114 self.current_smearer = None 114 # #2D smear accuracy default115 # 2D smear accuracy default 115 116 self.smear2d_accuracy = 'Low' 116 # #slit smear:117 # slit smear: 117 118 self.dxl = None 118 119 self.dxw = None 119 # #pinhole smear120 # pinhole smear 120 121 self.dx_min = None 121 122 self.dx_max = None 122 # #semar attrbs123 # smear attrbs 123 124 self.enable_smearer = None 124 125 self.disable_smearer = None 125 126 self.pinhole_smearer = None 126 127 self.slit_smearer = None 127 # #weigthattrbs128 # weight attrbs 128 129 self.dI_noweight = None 129 130 self.dI_didata = None 130 131 self.dI_sqrdata = None 131 132 self.dI_idata = None 132 # #other attrbs133 # other attrbs 133 134 self.dq_l = None 134 135 self.dq_r = None … … 150 151 self.disp_cb_dict = {} 151 152 152 # self.state = PageState(parent=parent)153 # #dictionary containing list of models153 # self.state = PageState(parent=parent) 154 # dictionary containing list of models 154 155 self.model_list_box = {} 155 156 156 # #Data member to store the dispersion object created157 # Data member to store the dispersion object created 157 158 self._disp_obj_dict = {} 158 # #selected parameters to apply dispersion159 # selected parameters to apply dispersion 159 160 self.disp_cb_dict = {} 160 # #smearer object161 # smearer object 161 162 self.enable2D = False 162 163 self._has_magnetic = False … … 166 167 self.structurebox = None 167 168 self.categorybox = None 168 # #list of model parameters. each item must have same length169 # #each item related to a given parameters170 # #[cb state, name, value, "+/-", error of fit, min, max , units]169 # list of model parameters. each item must have same length 170 # each item related to a given parameters 171 # [cb state, name, value, "+/-", error of fit, min, max , units] 171 172 self.parameters = [] 172 173 # non-fittable parameter whose value is astring 173 174 self.str_parameters = [] 174 # #list of parameters to fit , must be like self.parameters175 # list of parameters to fit , must be like self.parameters 175 176 self.param_toFit = [] 176 # #list of looking like parameters but with non fittable parameters info177 # list of looking like parameters but with non fittable parameters info 177 178 self.fixed_param = [] 178 # #list of looking like parameters but with fittable parameters info179 # list of looking like parameters but with fittable parameters info 179 180 self.fittable_param = [] 180 # #list of dispersion parameters181 # list of dispersion parameters 181 182 self.disp_list = [] 182 183 self.disp_name = "" 183 184 184 # #list of orientation parameters185 # list of orientation parameters 185 186 self.orientation_params = [] 186 187 self.orientation_params_disp = [] … … 189 190 # and this - commenting out on 4/8/2014 by PDB. Remove once clear 190 191 # it is pointless. 191 # if self.model !=None:192 # if self.model is not None: 192 193 # self.disp_list = self.model.getDispParamList() 193 194 self.temp_multi_functional = False 194 # #enable model 2D draw195 # enable model 2D draw 195 196 self.enable2D = False 196 # #check that the fit range is correct to plot the model again197 # check that the fit range is correct to plot the model again 197 198 self.fitrange = True 198 # #Create memento to save the current state199 # Create memento to save the current state 199 200 self.state = PageState(parent=self.parent, 200 201 model=self.model, data=self.data) 201 # #flag to determine if state has change202 # flag to determine if state has change 202 203 self.state_change = False 203 # #save customized array204 # save customized array 204 205 self.values = {} # type: Dict[str, List[float, ...]] 205 206 self.weights = {} # type: Dict[str, List[float, ...]] 206 # #retrieve saved state207 # retrieve saved state 207 208 self.number_saved_state = 0 208 # #dictionary of saved state209 # dictionary of saved state 209 210 self.saved_states = {} 210 # #Create context menu for page211 # Create context menu for page 211 212 self.popUpMenu = wx.Menu() 212 213 … … 221 222 self.popUpMenu.AppendSeparator() 222 223 223 # #Default locations224 # Default locations 224 225 self._default_save_location = os.getcwd() 225 # #save initial state on context menu226 # self.onSave(event=None)226 # save initial state on context menu 227 # self.onSave(event=None) 227 228 self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) 228 229 … … 230 231 self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down) 231 232 232 # #create the basic structure of the panel with empty sizer233 # create the basic structure of the panel with empty sizer 233 234 self.define_page_structure() 234 # #drawing Initial dispersion parameters sizer235 # drawing Initial dispersion parameters sizer 235 236 self.set_dispers_sizer() 236 237 237 # #layout238 # layout 238 239 self.set_layout() 239 240 … … 261 262 self._create_default_1d_data() 262 263 263 if self.model !=None:264 if self.model is not None: 264 265 if not self.data.is_data: 265 self._manager.page_finder[self.uid].set_fit_data( data=\266 266 self._manager.page_finder[self.uid].set_fit_data( 267 data=[self.data]) 267 268 self.on_smear_helper(update=True) 268 269 self.state.enable_smearer = self.enable_smearer.GetValue() … … 330 331 self.data.id = str(self.uid) + " data" 331 332 self.data.group_id = str(self.uid) + " Model2D" 332 # #Default values333 # Default values 333 334 self.data.detector.append(Detector()) 334 335 index = len(self.data.detector) - 1 … … 347 348 x = numpy.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) 348 349 y = numpy.linspace(start=ymin, stop=ymax, num=qstep, endpoint=True) 349 # #use data info instead350 # use data info instead 350 351 new_x = numpy.tile(x, (len(y), 1)) 351 352 new_y = numpy.tile(y, (len(x), 1)) … … 388 389 Update menu1 on cliking the page tap 389 390 """ 390 if self._manager.menu1 !=None:391 chain_menu = self._manager.menu1.FindItemById( \391 if self._manager.menu1 is not None: 392 chain_menu = self._manager.menu1.FindItemById( 392 393 self._manager.id_reset_flag) 393 394 chain_menu.Enable(self.batch_on) 394 395 sim_menu = self._manager.menu1.FindItemById(self._manager.id_simfit) 395 396 flag = self.data.is_data\ 396 and (self.model !=None)397 and (self.model is not None) 397 398 sim_menu.Enable(not self.batch_on and flag) 398 399 batch_menu = \ … … 535 536 fill sizer containing dispersity info 536 537 """ 537 # print "==== entering set_dispers_sizer ==="538 # print "==== entering set_dispers_sizer ===" 538 539 self.sizer4.Clear(True) 539 540 name = "Polydispersity and Orientational Distribution" … … 541 542 box_description.SetForegroundColour(wx.BLUE) 542 543 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 543 # ----------------------------------------------------544 # ---------------------------------------------------- 544 545 self.disable_disp = wx.RadioButton(self, wx.ID_ANY, 'Off', (10, 10), 545 546 style=wx.RB_GROUP) … … 561 562 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, 562 563 id=self.enable_disp.GetId()) 563 # MAC needs SetValue564 # MAC needs SetValue 564 565 self.disable_disp.SetValue(True) 565 566 sizer_dispersion = wx.BoxSizer(wx.HORIZONTAL) … … 573 574 sizer_dispersion.Add(self.disp_help_bt) 574 575 575 # #fill a sizer for dispersion576 # fill a sizer for dispersion 576 577 boxsizer1.Add(sizer_dispersion, 0, 577 578 wx.TOP|wx.BOTTOM|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, … … 580 581 581 582 boxsizer1.Add(self.sizer4_4) 582 # -----------------------------------------------------583 # ----------------------------------------------------- 583 584 self.sizer4.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 584 585 self.sizer4_4.Layout() … … 587 588 588 589 self.Refresh() 589 # #saving the state of enable dispersity button590 # saving the state of enable dispersity button 590 591 self.state.enable_disp = self.enable_disp.GetValue() 591 592 self.state.disable_disp = self.disable_disp.GetValue() … … 597 598 """ 598 599 menu = event.GetEventObject() 599 # #post help message for the selected model600 # post help message for the selected model 600 601 msg = menu.GetHelpString(event.GetId()) 601 602 msg += " reloaded" … … 604 605 name = menu.GetLabel(event.GetId()) 605 606 self._on_select_model_helper() 606 if self.model !=None:607 if self.model is not None: 607 608 self.m_name = self.model.name 608 609 if name in self.saved_states.keys(): 609 610 previous_state = self.saved_states[name] 610 # #reset state of checkbox,textcrtl and regular parameters value611 # reset state of checkbox,textcrtl and regular parameters value 611 612 612 613 self.reset_page(previous_state) … … 631 632 # Ask the user the location of the file to write to. 632 633 path = None 633 if self.parent !=None:634 if self.parent is not None: 634 635 self._default_save_location = \ 635 636 self._manager.parent._default_save_location … … 641 642 self._default_save_location = os.path.dirname(path) 642 643 self._manager.parent._default_save_location = \ 643 644 self._default_save_location 644 645 else: 645 646 return None … … 648 649 # Make sure the ext included in the file name 649 650 fName = os.path.splitext(path)[0] + extens 650 # the manager write the state into file651 # the manager write the state into file 651 652 self._manager.save_fit_state(filepath=fName, fitstate=new_state) 652 653 return new_state … … 656 657 Copy Parameter values to the clipboad 657 658 """ 658 if event !=None:659 if event is not None: 659 660 event.Skip() 660 661 # It seems MAC needs wxCallAfter … … 672 673 Paste Parameter values to the panel if possible 673 674 """ 674 # if event !=None:675 # if event is not None: 675 676 # event.Skip() 676 677 # It seems MAC needs wxCallAfter for the setvalues … … 678 679 wx.CallAfter(self.get_paste) 679 680 # messages depending on the flag 680 # self._copy_info(True)681 # self._copy_info(True) 681 682 682 683 def _copy_info(self, flag): … … 687 688 """ 688 689 # messages depending on the flag 689 if flag ==None:690 if flag is None: 690 691 msg = " Parameter values are copied to the clipboard..." 691 692 infor = 'warning' … … 715 716 save history of the data and model 716 717 """ 717 if self.model ==None:718 if self.model is None: 718 719 msg = "Can not bookmark; Please select Data and Model first..." 719 720 wx.MessageBox(msg, 'Info') … … 721 722 self.save_current_state() 722 723 new_state = self.state.clone() 723 # #Add model state on context menu724 # Add model state on context menu 724 725 self.number_saved_state += 1 725 726 current_time, current_date = self._get_time_stamp() 726 # name= self.model.name+"[%g]"%self.number_saved_state727 # name= self.model.name+"[%g]"%self.number_saved_state 727 728 name = "Fitting: %g]" % self.number_saved_state 728 729 name += self.model.__class__.__name__ … … 730 731 self.saved_states[name] = new_state 731 732 732 # #Add item in the context menu733 # Add item in the context menu 733 734 msg = "Model saved at %s on %s" % (current_time, current_date) 734 # #post help message for the selected model735 # post help message for the selected model 735 736 msg += " Saved! right click on this page to retrieve this model" 736 737 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 766 767 """ 767 768 try: 768 if path ==None:769 if path is None: 769 770 status = " Selected Distribution was not loaded: %s" % path 770 771 wx.PostEvent(self._manager.parent, … … 801 802 Store current state 802 803 """ 803 # #save model option804 if self.model !=None:804 # save model option 805 if self.model is not None: 805 806 self.disp_list = self.model.getDispParamList() 806 807 self.state.disp_list = copy.deepcopy(self.disp_list) 807 808 self.state.model = self.model.clone() 808 809 809 # model combobox: complex code because of mac's silent error810 if self.structurebox !=None:810 # model combobox: complex code because of mac's silent error 811 if self.structurebox is not None: 811 812 if self.structurebox.IsShown(): 812 813 self.state.structurecombobox = 'None' 813 814 s_select = self.structurebox.GetSelection() 814 815 if s_select > 0: 815 self.state.structurecombobox = self.structurebox.\816 GetString(s_select)817 if self.formfactorbox !=None:816 self.state.structurecombobox = \ 817 self.structurebox.GetString(s_select) 818 if self.formfactorbox is not None: 818 819 f_select = self.formfactorbox.GetSelection() 819 820 if f_select > 0: 820 self.state.formfactorcombobox = self.formfactorbox.\821 GetString(f_select)822 if self.categorybox !=None:821 self.state.formfactorcombobox = \ 822 self.formfactorbox.GetString(f_select) 823 if self.categorybox is not None: 823 824 cb_select = self.categorybox.GetSelection() 824 825 if cb_select > 0: 825 self.state.categorycombobox = self.categorybox.\826 GetString(cb_select)826 self.state.categorycombobox = \ 827 self.categorybox.GetString(cb_select) 827 828 828 829 self.state.enable2D = copy.deepcopy(self.enable2D) 829 830 self.state.values = copy.deepcopy(self.values) 830 831 self.state.weights = copy.deepcopy(self.weights) 831 # #save data832 # save data 832 833 self.state.data = copy.deepcopy(self.data) 833 834 self.state.qmax_x = self.qmax_x … … 864 865 self.state.values = copy.deepcopy(self.values) 865 866 self.state.weights = copy.deepcopy(self.weights) 866 # #save plotting range867 # save plotting range 867 868 self._save_plotting_range() 868 869 … … 874 875 self.state.str_parameters = [] 875 876 876 # #save checkbutton state and txtcrtl values877 # save checkbutton state and txtcrtl values 877 878 self._copy_parameters_state(self.str_parameters, 878 879 self.state.str_parameters) … … 886 887 self.state.fittable_param) 887 888 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 888 # save chisqr889 # save chisqr 889 890 self.state.tcChi = self.tcChi.GetValue() 890 891 … … 893 894 Store current state for fit_page 894 895 """ 895 # #save model option896 if self.model !=None:896 # save model option 897 if self.model is not None: 897 898 self.disp_list = self.model.getDispParamList() 898 899 self.state.disp_list = copy.deepcopy(self.disp_list) … … 902 903 self.state.values = copy.deepcopy(self.values) 903 904 self.state.weights = copy.deepcopy(self.weights) 904 # #save data905 # save data 905 906 self.state.data = copy.deepcopy(self.data) 906 907 … … 923 924 self.state.dI_sqrdata = copy.deepcopy(self.dI_sqrdata.GetValue()) 924 925 self.state.dI_idata = copy.deepcopy(self.dI_idata.GetValue()) 925 if hasattr(self, "disp_box") and self.disp_box !=None:926 if hasattr(self, "disp_box") and self.disp_box is not None: 926 927 self.state.disp_box = self.disp_box.GetCurrentSelection() 927 928 928 929 if len(self.disp_cb_dict) > 0: 929 930 for k, v in self.disp_cb_dict.iteritems(): 930 if v ==None:931 if v is None: 931 932 self.state.disp_cb_dict[k] = v 932 933 else: … … 942 943 self.state.weights = copy.deepcopy(self.weights) 943 944 944 # #save plotting range945 # save plotting range 945 946 self._save_plotting_range() 946 947 947 # #save checkbutton state and txtcrtl values948 # save checkbutton state and txtcrtl values 948 949 self._copy_parameters_state(self.orientation_params, 949 950 self.state.orientation_params) … … 964 965 msg = "Please load Data and select Model to start..." 965 966 wx.MessageBox(msg, 'Info') 966 return 967 return True 967 968 968 969 def set_model_state(self, state): … … 973 974 self.disp_list = state.disp_list 974 975 975 # #fill model combobox976 # fill model combobox 976 977 self._show_combox_helper() 977 # select the current model978 # select the current model 978 979 try: 979 980 # to support older version … … 1014 1015 self.structurebox.SetSelection(structfactor_pos) 1015 1016 1016 if state.multi_factor !=None:1017 if state.multi_factor is not None: 1017 1018 self.multifactorbox.SetSelection(state.multi_factor) 1018 1019 1019 # #reset state of checkbox,textcrtl and regular parameters value1020 # reset state of checkbox,textcrtl and regular parameters value 1020 1021 self._reset_parameters_state(self.orientation_params_disp, 1021 1022 state.orientation_params_disp) … … 1025 1026 state.str_parameters) 1026 1027 self._reset_parameters_state(self.parameters, state.parameters) 1027 # #display dispersion info layer1028 # display dispersion info layer 1028 1029 self.enable_disp.SetValue(state.enable_disp) 1029 1030 self.disable_disp.SetValue(state.disable_disp) 1030 1031 1031 if hasattr(self, "disp_box") and self.disp_box !=None:1032 if hasattr(self, "disp_box") and self.disp_box is not None: 1032 1033 self.disp_box.SetSelection(state.disp_box) 1033 1034 n = self.disp_box.GetCurrentSelection() … … 1041 1042 1042 1043 if hasattr(self.disp_cb_dict[item], "SetValue"): 1043 self.disp_cb_dict[item].SetValue( \1044 self.disp_cb_dict[item].SetValue( 1044 1045 state.disp_cb_dict[item]) 1045 1046 # Create the dispersion objects 1046 1047 disp_model = POLYDISPERSITY_MODELS['array']() 1047 1048 if hasattr(state, "values") and \ 1048 self.disp_cb_dict[item].GetValue() ==True:1049 self.disp_cb_dict[item].GetValue() is True: 1049 1050 if len(state.values) > 0: 1050 1051 self.values = state.values … … 1057 1058 self._disp_obj_dict[item] = disp_model 1058 1059 # Set the new model as the dispersion object 1059 # for the selected parameter1060 # for the selected parameter 1060 1061 self.model.set_dispersion(item, disp_model) 1061 1062 … … 1067 1068 for item in keys: 1068 1069 if item in self.disp_list and \ 1069 not itemin self.model.details:1070 item not in self.model.details: 1070 1071 self.model.details[item] = ["", None, None] 1071 1072 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1072 1073 self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1073 # #smearing info restore1074 # smearing info restore 1074 1075 if hasattr(self, "enable_smearer"): 1075 # #set smearing value whether or not the data1076 # contain the smearing info1076 # set smearing value whether or not the data 1077 # contain the smearing info 1077 1078 self.enable_smearer.SetValue(state.enable_smearer) 1078 1079 self.disable_smearer.SetValue(state.disable_smearer) … … 1086 1087 self.dI_idata.SetValue(state.dI_idata) 1087 1088 1088 # #we have two more options for smearing1089 # we have two more options for smearing 1089 1090 if self.pinhole_smearer.GetValue(): 1090 1091 self.onPinholeSmear(event=None) … … 1092 1093 self.onSlitSmear(event=None) 1093 1094 1094 # #reset state of checkbox,textcrtl and dispersity parameters value1095 # reset state of checkbox,textcrtl and dispersity parameters value 1095 1096 self._reset_parameters_state(self.fittable_param, state.fittable_param) 1096 1097 self._reset_parameters_state(self.fixed_param, state.fixed_param) 1097 1098 1098 # #draw the model with previous parameters value1099 # draw the model with previous parameters value 1099 1100 self._onparamEnter_helper() 1100 1101 self.select_param(event=None) 1101 # Save state_fit1102 # Save state_fit 1102 1103 self.save_current_state_fit() 1103 1104 self._lay_out() … … 1113 1114 if state.formfactorcombobox in list_item: 1114 1115 return self.categorybox.Items.index(key) 1116 return 0 1115 1117 1116 1118 def reset_page_helper(self, state): … … 1123 1125 state of the graphic interface 1124 1126 """ 1125 if state ==None:1127 if state is None: 1126 1128 return 1127 1129 # set data, etc. from the state … … 1132 1134 data = state.data 1133 1135 1134 if data ==None:1136 if data is None: 1135 1137 data_min = state.qmin 1136 1138 data_max = state.qmax … … 1156 1158 self.disp_list = state.disp_list 1157 1159 1158 ## set the state of the radio box 1159 #self.shape_rbutton.SetValue(state.shape_rbutton) 1160 #self.shape_indep_rbutton.SetValue(state.shape_indep_rbutton) 1161 #self.struct_rbutton.SetValue(state.struct_rbutton) 1162 #self.plugin_rbutton.SetValue(state.plugin_rbutton) 1163 1164 ## fill model combobox 1160 # fill model combobox 1165 1161 self._show_combox_helper() 1166 # select the current model1162 # select the current model 1167 1163 try: 1168 1164 # to support older version 1169 1165 category_pos = int(state.categorycombobox) 1170 1166 except: 1171 state.formfactorcombobox = unicode(state.formfactorcombobox.lower()) 1167 state.formfactorcombobox = state.formfactorcombobox.lower() 1168 state.formfactorcombobox = \ 1169 state.formfactorcombobox.replace('model', '') 1170 state.formfactorcombobox = unicode(state.formfactorcombobox) 1172 1171 state.categorycombobox = unicode(state.categorycombobox) 1173 category_pos = 01174 1172 if state.categorycombobox in self.categorybox.Items: 1175 1173 category_pos = self.categorybox.Items.index( … … 1194 1192 self.formfactorbox.Select(formfactor_pos) 1195 1193 1194 structfactor_pos = 0 1196 1195 try: 1197 1196 # to support older version … … 1199 1198 except: 1200 1199 if state.structurecombobox is not None: 1201 structfactor_pos = 01202 1200 state.structurecombobox = unicode(state.structurecombobox) 1203 1201 for ind_struct in range(self.structurebox.GetCount()): 1204 1202 if self.structurebox.GetString(ind_struct) == \ 1205 1203 (state.structurecombobox): 1206 1204 structfactor_pos = int(ind_struct) 1207 1205 break … … 1209 1207 self.structurebox.SetSelection(structfactor_pos) 1210 1208 1211 if state.multi_factor !=None:1209 if state.multi_factor is not None: 1212 1210 self.multifactorbox.SetSelection(state.multi_factor) 1213 1211 1214 # draw the panel according to the new model parameter1212 # draw the panel according to the new model parameter 1215 1213 self._on_select_model(event=None) 1216 1214 1217 1215 # take care of 2D button 1218 if data ==None and self.model_view.IsEnabled():1216 if data is None and self.model_view.IsEnabled(): 1219 1217 if self.enable2D: 1220 1218 self.model_view.SetLabel("2D Mode") … … 1222 1220 self.model_view.SetLabel("1D Mode") 1223 1221 1224 ## set the select all check box to the a given state 1225 self.cb1.SetValue(state.cb1) 1226 1227 ## reset state of checkbox,textcrtl and regular parameters value 1222 # reset state of checkbox,textcrtl and regular parameters value 1228 1223 self._reset_parameters_state(self.orientation_params_disp, 1229 1224 state.orientation_params_disp) … … 1233 1228 state.str_parameters) 1234 1229 self._reset_parameters_state(self.parameters, state.parameters) 1235 # #display dispersion info layer1230 # display dispersion info layer 1236 1231 self.enable_disp.SetValue(state.enable_disp) 1237 1232 self.disable_disp.SetValue(state.disable_disp) … … 1241 1236 self._set_dipers_Param(event=None) 1242 1237 self._reset_page_disp_helper(state) 1243 # #plotting range restore1238 # plotting range restore 1244 1239 self._reset_plotting_range(state) 1245 # #smearing info restore1240 # smearing info restore 1246 1241 if hasattr(self, "enable_smearer"): 1247 # #set smearing value whether or not the data1248 # contain the smearing info1242 # set smearing value whether or not the data 1243 # contain the smearing info 1249 1244 self.enable_smearer.SetValue(state.enable_smearer) 1250 1245 self.disable_smearer.SetValue(state.disable_smearer) … … 1264 1259 self.dI_idata.SetValue(False) 1265 1260 1266 # #we have two more options for smearing1261 # we have two more options for smearing 1267 1262 if self.pinhole_smearer.GetValue(): 1268 1263 self.dx_min = state.dx_min 1269 1264 self.dx_max = state.dx_max 1270 if self.dx_min !=None:1265 if self.dx_min is not None: 1271 1266 self.smear_pinhole_min.SetValue(str(self.dx_min)) 1272 if self.dx_max !=None:1267 if self.dx_max is not None: 1273 1268 self.smear_pinhole_max.SetValue(str(self.dx_max)) 1274 1269 self.onPinholeSmear(event=None) … … 1276 1271 self.dxl = state.dxl 1277 1272 self.dxw = state.dxw 1278 if self.dxl !=None:1273 if self.dxl is not None: 1279 1274 self.smear_slit_height.SetValue(str(self.dxl)) 1280 if self.dxw !=None:1275 if self.dxw is not None: 1281 1276 self.smear_slit_width.SetValue(str(self.dxw)) 1282 1277 else: … … 1284 1279 self.onSlitSmear(event=None) 1285 1280 1286 # #reset state of checkbox,textcrtl and dispersity parameters value1281 # reset state of checkbox,textcrtl and dispersity parameters value 1287 1282 self._reset_parameters_state(self.fittable_param, state.fittable_param) 1288 1283 self._reset_parameters_state(self.fixed_param, state.fixed_param) 1289 1284 1290 # #draw the model with previous parameters value1285 # draw the model with previous parameters value 1291 1286 self._onparamEnter_helper() 1292 # reset the value of chisqr when not consistent with the value computed1287 # reset the value of chisqr when not consistent with the value computed 1293 1288 self.tcChi.SetValue(str(self.state.tcChi)) 1294 # #reset context menu items1289 # reset context menu items 1295 1290 self._reset_context_menu() 1296 1291 1297 # #set the value of the current state to the state given as parameter1292 # set the value of the current state to the state given as parameter 1298 1293 self.state = state.clone() 1299 1294 self.state.m_name = self.m_name … … 1306 1301 for item in keys: 1307 1302 if item in self.disp_list and \ 1308 not itemin self.model.details:1303 item not in self.model.details: 1309 1304 self.model.details[item] = ["", None, None] 1310 # for k,v in self.state.disp_cb_dict.iteritems():1305 # for k,v in self.state.disp_cb_dict.iteritems(): 1311 1306 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1312 1307 self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) … … 1315 1310 1316 1311 for key, disp_type in state._disp_obj_dict.iteritems(): 1317 # disp_model = disp1312 # disp_model = disp 1318 1313 disp_model = POLYDISPERSITY_MODELS[disp_type]() 1319 1314 self._disp_obj_dict[key] = disp_model … … 1324 1319 self.model.set_dispersion(param_name, disp_model) 1325 1320 self.model._persistency_dict[key] = \ 1326 1321 [state.values, state.weights] 1327 1322 except Exception: 1328 1323 logging.error(traceback.format_exc()) 1329 1324 selection = self._find_polyfunc_selection(disp_model) 1330 1325 for list in self.fittable_param: 1331 if list[1] == key and list[7] !=None:1326 if list[1] == key and list[7] is not None: 1332 1327 list[7].SetSelection(selection) 1333 1328 # For the array disp_model, set the values and weights … … 1362 1357 open a dialog file to selected the customized dispersity 1363 1358 """ 1364 if self.parent !=None:1359 if self.parent is not None: 1365 1360 self._default_save_location = \ 1366 1361 self._manager.parent.get_save_location() … … 1381 1376 for name, _ in self.state.saved_states.iteritems(): 1382 1377 self.number_saved_state += 1 1383 # #Add item in the context menu1378 # Add item in the context menu 1384 1379 wx_id = ids.next() 1385 1380 msg = 'Save model and state %g' % self.number_saved_state … … 1398 1393 save radiobutton containing the type model that can be selected 1399 1394 """ 1400 # self.state.shape_rbutton = self.shape_rbutton.GetValue()1401 # self.state.shape_indep_rbutton = self.shape_indep_rbutton.GetValue()1402 # self.state.struct_rbutton = self.struct_rbutton.GetValue()1403 # self.state.plugin_rbutton = self.plugin_rbutton.GetValue()1395 # self.state.shape_rbutton = self.shape_rbutton.GetValue() 1396 # self.state.shape_indep_rbutton = self.shape_indep_rbutton.GetValue() 1397 # self.state.struct_rbutton = self.struct_rbutton.GetValue() 1398 # self.state.plugin_rbutton = self.plugin_rbutton.GetValue() 1404 1399 self.state.structurecombobox = self.structurebox.GetLabel() 1405 1400 self.state.formfactorcombobox = self.formfactorbox.GetLabel() 1406 1401 self.state.categorycombobox = self.categorybox.GetLabel() 1407 1402 1408 # #post state to fit panel1403 # post state to fit panel 1409 1404 event = PageInfoEvent(page=self) 1410 1405 wx.PostEvent(self.parent, event) … … 1418 1413 self.state.npts = self.npts_x 1419 1414 1420 def _onparamEnter_helper(self, is_modified =False):1415 def _onparamEnter_helper(self, is_modified=False): 1421 1416 """ 1422 1417 check if values entered by the user are changed and valid to replot … … 1424 1419 """ 1425 1420 # Flag to register when a parameter has changed. 1426 # is_modified = False1421 # is_modified = False 1427 1422 self.fitrange = True 1428 1423 is_2Ddata = False 1429 # self._undo.Enable(True)1424 # self._undo.Enable(True) 1430 1425 # check if 2d data 1431 1426 if self.data.__class__.__name__ == "Data2D": 1432 1427 is_2Ddata = True 1433 if self.model !=None:1434 # Either we get a is_modified = True passed in because1435 # _update_paramv_on_fit() has been called already or1428 if self.model is not None: 1429 # Either we get a is_modified = True passed in because 1430 # _update_paramv_on_fit() has been called already or 1436 1431 # we need to check here ourselves. 1437 1432 if not is_modified: … … 1460 1455 self.fitrange = False 1461 1456 1462 if not self.data.is_data: 1463 is_modified = True 1464 1465 ## if any value is modify draw model with new value 1457 # if any value is modify draw model with new value 1466 1458 if not self.fitrange: 1467 # self.btFit.Disable()1459 # self.btFit.Disable() 1468 1460 if is_2Ddata: 1469 1461 self.btEditMask.Disable() … … 1478 1470 self._draw_model() 1479 1471 self.Refresh() 1472 1473 # logging.info("is_modified flag set to %g",is_modified) 1480 1474 return is_modified 1481 1475 … … 1484 1478 make sure that update param values just before the fitting 1485 1479 """ 1486 # flag for qmin qmax check values1480 # flag for qmin qmax check values 1487 1481 flag = True 1488 1482 self.fitrange = True 1489 1483 is_modified = False 1490 1484 1491 # wx.PostEvent(self._manager.parent, StatusEvent(status=" \1492 # updating ... ",type="update"))1493 1494 # #So make sure that update param values on_Fit.1495 # self._undo.Enable(True)1496 if self.model !=None:1485 # wx.PostEvent(self._manager.parent, StatusEvent(status=" \ 1486 # updating ... ",type="update")) 1487 1488 # So make sure that update param values on_Fit. 1489 # self._undo.Enable(True) 1490 if self.model is not None: 1497 1491 if self.Npts_total.GetValue() != self.Npts_fit.GetValue(): 1498 1492 if not self.data.is_data: 1499 self._manager.page_finder[self.uid].set_fit_data( data=\1500 1501 # #Check the values1493 self._manager.page_finder[self.uid].set_fit_data( 1494 data=[self.data]) 1495 # Check the values 1502 1496 is_modified = (self._check_value_enter(self.fittable_param) 1503 1504 1497 or self._check_value_enter(self.fixed_param) 1498 or self._check_value_enter(self.parameters)) 1505 1499 1506 1500 # If qmin and qmax have been modified, update qmin and qmax and … … 1543 1537 enable_smearer=enable_smearer, 1544 1538 draw=False) 1545 if self.data !=None:1546 index_data = ((self.qmin_x <= self.data.x) & \1539 if self.data is not None: 1540 index_data = ((self.qmin_x <= self.data.x) & 1547 1541 (self.data.x <= self.qmax_x)) 1548 val = str(len(self.data.x[index_data ==True]))1542 val = str(len(self.data.x[index_data is True])) 1549 1543 self.Npts_fit.SetValue(val) 1550 1544 else: … … 1566 1560 flag = False 1567 1561 1568 # For invalid q range, disable the mask editor and fit button, vs.1562 # For invalid q range, disable the mask editor and fit button, vs. 1569 1563 if not self.fitrange: 1570 1564 if self._is_2D(): 1571 1565 self.btEditMask.Disable() 1572 1566 else: 1573 if self._is_2D() and 1567 if self._is_2D() and self.data.is_data and not self.batch_on: 1574 1568 self.btEditMask.Enable(True) 1575 1569 … … 1584 1578 logging.error(traceback.format_exc()) 1585 1579 1586 return flag, is_modified1580 return flag, is_modified 1587 1581 1588 1582 def _reset_parameters_state(self, listtorestore, statelist): … … 1598 1592 item_page = listtorestore[j] 1599 1593 item_page_info = statelist[j] 1600 # #change the state of the check box for simple parameters1601 if item_page[0] !=None:1594 # change the state of the check box for simple parameters 1595 if item_page[0] is not None: 1602 1596 item_page[0].SetValue(item_page_info[0]) 1603 if item_page[2] !=None:1597 if item_page[2] is not None: 1604 1598 item_page[2].SetValue(item_page_info[2]) 1605 1599 if item_page[2].__class__.__name__ == "ComboBox": … … 1607 1601 fun_val = self.model.fun_list[item_page_info[2]] 1608 1602 self.model.setParam(item_page_info[1], fun_val) 1609 if item_page[3] !=None:1610 # #show or hide text +/-1603 if item_page[3] is not None: 1604 # show or hide text +/- 1611 1605 if item_page_info[2]: 1612 1606 item_page[3].Show(True) 1613 1607 else: 1614 1608 item_page[3].Hide() 1615 if item_page[4] !=None:1616 # #show of hide the text crtl for fitting error1609 if item_page[4] is not None: 1610 # show of hide the text crtl for fitting error 1617 1611 if item_page_info[4][0]: 1618 1612 item_page[4].Show(True) … … 1620 1614 else: 1621 1615 item_page[3].Hide() 1622 if item_page[5] !=None:1623 # #show of hide the text crtl for fitting error1616 if item_page[5] is not None: 1617 # show of hide the text crtl for fitting error 1624 1618 item_page[5].Show(item_page_info[5][0]) 1625 1619 item_page[5].SetValue(item_page_info[5][1]) 1626 1620 1627 if item_page[6] !=None:1628 # #show of hide the text crtl for fitting error1621 if item_page[6] is not None: 1622 # show of hide the text crtl for fitting error 1629 1623 item_page[6].Show(item_page_info[6][0]) 1630 1624 item_page[6].SetValue(item_page_info[6][1]) … … 1642 1636 item_page = listtorestore[j] 1643 1637 item_page_info = statelist[j] 1644 # #change the state of the check box for simple parameters1645 1646 if item_page[0] !=None:1638 # change the state of the check box for simple parameters 1639 1640 if item_page[0] is not None: 1647 1641 item_page[0].SetValue(format_number(item_page_info[0], True)) 1648 1642 1649 if item_page[2] !=None:1643 if item_page[2] is not None: 1650 1644 param_name = item_page_info[1] 1651 1645 value = item_page_info[2] … … 1670 1664 1671 1665 checkbox_state = None 1672 if item[0] !=None:1666 if item[0] is not None: 1673 1667 checkbox_state = item[0].GetValue() 1674 1668 parameter_name = item[1] 1675 1669 parameter_value = None 1676 if item[2] !=None:1670 if item[2] is not None: 1677 1671 parameter_value = item[2].GetValue() 1678 1672 static_text = None 1679 if item[3] !=None:1673 if item[3] is not None: 1680 1674 static_text = item[3].IsShown() 1681 1675 error_value = None 1682 1676 error_state = None 1683 if item[4] !=None:1677 if item[4] is not None: 1684 1678 error_value = item[4].GetValue() 1685 1679 error_state = item[4].IsShown() … … 1687 1681 min_value = None 1688 1682 min_state = None 1689 if item[5] !=None:1683 if item[5] is not None: 1690 1684 min_value = item[5].GetValue() 1691 1685 min_state = item[5].IsShown() … … 1693 1687 max_value = None 1694 1688 max_state = None 1695 if item[6] !=None:1689 if item[6] is not None: 1696 1690 max_value = item[6].GetValue() 1697 1691 max_state = item[6].IsShown() 1698 1692 unit = None 1699 if item[7] !=None:1693 if item[7] is not None: 1700 1694 unit = item[7].GetLabel() 1701 1695 … … 1705 1699 [max_state, max_value], unit]) 1706 1700 1707 1708 1701 def _draw_model(self, update_chisqr=True, source='model'): 1709 1702 """ … … 1724 1717 :param chisqr: update chisqr value [bool] 1725 1718 """ 1726 # if self.check_invalid_panel():1719 # if self.check_invalid_panel(): 1727 1720 # return 1728 if self.model !=None:1721 if self.model is not None: 1729 1722 temp_smear = None 1730 1723 if hasattr(self, "enable_smearer"): … … 1738 1731 is_2d = self._is_2D() 1739 1732 self._manager.draw_model(self.model, 1740 data=self.data,1741 smearer=temp_smear,1742 qmin=float(self.qmin_x),1743 qmax=float(self.qmax_x),1744 page_id=self.uid,1745 toggle_mode_on=toggle_mode_on,1746 state=self.state,1747 enable2D=is_2d,1748 update_chisqr=update_chisqr,1749 source='model',1750 weight=weight)1733 data=self.data, 1734 smearer=temp_smear, 1735 qmin=float(self.qmin_x), 1736 qmax=float(self.qmax_x), 1737 page_id=self.uid, 1738 toggle_mode_on=toggle_mode_on, 1739 state=self.state, 1740 enable2D=is_2d, 1741 update_chisqr=update_chisqr, 1742 source='model', 1743 weight=weight) 1751 1744 1752 1745 def _on_show_sld(self, event=None): … … 1758 1751 1759 1752 from sas.sasgui.plottools import Data1D as pf_data1d 1760 # from sas.sasgui.perspectives.theory.profile_dialog import SLDPanel1753 # from sas.sasgui.perspectives.theory.profile_dialog import SLDPanel 1761 1754 from sas.sasgui.guiframe.local_perspectives.plotting.profile_dialog \ 1762 import SLDPanel1755 import SLDPanel 1763 1756 sld_data = pf_data1d(x, y) 1764 1757 sld_data.name = 'SLD' … … 1813 1806 self.structurebox.Disable() 1814 1807 self.formfactorbox.Clear() 1815 if mod_cat ==None:1808 if mod_cat is None: 1816 1809 return 1817 1810 m_list = [] … … 1875 1868 """ 1876 1869 tcrtl = event.GetEventObject() 1877 # Clear msg if previously shown.1870 # Clear msg if previously shown. 1878 1871 msg = "" 1879 1872 wx.PostEvent(self.parent, StatusEvent(status=msg)) … … 1894 1887 tcrtl.SetBackgroundColour("pink") 1895 1888 msg = "Model Error: wrong value entered: %s" % \ 1896 1889 sys.exc_info()[1] 1897 1890 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1898 1891 return … … 1902 1895 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1903 1896 return 1904 # Check if # of points for theory model are valid(>0).1905 if self.npts !=None:1897 # Check if # of points for theory model are valid(>0). 1898 if self.npts is not None: 1906 1899 if check_float(self.npts): 1907 1900 temp_npts = float(self.npts.GetValue()) … … 1919 1912 wx.PostEvent(self.parent, event) 1920 1913 self.state_change = False 1921 # Draw the model for a different range1914 # Draw the model for a different range 1922 1915 if not self.data.is_data: 1923 1916 self.create_default_data() … … 1930 1923 1931 1924 tcrtl = event.GetEventObject() 1932 # Clear msg if previously shown.1925 # Clear msg if previously shown. 1933 1926 msg = "" 1934 1927 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 1951 1944 tcrtl.SetBackgroundColour("pink") 1952 1945 msg = "Model Error: wrong value entered: %s" % \ 1953 1946 sys.exc_info()[1] 1954 1947 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1955 1948 return … … 1959 1952 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1960 1953 return 1961 # Check if # of points for theory model are valid(>0).1954 # Check if # of points for theory model are valid(>0). 1962 1955 if self.Npts_total.IsEditable(): 1963 1956 if check_float(self.Npts_total): … … 1977 1970 wx.PostEvent(self.parent, event) 1978 1971 self.state_change = False 1979 # Draw the model for a different range1972 # Draw the model for a different range 1980 1973 self.create_default_data() 1981 1974 self._draw_model() … … 1985 1978 call back for model selection 1986 1979 """ 1987 # #reset dictionary containing reference to dispersion1980 # reset dictionary containing reference to dispersion 1988 1981 self._disp_obj_dict = {} 1989 1982 self.disp_cb_dict = {} 1990 1983 self.temp_multi_functional = False 1991 1984 f_id = self.formfactorbox.GetCurrentSelection() 1992 # For MAC1985 # For MAC 1993 1986 form_factor = None 1994 1987 if f_id >= 0: … … 1997 1990 if form_factor is None or \ 1998 1991 not hasattr(form_factor, 'is_form_factor') or \ 1999 not form_factor.is_form_factor:1992 not form_factor.is_form_factor: 2000 1993 self.structurebox.Hide() 2001 1994 self.text2.Hide() … … 2009 2002 self.text2.Enable() 2010 2003 2011 if form_factor !=None:2004 if form_factor is not None: 2012 2005 # set multifactor for Mutifunctional models 2013 2006 if form_factor.is_multiplicity_model: … … 2017 2010 self._set_multfactor_combobox(multiplicity) 2018 2011 self._show_multfactor_combobox() 2019 # ToDo:this info should be called directly from the model2012 # ToDo: this info should be called directly from the model 2020 2013 text = form_factor.multiplicity_info[1] # 'No. of Shells: ' 2021 2014 … … 2026 2019 2027 2020 self.multi_factor = self.multifactorbox.GetClientData(m_id) 2028 if self.multi_factor ==None:2021 if self.multi_factor is None: 2029 2022 self.multi_factor = 0 2030 2023 self.multifactorbox.SetSelection(m_id) … … 2032 2025 text = '' 2033 2026 if form_factor.multiplicity_info[0] == \ 2034 2027 len(form_factor.multiplicity_info[2]): 2035 2028 text = form_factor.multiplicity_info[2][self.multi_factor] 2036 2029 self.mutifactor_text1.SetLabel(text) … … 2053 2046 struct_factor = self.structurebox.GetClientData(s_id) 2054 2047 2055 if struct_factor !=None:2056 from sas .sascalc.fit.MultiplicationModel import MultiplicationModel2048 if struct_factor is not None: 2049 from sasmodels.sasview_model import MultiplicationModel 2057 2050 self.model = MultiplicationModel(form_factor(self.multi_factor), 2058 2051 struct_factor()) … … 2060 2053 if len(form_factor.non_fittable) > 0: 2061 2054 self.temp_multi_functional = True 2062 elif form_factor !=None:2055 elif form_factor is not None: 2063 2056 if self.multi_factor is not None: 2064 2057 self.model = form_factor(self.multi_factor) … … 2075 2068 else: 2076 2069 self._has_magnetic = False 2077 # #post state to fit panel2070 # post state to fit panel 2078 2071 self.state.parameters = [] 2079 2072 self.state.model = self.model … … 2085 2078 self.Layout() 2086 2079 2087 2088 2080 def _validate_qrange(self, qmin_ctrl, qmax_ctrl): 2089 2081 """ … … 2105 2097 qmax = float(qmax_ctrl.GetValue()) 2106 2098 if qmin < qmax: 2107 # Make sure to set both colours white.2099 # Make sure to set both colours white. 2108 2100 qmin_ctrl.SetBackgroundColour(wx.WHITE) 2109 2101 qmin_ctrl.Refresh() … … 2125 2117 If valid, setvalues Npts_fit otherwise post msg. 2126 2118 """ 2127 # default flag2119 # default flag 2128 2120 flag = True 2129 2121 # Theory 2130 if self.data ==None and self.enable2D:2122 if self.data is None and self.enable2D: 2131 2123 return flag 2132 2124 for data in self.data_list: … … 2134 2126 radius = numpy.sqrt(data.qx_data * data.qx_data + 2135 2127 data.qy_data * data.qy_data) 2136 # get unmasked index2128 # get unmasked index 2137 2129 index_data = (float(self.qmin.GetValue()) <= radius) & \ 2138 2130 (radius <= float(self.qmax.GetValue())) 2139 2131 index_data = (index_data) & (data.mask) 2140 2132 index_data = (index_data) & (numpy.isfinite(data.data)) … … 2152 2144 flag = False 2153 2145 else: 2154 self.Npts_fit.SetValue(str(len(index_data[index_data ==True])))2146 self.Npts_fit.SetValue(str(len(index_data[index_data is True]))) 2155 2147 self.fitrange = True 2156 2148 … … 2162 2154 If valid, setvalues Npts_fit otherwise post msg. 2163 2155 """ 2164 # default flag2156 # default flag 2165 2157 flag = True 2166 2158 # Theory 2167 if self.data ==None:2159 if self.data is None: 2168 2160 return flag 2169 2161 for data in self.data_list: 2170 2162 # q value from qx and qy 2171 2163 radius = data.x 2172 # get unmasked index2164 # get unmasked index 2173 2165 index_data = (float(self.qmin.GetValue()) <= radius) & \ 2174 2166 (radius <= float(self.qmax.GetValue())) 2175 2167 index_data = (index_data) & (numpy.isfinite(data.y)) 2176 2168 … … 2187 2179 flag = False 2188 2180 else: 2189 self.Npts_fit.SetValue(str(len(index_data[index_data ==True])))2181 self.Npts_fit.SetValue(str(len(index_data[index_data is True]))) 2190 2182 self.fitrange = True 2191 2183 … … 2207 2199 is_modified = False 2208 2200 for item in list: 2209 # skip angle parameters for 1D2201 # skip angle parameters for 1D 2210 2202 if not self.enable2D and item in self.orientation_params: 2211 2203 continue … … 2252 2244 max_ctrl.SetBackgroundColour("pink") 2253 2245 max_ctrl.Refresh() 2254 #msg = "Invalid fit range for %s: min must be smaller than max"%name 2255 #wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2246 # msg = "Invalid fit range for %s: min must be smaller 2247 # than max"%name 2248 # wx.PostEvent(self._manager.parent, 2249 # StatusEvent(status=msg)) 2256 2250 continue 2257 2251 … … 2271 2265 # The configuration has changed but it won't change the 2272 2266 # computed curve so no need to set is_modified to True 2273 # is_modified = True2267 # is_modified = True 2274 2268 self.model.details[name][1:3] = low, high 2275 2269 … … 2289 2283 Redraw the model with the default dispersity (Gaussian) 2290 2284 """ 2291 # #On selction if no model exists.2292 if self.model ==None:2285 # On selction if no model exists. 2286 if self.model is None: 2293 2287 self.disable_disp.SetValue(True) 2294 2288 msg = "Please select a Model first..." … … 2300 2294 self._reset_dispersity() 2301 2295 2302 if self.model ==None:2296 if self.model is None: 2303 2297 self.model_disp.Hide() 2304 2298 self.sizer4_4.Clear(True) … … 2306 2300 2307 2301 if self.enable_disp.GetValue(): 2308 # #layout for model containing no dispersity parameters2302 # layout for model containing no dispersity parameters 2309 2303 2310 2304 self.disp_list = self.model.getDispParamList() … … 2313 2307 self._layout_sizer_noDipers() 2314 2308 else: 2315 # #set gaussian sizer2309 # set gaussian sizer 2316 2310 self._on_select_Disp(event=None) 2317 2311 else: 2318 2312 self.sizer4_4.Clear(True) 2319 2313 2320 # #post state to fit panel2314 # post state to fit panel 2321 2315 self.save_current_state() 2322 if event !=None:2316 if event is not None: 2323 2317 event = PageInfoEvent(page=self) 2324 2318 wx.PostEvent(self.parent, event) 2325 # draw the model with the current dispersity2326 2327 # Wojtek P, Oct 8, 2016: Calling draw_model seems to be unessecary.2328 # By comenting it we save an extra Iq calculation2329 # self._draw_model()2330 2331 # #Need to use FitInside again here to replace the next four lines.2332 # #Otherwised polydispersity off does not resize the scrollwindow.2333 # #PDB Nov 28, 20152319 # draw the model with the current dispersity 2320 2321 # Wojtek P, Oct 8, 2016: Calling draw_model seems to be unessecary. 2322 # By comenting it we save an extra Iq calculation 2323 # self._draw_model() 2324 2325 # Need to use FitInside again here to replace the next four lines. 2326 # Otherwised polydispersity off does not resize the scrollwindow. 2327 # PDB Nov 28, 2015 2334 2328 self.FitInside() 2335 2329 # self.sizer4_4.Layout() … … 2375 2369 self.weights = {} 2376 2370 2377 # from sas.models.dispersion_models import GaussianDispersion2371 # from sas.models.dispersion_models import GaussianDispersion 2378 2372 from sasmodels.weights import GaussianDispersion 2379 2373 if len(self.disp_cb_dict) == 0: … … 2396 2390 logging.error(traceback.format_exc()) 2397 2391 2398 # #save state into2392 # save state into 2399 2393 self.save_current_state() 2400 2394 self.Layout() … … 2408 2402 self._set_sizer_dispersion() 2409 2403 2410 # #Redraw the model2404 # Redraw the model 2411 2405 self._draw_model() 2412 # self._undo.Enable(True)2406 # self._undo.Enable(True) 2413 2407 event = PageInfoEvent(page=self) 2414 2408 wx.PostEvent(self.parent, event) … … 2425 2419 """ 2426 2420 # get ready for new event 2427 if event !=None:2421 if event is not None: 2428 2422 event.Skip() 2429 2423 # Get event object … … 2438 2432 dispersity = disp_box.GetClientData(selection) 2439 2433 2440 # disp_model = GaussianDispersion()2434 # disp_model = GaussianDispersion() 2441 2435 disp_model = dispersity() 2442 2436 # Get param names to reset the values of the param … … 2451 2445 else: 2452 2446 self._del_array_values(name1) 2453 # self._reset_array_disp(param_name)2447 # self._reset_array_disp(param_name) 2454 2448 self._disp_obj_dict[name1] = disp_model 2455 2449 self.model.set_dispersion(param_name, disp_model) … … 2537 2531 if path is None: 2538 2532 self.disp_cb_dict[name].SetValue(False) 2539 # self.noDisper_rbox.SetValue(True)2533 # self.noDisper_rbox.SetValue(True) 2540 2534 return 2541 2535 self._default_save_location = os.path.dirname(path) 2542 if self._manager !=None:2536 if self._manager is not None: 2543 2537 self._manager.parent._default_save_location = \ 2544 2538 self._default_save_location … … 2557 2551 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2558 2552 self._set_array_disp_model(name=name, disp=disp, 2559 2553 values=values, weights=weights) 2560 2554 return basename 2561 2555 … … 2576 2570 # Store the object to make it persist outside the 2577 2571 # scope of this method 2578 # TODO: refactor model to clean this up?2572 # TODO: refactor model to clean this up? 2579 2573 self.state.values = {} 2580 2574 self.state.weights = {} … … 2583 2577 2584 2578 # Set the new model as the dispersion object for the 2585 # selected parameter2586 # self.model.set_dispersion(p, disp_model)2579 # selected parameter 2580 # self.model.set_dispersion(p, disp_model) 2587 2581 # Store a reference to the weights in the model object 2588 # so that2582 # so that 2589 2583 # it's not lost when we use the model within another thread. 2590 2584 self.state.model = self.model.clone() 2591 2585 self.model._persistency_dict[name.split('.')[0]] = \ 2592 2586 [values, weights] 2593 2587 self.state.model._persistency_dict[name.split('.')[0]] = \ 2594 2588 [values, weights] 2595 2589 2596 2590 def _del_array_values(self, name=None): … … 2630 2624 Layout after self._draw_model 2631 2625 """ 2632 if ON_MAC ==True:2626 if ON_MAC is True: 2633 2627 time.sleep(1) 2634 2628 … … 2652 2646 """ 2653 2647 flag = True 2654 # #For 3 different cases: Data2D, Data1D, and theory2655 if self.model ==None:2648 # For 3 different cases: Data2D, Data1D, and theory 2649 if self.model is None: 2656 2650 msg = "Please select a model first..." 2657 2651 wx.MessageBox(msg, 'Info') … … 2665 2659 self.qmin_x = data_min 2666 2660 self.qmax_x = math.sqrt(x * x + y * y) 2667 # self.data.mask = numpy.ones(len(self.data.data),dtype=bool)2661 # self.data.mask = numpy.ones(len(self.data.data),dtype=bool) 2668 2662 # check smearing 2669 2663 if not self.disable_smearer.GetValue(): 2670 # #set smearing value whether or2664 # set smearing value whether or 2671 2665 # not the data contain the smearing info 2672 2666 if self.pinhole_smearer.GetValue(): … … 2675 2669 flag = True 2676 2670 2677 elif self.data ==None:2671 elif self.data is None: 2678 2672 self.qmin_x = _QMIN_DEFAULT 2679 2673 self.qmax_x = _QMAX_DEFAULT … … 2686 2680 # check smearing 2687 2681 if not self.disable_smearer.GetValue(): 2688 # #set smearing value whether or2682 # set smearing value whether or 2689 2683 # not the data contain the smearing info 2690 2684 if self.slit_smearer.GetValue(): … … 2697 2691 flag = False 2698 2692 2699 if flag ==False:2693 if flag is False: 2700 2694 msg = "Cannot Plot :Must enter a number!!! " 2701 2695 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) … … 2714 2708 self.state.qmax = self.qmax_x 2715 2709 2716 # reset the q range values2710 # reset the q range values 2717 2711 self._reset_plotting_range(self.state) 2718 2712 self._draw_model() … … 2755 2749 logging.error(traceback.format_exc()) 2756 2750 # Make sure the resduals plot goes to the last 2757 if res_item !=None:2751 if res_item is not None: 2758 2752 graphs.append(res_item[0]) 2759 2753 canvases.append(res_item[1]) … … 2774 2768 the # to the browser. 2775 2769 2776 :param ev t: on Help Button pressed event2777 """ 2778 2779 if self.model !=None:2770 :param event: on Help Button pressed event 2771 """ 2772 2773 if self.model is not None: 2780 2774 name = self.formfactorbox.GetValue() 2781 _TreeLocation = 'user/models/' + name.lower()+'.html'2775 _TreeLocation = 'user/models/' + name.lower()+'.html' 2782 2776 _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, 2783 2777 "", name + " Help") … … 2786 2780 _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, 2787 2781 "", "General Model Help") 2788 2789 2782 2790 2783 def on_model_help_clicked(self, event): … … 2798 2791 give the message that none is available. 2799 2792 2800 :param ev t: on Description Button pressed event2801 """ 2802 2803 if self.model ==None:2793 :param event: on Description Button pressed event 2794 """ 2795 2796 if self.model is None: 2804 2797 name = 'index.html' 2805 2798 else: … … 2808 2801 msg = 'Model description:\n' 2809 2802 info = "Info" 2810 if self.model !=None:2811 #frame.Destroy()2803 if self.model is not None: 2804 # frame.Destroy() 2812 2805 if str(self.model.description).rstrip().lstrip() == '': 2813 2806 msg += "Sorry, no information is available for this model." … … 2878 2871 for key in self.model.magnetic_params: 2879 2872 if key.count('M0') > 0: 2880 # reset mag value to zero fo safety2873 # reset mag value to zero fo safety 2881 2874 self.model.setParam(key, 0.0) 2882 2875 2883 2876 self.Show(False) 2884 2877 self.set_model_param_sizer(self.model) 2885 # self._set_sizer_dispersion()2878 # self._set_sizer_dispersion() 2886 2879 self.state.magnetic_on = self.magnetic_on 2887 2880 self.SetupScrolling() … … 2898 2891 running "file:///...." 2899 2892 2900 :param ev t: Triggers on clicking ? in polydispersity box2893 :param event: Triggers on clicking ? in polydispersity box 2901 2894 """ 2902 2895 … … 2936 2929 content = 'sasview_parameter_values:' 2937 2930 # Do it if params exist 2938 if self.parameters != []:2931 if self.parameters: 2939 2932 2940 2933 # go through the parameters … … 2980 2973 2981 2974 # Do it if params exist 2982 if self.parameters != []:2975 if self.parameters: 2983 2976 2984 2977 for param in self.parameters: 2985 content += param[1] #parameter name2978 content += param[1] # parameter name 2986 2979 content += tab 2987 2980 content += param[1] + "_err" … … 2990 2983 content += crlf 2991 2984 2992 # row of values and errors...2985 # row of values and errors... 2993 2986 for param in self.parameters: 2994 content += param[2].GetValue() #value2987 content += param[2].GetValue() # value 2995 2988 content += tab 2996 content += param[4].GetValue() #error2989 content += param[4].GetValue() # error 2997 2990 content += tab 2998 2991 … … 3000 2993 else: 3001 2994 return False 3002 3003 2995 3004 2996 def get_copy_latex(self): … … 3022 3014 3023 3015 # Do it if params exist 3024 if self.parameters != []:3016 if self.parameters: 3025 3017 3026 3018 content += '{|' … … 3031 3023 3032 3024 for index, param in enumerate(self.parameters): 3033 content += param[1].replace('_', '\_') #parameter name3025 content += param[1].replace('_', '\_') # parameter name 3034 3026 content += ' & ' 3035 3027 content += param[1].replace('_', '\_') + "\_err" … … 3039 3031 content += crlf 3040 3032 3041 # row of values and errors...3033 # row of values and errors... 3042 3034 for index, param in enumerate(self.parameters): 3043 content += param[2].GetValue() #parameter value3035 content += param[2].GetValue() # parameter value 3044 3036 content += ' & ' 3045 content += param[4].GetValue() #parameter error3037 content += param[4].GetValue() # parameter error 3046 3038 if index < len(self.parameters) - 1: 3047 3039 content += ' & ' … … 3054 3046 else: 3055 3047 return False 3056 3057 3048 3058 3049 def set_clipboard(self, content=None): … … 3101 3092 # 1D 3102 3093 else: 3103 # #for 1D all parameters except orientation3094 # for 1D all parameters except orientation 3104 3095 if not item[1] in orient_param: 3105 3096 try: … … 3133 3124 except Exception: 3134 3125 logging.error(traceback.format_exc()) 3135 content += name + ',' + str(check) + ',' +\ 3136 value + disfunc + ',' + bound_lo + ',' +\ 3137 bound_hi + ':' 3126 content += name + ',' + str(check) + ',' + value + disfunc + ',' + \ 3127 bound_lo + ',' + bound_hi + ':' 3138 3128 3139 3129 return content … … 3213 3203 3214 3204 # Do it if params exist 3215 if self.parameters != []:3205 if self.parameters: 3216 3206 # go through the parameters 3217 3207 self._get_paste_helper(self.parameters, … … 3261 3251 pd = int(pd) 3262 3252 except Exception: 3263 # continue3253 # continue 3264 3254 if not pd and pd != '': 3265 3255 continue … … 3289 3279 else: 3290 3280 is_true = None 3291 if is_true !=None:3281 if is_true is not None: 3292 3282 item[0].SetValue(is_true) 3293 3283 # 1D 3294 3284 else: 3295 # #for 1D all parameters except orientation3285 # for 1D all parameters except orientation 3296 3286 if not item[1] in orient_param: 3297 3287 name = item[1] … … 3302 3292 pd = value[0] 3303 3293 if name.count('.') > 0: 3304 # If this is parameter.width, then pd may be a floating 3305 # point value or it may be an array distribution. 3306 # Nothing to do for parameter.npts or parameter.nsigmas. 3294 # If this is parameter.width, then pd may be a 3295 # floating point value or it may be an array 3296 # distribution. Nothing to do for parameter.npts or 3297 # parameter.nsigmas. 3307 3298 try: 3308 3299 pd = float(pd) … … 3310 3301 pd = int(pd) 3311 3302 except: 3312 # continue3303 # continue 3313 3304 if not pd and pd != '': 3314 3305 continue … … 3338 3329 else: 3339 3330 is_true = None 3340 if is_true !=None:3331 if is_true is not None: 3341 3332 item[0].SetValue(is_true) 3333 3334 self.select_param(event=None) 3335 self.Refresh() 3342 3336 3343 3337 def _paste_poly_help(self, item, value): … … 3402 3396 logging.error(traceback.format_exc()) 3403 3397 print "Error in BasePage._paste_poly_help: %s" % \ 3404 3398 sys.exc_info()[1] 3405 3399 3406 3400 def _set_disp_cb(self, isarray, item): … … 3468 3462 self.categorybox.Clear() 3469 3463 cat_list = sorted(self.master_category_dict.keys()) 3470 if not uncat_strin cat_list:3464 if uncat_str not in cat_list: 3471 3465 cat_list.append(uncat_str) 3472 3466 … … 3478 3472 self.categorybox.SetSelection(0) 3479 3473 else: 3480 self.categorybox.SetSelection( \3474 self.categorybox.SetSelection( 3481 3475 self.categorybox.GetSelection()) 3482 # self._on_change_cat(None)3476 # self._on_change_cat(None) 3483 3477 3484 3478 def _on_change_cat(self, event): … … 3488 3482 self.model_name = None 3489 3483 category = self.categorybox.GetStringSelection() 3490 if category ==None:3484 if category is None: 3491 3485 return 3492 3486 self.model_box.Clear() … … 3499 3493 else: 3500 3494 for (model, enabled) in sorted(self.master_category_dict[category], 3501 key=lambda name: name[0]):3495 key=lambda name: name[0]): 3502 3496 if(enabled): 3503 3497 self.model_box.Append(model) … … 3508 3502 """ 3509 3503 # This should only be called once per fit tab 3510 # print "==== Entering _fill_model_sizer"3511 # #Add model function Details button in fitpanel.3512 # #The following 3 lines are for Mac. Let JHC know before modifying...3504 # print "==== Entering _fill_model_sizer" 3505 # Add model function Details button in fitpanel. 3506 # The following 3 lines are for Mac. Let JHC know before modifying... 3513 3507 title = "Model" 3514 3508 self.formfactorbox = None … … 3542 3536 self._populate_listbox() 3543 3537 wx.EVT_COMBOBOX(self.categorybox, wx.ID_ANY, self._show_combox) 3544 # self.shape_rbutton = wx.RadioButton(self, wx.ID_ANY, 'Shapes',3538 # self.shape_rbutton = wx.RadioButton(self, wx.ID_ANY, 'Shapes', 3545 3539 # style=wx.RB_GROUP) 3546 # self.shape_indep_rbutton = wx.RadioButton(self, wx.ID_ANY,3540 # self.shape_indep_rbutton = wx.RadioButton(self, wx.ID_ANY, 3547 3541 # "Shape-Independent") 3548 # self.struct_rbutton = wx.RadioButton(self, wx.ID_ANY,3542 # self.struct_rbutton = wx.RadioButton(self, wx.ID_ANY, 3549 3543 # "Structure Factor ") 3550 # self.plugin_rbutton = wx.RadioButton(self, wx.ID_ANY,3544 # self.plugin_rbutton = wx.RadioButton(self, wx.ID_ANY, 3551 3545 # "Uncategorized") 3552 3546 3553 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox,3547 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 3554 3548 # id=self.shape_rbutton.GetId()) 3555 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox,3549 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 3556 3550 # id=self.shape_indep_rbutton.GetId()) 3557 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox,3551 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 3558 3552 # id=self.struct_rbutton.GetId()) 3559 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox,3553 # self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, 3560 3554 # id=self.plugin_rbutton.GetId()) 3561 # MAC needs SetValue3555 # MAC needs SetValue 3562 3556 3563 3557 show_cat_button = wx.Button(self, wx.ID_ANY, "Modify") 3564 3558 cat_tip = "Modify model categories \n" 3565 3559 cat_tip += "(also accessible from the menu bar)." 3566 show_cat_button.SetToolTip( wx.ToolTip(cat_tip))3560 show_cat_button.SetToolTip(wx.ToolTip(cat_tip)) 3567 3561 show_cat_button.Bind(wx.EVT_BUTTON, self._on_modify_cat) 3568 3562 sizer_cat_box.Add(self.categorybox, 1, wx.RIGHT, 3) 3569 sizer_cat_box.Add((10, 10))3563 sizer_cat_box.Add((10, 10)) 3570 3564 sizer_cat_box.Add(show_cat_button) 3571 # self.shape_rbutton.SetValue(True)3565 # self.shape_rbutton.SetValue(True) 3572 3566 3573 3567 sizer_radiobutton = wx.GridSizer(2, 2, 5, 5) 3574 # sizer_radiobutton.Add(self.shape_rbutton)3575 # sizer_radiobutton.Add(self.shape_indep_rbutton)3576 sizer_radiobutton.Add((5, 5))3568 # sizer_radiobutton.Add(self.shape_rbutton) 3569 # sizer_radiobutton.Add(self.shape_indep_rbutton) 3570 sizer_radiobutton.Add((5, 5)) 3577 3571 sizer_radiobutton.Add(self.model_view, 1, wx.RIGHT, 5) 3578 # sizer_radiobutton.Add(self.plugin_rbutton)3579 # sizer_radiobutton.Add(self.struct_rbutton)3580 #sizer_radiobutton.Add((5,5))3572 # sizer_radiobutton.Add(self.plugin_rbutton) 3573 # sizer_radiobutton.Add(self.struct_rbutton) 3574 # sizer_radiobutton.Add((5,5)) 3581 3575 sizer_radiobutton.Add(self.model_help, 1, wx.RIGHT | wx.LEFT, 5) 3582 #sizer_radiobutton.Add((5,5))3576 # sizer_radiobutton.Add((5,5)) 3583 3577 sizer_radiobutton.Add(self.model_func, 1, wx.RIGHT, 5) 3584 3578 sizer_cat.Add(sizer_cat_box, 1, wx.LEFT, 2.5) … … 3596 3590 self.formfactorbox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) 3597 3591 self.formfactorbox.SetToolTip(wx.ToolTip("Select a Model")) 3598 if self.model !=None:3592 if self.model is not None: 3599 3593 self.formfactorbox.SetValue(self.model.name) 3600 3594 self.structurebox = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) … … 3605 3599 wx.EVT_COMBOBOX(self.structurebox, wx.ID_ANY, self._on_select_model) 3606 3600 wx.EVT_COMBOBOX(self.multifactorbox, wx.ID_ANY, self._on_select_model) 3607 # #check model type to show sizer3608 if self.model !=None:3601 # check model type to show sizer 3602 if self.model is not None: 3609 3603 print "_set_model_sizer_selection: disabled." 3610 # self._set_model_sizer_selection(self.model)3604 # self._set_model_sizer_selection(self.model) 3611 3605 3612 3606 sizer_selection.Add(self.text1) … … 3707 3701 """ 3708 3702 3703 3709 3704 class ModelTextCtrl(wx.TextCtrl): 3710 3705 """ … … 3719 3714 3720 3715 """ 3721 # #Set to True when the mouse is clicked while whole string is selected3716 # Set to True when the mouse is clicked while whole string is selected 3722 3717 full_selection = False 3723 # #Call back for EVT_SET_FOCUS events3718 # Call back for EVT_SET_FOCUS events 3724 3719 _on_set_focus_callback = None 3725 3720 … … 3743 3738 if set_focus_callback is None else set_focus_callback 3744 3739 self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus) 3745 self.Bind(wx.EVT_KILL_FOCUS, self._silent_kill_focus \3746 3747 self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter \3748 3740 self.Bind(wx.EVT_KILL_FOCUS, self._silent_kill_focus 3741 if kill_focus_callback is None else kill_focus_callback) 3742 self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter 3743 if text_enter_callback is None else text_enter_callback) 3749 3744 if not ON_MAC: 3750 self.Bind(wx.EVT_LEFT_UP, self._highlight_text \3751 3745 self.Bind(wx.EVT_LEFT_UP, self._highlight_text 3746 if mouse_up_callback is None else mouse_up_callback) 3752 3747 3753 3748 def _on_set_focus(self, event): … … 3789 3784 3790 3785 event.Skip() 3791 # pass3786 # pass
Note: See TracChangeset
for help on using the changeset viewer.