Changeset 308fa87 in sasview for fittingview/src/sans/perspectives
- Timestamp:
- Apr 27, 2012 5:04:53 PM (13 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- ac2b835
- Parents:
- f992a06
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fittingview/src/sans/perspectives/fitting/fitpage.py
rf32d144 r308fa87 846 846 ix = 0 847 847 iy += 1 848 self.sizer4_4.Add((20, 20),(iy,ix),(1,1),849 wx.LEFT |wx.EXPAND|wx.ADJUST_MINSIZE, 15)850 first_orient 848 self.sizer4_4.Add((20, 20), (iy, ix), (1, 1), 849 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 850 first_orient = True 851 851 for item in self.model.dispersion.keys(): 852 852 if item in self.model.orientation_params: 853 if not self.disp_cb_dict.has_key(item):854 self.disp_cb_dict[item] = None855 name0 ="Distribution of " + item856 name1 =item+".width"857 name2 =item+".npts"858 name3 =item+".nsigmas"853 if not item in self.disp_cb_dict: 854 self.disp_cb_dict[item] = None 855 name0 = "Distribution of " + item 856 name1 = item + ".width" 857 name2 = item + ".npts" 858 name3 = item + ".nsigmas" 859 859 860 if not self.model.details.has_key(name1):861 self.model.details [name1] = ["",None,None]860 if not name1 in self.model.details: 861 self.model.details[name1] = ["", None, None] 862 862 863 864 863 iy += 1 865 for p in self.model.dispersion[item].keys(): 866 867 if p =="width":864 for p in self.model.dispersion[item].keys(): 865 866 if p == "width": 868 867 ix = 0 869 868 cb = wx.CheckBox(self, -1, name0, (10, 10)) … … 871 870 cb.SetToolTipString("Check mark to fit") 872 871 wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) 873 self.sizer4_4.Add( cb,( iy, ix),(1,1), 874 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 875 5) 876 if self.data.__class__.__name__ == "Data2D" or \ 872 self.sizer4_4.Add(cb, (iy, ix), (1, 1), 873 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 874 if self.data.__class__.__name__ == "Data2D" or \ 877 875 self.enable2D: 878 876 cb.Show(True) … … 880 878 cb.Hide() 881 879 ix = 1 882 value= self.model.getParam(name1) 883 ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.3, 884 20),style=wx.TE_PROCESS_ENTER) 880 value = self.model.getParam(name1) 881 ctl1 = self.ModelTextCtrl(self, -1, 882 size=(_BOX_WIDTH / 1.3, 20), 883 style=wx.TE_PROCESS_ENTER) 885 884 poly_tip = "Absolute Sigma for %s." % item 886 885 ctl1.SetToolTipString(poly_tip) 887 ctl1.SetValue(str 886 ctl1.SetValue(str(format_number(value, True))) 888 887 if self.data.__class__.__name__ == "Data2D" or \ 889 888 self.enable2D: … … 891 890 values.SetLabel('PD[ratio], Sig[deg]') 892 891 poly_text = "PD(polydispersity for lengths):\n" 893 poly_text += 894 poly_text += 892 poly_text += "It should be a value between" 893 poly_text += "0 and 1\n" 895 894 poly_text += "Sigma for angles: \n" 896 895 poly_text += "It is the STD (ratio*mean)" … … 903 902 ctl1.Hide() 904 903 905 self.sizer4_4.Add(ctl1, (iy, ix),(1,1),wx.EXPAND)904 self.sizer4_4.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) 906 905 ## text to show error sign 907 906 ix = 2 908 text2 =wx.StaticText(self, -1, '+/-')909 self.sizer4_4.Add(text2, (iy, ix),(1,1),910 wx.EXPAND |wx.ADJUST_MINSIZE, 0)911 912 text2.Hide() 907 text2 = wx.StaticText(self, -1, '+/-') 908 self.sizer4_4.Add(text2, (iy, ix), (1, 1), 909 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 910 911 text2.Hide() 913 912 914 913 ix = 3 915 ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/1.3,20), 914 ctl2 = wx.TextCtrl(self, -1, 915 size=(_BOX_WIDTH / 1.3, 20), 916 916 style=0) 917 917 918 self.sizer4_4.Add(ctl2, (iy, ix),(1,1),919 wx.EXPAND |wx.ADJUST_MINSIZE, 0)918 self.sizer4_4.Add(ctl2, (iy, ix), (1, 1), 919 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 920 920 921 921 ctl2.Hide() 922 if self.data.__class__.__name__ == 922 if self.data.__class__.__name__ == "Data2D" or \ 923 923 self.enable2D: 924 if self.is_mac: 924 if self.is_mac: 925 925 text2.Show(True) 926 ctl2.Show(True) 926 ctl2.Show(True) 927 927 928 928 ix = 4 929 ctl3 = self.ModelTextCtrl(self, -1, 930 size=(_BOX_WIDTH /2,20),929 ctl3 = self.ModelTextCtrl(self, -1, 930 size=(_BOX_WIDTH / 2, 20), 931 931 style=wx.TE_PROCESS_ENTER, 932 text_enter_callback =self._onparamRangeEnter)933 934 self.sizer4_4.Add(ctl3, (iy, ix),(1,1),935 wx.EXPAND |wx.ADJUST_MINSIZE, 0)932 text_enter_callback=self._onparamRangeEnter) 933 934 self.sizer4_4.Add(ctl3, (iy, ix), (1, 1), 935 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 936 936 937 937 ctl3.Hide() 938 938 939 939 ix = 5 940 ctl4 = self.ModelTextCtrl(self, -1, 941 size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, 942 text_enter_callback = self._onparamRangeEnter) 943 self.sizer4_4.Add(ctl4, (iy,ix),(1,1), 944 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 940 ctl4 = self.ModelTextCtrl(self, -1, 941 size=(_BOX_WIDTH / 2, 20), 942 style=wx.TE_PROCESS_ENTER, 943 text_enter_callback=self._onparamRangeEnter) 944 self.sizer4_4.Add(ctl4, (iy, ix), (1, 1), 945 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 945 946 ctl4.Hide() 946 947 947 if self.data.__class__.__name__ == 948 if self.data.__class__.__name__ == "Data2D" or \ 948 949 self.enable2D: 949 950 ctl3.Show(True) 950 ctl4.Show(True) 951 ctl4.Show(True) 951 952 952 elif p=="npts": 953 ix = 6 954 value= self.model.getParam(name2) 955 Tctl = self.ModelTextCtrl(self, -1, 956 size=(_BOX_WIDTH/2.2, 20), 957 style=wx.TE_PROCESS_ENTER) 958 959 Tctl.SetValue(str (format_number(value))) 960 if self.data.__class__.__name__ == "Data2D" or \ 961 self.enable2D: 962 Tctl.Show(True) 963 else: 964 Tctl.Hide() 965 self.sizer4_4.Add(Tctl, (iy,ix),(1,1), 966 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 967 self.fixed_param.append([None,name2, Tctl,None,None, 968 None, None,None]) 969 self.orientation_params_disp.append([None,name2, 970 Tctl,None,None, 971 None, None,None]) 972 elif p=="nsigmas": 973 ix = 7 974 value= self.model.getParam(name3) 975 Tct2 = self.ModelTextCtrl(self, -1, 976 size=(_BOX_WIDTH/2.2,20), 977 style=wx.TE_PROCESS_ENTER) 978 979 Tct2.SetValue(str (format_number(value))) 980 if self.data.__class__.__name__ == "Data2D" or \ 981 self.enable2D: 982 Tct2.Show(True) 983 else: 984 Tct2.Hide() 985 self.sizer4_4.Add(Tct2, (iy,ix),(1,1), 986 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 987 988 989 self.fixed_param.append([None,name3, Tct2 990 ,None,None, None, None,None]) 991 992 self.orientation_params_disp.append([None,name3, 993 Tct2 ,None,None, None, None,None]) 994 995 996 ix = 8 997 disp_box = wx.ComboBox(self, -1,size=(65,-1), 998 style=wx.CB_READONLY, name = '%s'% name1) 953 elif p == "npts": 954 ix = 6 955 value = self.model.getParam(name2) 956 Tctl = self.ModelTextCtrl(self, -1, 957 size=(_BOX_WIDTH / 2.2, 20), 958 style=wx.TE_PROCESS_ENTER) 959 960 Tctl.SetValue(str(format_number(value))) 961 if self.data.__class__.__name__ == "Data2D" or \ 962 self.enable2D: 963 Tctl.Show(True) 964 else: 965 Tctl.Hide() 966 self.sizer4_4.Add(Tctl, (iy, ix), (1, 1), 967 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 968 self.fixed_param.append([None, name2, Tctl, None, None, 969 None, None, None]) 970 self.orientation_params_disp.append([None, name2, 971 Tctl, None, None, 972 None, None, None]) 973 elif p == "nsigmas": 974 ix = 7 975 value = self.model.getParam(name3) 976 Tct2 = self.ModelTextCtrl(self, -1, 977 size=(_BOX_WIDTH / 2.2, 20), 978 style=wx.TE_PROCESS_ENTER) 979 980 Tct2.SetValue(str(format_number(value))) 981 if self.data.__class__.__name__ == "Data2D" or \ 982 self.enable2D: 983 Tct2.Show(True) 984 else: 985 Tct2.Hide() 986 self.sizer4_4.Add(Tct2, (iy, ix), (1, 1), 987 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 988 989 self.fixed_param.append([None, name3, Tct2, 990 None, None, None, None, None]) 991 992 self.orientation_params_disp.append([None, name3, 993 Tct2, None, None, None, None, None]) 994 995 ix = 8 996 disp_box = wx.ComboBox(self, -1, size=(65, -1), 997 style=wx.CB_READONLY, name='%s' % name1) 999 998 for key, value in self.polydisp.iteritems(): 1000 999 name_disp = str(key) 1001 disp_box.Append(name_disp, value)1002 disp_box.SetStringSelection("gaussian") 1003 wx.EVT_COMBOBOX(disp_box, -1, self._on_disp_func)1004 self.sizer4_4.Add(disp_box, (iy,ix),(1,1), wx.EXPAND)1005 self.fittable_param.append([cb, name1,ctl1,text2,1000 disp_box.Append(name_disp, value) 1001 disp_box.SetStringSelection("gaussian") 1002 wx.EVT_COMBOBOX(disp_box, -1, self._on_disp_func) 1003 self.sizer4_4.Add(disp_box, (iy, ix), (1, 1), wx.EXPAND) 1004 self.fittable_param.append([cb, name1, ctl1, text2, 1006 1005 ctl2, ctl3, ctl4, disp_box]) 1007 self.orientation_params_disp.append([cb, name1,ctl1,1006 self.orientation_params_disp.append([cb, name1, ctl1, 1008 1007 text2, ctl2, ctl3, ctl4, disp_box]) 1009 1008 … … 1014 1013 disp_box.Hide() 1015 1014 1016 1017 self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) 1015 self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) 1018 1016 1019 self.state.model = self.model.clone() 1020 1017 self.state.model = self.model.clone() 1018 ## save state into 1021 1019 self.state.cb1 = self.cb1.GetValue() 1022 1020 self._copy_parameters_state(self.parameters, self.state.parameters) 1023 1021 self._copy_parameters_state(self.orientation_params_disp, 1024 1022 self.state.orientation_params_disp) 1025 self._copy_parameters_state(self.fittable_param, 1023 self._copy_parameters_state(self.fittable_param, 1026 1024 self.state.fittable_param) 1027 1025 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 1028 1026 1029 1030 wx.PostEvent(self.parent, StatusEvent(status=\ 1031 " Selected Distribution: Gaussian")) 1027 wx.PostEvent(self.parent, 1028 StatusEvent(status=" Selected Distribution: Gaussian")) 1032 1029 #Fill the list of fittable parameters 1033 1030 #self.select_all_param(event=None) … … 1035 1032 self.Layout() 1036 1033 1037 1038 1034 def _onDraw(self, event): 1039 1035 """ 1040 1036 Update and Draw the model 1041 """ 1042 if self.model == None:1043 msg ="Please select a Model first..."1037 """ 1038 if self.model == None: 1039 msg = "Please select a Model first..." 1044 1040 wx.MessageBox(msg, 'Info') 1045 1046 1041 return 1047 1042 """ … … 1049 1044 self.npts_x = self.Npts_total.GetValue() 1050 1045 self.Npts_fit.SetValue(self.npts_x) 1051 self.create_default_data() 1052 """ 1053 flag = self._update_paramv_on_fit() 1046 self.create_default_data() 1047 """ 1048 flag = self._update_paramv_on_fit() 1054 1049 1055 1050 wx.CallAfter(self._onparamEnter_helper) 1056 1051 if not flag: 1057 msg= "The parameters are invalid" 1058 wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) 1059 return 1060 1061 1062 def _onFit(self, event): 1052 msg = "The parameters are invalid" 1053 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 1054 return 1055 1056 def _onFit(self, event): 1063 1057 """ 1064 1058 Allow to fit 1065 1059 """ 1066 1060 if event != None: 1067 event.Skip() 1061 event.Skip() 1068 1062 if self.fit_started: 1069 1063 self._StopFit() 1070 1064 self.fit_started = False 1071 1065 wx.CallAfter(self.set_fitbutton) 1072 return 1073 1074 if len(self.parent._manager.fit_thread_list) >0 and\1066 return 1067 1068 if len(self.parent._manager.fit_thread_list) > 0 and\ 1075 1069 self.parent._manager._fit_engine != "park" and\ 1076 1070 self._manager.sim_page != None and \ 1077 self._manager.sim_page.uid == self.uid: 1071 self._manager.sim_page.uid == self.uid: 1078 1072 msg = "The FitEnging will be set to 'ParkMC'\n" 1079 1073 msg += " to fit with more than one data set..." 1080 1074 wx.MessageBox(msg, 'Info') 1081 #wx.PostEvent(self._manager.parent, StatusEvent(status=\1082 # "Fitting: %s"%msg))1083 1075 1084 1076 if self.data is None: 1085 1077 msg = "Please get Data first..." 1086 1078 wx.MessageBox(msg, 'Info') 1087 wx.PostEvent(self._manager.parent, StatusEvent(status=\1088 1079 wx.PostEvent(self._manager.parent, 1080 StatusEvent(status="Fit: %s" % msg)) 1089 1081 return 1090 1082 if self.model is None: 1091 1083 msg = "Please select a Model first..." 1092 1084 wx.MessageBox(msg, 'Info') 1093 wx.PostEvent(self._manager.parent, StatusEvent(status=\1094 "Fit: %s"%msg, type="stop"))1085 wx.PostEvent(self._manager.parent, 1086 StatusEvent(status="Fit: %s" % msg, type="stop")) 1095 1087 return 1096 1088 1097 1089 if len(self.param_toFit) <= 0: 1098 msg = "Select at least one parameter to fit"1090 msg = "Select at least one parameter to fit" 1099 1091 wx.MessageBox(msg, 'Info') 1100 wx.PostEvent(self._manager.parent, StatusEvent(status= msg,1101 type="stop"))1102 return 1103 1104 flag = self._update_paramv_on_fit() 1092 wx.PostEvent(self._manager.parent, 1093 StatusEvent(status=msg, type="stop")) 1094 return 1095 1096 flag = self._update_paramv_on_fit() 1105 1097 1106 1098 if self.batch_on and not self._is_2D(): … … 1109 1101 1110 1102 if not flag: 1111 msg = "Fitting range or parameters are invalid"1112 wx.PostEvent(self.parent.parent, StatusEvent(status= msg,1113 1114 return 1103 msg = "Fitting range or parameters are invalid" 1104 wx.PostEvent(self.parent.parent, 1105 StatusEvent(status=msg, type="stop")) 1106 return 1115 1107 1116 self.select_param(event =None) 1117 1118 #Clear errors if exist from previous fitting 1119 #self._clear_Err_on_Fit() 1120 1121 # Remove or do not allow fitting on the Q=0 point, especially 1122 # when y(q=0)=None at x[0]. 1108 self.select_param(event=None) 1109 1110 # Remove or do not allow fitting on the Q=0 point, especially 1111 # when y(q=0)=None at x[0]. 1123 1112 self.qmin_x = float(self.qmin.GetValue()) 1124 1113 self.qmax_x = float(self.qmax.GetValue()) 1125 1114 self._manager._reset_schedule_problem(value=0, uid=self.uid) 1126 self._manager.schedule_for_fit(uid=self.uid, value=1)1127 self._manager.set_fit_range(uid=self.uid, qmin=self.qmin_x,1128 qmax=self.qmax_x)1129 1130 #single fit 1115 self._manager.schedule_for_fit(uid=self.uid, value=1) 1116 self._manager.set_fit_range(uid=self.uid, qmin=self.qmin_x, 1117 qmax=self.qmax_x) 1118 1119 #single fit 1131 1120 #self._manager.onFit(uid=self.uid) 1132 1121 self.fit_started = self._manager.onFit(uid=self.uid) 1133 1122 wx.CallAfter(self.set_fitbutton) 1134 1123 1135 def set_fitbutton(self): 1124 def set_fitbutton(self): 1136 1125 """ 1137 1126 Set fit button label depending on the fit_started[bool] … … 1160 1149 if item.GetValue(): 1161 1150 if button_list.index(item) == 0: 1162 flag = 0 #dy = numpy.ones_like(dy_data)1151 flag = 0 # dy = numpy.ones_like(dy_data) 1163 1152 elif button_list.index(item) == 1: 1164 flag = 1 #dy = dy_data1153 flag = 1 # dy = dy_data 1165 1154 elif button_list.index(item) == 2: 1166 flag = 2 #dy = numpy.sqrt(numpy.abs(data))1155 flag = 2 # dy = numpy.sqrt(numpy.abs(data)) 1167 1156 elif button_list.index(item) == 3: 1168 flag = 3 # dy = numpy.abs(data)1157 flag = 3 # dy = numpy.abs(data) 1169 1158 break 1170 1159 return flag 1171 1160 1172 1173 1161 def _StopFit(self, event=None): 1174 1162 """ 1175 Stop fit 1163 Stop fit 1176 1164 """ 1177 1165 if event != None: … … 1188 1176 self.model.name = "M" + str(self.index_model) 1189 1177 1190 1191 def _on_select_model(self, event=None): 1178 def _on_select_model(self, event=None): 1192 1179 """ 1193 1180 call back for model selection 1194 """ 1195 self.Show(False) 1196 copy_flag = False 1197 is_poly_enabled = None 1181 """ 1182 self.Show(False) 1183 copy_flag = False 1184 is_poly_enabled = None 1198 1185 if event != None: 1199 1186 if (event.GetEventObject() == self.formfactorbox\ … … 1202 1189 or event.GetEventObject() == self.multifactorbox: 1203 1190 copy_flag = self.get_copy_params() 1204 is_poly_enabled = self.enable_disp.GetValue() 1205 1206 self._on_select_model_helper() 1207 self.set_model_param_sizer(self.model) 1191 is_poly_enabled = self.enable_disp.GetValue() 1192 1193 self._on_select_model_helper() 1194 self.set_model_param_sizer(self.model) 1208 1195 if self.model is None: 1209 1196 self._set_bookmark_flag(False) … … 1216 1203 except: 1217 1204 pass 1218 #self.btFit.SetFocus()1219 1205 self.state.enable_disp = self.enable_disp.GetValue() 1220 1206 self.state.disable_disp = self.disable_disp.GetValue() … … 1222 1208 self.state.slit_smearer = self.slit_smearer.GetValue() 1223 1209 1224 self.state.structurecombobox = self.structurebox.GetLabel() #.GetCurrentSelection()1225 self.state.formfactorcombobox = self.formfactorbox.GetLabel() #.GetCurrentSelection()1210 self.state.structurecombobox = self.structurebox.GetLabel() 1211 self.state.formfactorcombobox = self.formfactorbox.GetLabel() 1226 1212 self.enable_fit_button() 1227 1213 if self.model != None: … … 1232 1218 self._set_paste_flag(True) 1233 1219 if self.data is not None: 1234 is_data = check_data_validity(self.data) 1220 is_data = check_data_validity(self.data) 1235 1221 if is_data: 1236 1222 self._set_bookmark_flag(True) … … 1261 1247 (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() 1262 1248 1263 ## set smearing value whether or not 1249 ## set smearing value whether or not 1264 1250 # the data contain the smearing info 1265 evt = ModelEventbox(model=self.model, 1266 smearer=temp_smear,1267 1268 1269 1270 1271 qmax=float(self.qmax_x))1251 evt = ModelEventbox(model=self.model, 1252 smearer=temp_smear, 1253 enable_smearer=not self.disable_smearer.GetValue(), 1254 qmin=float(self.qmin_x), 1255 uid=self.uid, 1256 caption=self.window_caption, 1257 qmax=float(self.qmax_x)) 1272 1258 1273 1259 self._manager._on_model_panel(evt=evt) … … 1277 1263 self.state.model.name = self.model.name 1278 1264 1279 1280 1265 if event != None: 1281 1266 ## post state to fit panel 1282 new_event = PageInfoEvent(page =self)1283 wx.PostEvent(self.parent, new_event) 1267 new_event = PageInfoEvent(page=self) 1268 wx.PostEvent(self.parent, new_event) 1284 1269 #update list of plugins if new plugin is available 1285 1270 if self.plugin_rbutton.GetValue(): … … 1311 1296 self.slit_smearer.Enable(False) 1312 1297 self.pinhole_smearer.Enable(False) 1313 self.btEditMask.Disable() 1298 self.btEditMask.Disable() 1314 1299 self.EditMask_title.Disable() 1315 1300 1316 self.Show(True) 1301 self.Show(True) 1317 1302 self.SetupScrolling() 1318 1303 1319 def _onparamEnter(self, event):1320 """ 1304 def _onparamEnter(self, event): 1305 """ 1321 1306 when enter value on panel redraw model according to changed 1322 1307 """ 1323 if self.model == None:1324 msg ="Please select a Model first..."1308 if self.model == None: 1309 msg = "Please select a Model first..." 1325 1310 wx.MessageBox(msg, 'Info') 1326 #wx.PostEvent(self._manager.parent, StatusEvent(status=\1327 # "Parameters: %s"%msg))1328 1311 return 1329 1312 … … 1333 1316 #get event object 1334 1317 tcrtl = event.GetEventObject() 1335 1336 #wx.PostEvent(self._manager.parent, StatusEvent(status=" \1337 # updating ... ",type="update"))1338 1318 #Clear msg if previously shown. 1339 msg = ""1340 wx.PostEvent(self.parent.parent, StatusEvent(status = msg))1319 msg = "" 1320 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 1341 1321 1342 1322 if check_float(tcrtl): 1343 flag = self._onparamEnter_helper() 1344 self.set_npts2fit() 1345 if self.fitrange: 1323 flag = self._onparamEnter_helper() 1324 self.set_npts2fit() 1325 if self.fitrange: 1346 1326 temp_smearer = None 1347 1327 if not self.disable_smearer.GetValue(): 1348 temp_smearer = self.current_smearer1349 ## set smearing value whether or not 1328 temp_smearer = self.current_smearer 1329 ## set smearing value whether or not 1350 1330 # the data contain the smearing info 1351 1331 if self.slit_smearer.GetValue(): … … 1355 1335 flag1 = self.update_pinhole_smear() 1356 1336 flag = flag or flag1 1357 elif self.data.__class__.__name__ != 1337 elif self.data.__class__.__name__ != "Data2D" and \ 1358 1338 not self.enable2D: 1359 self._manager.set_smearer(smearer=temp_smearer, 1339 self._manager.set_smearer(smearer=temp_smearer, 1360 1340 fid=self.data.id, 1361 1341 uid=self.uid, 1362 qmin=float(self.qmin_x),1363 qmax=float(self.qmax_x),1342 qmin=float(self.qmin_x), 1343 qmax=float(self.qmax_x), 1364 1344 enable_smearer=not self.disable_smearer.GetValue(), 1365 draw=True) 1366 if flag: 1345 draw=True) 1346 if flag: 1367 1347 #self.compute_chisqr(smearer= temp_smearer) 1368 1348 … … 1370 1350 if self.state_change: 1371 1351 #self._undo.Enable(True) 1372 event = PageInfoEvent(page =self)1352 event = PageInfoEvent(page=self) 1373 1353 wx.PostEvent(self.parent, event) 1374 self.state_change = False1375 else: 1376 # invalid fit range: do nothing here: 1377 # msg already displayed in validate 1378 return 1354 self.state_change = False 1355 else: 1356 # invalid fit range: do nothing here: 1357 # msg already displayed in validate 1358 return 1379 1359 else: 1380 1360 self.save_current_state() 1381 msg = "Cannot Plot :Must enter a number!!! "1382 wx.PostEvent(self.parent.parent, StatusEvent(status = msg))1361 msg = "Cannot Plot :Must enter a number!!! " 1362 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 1383 1363 1384 self.save_current_state() 1385 return 1364 self.save_current_state() 1365 return 1386 1366 1387 1367 def _onparamRangeEnter(self, event): … … 1389 1369 Check validity of value enter in the parameters range field 1390 1370 """ 1391 #if self.check_invalid_panel(): 1392 # return 1393 tcrtl= event.GetEventObject() 1371 tcrtl = event.GetEventObject() 1394 1372 #Clear msg if previously shown. 1395 msg = ""1396 wx.PostEvent(self.parent.parent, StatusEvent(status = msg))1373 msg = "" 1374 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 1397 1375 # Flag to register when a parameter has changed. 1398 1376 is_modified = False 1399 if tcrtl.GetValue().lstrip().rstrip() !="":1377 if tcrtl.GetValue().lstrip().rstrip() != "": 1400 1378 try: 1401 value = float(tcrtl.GetValue())1402 1379 tcrtl.SetBackgroundColour(wx.WHITE) 1403 self._check_value_enter(self.fittable_param ,is_modified)1404 self._check_value_enter(self.parameters ,is_modified)1380 self._check_value_enter(self.fittable_param, is_modified) 1381 self._check_value_enter(self.parameters, is_modified) 1405 1382 except: 1406 1383 tcrtl.SetBackgroundColour("pink") 1407 msg = "Model Error:wrong value entered : %s"% sys.exc_value1408 wx.PostEvent(self.parent.parent, StatusEvent(status = msg))1409 return 1384 msg = "Model Error:wrong value entered : %s" % sys.exc_value 1385 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 1386 return 1410 1387 else: 1411 tcrtl.SetBackgroundColour(wx.WHITE)1388 tcrtl.SetBackgroundColour(wx.WHITE) 1412 1389 1413 1390 #self._undo.Enable(True) 1414 1391 self.save_current_state() 1415 event = PageInfoEvent(page =self)1392 event = PageInfoEvent(page=self) 1416 1393 wx.PostEvent(self.parent, event) 1417 self.state_change= False 1418 1419 1394 self.state_change = False 1395 1420 1396 def _onQrangeEnter(self, event): 1421 1397 """ … … 1424 1400 tcrtl = event.GetEventObject() 1425 1401 #Clear msg if previously shown. 1426 msg = ""1427 wx.PostEvent(self.parent.parent, StatusEvent(status = msg))1402 msg = "" 1403 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 1428 1404 # For theory mode 1429 1405 if not self.data.is_data: … … 1432 1408 self.create_default_data() 1433 1409 # Flag to register when a parameter has changed. 1434 is_modified = False 1435 if tcrtl.GetValue().lstrip().rstrip()!="": 1410 if tcrtl.GetValue().lstrip().rstrip() != "": 1436 1411 try: 1437 value = float(tcrtl.GetValue())1438 1412 tcrtl.SetBackgroundColour(wx.WHITE) 1439 1440 1413 # If qmin and qmax have been modified, update qmin and qmax 1441 if self._validate_qrange( 1414 if self._validate_qrange(self.qmin, self.qmax): 1442 1415 tempmin = float(self.qmin.GetValue()) 1443 1416 if tempmin != self.qmin_x: … … 1448 1421 else: 1449 1422 tcrtl.SetBackgroundColour("pink") 1450 msg= "Model Error:wrong value entered : %s"% sys.exc_value 1451 wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) 1452 return 1453 1423 msg = "Model Error:wrong value entered : %s" % sys.exc_value 1424 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 1425 return 1454 1426 except: 1455 1427 tcrtl.SetBackgroundColour("pink") 1456 msg = "Model Error:wrong value entered : %s"% sys.exc_value1457 wx.PostEvent(self.parent.parent, StatusEvent(status = msg))1458 return 1428 msg = "Model Error:wrong value entered : %s" % sys.exc_value 1429 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 1430 return 1459 1431 #Check if # of points for theory model are valid(>0). 1460 1432 # check for 2d 1461 1433 if self.data.__class__.__name__ == "Data2D" or \ 1462 1434 self.enable2D: 1463 # set mask 1464 radius = numpy.sqrt(self.data.qx_data*self.data.qx_data +1465 self.data.qy_data *self.data.qy_data)1466 index_data = ((self.qmin_x <= radius) & \1467 (radius <= self.qmax_x))1468 index_data = (index_data) &(self.data.mask)1469 index_data = (index_data) &(numpy.isfinite(self.data.data))1435 # set mask 1436 radius = numpy.sqrt(self.data.qx_data * self.data.qx_data + 1437 self.data.qy_data * self.data.qy_data) 1438 index_data = ((self.qmin_x <= radius) & \ 1439 (radius <= self.qmax_x)) 1440 index_data = (index_data) & (self.data.mask) 1441 index_data = (index_data) & (numpy.isfinite(self.data.data)) 1470 1442 if len(index_data[index_data]) < 10: 1471 1443 msg = "Cannot Plot :No or too little npts in" 1472 1444 msg += " that data range!!! " 1473 wx.PostEvent(self.parent.parent, 1445 wx.PostEvent(self.parent.parent, 1474 1446 StatusEvent(status=msg)) 1475 1447 return … … 1477 1449 #self.data.mask = index_data 1478 1450 #self.Npts_fit.SetValue(str(len(self.data.mask))) 1479 self.set_npts2fit() 1451 self.set_npts2fit() 1480 1452 else: 1481 index_data = ((self.qmin_x <= self.data.x) & \1453 index_data = ((self.qmin_x <= self.data.x) & \ 1482 1454 (self.data.x <= self.qmax_x)) 1483 1455 self.Npts_fit.SetValue(str(len(self.data.x[index_data]))) … … 1487 1459 self._save_plotting_range() 1488 1460 else: 1489 tcrtl.SetBackgroundColour("pink")1490 msg= "Model Error:wrong value entered!!!"1491 wx.PostEvent(self.parent.parent, StatusEvent(status = msg))1461 tcrtl.SetBackgroundColour("pink") 1462 msg = "Model Error:wrong value entered!!!" 1463 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 1492 1464 1493 1465 self._draw_model() 1494 1466 self.save_current_state() 1495 event = PageInfoEvent(page =self)1467 event = PageInfoEvent(page=self) 1496 1468 wx.PostEvent(self.parent, event) 1497 self.state_change = False1469 self.state_change = False 1498 1470 return 1499 1471 1500 1472 def _clear_Err_on_Fit(self): 1501 1473 """ 1502 hide the error text control shown 1474 hide the error text control shown 1503 1475 after fitting 1504 1476 """ 1505 1477 if self.is_mac: 1506 1478 return 1507 if hasattr(self, "text2_3"):1479 if hasattr(self, "text2_3"): 1508 1480 self.text2_3.Hide() 1509 1481 1510 if len(self.parameters) >0:1482 if len(self.parameters) > 0: 1511 1483 for item in self.parameters: 1512 1484 #Skip t ifhe angle parameters if 1D data 1513 if self.data.__class__.__name__ != 1485 if self.data.__class__.__name__ != "Data2D" and \ 1514 1486 not self.enable2D: 1515 1487 if item in self.orientation_params: … … 1517 1489 if item in self.param_toFit: 1518 1490 continue 1519 ## hide statictext +/- 1520 if len(item) < 4 1491 ## hide statictext +/- 1492 if len(item) < 4: 1521 1493 continue 1522 if item[3] !=None and item[3].IsShown():1494 if item[3] != None and item[3].IsShown(): 1523 1495 item[3].Hide() 1524 1496 ## hide textcrtl for error after fit 1525 if item[4] !=None and item[4].IsShown():1497 if item[4] != None and item[4].IsShown(): 1526 1498 item[4].Hide() 1527 1499 1528 if len(self.fittable_param) >0:1500 if len(self.fittable_param) > 0: 1529 1501 for item in self.fittable_param: 1530 1502 #Skip t ifhe angle parameters if 1D data 1531 if self.data.__class__.__name__ != 1503 if self.data.__class__.__name__ != "Data2D" and \ 1532 1504 not self.enable2D: 1533 1505 if item in self.orientation_params: … … 1535 1507 if item in self.param_toFit: 1536 1508 continue 1537 if len(item) < 4 1509 if len(item) < 4: 1538 1510 continue 1539 ## hide statictext +/- 1540 if item[3] !=None and item[3].IsShown():1511 ## hide statictext +/- 1512 if item[3] != None and item[3].IsShown(): 1541 1513 item[3].Hide() 1542 1514 ## hide textcrtl for error after fit 1543 if item[4] !=None and item[4].IsShown():1515 if item[4] != None and item[4].IsShown(): 1544 1516 item[4].Hide() 1545 return 1517 return 1546 1518 1547 1519 def _get_defult_custom_smear(self): … … 1550 1522 """ 1551 1523 # get the default values 1552 if self.dxl == None: self.dxl = 0.0 1553 if self.dxw == None: self.dxw = "" 1554 if self.dx_min == None: self.dx_min = SMEAR_SIZE_L 1555 if self.dx_max == None: self.dx_max = SMEAR_SIZE_H 1524 if self.dxl == None: 1525 self.dxl = 0.0 1526 if self.dxw == None: 1527 self.dxw = "" 1528 if self.dx_min == None: 1529 self.dx_min = SMEAR_SIZE_L 1530 if self.dx_max == None: 1531 self.dx_max = SMEAR_SIZE_H 1556 1532 1557 1533 def _get_smear_info(self): … … 1559 1535 Get the smear info from data. 1560 1536 1561 :return: self.smear_type, self.dq_l and self.dq_r, 1562 respectively the type of the smear, dq_min and 1563 dq_max for pinhole smear data 1537 :return: self.smear_type, self.dq_l and self.dq_r, 1538 respectively the type of the smear, dq_min and 1539 dq_max for pinhole smear data 1564 1540 while dxl and dxw for slit smear 1565 1566 """ 1567 1541 """ 1568 1542 # default 1569 1543 self.smear_type = None … … 1573 1547 if self.data is None: 1574 1548 return 1575 elif self.data.__class__.__name__ == 1576 self.enable2D:1577 if data.dqx_data == None or data.dqy_data == None:1549 elif self.data.__class__.__name__ == "Data2D" or \ 1550 self.enable2D: 1551 if data.dqx_data == None or data.dqy_data == None: 1578 1552 return 1579 elif self.current_smearer != None and (data.dqx_data.any()!=0) and \ 1580 (data.dqx_data.any()!=0): 1553 elif self.current_smearer != None \ 1554 and data.dqx_data.any() != 0 \ 1555 and data.dqx_data.any() != 0: 1581 1556 self.smear_type = "Pinhole2d" 1582 self.dq_l = format_number(numpy.average(data.dqx_data)) 1583 self.dq_r = format_number(numpy.average(data.dqy_data)) 1584 return 1585 else: 1557 self.dq_l = format_number(numpy.average(data.dqx_data)) 1558 self.dq_r = format_number(numpy.average(data.dqy_data)) 1559 return 1560 else: 1586 1561 return 1587 1562 # check if it is pinhole smear and get min max if it is. 1588 if data.dx != None and all(data.dx != 0):1589 self.smear_type = "Pinhole" 1563 if data.dx != None and all(data.dx != 0): 1564 self.smear_type = "Pinhole" 1590 1565 self.dq_l = data.dx[0] 1591 1566 self.dq_r = data.dx[-1] 1592 1567 1593 1568 # check if it is slit smear and get min max if it is. 1594 elif data.dxl != None or data.dxw != None: 1595 self.smear_type = "Slit" 1596 if data.dxl != None and all(data.dxl != 0):1569 elif data.dxl != None or data.dxw != None: 1570 self.smear_type = "Slit" 1571 if data.dxl != None and all(data.dxl != 0): 1597 1572 self.dq_l = data.dxl[0] 1598 if data.dxw != None and all(data.dxw != 0):1599 self.dq_r = data.dxw[0] 1600 #return self.smear_type,self.dq_l,self.dq_r 1573 if data.dxw != None and all(data.dxw != 0): 1574 self.dq_r = data.dxw[0] 1575 #return self.smear_type,self.dq_l,self.dq_r 1601 1576 1602 def _show_smear_sizer(self): 1577 def _show_smear_sizer(self): 1603 1578 """ 1604 1579 Show only the sizers depending on smear selection … … 1626 1601 if self.smear_type == 'Slit': 1627 1602 self.smear_description_slit_height.Show(True) 1628 self.smear_description_slit_width.Show(True) 1603 self.smear_description_slit_width.Show(True) 1629 1604 elif self.smear_type == 'Pinhole': 1630 1605 self.smear_description_pin_min.Show(True) … … 1680 1655 def _set_accuracy_list(self): 1681 1656 """ 1682 Set the list of an accuracy in 2D custum smear: Xhigh, High, Med, or Low 1657 Set the list of an accuracy in 2D custum smear: 1658 Xhigh, High, Med, or Low 1683 1659 """ 1684 1660 # list of accuracy choices 1685 list = ['Low', 'Med','High','Xhigh']1661 list = ['Low', 'Med', 'High', 'Xhigh'] 1686 1662 for idx in range(len(list)): 1687 self.smear_accuracy.Append(list[idx], idx)1663 self.smear_accuracy.Append(list[idx], idx) 1688 1664 1689 def _set_fun_box_list(self, fun_box):1665 def _set_fun_box_list(self, fun_box): 1690 1666 """ 1691 1667 Set the list of func for multifunctional models … … 1704 1680 for key, val in list.iteritems(): 1705 1681 if (val == ind): 1706 fun_box.Append(key, val)1682 fun_box.Append(key, val) 1707 1683 break 1708 1684 ind += 1 1709 1685 1710 def _on_select_accuracy(self, event):1686 def _on_select_accuracy(self, event): 1711 1687 """ 1712 1688 Select an accuracy in 2D custom smear: Xhigh, High, Med, or Low … … 1718 1694 if self.pinhole_smearer.GetValue(): 1719 1695 self.onPinholeSmear(event=None) 1720 else: 1696 else: 1721 1697 self.onSmear(event=None) 1722 1698 if self.current_smearer != None: 1723 self.current_smearer.set_accuracy(accuracy = 1724 self.smear2d_accuracy) 1699 self.current_smearer.set_accuracy(accuracy=self.smear2d_accuracy) 1725 1700 event.Skip() 1726 1701 1727 def _on_fun_box(self, event):1702 def _on_fun_box(self, event): 1728 1703 """ 1729 1704 Select an func: Erf,Rparabola,LParabola … … 1733 1708 name = fun_box.Name 1734 1709 value = fun_box.GetValue() 1735 if self.model.fun_list.has_key(value):1710 if value in self.model.fun_list: 1736 1711 fun_val = self.model.fun_list[value] 1737 1712 1738 self.model.setParam(name, fun_val)1713 self.model.setParam(name, fun_val) 1739 1714 # save state 1740 self._copy_parameters_state(self.str_parameters, 1715 self._copy_parameters_state(self.str_parameters, 1741 1716 self.state.str_parameters) 1742 1717 # update params 1743 self._update_paramv_on_fit() 1718 self._update_paramv_on_fit() 1744 1719 # draw 1745 1720 self._draw_model() … … 1748 1723 event.Skip() 1749 1724 1750 def _onMask(self, event): 1725 def _onMask(self, event): 1751 1726 """ 1752 1727 Build a panel to allow to edit Mask 1753 1728 """ 1754 1755 1729 from sans.guiframe.local_perspectives.plotting.masking \ 1756 1730 import MaskPanel as MaskDialog 1757 1731 1758 1732 self.panel = MaskDialog(base=self, data=self.data, id=wx.NewId()) 1759 #self.panel.Bind(wx.EVT_CLOSE, self._draw_masked_model)1760 1733 self.panel.ShowModal() 1761 #wx.PostEvent(self.parent, event)1762 1734 1763 1735 def _draw_masked_model(self, event): … … 1765 1737 Draw model image w/mask 1766 1738 """ 1767 #event.Skip()1768 1739 is_valid_qrange = self._update_paramv_on_fit() 1769 1740 1770 1741 if is_valid_qrange and self.model != None: 1771 #self.panel.Show(0)1772 #self.panel.Destroy() # frame1773 1742 self.panel.MakeModal(False) 1774 event.Skip() 1743 event.Skip() 1775 1744 # try re draw the model plot if it exists 1776 1745 self._draw_model() 1777 1746 self.set_npts2fit() 1778 1747 elif self.model == None: 1779 #self.panel.Show(0)1780 #self.panel.Destroy() # frame1781 1748 self.panel.MakeModal(False) 1782 1749 event.Skip() 1783 1750 self.set_npts2fit() 1784 msg = "No model is found on updating MASK in the model plot... "1785 wx.PostEvent(self.parent.parent, StatusEvent(status = msg))1751 msg = "No model is found on updating MASK in the model plot... " 1752 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 1786 1753 else: 1787 1754 event.Skip() … … 1789 1756 self.panel.ShowMessage(msg) 1790 1757 1791 1792 1758 def _set_smear(self, data): 1793 1759 """ … … 1796 1762 return 1797 1763 self.current_smearer = smear_selection(data, self.model) 1798 flag = 1764 flag = self.disable_smearer.GetValue() 1799 1765 self.disable_smearer.SetValue(flag) 1800 1766 if self.current_smearer == None: … … 1839 1805 qmin, qmax, npts = None, None, None 1840 1806 if data is not None: 1841 if not hasattr(data, "data"):1807 if not hasattr(data, "data"): 1842 1808 qmin = min(data.x) 1843 # Maximum value of data 1809 # Maximum value of data 1844 1810 qmax = max(data.x) 1845 1811 npts = len(data.x) 1846 1812 else: 1847 1813 qmin = 0 1848 x = max(math.fabs(data.xmin), math.fabs(data.xmax)) 1814 x = max(math.fabs(data.xmin), math.fabs(data.xmax)) 1849 1815 y = max(math.fabs(data.ymin), math.fabs(data.ymax)) 1850 ## Maximum value of data 1851 qmax = math.sqrt(x *x + y*y)1816 ## Maximum value of data 1817 qmax = math.sqrt(x * x + y * y) 1852 1818 npts = len(data.data) 1853 1819 return qmin, qmax, npts 1854 1820 1855 1856 1821 def set_data(self, data): 1857 1822 """ 1858 reset the current data 1859 """ 1860 from sans.guiframe.dataFitting import check_data_validity 1823 reset the current data 1824 """ 1861 1825 id = None 1862 1826 flag = False 1863 1827 is_data = False 1864 1828 if self.data is not None: 1865 is_data = check_data_validity(self.data) 1829 is_data = check_data_validity(self.data) 1866 1830 if not is_data and data is not None: 1867 1831 flag = True … … 1891 1855 self._set_smear(data) 1892 1856 # more disables for 2D 1893 if self.data.__class__.__name__ == 1857 if self.data.__class__.__name__ == "Data2D" or \ 1894 1858 self.enable2D: 1895 1859 self.slit_smearer.Disable() 1896 self.pinhole_smearer.Enable(True) 1860 self.pinhole_smearer.Enable(True) 1897 1861 self.default_mask = copy.deepcopy(self.data.mask) 1898 1862 if self.data.err_data == None or\ … … 1907 1871 self.weightbt_string = self.dI_didata.GetLabelText() 1908 1872 else: 1909 self.slit_smearer.Enable(True) 1910 self.pinhole_smearer.Enable(True) 1873 self.slit_smearer.Enable(True) 1874 self.pinhole_smearer.Enable(True) 1911 1875 if self.data.dy == None or\ 1912 1876 (self.data.dy == 1).all() or\ … … 1919 1883 self.dI_didata.SetValue(True) 1920 1884 self.weightbt_string = self.dI_didata.GetLabelText() 1921 # Enable weighting radio uttons 1922 self.dI_noweight.Enable(True) 1885 # Enable weighting radio uttons 1886 self.dI_noweight.Enable(True) 1923 1887 self.dI_sqrdata.Enable(True) 1924 1888 self.dI_idata.Enable(True) … … 1927 1891 self.structurebox.Enable() 1928 1892 data_name = self.data.name 1929 _, _, npts = 1893 _, _, npts = self.compute_data_range(self.data) 1930 1894 #set maximum range for x in linear scale 1931 if not hasattr(self.data, "data"): #Display only for 1D data fit1932 self.btEditMask.Disable() 1895 if not hasattr(self.data, "data"): # Display only for 1D data fit 1896 self.btEditMask.Disable() 1933 1897 self.EditMask_title.Disable() 1934 1898 else: 1935 self.btEditMask.Enable() 1936 self.EditMask_title.Enable() 1899 self.btEditMask.Enable() 1900 self.EditMask_title.Enable() 1937 1901 1938 1902 self.Npts_total.SetValue(str(npts)) … … 1947 1911 self.state.data = data 1948 1912 self.enable_fit_button() 1949 # send graph_id to page_finder 1913 # send graph_id to page_finder 1950 1914 self._manager.set_graph_id(uid=self.uid, graph_id=self.graph_id) 1951 1915 #focus the page … … 1956 1920 self.slit_smearer.Enable(False) 1957 1921 self.pinhole_smearer.Enable(False) 1958 self.btEditMask.Disable() 1922 self.btEditMask.Disable() 1959 1923 self.EditMask_title.Disable() 1960 1924 1961 1962 1925 self.on_set_focus(None) 1963 1926 self.Refresh() … … 1968 1931 self.disable_smearer.SetValue(True) 1969 1932 self.onSmear(None) 1970 #self._set_smear(self.data)1971 1933 1972 1934 if self.data.__class__.__name__ == "Data2D": … … 1979 1941 #replace data plot on combo box selection 1980 1942 #by removing the previous selected data 1981 wx.PostEvent(self._manager.parent, NewPlotEvent(action="remove", 1982 group_id=self.graph_id, id=id)) 1943 wx.PostEvent(self._manager.parent, 1944 NewPlotEvent(action="remove", 1945 group_id=self.graph_id, id=id)) 1983 1946 #plot the current selected data 1984 wx.PostEvent(self._manager.parent, NewPlotEvent(plot=self.data, 1985 title=str(self.data.title))) 1986 #self._manager.store_data(uid=self.uid, data_list=self.data_list, 1987 # caption=self.window_name) 1947 wx.PostEvent(self._manager.parent, 1948 NewPlotEvent(plot=self.data, 1949 title=str(self.data.title))) 1988 1950 self._draw_model() 1989 1951 … … 1992 1954 Prevent further handling of the mouse event on Npts_total 1993 1955 by not calling Skip(). 1994 """ 1956 """ 1995 1957 pass 1996 1958 1997 def reset_page(self, state, first=False):1959 def reset_page(self, state, first=False): 1998 1960 """ 1999 1961 reset the state … … 2001 1963 self.reset_page_helper(state) 2002 1964 2003 self.select_param(event = None)1965 self.select_param(event=None) 2004 1966 #Save state_fit 2005 1967 self.save_current_state_fit() … … 2011 1973 return the fitting range 2012 1974 """ 2013 return float(self.qmin_x) 1975 return float(self.qmin_x), float(self.qmax_x) 2014 1976 2015 1977 def get_npts2fit(self): … … 2023 1985 return 2024 1986 npts2fit = 0 2025 qmin, qmax = self.get_range()1987 qmin, qmax = self.get_range() 2026 1988 if self.data.__class__.__name__ == "Data2D" or \ 2027 1989 self.enable2D: 2028 radius = numpy.sqrt( self.data.qx_data*self.data.qx_data +2029 self.data.qy_data *self.data.qy_data)2030 index_data = (self.qmin_x <= radius) &(radius<= self.qmax_x)2031 index_data = (index_data)&(self.data.mask)2032 index_data = (index_data) &(numpy.isfinite(self.data.data))1990 radius = numpy.sqrt(self.data.qx_data * self.data.qx_data + 1991 self.data.qy_data * self.data.qy_data) 1992 index_data = (self.qmin_x <= radius) & (radius <= self.qmax_x) 1993 index_data = (index_data) & (self.data.mask) 1994 index_data = (index_data) & (numpy.isfinite(self.data.data)) 2033 1995 npts2fit = len(self.data.data[index_data]) 2034 1996 else: 2035 1997 for qx in self.data.x: 2036 2037 1998 if qx >= qmin and qx <= qmax: 1999 npts2fit += 1 2038 2000 return npts2fit 2039 2001 2040 2002 def set_npts2fit(self): 2041 2003 """ 2042 setValue Npts for fitting 2004 setValue Npts for fitting 2043 2005 """ 2044 2006 self.Npts_fit.SetValue(str(self.get_npts2fit())) … … 2055 2017 checked.Theses TextCtrl will allow reference to parameters to fit. 2056 2018 2057 :raise: if return an empty list of parameter fit will nnote work 2019 :raise: if return an empty list of parameter fit will nnote work 2058 2020 properly so raise ValueError,"missing parameter to fit" 2059 2021 """ 2060 if self.param_toFit != []:2022 if self.param_toFit != []: 2061 2023 return self.param_toFit 2062 2024 else: 2063 msg = "missing parameters to fit" 2025 msg = "missing parameters to fit" 2064 2026 wx.MessageBox(msg, 'warning') 2065 2027 return False 2066 #raise ValueError,"missing parameters to fit"2067 2028 2068 2029 def onsetValues(self, chisqr, p_name, out, cov): … … 2079 2040 self._on_fit_complete() 2080 2041 if out == None or not numpy.isfinite(chisqr): 2081 raise ValueError,"Fit error occured..." 2042 raise ValueError,"Fit error occured..." 2082 2043 2083 2044 is_modified = False 2084 has_error = False 2085 dispersity = '' 2045 has_error = False 2046 dispersity = '' 2086 2047 2087 2048 #Hide textctrl boxes of errors. 2088 self._clear_Err_on_Fit() 2049 self._clear_Err_on_Fit() 2089 2050 2090 2051 #Check if chi2 is finite 2091 2052 if chisqr != None and numpy.isfinite(chisqr): 2092 #format chi2 2093 if self.engine_type == "park": 2094 npt_fit = float(self.get_npts2fit()) 2095 # Taking care this in parkemgine 2096 #if npt_fit > 0: 2097 # chisqr =chisqr/npt_fit 2098 chi2 = format_number(chisqr, True) 2099 self.tcChi.SetValue(chi2) 2100 self.tcChi.Refresh() 2053 #format chi2 2054 if self.engine_type == "park": 2055 npt_fit = float(self.get_npts2fit()) 2056 chi2 = format_number(chisqr, True) 2057 self.tcChi.SetValue(chi2) 2058 self.tcChi.Refresh() 2101 2059 else: 2102 2060 self.tcChi.SetValue("-") … … 2108 2066 try: 2109 2067 if self.enable_disp.GetValue(): 2110 if hasattr(self, "text_disp_1"):2068 if hasattr(self, "text_disp_1"): 2111 2069 if self.text_disp_1 != None and not self.is_mac: 2112 2070 self.text_disp_1.Hide() … … 2115 2073 pass 2116 2074 2117 2118 2075 i = 0 2119 2076 #Set the panel when fit result are list 2120 for item in self.param_toFit: 2121 if len(item) >5 and item != None:2077 for item in self.param_toFit: 2078 if len(item) > 5 and item != None: 2122 2079 ## reset error value to initial state 2123 2080 if not self.is_mac: … … 2126 2083 for ind in range(len(out)): 2127 2084 if item[1] == p_name[ind]: 2128 break 2129 if len(out) <=len(self.param_toFit) and out[ind] !=None:2130 val_out = format_number(out[ind], True) 2085 break 2086 if len(out) <= len(self.param_toFit) and out[ind] != None: 2087 val_out = format_number(out[ind], True) 2131 2088 item[2].SetValue(val_out) 2132 2089 2133 if(cov != None and len(cov) == len(out)):2090 if(cov != None and len(cov) == len(out)): 2134 2091 try: 2135 if dispersity != None:2092 if dispersity != None: 2136 2093 if self.enable_disp.GetValue(): 2137 if hasattr(self, "text_disp_1"):2138 if self.text_disp_1 !=None:2094 if hasattr(self, "text_disp_1"): 2095 if self.text_disp_1 != None: 2139 2096 if not self.text_disp_1.IsShown()\ 2140 2097 and not self.is_mac: 2141 2098 self.text_disp_1.Show(True) 2142 2099 except: 2143 pass 2100 pass 2144 2101 2145 if cov[ind] !=None:2102 if cov[ind] != None: 2146 2103 if numpy.isfinite(float(cov[ind])): 2147 2104 val_err = format_number(cov[ind], True) … … 2151 2108 item[4].SetValue(val_err) 2152 2109 has_error = True 2153 i += 1 2110 i += 1 2154 2111 #Show error title when any errors displayed 2155 if has_error: 2112 if has_error: 2156 2113 if not self.text2_3.IsShown(): 2157 self.text2_3.Show(True) 2158 ## save current state 2159 self.save_current_state() 2160 2161 #self._lay_out() 2114 self.text2_3.Show(True) 2115 ## save current state 2116 self.save_current_state() 2117 2162 2118 if not self.is_mac: 2163 self.Layout() 2164 self.Refresh() 2165 self._mac_sleep(0.1) 2119 self.Layout() 2120 self.Refresh() 2121 self._mac_sleep(0.1) 2166 2122 #plot model ( when drawing, do not update chisqr value again) 2167 self._draw_model(update_chisqr=False, source = 'fit') 2168 #PostStatusEvent 2169 #msg = "Fit completed!dddd " 2170 #wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2123 self._draw_model(update_chisqr=False, source='fit') 2171 2124 2172 2125 def onWeighting(self, event): … … 2186 2139 if is_2D == None: 2187 2140 is_2D = self._is_2D() 2188 weight = get_weight(data=self.data, 2189 is2d=is_2D, 2141 weight = get_weight(data=self.data, 2142 is2d=is_2D, 2190 2143 flag=flag_weight) 2191 self._manager.set_fit_weight(uid=self.uid, 2192 flag=flag_weight, 2193 is2d=is_2D, 2144 self._manager.set_fit_weight(uid=self.uid, 2145 flag=flag_weight, 2146 is2d=is_2D, 2194 2147 fid=None) 2195 2148 … … 2207 2160 if event == None: 2208 2161 return 2209 msg ="Please select a Model first..."2162 msg = "Please select a Model first..." 2210 2163 wx.MessageBox(msg, 'Info') 2211 wx.PostEvent(self._manager.parent, StatusEvent(status=\2212 "Smear: %s"%msg))2164 wx.PostEvent(self._manager.parent, 2165 StatusEvent(status="Smear: %s" % msg)) 2213 2166 return 2214 2167 2215 2168 # Need update param values 2216 self._update_paramv_on_fit() 2169 self._update_paramv_on_fit() 2217 2170 2218 2171 # msg default 2219 2172 msg = None 2220 2173 if event != None: 2221 tcrtl = event.GetEventObject()2174 tcrtl = event.GetEventObject() 2222 2175 # event case of radio button 2223 if tcrtl.GetValue() == True:2176 if tcrtl.GetValue() == True: 2224 2177 self.dx_min = 0.0 2225 2178 self.dx_max = 0.0 … … 2228 2181 is_new_pinhole = self._is_changed_pinhole() 2229 2182 else: 2230 is_new_pinhole = True 2183 is_new_pinhole = True 2231 2184 # if any value is changed 2232 2185 if is_new_pinhole: 2233 2186 msg = self._set_pinhole_smear() 2234 # hide all silt sizer 2187 # hide all silt sizer 2235 2188 self._hide_all_smear_info() 2236 2189 2237 ##Calculate chi2 2238 temp_smearer = self.current_smearer 2239 #self.compute_chisqr(smearer= temp_smearer) 2240 2241 # show relevant slit sizers 2190 # show relevant slit sizers 2242 2191 self._show_smear_sizer() 2243 2192 2244 2193 self.sizer_set_smearer.Layout() 2245 self.Layout() 2246 2247 if event != None: 2248 event.Skip() 2194 self.Layout() 2195 2196 if event != None: 2197 event.Skip() 2249 2198 #self._undo.Enable(True) 2250 2199 self.save_current_state() 2251 event = PageInfoEvent(page =self)2200 event = PageInfoEvent(page=self) 2252 2201 wx.PostEvent(self.parent, event) 2253 2202 2254 def _is_changed_pinhole(self): 2203 def _is_changed_pinhole(self): 2255 2204 """ 2256 2205 check if any of pinhole smear is changed … … 2263 2212 pin_max = self.smear_pinhole_max.GetValue() 2264 2213 2265 # Check changes in slit width 2214 # Check changes in slit width 2266 2215 try: 2267 2216 dx_min = float(pin_min) … … 2303 2252 2304 2253 get_pin_min = self.smear_pinhole_min 2305 get_pin_max = self.smear_pinhole_max 2254 get_pin_max = self.smear_pinhole_max 2306 2255 2307 2256 if not check_float(get_pin_min): 2308 2257 get_pin_min.SetBackgroundColour("pink") 2309 msg = "Model Error:wrong value entered!!!"2310 elif not check_float(get_pin_max 2258 msg = "Model Error:wrong value entered!!!" 2259 elif not check_float(get_pin_max): 2311 2260 get_pin_max.SetBackgroundColour("pink") 2312 msg = "Model Error:wrong value entered!!!"2261 msg = "Model Error:wrong value entered!!!" 2313 2262 else: 2314 if len_data < 2: len_data = 2 2263 if len_data < 2: 2264 len_data = 2 2315 2265 self.dx_min = float(get_pin_min.GetValue()) 2316 2266 self.dx_max = float(get_pin_max.GetValue()) 2317 2267 if self.dx_min < 0: 2318 2268 get_pin_min.SetBackgroundColour("pink") 2319 msg = "Model Error:This value can not be negative!!!"2320 elif self.dx_max < 0:2269 msg = "Model Error:This value can not be negative!!!" 2270 elif self.dx_max < 0: 2321 2271 get_pin_max.SetBackgroundColour("pink") 2322 msg = "Model Error:This value can not be negative!!!"2323 elif self.dx_min != None and self.dx_max != None: 2272 msg = "Model Error:This value can not be negative!!!" 2273 elif self.dx_min != None and self.dx_max != None: 2324 2274 if self._is_2D(): 2325 data.dqx_data[data.dqx_data ==0] = self.dx_min2326 data.dqy_data[data.dqy_data ==0] = self.dx_max2275 data.dqx_data[data.dqx_data == 0] = self.dx_min 2276 data.dqy_data[data.dqy_data == 0] = self.dx_max 2327 2277 elif self.dx_min == self.dx_max: 2328 data.dx[data.dx ==0] = self.dx_min2278 data.dx[data.dx == 0] = self.dx_min 2329 2279 else: 2330 step = (self.dx_max - self.dx_min)/(len_data-1) 2331 data.dx = numpy.arange(self.dx_min,self.dx_max+step/1.1, 2332 step) 2333 elif self.dx_min != None: 2334 if self._is_2D(): data.dqx_data[data.dqx_data==0] = self.dx_min 2335 else: data.dx[data.dx==0] = self.dx_min 2280 step = (self.dx_max - self.dx_min) / (len_data - 1) 2281 data.dx = numpy.arange(self.dx_min, 2282 self.dx_max + step / 1.1, 2283 step) 2284 elif self.dx_min != None: 2285 if self._is_2D(): 2286 data.dqx_data[data.dqx_data == 0] = self.dx_min 2287 else: 2288 data.dx[data.dx == 0] = self.dx_min 2336 2289 elif self.dx_max != None: 2337 if self._is_2D(): data.dqy_data[data.dqy_data==0] = self.dx_max 2338 else: data.dx[data.dx==0] = self.dx_max 2290 if self._is_2D(): 2291 data.dqy_data[data.dqy_data == 0] = self.dx_max 2292 else: 2293 data.dx[data.dx == 0] = self.dx_max 2339 2294 self.current_smearer = smear_selection(data, self.model) 2340 2295 # 2D need to set accuracy 2341 if self._is_2D(): 2342 self.current_smearer.set_accuracy(accuracy = \ 2343 self.smear2d_accuracy) 2296 if self._is_2D(): 2297 self.current_smearer.set_accuracy(accuracy=self.smear2d_accuracy) 2344 2298 2345 2299 if msg != None: 2346 wx.PostEvent(self._manager.parent, StatusEvent(status = msg))2300 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2347 2301 else: 2348 2302 get_pin_min.SetBackgroundColour("white") … … 2353 2307 fid=self.data.id, 2354 2308 qmin=float(self.qmin_x), 2355 qmax= 2309 qmax=float(self.qmax_x), 2356 2310 enable_smearer=not self.disable_smearer.GetValue(), 2357 2311 uid=self.uid) … … 2361 2315 """ 2362 2316 called by kill_focus on pinhole TextCntrl 2363 to update the changes 2317 to update the changes 2364 2318 2365 2319 :return: False when wrong value was entered … … 2370 2324 # check if any value is changed 2371 2325 if self._is_changed_pinhole(): 2372 msg = self._set_pinhole_smear() 2373 #self._undo.Enable(True) 2326 msg = self._set_pinhole_smear() 2374 2327 wx.CallAfter(self.save_current_state) 2375 2328 2376 2329 if msg != None: 2377 return False 2330 return False 2378 2331 else: 2379 2332 return True … … 2388 2341 if event == None: 2389 2342 return 2390 msg ="Please select a Model first..."2343 msg = "Please select a Model first..." 2391 2344 wx.MessageBox(msg, 'Info') 2392 wx.PostEvent(self._manager.parent, StatusEvent(status=\2393 "Smear: %s"%msg))2345 wx.PostEvent(self._manager.parent, 2346 StatusEvent(status="Smear: %s" % msg)) 2394 2347 return 2395 2348 … … 2401 2354 # for event given 2402 2355 if event != None: 2403 tcrtl = event.GetEventObject()2356 tcrtl = event.GetEventObject() 2404 2357 # event case of radio button 2405 2358 if tcrtl.GetValue(): … … 2410 2363 is_new_slit = self._is_changed_slit() 2411 2364 else: 2412 is_new_slit = True 2365 is_new_slit = True 2413 2366 2414 2367 # if any value is changed … … 2417 2370 2418 2371 # hide all silt sizer 2419 self._hide_all_smear_info() 2420 ##Calculate chi2 2421 #self.compute_chisqr(smearer= self.current_smearer) 2422 # show relevant slit sizers 2372 self._hide_all_smear_info() 2373 # show relevant slit sizers 2423 2374 self._show_smear_sizer() 2424 2375 self.sizer_set_smearer.Layout() … … 2426 2377 2427 2378 if event != None: 2428 event.Skip() 2429 #self._undo.Enable(True) 2379 event.Skip() 2430 2380 self.save_current_state() 2431 event = PageInfoEvent(page =self)2381 event = PageInfoEvent(page=self) 2432 2382 wx.PostEvent(self.parent, event) 2433 2383 if msg != None: 2434 wx.PostEvent(self._manager.parent, StatusEvent(status =msg))2435 2436 def _is_changed_slit(self): 2384 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2385 2386 def _is_changed_slit(self): 2437 2387 """ 2438 2388 check if any of slit lengths is changed … … 2445 2395 height = self.smear_slit_height.GetValue() 2446 2396 2447 # check and change the box bg color if it was pink 2397 # check and change the box bg color if it was pink 2448 2398 # but it should be white now 2449 2399 # because this is the case that _set_slit_smear() will not handle 2450 if height.lstrip().rstrip() =="":2400 if height.lstrip().rstrip() == "": 2451 2401 self.smear_slit_height.SetBackgroundColour(wx.WHITE) 2452 if width.lstrip().rstrip() =="":2402 if width.lstrip().rstrip() == "": 2453 2403 self.smear_slit_width.SetBackgroundColour(wx.WHITE) 2454 2404 2455 # Check changes in slit width 2456 if width == "": 2405 # Check changes in slit width 2406 if width == "": 2457 2407 dxw = 0.0 2458 2408 else: … … 2465 2415 2466 2416 # Check changes in slit heigth 2467 if height == "": 2417 if height == "": 2468 2418 dxl = 0.0 2469 2419 else: … … 2484 2434 of the values entered for slit smear 2485 2435 """ 2486 if self.data.__class__.__name__ == 2436 if self.data.__class__.__name__ == "Data2D" or \ 2487 2437 self.enable2D: 2488 2438 return 2489 temp_smearer = None2490 2439 # make sure once more if it is smearer 2491 2440 data = copy.deepcopy(self.data) … … 2498 2447 try: 2499 2448 self.dxl = float(self.smear_slit_height.GetValue()) 2500 data.dxl = self.dxl * numpy.ones(data_len)2449 data.dxl = self.dxl * numpy.ones(data_len) 2501 2450 self.smear_slit_height.SetBackgroundColour(wx.WHITE) 2502 except: 2451 except: 2503 2452 data.dxl = numpy.zeros(data_len) 2504 if self.smear_slit_height.GetValue().lstrip().rstrip() !="":2453 if self.smear_slit_height.GetValue().lstrip().rstrip() != "": 2505 2454 self.smear_slit_height.SetBackgroundColour("pink") 2506 msg = "Wrong value entered... " 2455 msg = "Wrong value entered... " 2507 2456 else: 2508 2457 self.smear_slit_height.SetBackgroundColour(wx.WHITE) … … 2510 2459 self.dxw = float(self.smear_slit_width.GetValue()) 2511 2460 self.smear_slit_width.SetBackgroundColour(wx.WHITE) 2512 data.dxw = self.dxw * numpy.ones(data_len)2513 except: 2461 data.dxw = self.dxw * numpy.ones(data_len) 2462 except: 2514 2463 data.dxw = numpy.zeros(data_len) 2515 if self.smear_slit_width.GetValue().lstrip().rstrip() !="":2464 if self.smear_slit_width.GetValue().lstrip().rstrip() != "": 2516 2465 self.smear_slit_width.SetBackgroundColour("pink") 2517 2466 msg = "Wrong Fit value entered... " … … 2520 2469 2521 2470 self.current_smearer = smear_selection(data, self.model) 2522 #temp_smearer = self.current_smearer2523 2471 ## set smearing value whether or not the data contain the smearing info 2524 self._manager.set_smearer(smearer=self.current_smearer, 2472 self._manager.set_smearer(smearer=self.current_smearer, 2525 2473 fid=self.data.id, 2526 qmin=float(self.qmin_x), 2527 qmax= 2474 qmin=float(self.qmin_x), 2475 qmax=float(self.qmax_x), 2528 2476 enable_smearer=not self.disable_smearer.GetValue(), 2529 uid=self.uid) 2477 uid=self.uid) 2530 2478 return msg 2531 2479 … … 2533 2481 """ 2534 2482 called by kill_focus on pinhole TextCntrl 2535 to update the changes 2483 to update the changes 2536 2484 2537 2485 :return: False when wrong value was entered 2538 2486 2539 """ 2487 """ 2540 2488 # msg default 2541 2489 msg = None 2542 2490 # check if any value is changed 2543 2491 if self._is_changed_slit(): 2544 msg = self._set_slit_smear() 2492 msg = self._set_slit_smear() 2545 2493 #self._undo.Enable(True) 2546 2494 self.save_current_state() 2547 2495 2548 2496 if msg != None: 2549 return False 2497 return False 2550 2498 else: 2551 2499 return True … … 2556 2504 are compute when fitting 2557 2505 """ 2558 if event != None: 2559 event.Skip() 2506 if event != None: 2507 event.Skip() 2560 2508 if self.data is None: 2561 2509 return … … 2565 2513 if event == None: 2566 2514 return 2567 msg ="Please select a Model first..."2515 msg = "Please select a Model first..." 2568 2516 wx.MessageBox(msg, 'Info') 2569 wx.PostEvent(self._manager.parent, StatusEvent(status=\2570 "Smear: %s"%msg))2517 wx.PostEvent(self._manager.parent, 2518 StatusEvent(status="Smear: %s" % msg)) 2571 2519 return 2572 2520 # Need update param values 2573 2521 self._update_paramv_on_fit() 2574 temp_smearer = self.on_smear_helper() 2522 temp_smearer = self.on_smear_helper() 2575 2523 2576 2524 self.sizer_set_smearer.Layout() … … 2579 2527 2580 2528 ## set smearing value whether or not the data contain the smearing info 2581 wx.CallAfter(self._manager.set_smearer, uid=self.uid, smearer=temp_smearer, 2582 fid=self.data.id, 2583 qmin=float(self.qmin_x), 2584 qmax=float(self.qmax_x), 2585 enable_smearer=not self.disable_smearer.GetValue(), 2586 draw=True) 2587 2588 self.state.enable_smearer= self.enable_smearer.GetValue() 2589 self.state.disable_smearer=self.disable_smearer.GetValue() 2529 wx.CallAfter(self._manager.set_smearer, uid=self.uid, 2530 smearer=temp_smearer, 2531 fid=self.data.id, 2532 qmin=float(self.qmin_x), 2533 qmax=float(self.qmax_x), 2534 enable_smearer=not self.disable_smearer.GetValue(), 2535 draw=True) 2536 2537 self.state.enable_smearer = self.enable_smearer.GetValue() 2538 self.state.disable_smearer = self.disable_smearer.GetValue() 2590 2539 self.state.pinhole_smearer = self.pinhole_smearer.GetValue() 2591 2540 self.state.slit_smearer = self.slit_smearer.GetValue() … … 2598 2547 """ 2599 2548 self._get_smear_info() 2600 temp_smearer = None2601 2549 #renew smear sizer 2602 2550 if self.smear_type != None: 2603 2551 self.smear_description_smear_type.SetValue(str(self.smear_type)) 2604 self.smear_data_left.SetValue(str(self.dq_l)) 2605 self.smear_data_right.SetValue(str(self.dq_r)) 2552 self.smear_data_left.SetValue(str(self.dq_l)) 2553 self.smear_data_right.SetValue(str(self.dq_r)) 2606 2554 2607 2555 self._hide_all_smear_info() … … 2613 2561 self.current_smearer = temp_smearer 2614 2562 if self.enable_smearer.GetValue(): 2615 if hasattr(self.data,"dxl"): 2616 msg= ": Resolution smearing parameters" 2617 if hasattr(self.data,"dxw"): 2618 msg= ": Slit smearing parameters" 2619 if self.current_smearer ==None: 2620 wx.PostEvent(self._manager.parent, StatusEvent(status=\ 2621 "Data contains no smearing information")) 2563 if self.current_smearer == None: 2564 wx.PostEvent(self._manager.parent, 2565 StatusEvent(status="Data contains no smearing information")) 2622 2566 else: 2623 wx.PostEvent(self._manager.parent, StatusEvent(status=\ 2624 "Data contains smearing information")) 2625 2626 #self.smear_description_dqdata.Show(True) 2567 wx.PostEvent(self._manager.parent, 2568 StatusEvent(status="Data contains smearing information")) 2569 2627 2570 self.smear_data_left.Show(True) 2628 2571 self.smear_data_right.Show(True) 2629 temp_smearer = self.current_smearer2572 temp_smearer = self.current_smearer 2630 2573 elif self.disable_smearer.GetValue(): 2631 2574 self.smear_description_none.Show(True) … … 2638 2581 return temp_smearer 2639 2582 2640 def on_complete_chisqr(self, event): 2583 def on_complete_chisqr(self, event): 2641 2584 """ 2642 2585 Display result chisqr on the panel … … 2645 2588 try: 2646 2589 if event == None: 2647 output = "-"2590 output = "-" 2648 2591 elif not numpy.isfinite(event.output): 2649 output = "-"2592 output = "-" 2650 2593 else: 2651 2594 output = event.output … … 2653 2596 self.state.tcChi = self.tcChi.GetValue() 2654 2597 except: 2655 pass 2598 pass 2656 2599 2657 2658 2600 def get_all_checked_params(self): 2659 2601 """ 2660 Found all parameters current check and add them to list of parameters to 2602 Found all parameters current check and add them to list of parameters to 2661 2603 fit 2662 2604 """ … … 2668 2610 if item[0].GetValue() and item not in self.param_toFit: 2669 2611 self.param_toFit.append(item) 2670 self.save_current_state_fit() 2612 self.save_current_state_fit() 2671 2613 2672 2614 2673 event = PageInfoEvent(page =self)2674 wx.PostEvent(self.parent, event) 2615 event = PageInfoEvent(page=self) 2616 wx.PostEvent(self.parent, event) 2675 2617 param2fit = [] 2676 2618 for item in self.param_toFit: 2677 2619 if item[0]: 2678 param2fit.append(item[1]) 2620 param2fit.append(item[1]) 2679 2621 self.parent._manager.set_param2fit(self.uid, param2fit) 2680 2622 2681 def select_all_param(self, event): 2623 def select_all_param(self, event): 2682 2624 """ 2683 2625 set to true or false all checkBox given the main checkbox value cb1 2684 """ 2626 """ 2685 2627 self.param_toFit = [] 2686 2628 if self.parameters !=[]: … … 2688 2630 for item in self.parameters: 2689 2631 ## for data2D select all to fit 2690 if self.data.__class__.__name__ == "Data2D" or \2632 if self.data.__class__.__name__ == "Data2D" or \ 2691 2633 self.enable2D: 2692 2634 item[0].SetValue(True) … … 2696 2638 if not item in self.orientation_params: 2697 2639 item[0].SetValue(True) 2698 self.param_toFit.append(item 2640 self.param_toFit.append(item) 2699 2641 #if len(self.fittable_param)>0: 2700 2642 for item in self.fittable_param: 2701 if self.data.__class__.__name__ == "Data2D" or \2643 if self.data.__class__.__name__ == "Data2D" or \ 2702 2644 self.enable2D: 2703 2645 item[0].SetValue(True) … … 2713 2655 if not item in self.orientation_params_disp: 2714 2656 item[0].SetValue(True) 2715 self.param_toFit.append(item 2657 self.param_toFit.append(item) 2716 2658 try: 2717 2659 if len(self.values[item[1]]) > 0: … … 2725 2667 for item in self.fittable_param: 2726 2668 item[0].SetValue(False) 2727 self.param_toFit =[]2669 self.param_toFit = [] 2728 2670 2729 self.save_current_state_fit() 2671 self.save_current_state_fit() 2730 2672 2731 if event != None:2673 if event != None: 2732 2674 #self._undo.Enable(True) 2733 2675 ## post state to fit panel 2734 event = PageInfoEvent(page =self)2735 wx.PostEvent(self.parent, event) 2676 event = PageInfoEvent(page=self) 2677 wx.PostEvent(self.parent, event) 2736 2678 param2fit = [] 2737 2679 for item in self.param_toFit: 2738 2680 if item[0]: 2739 param2fit.append(item[1]) 2681 param2fit.append(item[1]) 2740 2682 self.parent._manager.set_param2fit(self.uid, param2fit) 2741 2683 2742 2743 2684 def select_param(self,event): 2744 2685 """ … … 2756 2697 if item[0].GetValue(): 2757 2698 if not (item in self.param_toFit): 2758 self.param_toFit.append(item )2699 self.param_toFit.append(item) 2759 2700 else: 2760 2701 #remove parameters from the fitting list … … 2762 2703 self.param_toFit.remove(item) 2763 2704 2764 #Select parameters to fit for list of fittable parameters 2765 # with dispersion 2705 #Select parameters to fit for list of fittable parameters 2706 # with dispersion 2766 2707 for item in self.fittable_param: 2767 2708 #Skip t ifhe angle parameters if 1D data 2768 if self.data.__class__.__name__ != 2709 if self.data.__class__.__name__ != "Data2D" and\ 2769 2710 not self.enable2D: 2770 2711 if item in self.orientation_params: … … 2772 2713 if item[0].GetValue(): 2773 2714 if not (item in self.param_toFit): 2774 self.param_toFit.append(item) 2715 self.param_toFit.append(item) 2775 2716 else: 2776 2717 #remove parameters from the fitting list … … 2778 2719 self.param_toFit.remove(item) 2779 2720 2780 #Calculate num. of angle parameters 2781 if self.data.__class__.__name__ == 2721 #Calculate num. of angle parameters 2722 if self.data.__class__.__name__ == "Data2D" or \ 2782 2723 self.enable2D: 2783 2724 len_orient_para = 0 2784 2725 else: 2785 len_orient_para = len(self.orientation_params) # assume even len2726 len_orient_para = len(self.orientation_params) # assume even len 2786 2727 #Total num. of angle parameters 2787 2728 if len(self.fittable_param) > 0: 2788 2729 len_orient_para *= 2 2789 #Set the value of checkbox that selected every checkbox or not 2790 if len(self.parameters) +len(self.fittable_param)-len_orient_para ==\2730 #Set the value of checkbox that selected every checkbox or not 2731 if len(self.parameters) + len(self.fittable_param) - len_orient_para ==\ 2791 2732 len(self.param_toFit): 2792 2733 self.cb1.SetValue(True) … … 2794 2735 self.cb1.SetValue(False) 2795 2736 2796 2797 2798 2737 self.save_current_state_fit() 2799 if event !=None: 2800 #self._undo.Enable(True) 2738 if event != None: 2801 2739 ## post state to fit panel 2802 event = PageInfoEvent(page =self)2803 wx.PostEvent(self.parent, event) 2740 event = PageInfoEvent(page=self) 2741 wx.PostEvent(self.parent, event) 2804 2742 2805 2743 param2fit = [] 2806 2744 for item in self.param_toFit: 2807 2745 if item[0]: 2808 param2fit.append(item[1]) 2746 param2fit.append(item[1]) 2809 2747 self.parent._manager.set_param2fit(self.uid, param2fit) 2810 2748 … … 2819 2757 self.parameters = [] 2820 2758 self.str_parameters = [] 2821 self.param_toFit =[]2822 self.fittable_param =[]2823 self.fixed_param =[]2824 self.orientation_params =[]2825 self.orientation_params_disp =[]2826 2827 if model == None:2759 self.param_toFit = [] 2760 self.fittable_param = [] 2761 self.fixed_param = [] 2762 self.orientation_params = [] 2763 self.orientation_params_disp = [] 2764 2765 if model == None: 2828 2766 self.sizer3.Layout() 2829 2767 self.SetupScrolling() 2830 2768 return 2831 2769 ## the panel is drawn using the current value of the fit engine 2832 if self.engine_type==None and self._manager != None:2770 if self.engine_type==None and self._manager != None: 2833 2771 self.engine_type= self._manager._return_engine_type() 2834 2772
Note: See TracChangeset
for help on using the changeset viewer.