Changeset 7609f1a in sasview
- Timestamp:
- Mar 26, 2010 3:50:29 PM (15 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 83ad478
- Parents:
- c6036f5
- Location:
- sansview/perspectives/fitting
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/basepage.py
r2f189dc r7609f1a 172 172 if set_focus_callback is None else set_focus_callback 173 173 self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus) 174 self.Bind(wx.EVT_KILL_FOCUS, parent._onparamEnter\174 self.Bind(wx.EVT_KILL_FOCUS, self._silent_kill_focus \ 175 175 if kill_focus_callback is None else kill_focus_callback) 176 176 self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter \ … … 210 210 if start==end: 211 211 control.SetSelection(-1,-1) 212 212 213 def _silent_kill_focus(self,event): 214 """ 215 do nothing to kill focus 216 """ 217 event.Skip() 218 pass 219 213 220 def set_page_info(self, page_info): 214 221 """ … … 318 325 self.event_owner = owner 319 326 self.state.event_owner = owner 320 327 321 328 def get_data(self): 322 329 """ 323 330 return the current data 324 331 """ 325 return self.data 332 return self.data 333 326 334 def set_manager(self, manager): 327 335 """ … … 664 672 self.state.enable_smearer = copy.deepcopy(self.enable_smearer.GetValue()) 665 673 self.state.disable_smearer = copy.deepcopy(self.disable_smearer.GetValue()) 666 674 675 self.state.pinhole_smearer = copy.deepcopy(self.pinhole_smearer.GetValue()) 676 self.state.slit_smearer = copy.deepcopy(self.slit_smearer.GetValue()) 677 667 678 if hasattr(self,"disp_box"): 668 679 self.state.disp_box = self.disp_box.GetCurrentSelection() … … 744 755 self.state.enable_smearer = copy.deepcopy(self.enable_smearer.GetValue()) 745 756 self.state.disable_smearer = copy.deepcopy(self.disable_smearer.GetValue()) 757 758 self.state.pinhole_smearer = copy.deepcopy(self.pinhole_smearer.GetValue()) 759 self.state.slit_smearer = copy.deepcopy(self.slit_smearer.GetValue()) 746 760 747 761 if hasattr(self,"disp_box"): … … 897 911 self.disable_smearer.SetValue(state.disable_smearer) 898 912 self.onSmear(event=None) 913 self.pinhole_smearer.SetValue(state.pinhole_smearer) 914 self.slit_smearer.SetValue(state.slit_smearer) 915 ## we have two more options for smearing 916 if self.pinhole_smearer.GetValue(): self.onPinholeSmear(event=None) 917 elif self.slit_smearer.GetValue(): self.onSlitSmear(event=None) 899 918 900 919 ## reset state of checkbox,textcrtl and dispersity parameters value … … 1033 1052 """ 1034 1053 #flag for qmin qmax check values 1035 flag = False1054 flag = True 1036 1055 is_modified = False 1037 1056 ##So make sure that update param values on_Fit. … … 1054 1073 if tempmax != self.qmax_x: 1055 1074 self.qmax_x = tempmax 1056 flag = True 1057 else: 1058 flag = False 1059 else: 1075 if tempmax == tempmin: 1076 flag = False 1077 temp_smearer = None 1078 if not self.disable_smearer.GetValue(): 1079 temp_smearer= self.current_smearer 1080 if self.slit_smearer.GetValue(): 1081 flag = self.update_slit_smear() 1082 elif self.pinhole_smearer.GetValue(): 1083 flag = self.update_pinhole_smear() 1084 else: 1085 self.manager.set_smearer(smearer=temp_smearer, qmin= float(self.qmin_x), 1086 qmax= float(self.qmax_x)) 1087 elif self.data.__class__.__name__ !="Data2D": 1088 self.manager.set_smearer(smearer=temp_smearer, qmin= float(self.qmin_x), 1089 qmax= float(self.qmax_x)) 1090 else: flag = False 1091 else: 1060 1092 flag = False 1061 msg= "Cannot Fit :Must select a model!!! " 1093 1094 if not flag: 1095 msg= "Cannot Fit :Must select a model or Fitting range is not valid!!! " 1062 1096 wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) 1063 1097 1098 self.save_current_state() 1064 1099 return flag 1065 1100 … … 1292 1327 temp_smear=None 1293 1328 if hasattr(self, "enable_smearer"): 1294 if self.enable_smearer.GetValue():1295 temp_smear= self. smearer1329 if not self.disable_smearer.GetValue(): 1330 temp_smear= self.current_smearer 1296 1331 1297 1332 self.manager.draw_model(self.model, data=self.data, … … 1449 1484 1450 1485 return 0 1451 1452 def _onparamEnter(self,event):1486 1487 #def _onparamEnter(self,event): 1453 1488 """ 1454 when enter value on panel redraw model according to changed 1489 #when enter value on panel redraw model according to changed 1490 """ 1455 1491 """ 1456 1492 tcrtl= event.GetEventObject() … … 1476 1512 #event.Skip() 1477 1513 return 1478 1514 """ 1479 1515 def _onQrangeEnter(self, event): 1480 1516 """ … … 1599 1635 qmin = float(qmin_ctrl.GetValue()) 1600 1636 qmax = float(qmax_ctrl.GetValue()) 1601 if qmin < qmax:1637 if qmin <= qmax: 1602 1638 #Make sure to set both colours white. 1603 1639 qmin_ctrl.SetBackgroundColour(wx.WHITE) … … 1946 1982 1947 1983 self.qmin = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20),style=wx.TE_PROCESS_ENTER, 1948 kill_focus_callback = self._onQrangeEnter, 1949 text_enter_callback = self._onQrangeEnter) 1984 text_enter_callback = self._onparamEnter) 1950 1985 self.qmin.SetValue(str(self.qmin_x)) 1951 1986 self.qmin.SetToolTipString("Minimun value of Q in linear scale.") 1952 1987 1953 1988 self.qmax = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20),style=wx.TE_PROCESS_ENTER, 1954 kill_focus_callback = self._onQrangeEnter, 1955 text_enter_callback = self._onQrangeEnter) 1989 text_enter_callback = self._onparamEnter) 1956 1990 self.qmax.SetValue(str(self.qmax_x)) 1957 1991 self.qmax.SetToolTipString("Maximum value of Q in linear scale.") … … 2037 2071 #On 'Reset' button for Q range clicked 2038 2072 """ 2073 flag = True 2039 2074 if self.check_invalid_panel(): 2040 2075 return … … 2049 2084 self.qmin_x = min(self.data.x) 2050 2085 self.qmax_x = max(self.data.x) 2086 # check smearing 2087 if not self.disable_smearer.GetValue(): 2088 temp_smearer= self.current_smearer 2089 ## set smearing value whether or not the data contain the smearing info 2090 if self.slit_smearer.GetValue(): 2091 flag = self.update_slit_smear() 2092 elif self.pinhole_smearer.GetValue(): 2093 flag = self.update_pinhole_smear() 2094 else: 2095 flag = True 2051 2096 else: 2052 2097 self.qmin_x = _QMIN_DEFAULT … … 2055 2100 self.state.npts = self.num_points 2056 2101 2057 2102 if flag == False: 2103 msg= "Cannot Plot :Must enter a number!!! " 2104 wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) 2105 2106 self.save_current_state() 2058 2107 self.state.qmin = self.qmin_x 2059 2108 self.state.qmax = self.qmax_x -
sansview/perspectives/fitting/fitpage.py
r00e8df8 r7609f1a 9 9 import time 10 10 from sans.models.dispersion_models import ArrayDispersion, GaussianDispersion 11 11 from DataLoader.data_info import Data1D 12 12 from sans.guicomm.events import StatusEvent 13 13 from sans.guiframe.utils import format_number,check_float 14 14 15 15 ## event to post model to fit to fitting plugins 16 16 (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() … … 21 21 _BOX_WIDTH = 76 22 22 _DATA_BOX_WIDTH = 300 23 SMEAR_SIZE_L = 0.005 24 SMEAR_SIZE_H = 0.01 25 23 26 import basepage 24 27 from basepage import BasicPage … … 47 50 ## default fitengine type 48 51 self.engine_type = None 52 ## smear default 53 self.smearer = None 54 self.current_smearer = None 55 self.dxl = None 56 self.dxw = None 57 self.dx_min = None 58 self.dx_max = None 49 59 50 60 ## draw sizer 51 61 self._fill_datainfo_sizer() 52 62 63 # get smear info from data 64 self._get_smear_info() 65 53 66 self._fill_model_sizer( self.sizer1) 54 67 68 self._get_defult_custom_smear() 69 55 70 self._fill_range_sizer() 56 self.enable_smearer.Disable() 57 self.disable_smearer.Disable() 71 58 72 if self.data is None: 59 73 self.formfactorbox.Disable() 60 74 self.structurebox.Disable() 61 75 else: 62 self.smearer = smear_selection( self.data)76 self.smearer = smear_selection( self.data ) 63 77 if self.smearer ==None: 64 78 self.enable_smearer.Disable() 65 self.disable_smearer.Disable() 79 #self.disable_smearer.Disable() 80 66 81 self.disp_cb_dict = {} 67 82 ## to update the panel according to the fit engine type selected … … 155 170 """ 156 171 title = "Fitting" 172 #smear messages & titles 173 smear_message_none = "No smearing is selected..." 174 smear_message_dqdata = "The dQ data is being used for smearing..." 175 smear_message_2d = "No smearing is supported for 2D model fitting..." 176 smear_message_new_ssmear = "Please enter only the value of interest to customize smearing..." 177 smear_message_new_psmear = "Please enter both; the dQ will be generated by interpolation..." 178 smear_message_pinhole_min_title = "dQ_min[1/A]:" 179 smear_message_pinhole_max_title = "dQ_max[1/A]:" 180 smear_message_slit_height_title = "Slit height[1/A]:" 181 smear_message_slit_width_title = "Slit width[1/A]:" 182 183 self._get_smear_info() 184 157 185 box_description_range = wx.StaticBox(self, -1,str(title)) 158 186 boxsizer_range = wx.StaticBoxSizer(box_description_range, wx.VERTICAL) … … 166 194 167 195 sizer_fit.Add((5,5),1, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 168 sizer_fit.Add(self.btFit,0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 35)196 sizer_fit.Add(self.btFit,0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 63) 169 197 sizer_fit.Layout() 198 self.sizer_set_smearer = wx.BoxSizer(wx.VERTICAL) 170 199 sizer_smearer = wx.BoxSizer(wx.HORIZONTAL) 200 self.sizer_new_smear= wx.BoxSizer(wx.HORIZONTAL) 201 self.sizer_set_masking = wx.BoxSizer(wx.HORIZONTAL) 202 sizer_chi2 = wx.BoxSizer(wx.VERTICAL) 203 smear_set_box= wx.StaticBox(self, -1,'Set Instrumental Smearing') 204 sizer_smearer_box = wx.StaticBoxSizer(smear_set_box, wx.HORIZONTAL) 205 sizer_smearer_box.SetMinSize((_DATA_BOX_WIDTH,85)) 206 207 #textcntrl for new resolution 208 self.smear_pinhole_max = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH-20,20),style=wx.TE_PROCESS_ENTER, 209 text_enter_callback = self.onPinholeSmear) 210 self.smear_pinhole_min = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH-20,20),style=wx.TE_PROCESS_ENTER, 211 text_enter_callback = self.onPinholeSmear) 212 self.smear_slit_height= self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH-20,20),style=wx.TE_PROCESS_ENTER, 213 text_enter_callback = self.onSlitSmear) 214 self.smear_slit_width = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH-20,20),style=wx.TE_PROCESS_ENTER, 215 text_enter_callback = self.onSlitSmear) 216 self.smear_data_left= BGTextCtrl(self, -1, size=(_BOX_WIDTH-20,20), style=0) 217 self.smear_data_left.SetValue(str(self.dq_l)) 218 self.smear_data_right = BGTextCtrl(self, -1, size=(_BOX_WIDTH-20,20), style=0) 219 self.smear_data_right.SetValue(str(self.dq_r)) 220 221 #set default values 222 self.smear_pinhole_max.SetValue(str(self.dx_max)) 223 self.smear_pinhole_min.SetValue(str(self.dx_min)) 224 self.smear_slit_height.SetValue(str(self.dxl)) 225 self.smear_slit_width.SetValue(str(self.dxw)) 226 171 227 #Filling the sizer containing instruments smearing info. 172 self.disable_smearer = wx.RadioButton(self, -1, 'No', style=wx.RB_GROUP) 173 self.enable_smearer = wx.RadioButton(self, -1, 'Yes') 228 self.disable_smearer = wx.RadioButton(self, -1, 'None', style=wx.RB_GROUP) 229 self.enable_smearer = wx.RadioButton(self, -1, 'Use dQ Data') 230 #self.enable_smearer.SetToolTipString("Click to use the loaded dQ data for smearing.") 231 self.pinhole_smearer = wx.RadioButton(self, -1, 'Custom Pinhole Smear') 232 #self.pinhole_smearer.SetToolTipString("Click to input custom resolution for pinhole smearing.") 233 self.slit_smearer = wx.RadioButton(self, -1, 'Custom Slit Smear') 234 #self.slit_smearer.SetToolTipString("Click to input custom resolution for slit smearing.") 174 235 self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.disable_smearer.GetId()) 175 236 self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.enable_smearer.GetId()) 237 self.Bind(wx.EVT_RADIOBUTTON, self.onPinholeSmear, id=self.pinhole_smearer.GetId()) 238 self.Bind(wx.EVT_RADIOBUTTON, self.onSlitSmear, id=self.slit_smearer.GetId()) 176 239 self.disable_smearer.SetValue(True) 177 240 178 sizer_smearer.Add(wx.StaticText(self,-1,'Instrument Smearing? ')) 179 sizer_smearer.Add((10, 10)) 180 sizer_smearer.Add( self.enable_smearer ) 241 # add 4 types of smearing to the sizer 242 sizer_smearer.Add( self.disable_smearer,0, wx.LEFT, 10) 181 243 sizer_smearer.Add((10,10)) 182 sizer_smearer.Add( self.disable_smearer ) 183 #Display Chi^2/dof 184 sizer_smearer.Add((78,10)) 244 sizer_smearer.Add( self.enable_smearer) 245 sizer_smearer.Add((10,10)) 246 sizer_smearer.Add( self.pinhole_smearer ) 247 sizer_smearer.Add((10,10)) 248 sizer_smearer.Add( self.slit_smearer ) 249 sizer_smearer.Add((10,10)) 250 251 # static box for chi2 185 252 box_description= wx.StaticBox(self, -1,'Chi2/dof') 186 253 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 187 boxsizer1.SetMinSize(( 80,-1))188 temp_smearer = None189 if self.enable_smearer.GetValue():190 temp_smearer= self.smearer191 254 boxsizer1.SetMinSize((70,40)) 255 256 257 258 # StaticText for chi2 and smear 192 259 self.tcChi = wx.StaticText(self, -1, "-", style=wx.ALIGN_LEFT) 193 194 boxsizer1.Add( self.tcChi ) 195 sizer_smearer.Add( boxsizer1 ) 196 260 self.smear_description_none = wx.StaticText(self, -1, smear_message_none , style=wx.ALIGN_LEFT) 261 self.smear_description_dqdata = wx.StaticText(self, -1, smear_message_dqdata , style=wx.ALIGN_LEFT) 262 self.smear_description_type = wx.StaticText(self, -1, "Type:" , style=wx.ALIGN_LEFT) 263 self.smear_description_smear_type = BGTextCtrl(self, -1, size=(45,20), style=0) 264 self.smear_description_smear_type.SetValue(str(self.dq_l)) 265 self.SetBackgroundColour(self.GetParent().GetBackgroundColour()) 266 self.smear_description_2d = wx.StaticText(self, -1, smear_message_2d , style=wx.ALIGN_LEFT) 267 self.smear_message_new_s = wx.StaticText(self, -1, smear_message_new_ssmear , style=wx.ALIGN_LEFT) 268 self.smear_message_new_p = wx.StaticText(self, -1, smear_message_new_psmear , style=wx.ALIGN_LEFT) 269 self.smear_description_pin_min = wx.StaticText(self, -1, smear_message_pinhole_min_title , style=wx.ALIGN_LEFT) 270 self.smear_description_pin_max = wx.StaticText(self, -1, smear_message_pinhole_max_title , style=wx.ALIGN_LEFT) 271 self.smear_description_slit_height = wx.StaticText(self, -1, smear_message_slit_height_title , style=wx.ALIGN_LEFT) 272 self.smear_description_slit_width = wx.StaticText(self, -1, smear_message_slit_width_title , style=wx.ALIGN_LEFT) 273 274 #arrange sizers 275 boxsizer1.Add( self.tcChi ) 276 self.sizer_set_smearer.Add(sizer_smearer ) 277 self.sizer_set_smearer.Add((10,10)) 278 self.sizer_set_smearer.Add( self.smear_description_none,0, wx.CENTER, 10 ) 279 self.sizer_set_smearer.Add( self.smear_description_dqdata,0, wx.CENTER, 10 ) 280 self.sizer_set_smearer.Add( self.smear_description_2d,0, wx.CENTER, 10 ) 281 self.sizer_new_smear.Add( self.smear_description_type,0, wx.CENTER, 10 ) 282 self.sizer_new_smear.Add( self.smear_description_smear_type,0, wx.CENTER, 10 ) 283 self.sizer_new_smear.Add((15,-1)) 284 self.sizer_new_smear.Add( self.smear_description_pin_min,0, wx.CENTER, 10 ) 285 self.sizer_new_smear.Add( self.smear_description_slit_height,0, wx.CENTER, 10 ) 286 self.sizer_new_smear.Add( self.smear_pinhole_min,0, wx.CENTER, 10 ) 287 self.sizer_new_smear.Add( self.smear_slit_height,0, wx.CENTER, 10 ) 288 self.sizer_new_smear.Add( self.smear_data_left,0, wx.CENTER, 10 ) 289 self.sizer_new_smear.Add((20,-1)) 290 self.sizer_new_smear.Add( self.smear_description_pin_max,0, wx.CENTER, 10 ) 291 self.sizer_new_smear.Add( self.smear_description_slit_width,0, wx.CENTER, 10 ) 292 self.sizer_new_smear.Add( self.smear_pinhole_max,0, wx.CENTER, 10 ) 293 self.sizer_new_smear.Add( self.smear_slit_width,0, wx.CENTER, 10 ) 294 self.sizer_new_smear.Add( self.smear_data_right,0, wx.CENTER, 10 ) 295 296 self.sizer_set_smearer.Add( self.smear_message_new_s,0, wx.CENTER, 10) 297 self.sizer_set_smearer.Add( self.smear_message_new_p,0, wx.CENTER, 10) 298 self.sizer_set_smearer.Add((5,2)) 299 self.sizer_set_smearer.Add( self.sizer_new_smear,0, wx.CENTER, 10 ) 300 301 # add all to chi2 sizer 302 303 sizer_smearer_box.Add(self.sizer_set_smearer) 304 305 sizer_chi2.Add(sizer_smearer_box) 306 sizer_chi2.Add((-1,5)) 307 self.sizer_set_masking.Add((305,-1)) 308 self.sizer_set_masking.Add(boxsizer1,0, wx.RIGHT, 10) 309 sizer_chi2.Add(self.sizer_set_masking ) 310 311 #sizer_smearer_box.Add(sizer_chi2) 312 # hide all smear messages and textctrl 313 self._hide_all_smear_info() 314 315 # get smear_selection 316 self.current_smearer= smear_selection( self.data ) 317 print "self.current_smearer",self.current_smearer,self.data.__class__.__name__ 318 # Show only the relevant smear messages, etc 319 if self.current_smearer == None: 320 if self.data.__class__.__name__ != 'Data2D': 321 self.smear_description_none.Show(True) 322 self.enable_smearer.Disable() 323 else: 324 print "2dl" 325 self.smear_description_2d.Show(True) 326 self.pinhole_smearer.Disable() 327 self.slit_smearer.Disable() 328 self.enable_smearer.Disable() 329 else: self._show_smear_sizer() 330 331 197 332 #Set sizer for Fitting section 198 self._set_range_sizer( title=title,box_sizer=boxsizer_range, object1=sizer_ smearer, object= sizer_fit)199 333 self._set_range_sizer( title=title,box_sizer=boxsizer_range, object1=sizer_chi2, object= sizer_fit) 334 200 335 def _fill_datainfo_sizer(self): 201 336 """ … … 229 364 #Filling the sizer containing data related fields 230 365 #self.dataSource = wx.StaticText(self, -1,str(self.data.name)) 231 self.dataSource = wx.TextCtrl(self, -1)366 self.dataSource = BGTextCtrl(self, -1) 232 367 self.dataSource.SetValue(str(data_name)) 233 self.dataSource.SetEditable(False)368 #self.dataSource.SetEditable(False) 234 369 self.dataSource.SetMinSize((_DATA_BOX_WIDTH, -1)) 235 370 sizer_data.Add(wx.StaticText(self, -1, 'Source Name : ')) … … 242 377 sizer_range = wx.BoxSizer(wx.HORIZONTAL) 243 378 sizer_range.Add( text4_3 ,0, wx.RIGHT, 10) 244 self.minimum_q = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20))379 self.minimum_q = BGTextCtrl(self, -1, size=(_BOX_WIDTH,20)) 245 380 self.minimum_q.SetValue(str(data_min)) 246 self.minimum_q.SetEditable(False)247 self.maximum_q = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))381 #self.minimum_q.SetEditable(False) 382 self.maximum_q = BGTextCtrl(self, -1,size=(_BOX_WIDTH,20)) 248 383 self.maximum_q.SetValue(str(data_max)) 249 self.maximum_q.SetEditable(False)384 #self.maximum_q.SetEditable(False) 250 385 sizer_range.Add(wx.StaticText(self, -1, "Min: "),0, wx.LEFT, 10) 251 386 sizer_range.Add(self.minimum_q,0, wx.LEFT, 10) … … 388 523 ix = 4 389 524 ctl3 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, 390 kill_focus_callback = self._onparamRangeEnter,391 525 text_enter_callback = self._onparamRangeEnter) 392 526 … … 396 530 ix = 5 397 531 ctl4 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, 398 kill_focus_callback = self._onparamRangeEnter,399 532 text_enter_callback = self._onparamRangeEnter) 400 533 self.sizer4_4.Add(ctl4, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) … … 487 620 ix = 4 488 621 ctl3 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, 489 kill_focus_callback = self._onparamRangeEnter,490 622 text_enter_callback = self._onparamRangeEnter) 491 623 … … 496 628 ix = 5 497 629 ctl4 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, 498 kill_focus_callback = self._onparamRangeEnter,499 630 text_enter_callback = self._onparamRangeEnter) 500 631 self.sizer4_4.Add(ctl4, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) … … 584 715 585 716 if not flag: 586 msg= "Fitting range invalid"717 msg= "Fitting range or parameters are invalid" 587 718 wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) 588 719 return … … 663 794 self.state.enable_disp = self.enable_disp.GetValue() 664 795 self.state.disable_disp = self.disable_disp.GetValue() 796 self.state.pinhole_smearer = self.pinhole_smearer.GetValue() 797 self.state.slit_smearer = self.slit_smearer.GetValue() 665 798 666 799 self.state.structurecombobox = self.structurebox.GetCurrentSelection() … … 687 820 688 821 if check_float(tcrtl): 689 flag = self._onparamEnter_helper() 690 if flag: 691 temp_smearer = None 692 if self.enable_smearer.GetValue(): 693 temp_smearer= self.smearer 822 flag = self._onparamEnter_helper() 823 temp_smearer = None 824 if not self.disable_smearer.GetValue(): 825 temp_smearer= self.current_smearer 826 ## set smearing value whether or not the data contain the smearing info 827 if self.slit_smearer.GetValue(): 828 flag1 = self.update_slit_smear() 829 flag = flag or flag1 830 elif self.pinhole_smearer.GetValue(): 831 flag1 = self.update_pinhole_smear() 832 flag = flag or flag1 833 else: 834 self.manager.set_smearer(smearer=temp_smearer, qmin= float(self.qmin_x), 835 qmax= float(self.qmax_x)) 836 if flag: 694 837 self.compute_chisqr(smearer= temp_smearer) 695 838 … … 699 842 event = PageInfoEvent(page = self) 700 843 wx.PostEvent(self.parent, event) 701 self.state_change= False 702 self.save_current_state() 844 self.state_change= False 703 845 else: 704 846 self.save_current_state() 705 847 msg= "Cannot Plot :Must enter a number!!! " 706 848 wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) 707 return 708 709 849 850 self.save_current_state() 851 return 852 710 853 def _onparamRangeEnter(self, event): 711 854 """ … … 841 984 return 842 985 986 def _get_defult_custom_smear(self): 987 """ 988 Get the defult values for custum smearing. 989 """ 990 991 # get the default values 992 if self.dxl == None: self.dxl = 0.0 993 if self.dxw == None: self.dxw = "" 994 if self.dx_min == None: self.dx_min = SMEAR_SIZE_L 995 if self.dx_max == None: self.dx_max = SMEAR_SIZE_H 996 997 def _get_smear_info(self): 998 """ 999 Get the smear info from data. 1000 @return: self.smear_type, self.dq_l and self.dq_r, 1001 respectively the type of the smear, dq_min and dq_max for pinhole smear data 1002 while dxl and dxw for slit smear 1003 """ 1004 1005 # default 1006 self.smear_type = None 1007 self.dq_l = None 1008 self.dq_r = None 1009 1010 if self.data is None or\ 1011 self.data.__class__.__name__ == 'Data2D': 1012 return 1013 1014 data = self.data 1015 1016 # check if it is pinhole smear and get min max if it is. 1017 if data.dx != None and all(data.dx !=0): 1018 self.smear_type = "Pinhole" 1019 self.dq_l = numpy.min(data.dx) 1020 self.dq_r = numpy.max(data.dx) 1021 1022 # check if it is slit smear and get min max if it is. 1023 elif data.dxl != None or data.dxw != None: 1024 self.smear_type = "Slit" 1025 if data.dxl != None and all(data.dxl !=0): 1026 self.dq_l = data.dxl[0] 1027 if data.dxw != None and all(data.dxw !=0): 1028 self.dq_r = data.dxw[0] 1029 1030 #return self.smear_type,self.dq_l,self.dq_r 1031 1032 def _show_smear_sizer(self): 1033 """ 1034 Show only the sizers depending on smear selection 1035 """ 1036 if self.disable_smearer.GetValue(): 1037 self.smear_description_none.Show(True) 1038 elif self.enable_smearer.GetValue(): 1039 self.smear_description_dqdata.Show(True) 1040 if self.smear_type != None: 1041 self.smear_description_type.Show(True) 1042 self.smear_description_smear_type.Show(True) 1043 if self.smear_type == 'Slit': 1044 self.smear_description_slit_height.Show(True) 1045 self.smear_description_slit_width.Show(True) 1046 elif self.smear_type == 'Pinhole': 1047 self.smear_description_pin_min.Show(True) 1048 self.smear_description_pin_max.Show(True) 1049 self.smear_data_left.Show(True) 1050 self.smear_data_right.Show(True) 1051 elif self.pinhole_smearer.GetValue(): 1052 self.smear_message_new_p.Show(True) 1053 self.smear_description_pin_min.Show(True) 1054 self.smear_pinhole_min.Show(True) 1055 self.smear_description_pin_max.Show(True) 1056 self.smear_pinhole_max.Show(True) 1057 elif self.slit_smearer.GetValue(): 1058 self.smear_message_new_s.Show(True) 1059 self.smear_description_slit_height.Show(True) 1060 self.smear_slit_height.Show(True) 1061 self.smear_description_slit_width.Show(True) 1062 self.smear_slit_width.Show(True) 1063 1064 def _hide_all_smear_info(self): 1065 """ 1066 Hide all smearing messages in the set_smearer sizer 1067 """ 1068 self.smear_description_none.Hide() 1069 self.smear_description_dqdata.Hide() 1070 self.smear_description_type.Hide() 1071 self.smear_description_smear_type.Hide() 1072 self.smear_description_2d.Hide() 1073 self.smear_data_left.Hide() 1074 self.smear_data_right.Hide() 1075 self.smear_description_pin_min.Hide() 1076 self.smear_pinhole_min.Hide() 1077 self.smear_description_pin_max.Hide() 1078 self.smear_pinhole_max.Hide() 1079 self.smear_description_slit_height.Hide() 1080 self.smear_slit_height.Hide() 1081 self.smear_description_slit_width.Hide() 1082 self.smear_slit_width.Hide() 1083 self.smear_message_new_p.Hide() 1084 self.smear_message_new_s.Hide() 1085 843 1086 844 1087 def set_data(self, data): … … 857 1100 if self.smearer == None: 858 1101 self.enable_smearer.Disable() 859 self.disable_smearer.Disable()860 1102 else: 861 1103 self.enable_smearer.Enable() 862 self.disable_smearer.Enable() 1104 1105 # more disables for 2D 1106 if self.data.__class__.__name__ =="Data2D": 1107 self.smear_description_none.Hide() 1108 self.smear_description_2d.Show(True) 1109 self.pinhole_smearer.Disable() 1110 self.slit_smearer.Disable() 863 1111 864 1112 self.formfactorbox.Enable() … … 892 1140 self.state.qmax = self.qmax_x 893 1141 894 1142 895 1143 def reset_page(self, state,first=False): 896 1144 """ … … 972 1220 if chisqr != None or numpy.isfinite(chisqr): 973 1221 #format chi2 974 if self.engine_type == "park" and npt_fit > 0:1222 if self.engine_type == "park": 975 1223 npt_fit = float(self.get_npts2fit()) 976 chisqr =chisqr/npt_fit 1224 if npt_fit > 0: 1225 chisqr =chisqr/npt_fit 977 1226 chi2 = format_number(chisqr) 978 1227 self.tcChi.SetLabel(chi2) … … 1076 1325 msg = "Fit completed! " 1077 1326 wx.PostEvent(self.manager.parent, StatusEvent(status=msg)) 1078 1079 1327 1328 def onPinholeSmear(self, event): 1329 """ 1330 Create a custom pinhole smear object that will change the way residuals 1331 are compute when fitting 1332 """ 1333 1334 if self.check_invalid_panel(): 1335 return 1336 if self.model ==None: 1337 msg="Need model and data to smear plot" 1338 wx.PostEvent(self.manager.parent, StatusEvent(status=\ 1339 "Smear: %s"%msg)) 1340 return 1341 1342 # msg default 1343 msg = None 1344 if event != None: 1345 tcrtl= event.GetEventObject() 1346 # event case of radio button 1347 if tcrtl.GetValue()== True: 1348 self.dx_min = 0.0 1349 self.dx_max = 0.0 1350 is_new_pinhole = True 1351 else: 1352 is_new_pinhole = self._is_changed_pinhole() 1353 # if any value is changed 1354 if is_new_pinhole: 1355 msg = self._set_pinhole_smear() 1356 # hide all silt sizer 1357 self._hide_all_smear_info() 1358 1359 ##Calculate chi2 1360 self.compute_chisqr(smearer= self.current_smearer) 1361 # show relevant slit sizers 1362 self._show_smear_sizer() 1363 self.sizer_set_smearer.Layout() 1364 self.Layout() 1365 1366 if event != None: 1367 event.Skip() 1368 #self._undo.Enable(True) 1369 self.save_current_state() 1370 event = PageInfoEvent(page = self) 1371 wx.PostEvent(self.parent, event) 1372 1373 def _is_changed_pinhole(self): 1374 """ 1375 check if any of pinhole smear is changed 1376 return: True or False 1377 """ 1378 # get the values 1379 pin_min = self.smear_pinhole_min.GetValue() 1380 pin_max = self.smear_pinhole_max.GetValue() 1381 1382 # Check changes in slit width 1383 try: 1384 dx_min = float(pin_min) 1385 except: 1386 return True 1387 if self.dx_min != dx_min: 1388 return True 1389 1390 # Check changes in slit heigth 1391 try: 1392 dx_max = float(pin_max) 1393 except: 1394 return True 1395 if self.dx_max != dx_max: 1396 return True 1397 return False 1398 1399 def _set_pinhole_smear(self): 1400 """ 1401 Set custom pinhole smear 1402 return: msg 1403 """ 1404 # copy data 1405 data = copy.deepcopy(self.data) 1406 data_len = len(data.x) 1407 data.dx = None 1408 data.dxl = None 1409 data.dxw = None 1410 msg = None 1411 1412 # make sure once more if it is smearer 1413 data = copy.deepcopy(self.data) 1414 len_data = len(data.x) 1415 data.dx = numpy.zeros(len_data) 1416 get_pin_min = self.smear_pinhole_min 1417 get_pin_max = self.smear_pinhole_max 1418 1419 if self._validate_qrange(get_pin_min, get_pin_max ): 1420 if len_data < 2: len_data = 2 1421 self.dx_min = float(get_pin_min.GetValue()) 1422 self.dx_max = float(get_pin_max.GetValue()) 1423 if self.dx_min != None and self.dx_max != None: 1424 if self.dx_min == self.dx_max: 1425 data.dx[data.dx==0] = self.dx_min 1426 else: 1427 step = math.fabs(self.dx_max - self.dx_min)/(len_data-1) 1428 data.dx = numpy.arange(self.dx_min,self.dx_max+step/1.1,step) 1429 elif self.dx_min != None: 1430 data.dx[data.dx==0] = self.dx_min 1431 elif self.dx_max != None: 1432 data.dx[data.dx==0] = self.dx_max 1433 self.current_smearer = smear_selection(data) 1434 1435 else: 1436 get_pin_min.SetBackgroundColour("pink") 1437 get_pin_max.SetBackgroundColour("pink") 1438 msg= "Model Error:wrong value entered!!!" 1439 wx.PostEvent(self.manager.parent, StatusEvent(status = msg )) 1440 ## set smearing value whether or not the data contain the smearing info 1441 self.manager.set_smearer(smearer=self.current_smearer, qmin= float(self.qmin_x),qmax= float(self.qmax_x)) 1442 1443 return msg 1444 1445 def update_pinhole_smear(self): 1446 """ 1447 called by kill_focus on pinhole TextCntrl 1448 to update the changes 1449 return: msg: False when wrong value was entered 1450 """ 1451 # msg default 1452 msg = None 1453 # check if any value is changed 1454 if self._is_changed_pinhole(): 1455 msg = self._set_pinhole_smear() 1456 #self._undo.Enable(True) 1457 self.save_current_state() 1458 1459 if msg != None: 1460 return False 1461 else: 1462 return True 1463 1464 def onSlitSmear(self, event): 1465 """ 1466 Create a custom slit smear object that will change the way residuals 1467 are compute when fitting 1468 """ 1469 1470 1471 if self.check_invalid_panel(): 1472 return 1473 if self.model ==None: 1474 msg="Need model and data to smear plot" 1475 wx.PostEvent(self.manager.parent, StatusEvent(status=\ 1476 "Smear: %s"%msg)) 1477 return 1478 # msg default 1479 msg = None 1480 # for event given 1481 if event != None: 1482 tcrtl= event.GetEventObject() 1483 # event case of radio button 1484 if tcrtl.GetValue(): 1485 self.dxl = 0.0 1486 self.dxw = 0.0 1487 is_new_slit = True 1488 else: 1489 is_new_slit = self._is_changed_slit() 1490 1491 # if any value is changed 1492 if is_new_slit: 1493 msg = self._set_slit_smear() 1494 # hide all silt sizer 1495 self._hide_all_smear_info() 1496 ##Calculate chi2 1497 self.compute_chisqr(smearer= self.current_smearer) 1498 # show relevant slit sizers 1499 self._show_smear_sizer() 1500 self.sizer_set_smearer.Layout() 1501 self.Layout() 1502 1503 if event != None: 1504 event.Skip() 1505 #self._undo.Enable(True) 1506 self.save_current_state() 1507 event = PageInfoEvent(page = self) 1508 wx.PostEvent(self.parent, event) 1509 if msg != None: 1510 wx.PostEvent(self.manager.parent, StatusEvent(status = msg)) 1511 1512 1513 def _is_changed_slit(self): 1514 """ 1515 check if any of slit lengths is changed 1516 return: True or False 1517 """ 1518 # get the values 1519 width = self.smear_slit_width.GetValue() 1520 height = self.smear_slit_height.GetValue() 1521 1522 # check and change the box bg color if it was pink but it should be white now 1523 # because this is the case that _set_slit_smear() will not handle 1524 if height.lstrip().rstrip()=="": 1525 self.smear_slit_height.SetBackgroundColour(wx.WHITE) 1526 if width.lstrip().rstrip()=="": 1527 self.smear_slit_width.SetBackgroundColour(wx.WHITE) 1528 1529 # Check changes in slit width 1530 if width == "": 1531 dxw = 0.0 1532 else: 1533 try: 1534 dxw = float(width) 1535 except: 1536 return True 1537 if self.dxw != dxw: 1538 return True 1539 1540 # Check changes in slit heigth 1541 if height == "": 1542 dxl = 0.0 1543 else: 1544 try: 1545 dxl = float(height) 1546 except: 1547 return True 1548 if self.dxl != dxl: 1549 return True 1550 return False 1551 1552 def _set_slit_smear(self): 1553 """ 1554 Set custom slit smear 1555 return: msg 1556 """ 1557 temp_smearer = None 1558 # make sure once more if it is smearer 1559 data = copy.deepcopy(self.data) 1560 data_len = len(data.x) 1561 data.dx = None 1562 data.dxl = None 1563 data.dxw = None 1564 msg = None 1565 1566 try: 1567 self.dxl = float(self.smear_slit_height.GetValue()) 1568 data.dxl = self.dxl* numpy.ones(data_len) 1569 self.smear_slit_height.SetBackgroundColour(wx.WHITE) 1570 except: 1571 data.dxl = numpy.zeros(data_len) 1572 if self.smear_slit_height.GetValue().lstrip().rstrip()!="": 1573 self.smear_slit_height.SetBackgroundColour("pink") 1574 msg = "Wrong value entered... " 1575 else: 1576 self.smear_slit_height.SetBackgroundColour(wx.WHITE) 1577 try: 1578 self.dxw = float(self.smear_slit_width.GetValue()) 1579 self.smear_slit_width.SetBackgroundColour(wx.WHITE) 1580 data.dxw = self.dxw* numpy.ones(data_len) 1581 except: 1582 data.dxw = numpy.zeros(data_len) 1583 if self.smear_slit_width.GetValue().lstrip().rstrip()!="": 1584 self.smear_slit_width.SetBackgroundColour("pink") 1585 msg = "Wrong Fit value entered... " 1586 else: 1587 self.smear_slit_width.SetBackgroundColour(wx.WHITE) 1588 1589 self.current_smearer = smear_selection(data) 1590 #temp_smearer = self.current_smearer 1591 ## set smearing value whether or not the data contain the smearing info 1592 self.manager.set_smearer(smearer=self.current_smearer, qmin= float(self.qmin_x), qmax= float(self.qmax_x)) 1593 1594 return msg 1595 1596 1597 def update_slit_smear(self): 1598 """ 1599 called by kill_focus on pinhole TextCntrl 1600 to update the changes 1601 return: msg: False when wrong value was entered 1602 """ 1603 # msg default 1604 msg = None 1605 # check if any value is changed 1606 if self._is_changed_slit(): 1607 msg = self._set_slit_smear() 1608 #self._undo.Enable(True) 1609 self.save_current_state() 1610 1611 if msg != None: 1612 return False 1613 else: 1614 return True 1615 1616 1080 1617 def onSmear(self, event): 1081 1618 """ … … 1091 1628 return 1092 1629 temp_smearer = None 1093 1630 self._get_smear_info() 1631 1632 #renew smear sizer 1633 if self.smear_type != None: 1634 self.smear_description_smear_type.SetValue(str(self.smear_type)) 1635 self.smear_data_left.SetValue(str(self.dq_l)) 1636 self.smear_data_right.SetValue(str(self.dq_r)) 1637 1638 self._hide_all_smear_info() 1639 1640 data = copy.deepcopy(self.data) 1641 # make sure once more if it is smearer 1642 self.current_smearer = smear_selection(data) 1643 1094 1644 if self.enable_smearer.GetValue(): 1095 temp_smearer= self. smearer1645 temp_smearer= self.current_smearer 1096 1646 if hasattr(self.data,"dxl"): 1647 1097 1648 msg= ": Resolution smearing parameters" 1098 1649 if hasattr(self.data,"dxw"): … … 1104 1655 wx.PostEvent(self.manager.parent, StatusEvent(status=\ 1105 1656 "Data contains smearing information %s"%msg)) 1106 1657 self.smear_description_dqdata.Show(True) 1658 self.smear_data_left.Show(True) 1659 self.smear_data_right.Show(True) 1660 elif self.disable_smearer.GetValue(): 1661 self.smear_description_none.Show(True) 1662 1663 self._show_smear_sizer() 1664 self.sizer_set_smearer.Layout() 1665 self.Layout() 1107 1666 ## set smearing value whether or not the data contain the smearing info 1108 1667 self.manager.set_smearer(smearer=temp_smearer, qmin= float(self.qmin_x), … … 1113 1672 self.state.enable_smearer= self.enable_smearer.GetValue() 1114 1673 self.state.disable_smearer=self.disable_smearer.GetValue() 1115 1674 self.state.pinhole_smearer = self.pinhole_smearer.GetValue() 1675 self.state.slit_smearer = self.slit_smearer.GetValue() 1676 1116 1677 def complete_chisqr(self, output, elapsed=None): 1117 1678 """ … … 1417 1978 ix += 1 1418 1979 ctl3 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, 1419 kill_focus_callback = self._onparamRangeEnter,1420 1980 text_enter_callback = self._onparamRangeEnter) 1421 1981 … … 1425 1985 ix += 1 1426 1986 ctl4 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, 1427 kill_focus_callback = self._onparamRangeEnter,1428 1987 text_enter_callback = self._onparamRangeEnter) 1429 1988 sizer.Add(ctl4, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) … … 1516 2075 ix += 1 1517 2076 ctl3 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, 1518 kill_focus_callback = self._onparamRangeEnter,1519 2077 text_enter_callback = self._onparamRangeEnter) 1520 2078 … … 1524 2082 ix += 1 1525 2083 ctl4 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, 1526 kill_focus_callback = self._onparamRangeEnter,1527 2084 text_enter_callback = self._onparamRangeEnter) 1528 2085 sizer.Add(ctl4, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) … … 1571 2128 self.SetScrollbars(20,20,25,65) 1572 2129 1573 2130 class BGTextCtrl(wx.TextCtrl): 2131 """ 2132 Text control used to display outputs. 2133 No editing allowed. The background is 2134 grayed out. User can't select text. 2135 """ 2136 def __init__(self, *args, **kwds): 2137 wx.TextCtrl.__init__(self, *args, **kwds) 2138 self.SetEditable(False) 2139 self.SetBackgroundColour(self.GetParent().GetBackgroundColour()) 2140 2141 # Bind to mouse event to avoid text highlighting 2142 # The event will be skipped once the call-back 2143 # is called. 2144 self.Bind(wx.EVT_MOUSE_EVENTS, self._click) 2145 2146 def _click(self, event): 2147 """ 2148 Prevent further handling of the mouse event 2149 by not calling Skip(). 2150 """ 2151 pass 1574 2152 1575 2153 class HelpWindow(wx.Frame): -
sansview/perspectives/fitting/pagestate.py
rb421b1a r7609f1a 51 51 ## smearer info 52 52 self.smearer=None 53 self.smear_type = None 54 self.dq_l = None 55 self.dq_r = None 56 53 57 #list of dispersion paramaters 54 58 self.disp_list =[] … … 85 89 self.enable_smearer = False 86 90 self.disable_smearer = True 91 self.pinhole_smearer = False 92 self.slit_smearer = False 87 93 ## disperity selection 88 94 self.enable_disp= False … … 138 144 obj.enable_smearer = copy.deepcopy(self.enable_smearer) 139 145 obj.disable_smearer = copy.deepcopy(self.disable_smearer) 146 obj.pinhole_smearer = copy.deepcopy(self.pinhole_smearer) 147 obj.slit_smearer = copy.deepcopy(self.slit_smearer) 148 obj.smear_type = copy.deepcopy(self.smear_type) 149 obj.dq_l = copy.deepcopy(self.dq_l) 150 obj.dq_r = copy.deepcopy(self.dq_r) 151 140 152 141 153 obj.disp_box = copy.deepcopy(self.disp_box)
Note: See TracChangeset
for help on using the changeset viewer.