Changeset 26bf293 in sasview
- Timestamp:
- Feb 2, 2009 7:28:06 PM (16 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:
- ca88b2e
- Parents:
- 2cf2b87
- Location:
- sansview/perspectives/fitting
- Files:
-
- 2 deleted
- 6 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/fit_thread.py
re9b4cc4 r26bf293 170 170 raise 171 171 except: 172 wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value)) 172 raise 173 #wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value)) 173 174 return 174 175 -
sansview/perspectives/fitting/fitpage1D.py
r00d083c r26bf293 5 5 import copy 6 6 import sans.models.dispersion_models 7 from sans.guicomm.events import StatusEvent 7 from sans.guicomm.events import StatusEvent 8 from sans.guiframe.utils import format_number 9 from modelpage import ModelPage 10 from modelpage import format_number 8 11 (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() 9 12 _BOX_WIDTH = 80 10 13 11 def format_number(value, high=False):12 """13 Return a float in a standardized, human-readable formatted string14 """15 try:16 value = float(value)17 except:18 print "returning 0"19 return "0"20 21 if high:22 return "%-6.4g" % value23 else:24 return "%-5.3g" % value25 14 26 from modelpage import format_number 27 from modelpage import ModelPage 15 28 16 class FitPage1D(ModelPage): 29 17 """ … … 45 33 Initialization of the Panel 46 34 """ 47 #self.scroll = wx.ScrolledWindow(self)48 35 self.data = data 36 self.enable2D=False 49 37 self.manager = None 50 38 self.parent = parent … … 52 40 #panel interface 53 41 self.vbox = wx.BoxSizer(wx.VERTICAL) 42 self.sizer10 = wx.GridBagSizer(5,5) 43 self.sizer9 = wx.GridBagSizer(5,5) 44 self.sizer8 = wx.GridBagSizer(5,5) 45 self.sizer7 = wx.GridBagSizer(5,5) 54 46 self.sizer6 = wx.GridBagSizer(5,5) 55 47 self.sizer5 = wx.GridBagSizer(5,5) … … 58 50 self.sizer2 = wx.GridBagSizer(5,5) 59 51 self.sizer1 = wx.GridBagSizer(5,5) 60 61 52 # Add layer 53 #data info layer 54 self.vbox.Add(self.sizer1) 55 #data range 56 self.vbox.Add(self.sizer2) 57 #instrument smearing selection layer 58 self.vbox.Add(self.sizer3) 59 #model selection 60 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 61 self.vbox.Add(self.sizer4) 62 #model paramaters layer 63 self.vbox.Add(self.sizer5) 64 #polydispersion selected 65 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 66 self.vbox.Add(self.sizer6) 67 #combox box for type of dispersion 68 self.vbox.Add(self.sizer7) 69 #dispersion parameters layer 70 self.vbox.Add(self.sizer8) 71 #fit info layer 72 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 73 self.vbox.Add(self.sizer9) 74 #close layer 75 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 76 self.vbox.Add(self.sizer10) 77 78 #---------sizer 1 draw-------------------------------- 62 79 self.DataSource =wx.StaticText(self, -1,str(data.name)) 63 80 self.smearer_box = wx.ComboBox(self, -1) … … 74 91 self.smearer_box.Insert(str(v),i) 75 92 i+=1 93 94 # Minimum value of data 95 self.data_min = wx.StaticText(self, -1,str(format_number(numpy.min(data.x)))) 96 # Maximum value of data 97 self.data_max = wx.StaticText(self, -1,str(format_number(numpy.max(data.x)))) 98 #Filing the sizer containing data related fields 99 ix = 0 100 iy = 1 101 self.sizer1.Add(wx.StaticText(self, -1, 'Data Source Name : '),(iy,ix),\ 102 (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 103 104 ix += 1 105 self.sizer1.Add(self.DataSource,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 106 107 #---------sizer 2 draw-------------------------------- 108 ix = 0 109 iy = 1 110 #set maximum range for x in linear scale 111 self.text4_3 = wx.StaticText(self, -1, 'Maximum Data Range(Linear)', style=wx.ALIGN_LEFT) 112 self.sizer2.Add(self.text4_3,(iy,ix),(1,1),\ 113 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 114 ix += 2 115 self.sizer2.Add(wx.StaticText(self, -1, 'Min :'),(iy, ix),(1,1),\ 116 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 117 ix += 1 118 self.sizer2.Add(self.data_min,(iy, ix),(1,1),\ 119 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 120 ix += 1 121 self.sizer2.Add(wx.StaticText(self, -1, 'Max : '),(iy, ix),(1,1),\ 122 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 123 ix += 1 124 self.sizer2.Add(self.data_max,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 125 126 #----sizer 3 draw-------------------------------- 127 ix = 0 128 iy = 1 129 self.sizer3.Add(wx.StaticText(self,-1,'Instrument Smearing'),(iy,ix),(1,1)\ 130 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 131 ix += 1 132 self.sizer3.Add(self.smearer_box,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 133 ix =0 134 iy+=1 135 self.sizer3.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 136 137 #------------------ sizer 4 draw------------------------ 76 138 self.modelbox = wx.ComboBox(self, -1) 139 140 #filling sizer2 141 ix = 0 142 iy = 1 143 self.sizer4.Add(wx.StaticText(self,-1,'Model'),(iy,ix),(1,1)\ 144 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 145 ix += 1 146 self.sizer4.Add(self.modelbox,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 147 148 #----------sizer6------------------------------------------------- 149 self.disable_disp = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP) 150 self.enable_disp = wx.RadioButton(self, -1, 'Yes', (10, 30)) 151 self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.disable_disp.GetId()) 152 self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.enable_disp.GetId()) 153 ix= 0 154 iy=1 155 self.sizer6.Add(wx.StaticText(self,-1,'Polydispersity: '),(iy,ix),(1,1)\ 156 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 157 ix += 1 158 self.sizer6.Add(self.enable_disp ,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 159 ix += 1 160 self.sizer6.Add(self.disable_disp ,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 161 ix =0 162 iy+=1 163 self.sizer6.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 164 165 166 #---------sizer 9 draw---------------------------------------- 167 self.tcChi = wx.StaticText(self, -1, str(0), style=wx.ALIGN_LEFT) 168 self.tcChi.Hide() 169 self.text1_1 = wx.StaticText(self, -1, 'Chi2/dof', style=wx.ALIGN_LEFT) 170 self.text1_1.Hide() 171 77 172 id = wx.NewId() 78 173 self.btFit =wx.Button(self,id,'Fit') 79 174 self.btFit.Bind(wx.EVT_BUTTON, self.onFit,id=id) 80 175 self.btFit.SetToolTipString("Perform fit.") 81 self.static_line_1 = wx.StaticLine(self, -1) 82 83 self.vbox.Add(self.sizer3) 84 self.vbox.Add(self.sizer2) 85 self.vbox.Add(self.static_line_1, 0, wx.EXPAND, 0) 86 self.vbox.Add(self.sizer5) 87 self.vbox.Add(self.sizer6) 88 self.vbox.Add(self.sizer4) 89 self.vbox.Add(self.sizer1) 90 176 ## Q range 177 print "self.data fitpage1D" , self.data,hasattr(self.data,"data") 178 if not hasattr(self.data,"data"): 179 self.qmin_x= numpy.min(self.data.x) 180 self.qmax_x= numpy.max(self.data.x) 181 else: 182 radius1= math.sqrt(math.pow(self.data.xmin, 2)+ math.pow(self.data.ymin, 2)) 183 radius2= math.sqrt(math.pow(self.data.xmax, 2)+ math.pow(self.data.ymin, 2)) 184 radius3= math.sqrt(math.pow(self.data.xmin, 2)+ math.pow(self.data.ymax, 2)) 185 radius4= math.sqrt(math.pow(self.data.xmax, 2)+ math.pow(self.data.ymax, 2)) 186 self.qmin_x =0 187 self.qmax_x= max(radius1, radius2, radius3, radius4) 188 print "data2D range",self.qmax_x 189 self.num_points= 100 190 191 192 193 self.qmin = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 194 self.qmin.SetValue(str(format_number(self.qmin_x))) 195 self.qmin.SetToolTipString("Minimun value of x in linear scale.") 196 self.qmin.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 197 self.qmin.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) 198 self.qmin.Disable() 199 200 self.qmax = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 201 self.qmax.SetValue(str(format_number(self.qmax_x))) 202 self.qmax.SetToolTipString("Maximum value of x in linear scale.") 203 self.qmax.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 204 self.qmax.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) 205 self.qmax.Disable() 206 207 self.npts = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 208 self.npts.SetValue(format_number(self.num_points)) 209 self.npts.SetToolTipString("Number of point to plot.") 210 self.npts.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 211 self.npts.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) 212 self.npts.Disable() 213 self.npts.Hide() 214 ix = 0 215 iy = 1 216 self.sizer9.Add(wx.StaticText(self, -1, 'Fitting Range'),(iy, ix),(1,1),\ 217 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 218 ix += 1 219 self.sizer9.Add(wx.StaticText(self, -1, 'Min'),(iy, ix),(1,1),\ 220 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 221 ix += 1 222 self.sizer9.Add(wx.StaticText(self, -1, 'Max'),(iy, ix),(1,1),\ 223 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 224 #ix += 1 225 #self.sizer9.Add(wx.StaticText(self, -1, 'Npts'),(iy, ix),(1,1),\ 226 # wx.EXPAND|wx.ADJUST_MINSIZE, 0) 227 ix = 0 228 iy += 1 229 self.sizer9.Add(wx.StaticText(self, -1, 'x range'),(iy, ix),(1,1),\ 230 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 231 ix += 1 232 self.sizer9.Add(self.qmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 233 ix += 1 234 self.sizer9.Add(self.qmax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 235 ix += 1 236 self.sizer9.Add(self.npts,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 237 ix = 0 238 iy += 1 239 self.sizer9.Add(self.text1_1,(iy,ix),(1,1),\ 240 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 241 ix += 1 242 self.sizer9.Add(self.tcChi,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 243 ix +=2 244 self.sizer9.Add(self.btFit,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 245 ix =0 246 iy+=1 247 self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 248 #----------sizer 10 draw------------------------------------------------------ 91 249 id = wx.NewId() 92 250 self.btClose =wx.Button(self,id,'Close') 93 251 self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id) 94 252 self.btClose.SetToolTipString("Close page.") 95 ix = 0 96 iy = 1 97 self.sizer3.Add(wx.StaticText(self, -1, 'Data Source Name : '),(iy,ix),\ 98 (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 99 ix += 1 100 self.sizer3.Add(self.DataSource,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 101 ix += 1 102 self.sizer3.Add((20,20),(iy,ix),(1,1),wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE,0) 103 ix = 0 104 iy += 1 105 self.sizer3.Add(wx.StaticText(self,-1,'Instrument Smearing'),(iy,ix),(1,1)\ 106 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 107 ix += 1 108 self.sizer3.Add(self.smearer_box,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 109 110 ix = 0 111 iy += 1 112 self.sizer3.Add(wx.StaticText(self,-1,'Model'),(iy,ix),(1,1)\ 113 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 114 ix += 1 115 self.sizer3.Add(self.modelbox,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 116 117 ix = 0 118 iy = 1 119 #set maximum range for x in linear scale 120 self.text4_3 = wx.StaticText(self, -1, 'Maximum Data Range(Linear)', style=wx.ALIGN_LEFT) 121 self.sizer4.Add(self.text4_3,(iy,ix),(1,1),\ 122 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 123 ix += 1 124 self.sizer4.Add(wx.StaticText(self, -1, 'Min'),(iy, ix),(1,1),\ 125 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 126 ix += 2 127 self.sizer4.Add(wx.StaticText(self, -1, 'Max'),(iy, ix),(1,1),\ 128 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 129 ix = 0 130 iy += 1 131 self.sizer4.Add(wx.StaticText(self, -1, 'x range'),(iy, ix),(1,1),\ 132 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 133 ix += 1 134 self.xmin = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 135 self.xmin.SetValue(format_number(numpy.min(data.x))) 136 self.xmin.SetToolTipString("Minimun value of x in linear scale.") 137 self.xmin.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter) 138 self.xmin.Bind(wx.EVT_TEXT_ENTER, self._onTextEnter) 139 self.xmin.Disable() 140 self.sizer4.Add(self.xmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 141 142 143 ix += 2 144 self.xmax = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 145 self.xmax.SetValue(format_number(numpy.max(data.x))) 146 self.xmax.SetToolTipString("Maximum value of x in linear scale.") 147 self.xmax.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter) 148 self.xmax.Bind(wx.EVT_TEXT_ENTER, self._onTextEnter) 149 self.xmax.Disable() 150 self.sizer4.Add(self.xmax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 253 254 ix= 3 255 iy= 1 256 self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 257 ix +=1 258 self.sizer10.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 151 259 ix =0 152 260 iy+=1 153 self.sizer4.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 154 #Set chisqr result into TextCtrl 155 ix = 0 156 iy = 1 157 158 self.text1_1 = wx.StaticText(self, -1, 'Chi2/dof', style=wx.ALIGN_LEFT) 159 #self.sizer1.Add(self.text1_1,1) 160 self.sizer1.Add(self.text1_1,(iy,ix),(1,1),\ 161 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 162 ix += 1 163 self.tcChi = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 164 self.tcChi.SetToolTipString("Chi^2 over degrees of freedom.") 165 #self.sizer1.Add(self.tcChi, 1, wx.R | wx.BOTTOM , 5) 166 self.sizer1.Add(self.tcChi,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 167 ix +=2 168 #self.sizer1.Add(self.btFit, 1, wx.LEFT | wx.BOTTOM , 5) 169 self.sizer1.Add(self.btFit,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 170 ix+= 2 171 self.sizer1.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 172 #self.sizer1.Add( self.btClose,1, wx.LEFT | wx.BOTTOM , 5) 173 self.tcChi.Disable() 174 ix= 0 175 iy+=1 176 self.sizer1.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 177 #self.sizer1.Add((20,20), 0) 261 self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 262 178 263 # contains link between model ,all its parameters, and panel organization 179 264 self.parameters=[] 180 265 self.fixed_param=[] 266 #list of dispersion paramaters 267 self.disp_list=None 181 268 #contains link between a model and selected parameters to fit 182 269 self.param_toFit=[] … … 185 272 #dictionary of model name and model class 186 273 self.model_list_box={} 187 self.data = data 188 ## Q range 189 self.qmin= 0.001 190 self.qmax= 0.1 274 275 191 276 192 277 self.vbox.Layout() … … 198 283 self.Layout() 199 284 self.GrandParent.GetSizer().Layout() 200 201 202 203 204 205 206 def compute_chisqr(self): 285 286 def compute_chisqr2D(self): 207 287 """ @param fn: function that return model value 208 288 @return residuals 209 289 """ 210 211 290 flag=self.checkFitRange() 291 res=[] 212 292 if flag== True: 213 293 try: 214 qmin = float(self.xmin.GetValue()) 215 qmax = float(self.xmax.GetValue()) 216 x,y,dy = [numpy.asarray(v) for v in (self.data.x,self.data.y,self.data.dy)] 217 if qmin==None and qmax==None: 218 fx =numpy.asarray([self.model.run(v) for v in x]) 219 res=(y - fx)/dy 220 else: 221 idx = (x>= qmin) & (x <=qmax) 222 fx = numpy.asarray([self.model.run(item)for item in x[idx ]]) 223 res= (y[idx] - fx)/dy[idx] 294 self.qmin_x = float(self.qmin.GetValue()) 295 self.qmax_x = float(self.qmax.GetValue()) 224 296 297 for i in range(len(self.data.x_bins)): 298 if self.data.x_bins[i]>= self.qmin_x and self.data.x_bins[i]<= self.qmax_x: 299 for j in range(len(self.data.y_bins)): 300 if self.data.y_bins[j]>= self.qmin_x and self.data.y_bins[j]<= self.qmax_x: 301 res.append( (self.data.data[j][i]- self.model.runXY(\ 302 [self.data.x_bins[i],self.data.y_bins[j]]))\ 303 /self.data.err_data[j][i] ) 304 sum=0 225 305 226 sum=0227 306 for item in res: 228 307 if numpy.isfinite(item): 229 308 sum +=item 309 #print "chisqr : sum 2D", xmin, xmax, ymin, ymax,sum 310 #print res 230 311 self.tcChi.SetValue(format_number(math.fabs(sum))) 231 312 except: 232 313 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 233 314 "Chisqr cannot be compute: %s"% sys.exc_value)) 234 235 236 def onFit(self,event): 237 """ signal for fitting""" 238 315 316 317 def compute_chisqr(self): 318 """ @param fn: function that return model value 319 @return residuals 320 """ 321 239 322 flag=self.checkFitRange() 240 self.set_manager(self.manager) 241 242 qmin=float(self.xmin.GetValue()) 243 qmax =float( self.xmax.GetValue()) 244 if len(self.param_toFit) >0 and flag==True: 245 self.manager.schedule_for_fit( value=1,fitproblem =None) 246 self.manager._on_single_fit(qmin=qmin,qmax=qmax) 247 else: 248 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 249 "Select at least on parameter to fit ")) 250 251 323 if flag== True: 324 try: 325 if hasattr(self.data,"data"): 326 self.compute_chisqr2D() 327 return 328 else: 329 self.qmin_x = float(self.qmin.GetValue()) 330 self.qmax_x = float(self.qmax.GetValue()) 331 x,y,dy = [numpy.asarray(v) for v in (self.data.x,self.data.y,self.data.dy)] 332 if self.qmin_x==None and self.qmax_x==None: 333 fx =numpy.asarray([self.model.run(v) for v in x]) 334 res=(y - fx)/dy 335 else: 336 idx = (x>= self.qmin_x) & (x <=self.qmax_x) 337 fx = numpy.asarray([self.model.run(item)for item in x[idx ]]) 338 res= (y[idx] - fx)/dy[idx] 339 340 341 sum=0 342 for item in res: 343 if numpy.isfinite(item): 344 sum +=item 345 self.tcChi.SetLabel(format_number(math.fabs(sum))) 346 except: 347 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 348 "Chisqr cannot be compute: %s"% sys.exc_value)) 349 252 350 def _on_select_model(self,event): 253 351 """ … … 256 354 """ 257 355 self.btFit.SetFocus() 356 self.disable_disp.SetValue(True) 357 self.sizer8.Clear(True) 358 self.sizer7.Clear(True) 359 self.vbox.Layout() 360 self.SetScrollbars(20,20,55,40) 361 self.Layout() 362 self.parent.GetSizer().Layout() 258 363 for item in self.model_list_box.itervalues(): 259 364 name = item.__name__ … … 270 375 except: 271 376 raise #ValueError,"model.name is not equal to model class name" 272 break 273 377 break 378 def onFit(self,event): 379 """ signal for fitting""" 380 381 flag=self.checkFitRange() 382 self.set_manager(self.manager) 383 384 self.qmin_x=float(self.qmin.GetValue()) 385 self.qmax_x =float( self.qmax.GetValue()) 386 if len(self.param_toFit) >0 and flag==True: 387 self.manager.schedule_for_fit( value=1,fitproblem =None) 388 self.manager._on_single_fit(qmin=self.qmin_x,qmax=self.qmax_x) 389 else: 390 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 391 "Select at least on parameter to fit ")) 392 393 274 394 def _onTextEnter(self,event): 275 395 """ … … 288 408 "Drawing Error:wrong value entered %s"% sys.exc_value)) 289 409 290 def checkFitRange(self): 291 """ 292 Check the validity of fitting range 293 @note: xmin should always be less than xmax or else each control box 294 background is colored in pink. 295 """ 296 297 flag = True 298 valueMin = self.xmin.GetValue() 299 valueMax = self.xmax.GetValue() 300 # Check for possible values entered 301 #print "fitpage: checkfitrange:",valueMin,valueMax 302 try: 303 if (float(valueMax)> float(valueMin)): 304 self.xmax.SetBackgroundColour(wx.WHITE) 305 self.xmin.SetBackgroundColour(wx.WHITE) 306 else: 307 flag = False 308 self.xmin.SetBackgroundColour("pink") 309 self.xmax.SetBackgroundColour("pink") 310 except: 311 flag = False 312 self.xmin.SetBackgroundColour("pink") 313 self.xmax.SetBackgroundColour("pink") 314 315 self.xmin.Refresh() 316 self.xmax.Refresh() 317 return flag 318 319 410 320 411 321 412 def get_param_list(self): … … 331 422 raise ValueError,"missing parameter to fit" 332 423 333 334 def set_panel(self,model): 424 425 426 def old_set_panel(self,model): 335 427 """ 336 428 Build the panel from the model content 337 429 @param model: the model selected in combo box for fitting purpose 338 430 """ 339 self.sizer2.Clear(True)340 431 self.sizer5.Clear(True) 341 self.sizer6.Clear(True)342 432 self.parameters = [] 343 433 self.param_toFit=[] … … 346 436 #print "fitpage1D : dispersion list",self.model.getDispParamList() 347 437 keys.sort() 348 disp_list=self.model.getDispParamList()349 fixed=self.model.fixed350 print "fixed",fixed351 #model.setParam("scale", 2)352 #print "model sphere scale fixed?", self.model.is_fittable("scale")353 ip=0354 iq=1355 356 438 ik=0 357 439 im=1 358 if len(disp_list)>0: 359 disp = wx.StaticText(self, -1, 'Dispersion') 360 self.sizer5.Add(disp,( iq, ip),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 361 ip += 1 362 values = wx.StaticText(self, -1, 'Values') 363 self.sizer5.Add(values,( iq, ip),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 364 365 disp_list.sort() 440 366 441 iy = 1 367 442 ix = 0 368 443 self.cb1 = wx.CheckBox(self, -1,"Select all", (10, 10)) 369 444 wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param) 370 self.sizer 2.Add(self.cb1,(iy, ix),(1,1),\445 self.sizer5.Add(self.cb1,(iy, ix),(1,1),\ 371 446 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 372 447 ix +=1 373 448 self.text2_2 = wx.StaticText(self, -1, 'Values') 374 self.sizer 2.Add(self.text2_2,(iy, ix),(1,1),\449 self.sizer5.Add(self.text2_2,(iy, ix),(1,1),\ 375 450 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 376 451 ix +=2 377 452 self.text2_3 = wx.StaticText(self, -1, 'Errors') 378 self.sizer 2.Add(self.text2_3,(iy, ix),(1,1),\453 self.sizer5.Add(self.text2_3,(iy, ix),(1,1),\ 379 454 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 380 455 self.text2_3.Hide() 381 456 ix +=1 382 457 self.text2_4 = wx.StaticText(self, -1, 'Units') 383 self.sizer 2.Add(self.text2_4,(iy, ix),(1,1),\458 self.sizer5.Add(self.text2_4,(iy, ix),(1,1),\ 384 459 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 385 460 self.text2_4.Hide() 386 #print "keys", keys 387 #print "disp_list", disp_list 388 #print "fix_list",fixed 461 disp_list=self.model.getDispParamList() 389 462 for item in keys: 390 463 if not item in disp_list: … … 394 467 cb = wx.CheckBox(self, -1, item, (10, 10)) 395 468 cb.SetValue(False) 396 self.sizer 2.Add( cb,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)469 self.sizer5.Add( cb,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 397 470 wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) 398 471 … … 403 476 ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 404 477 ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) 405 self.sizer 2.Add(ctl1, (iy,ix),(1,1), wx.EXPAND)478 self.sizer5.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) 406 479 407 480 ix += 1 408 481 text2=wx.StaticText(self, -1, '+/-') 409 self.sizer 2.Add(text2,(iy, ix),(1,1),\482 self.sizer5.Add(text2,(iy, ix),(1,1),\ 410 483 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 411 484 text2.Hide() 412 485 ix += 1 413 486 ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) 414 self.sizer 2.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)487 self.sizer5.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 415 488 ctl2.Hide() 416 489 ix +=1 … … 420 493 except: 421 494 units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) 422 self.sizer2.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 495 self.sizer5.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 496 """ 423 497 else: 424 if item in fixed:498 if not item in fixed: 425 499 ip = 0 426 500 iq += 1 … … 452 526 im += 1 453 527 #save data 454 528 """ 455 529 self.parameters.append([cb,ctl1,text2,ctl2]) 456 530 457 531 iy+=1 458 self.sizer 2.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)532 self.sizer5.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 459 533 460 534 #Display units text on panel … … 499 573 item[3].Hide() 500 574 except: 501 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\502 "Drawing Error:wrong value entered : %s"% sys.exc_value))575 #enter dispersion value 576 pass 503 577 self.set_model_parameter() 504 578 505 def set_model_parameter(self): 506 if len(self.parameters) !=0 and self.model !=None: 507 # Flag to register when a parameter has changed. 508 is_modified = False 509 for item in self.fixed_param: 510 511 try: 512 name=str(item[0]) 513 value= float(item[1].GetValue()) 514 # print "model para", name,value 515 # If the value of the parameter has changed, 516 # update the model and set the is_modified flag 517 if value != self.model.getParam(name): 518 self.model.setParam(name,value) 519 is_modified = True 520 except: 521 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 522 "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) 523 524 for item in self.parameters: 525 # print "paramters",str(item[0].GetLabelText()) 526 try: 527 name=str(item[0].GetLabelText()) 528 value= float(item[1].GetValue()) 529 # print "model para", name,value 530 # If the value of the parameter has changed, 531 # update the model and set the is_modified flag 532 if value != self.model.getParam(name): 533 self.model.setParam(name,value) 534 is_modified = True 535 except: 536 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 537 "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) 538 539 # Here we should check whether the boundaries have been modified. 540 # If qmin and qmax have been modified, update qmin and qmax and 541 # set the is_modified flag to True 542 if float(self.xmin.GetValue()) != self.qmin: 543 self.qmin = float(self.xmin.GetValue()) 544 is_modified = True 545 if float(self.xmax.GetValue()) != self.qmax: 546 self.qmax = float(self.xmax.GetValue()) 547 is_modified = True 548 549 if is_modified: 550 self.manager.redraw_model(qmin=self.qmin, qmax=self.qmax) 551 579 552 580 def select_all_param(self,event): 553 581 """ … … 597 625 598 626 if not (len(self.param_toFit ) >0): 599 self. xmin.Disable()600 self. xmax.Disable()627 self.qmin.Disable() 628 self.qmax.Disable() 601 629 else: 602 self. xmin.Enable()603 self. xmax.Enable()630 self.qmin.Enable() 631 self.qmax.Enable() 604 632 605 633 … … 615 643 """ 616 644 #print "fitting : onsetvalues out",out 617 self.tcChi.Clear() 618 self.tcChi.SetValue(format_number(chisqr)) 645 self.tcChi.SetLabel(format_number(chisqr)) 619 646 params = {} 620 647 is_modified = False -
sansview/perspectives/fitting/fitpage2D.py
re9b4cc4 r26bf293 27 27 28 28 def __init__(self, parent,data, *args, **kwargs): 29 wx.ScrolledWindow.__init__(self, parent, *args, **kwargs)29 FitPage1D.__init__(self, parent, *args, **kwargs) 30 30 """ 31 31 Initialization of the Panel 32 32 """ 33 self.manager = None34 self.parent = parent35 self.event_owner=None36 #panel interface37 self.vbox = wx.BoxSizer(wx.VERTICAL)38 self.sizer6 = wx.GridBagSizer(5,5)39 self.sizer5 = wx.GridBagSizer(5,5)40 self.sizer4 = wx.GridBagSizer(5,5)41 self.sizer3 = wx.GridBagSizer(5,5)42 self.sizer2 = wx.GridBagSizer(5,5)43 self.sizer1 = wx.GridBagSizer(5,5)44 45 #self.DataSource = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))46 #self.DataSource.SetToolTipString("name of data to fit")47 #self.DataSource.SetValue(str(data.name))48 #self.DataSource.Disable()49 self.DataSource =wx.StaticText(self, -1,str(data.name))50 self.modelbox = wx.ComboBox(self, -1)51 id = wx.NewId()52 self.btFit =wx.Button(self,id,'Fit')53 self.btFit.Bind(wx.EVT_BUTTON, self.onFit,id=id)54 self.btFit.SetToolTipString("Perform fit.")55 self.static_line_1 = wx.StaticLine(self, -1)56 57 self.vbox.Add(self.sizer3)58 self.vbox.Add(self.sizer2)59 self.vbox.Add(self.static_line_1, 0, wx.EXPAND, 0)60 self.vbox.Add(self.sizer5)61 self.vbox.Add(self.sizer6)62 self.vbox.Add(self.sizer4)63 self.vbox.Add(self.sizer1)64 ## Q range65 self.qmin= 0.00166 self.qmax= 0.167 68 id = wx.NewId()69 self.btClose =wx.Button(self,id,'Close')70 self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id)71 self.btClose.SetToolTipString("Close page.")72 ix = 073 iy = 174 self.sizer3.Add(wx.StaticText(self, -1, 'Data Source'),(iy,ix),\75 (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)76 ix += 177 self.sizer3.Add(self.DataSource,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)78 ix += 179 self.sizer3.Add((20,20),(iy,ix),(1,1),wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE,0)80 ix = 081 iy += 182 self.sizer3.Add(wx.StaticText(self,-1,'Model'),(iy,ix),(1,1)\83 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)84 ix += 185 self.sizer3.Add(self.modelbox,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)86 87 ix = 088 iy = 189 #set maximum range for x in linear scale90 self.text4_3 = wx.StaticText(self, -1, 'Maximum Data\n Range (Linear)', style=wx.ALIGN_LEFT)91 self.sizer4.Add(self.text4_3,(iy,ix),(1,1),\92 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)93 ix += 194 self.text4_1 = wx.StaticText(self, -1, 'Min')95 self.sizer4.Add(self.text4_1,(iy, ix),(1,1),\96 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)97 #self.text4_1.Hide()98 ix += 299 self.text4_2 = wx.StaticText(self, -1, 'Max')100 self.sizer4.Add(self.text4_2,(iy, ix),(1,1),\101 wx.EXPAND|wx.ADJUST_MINSIZE, 0)102 #self.text4_2.Hide()103 33 104 #self.text4_3.Hide()105 ix = 0106 iy += 1107 self.text4_4 = wx.StaticText(self, -1, 'x range')108 self.sizer4.Add(self.text4_4,(iy, ix),(1,1),\109 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)110 ix += 1111 self.xmin = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))112 self.xmin.SetValue(format_number(data.xmin))113 self.xmin.SetToolTipString("Minimun value of x in linear scale.")114 self.sizer4.Add(self.xmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)115 self.xmin.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)116 self.xmin.Bind(wx.EVT_TEXT_ENTER, self._onTextEnter)117 118 ix += 2119 self.xmax = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))120 self.xmax.SetValue(format_number(data.xmax))121 self.xmax.SetToolTipString("Maximum value of x in linear scale.")122 self.sizer4.Add(self.xmax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)123 self.xmax.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)124 self.xmax.Bind(wx.EVT_TEXT_ENTER, self._onTextEnter)125 126 iy +=1127 ix = 0128 self.text4_5 = wx.StaticText(self, -1, 'y range')129 self.sizer4.Add(self.text4_5,(iy, ix),(1,1),\130 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)131 ix += 1132 self.ymin = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))133 self.ymin.SetValue(format_number(data.ymin))134 self.ymin.SetToolTipString("Minimun value of y in linear scale.")135 self.sizer4.Add(self.ymin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)136 self.ymin.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)137 self.ymin.Bind(wx.EVT_TEXT_ENTER, self._onTextEnter)138 139 ix += 2140 self.ymax = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))141 self.ymax.SetValue(format_number(data.ymax))142 self.ymax.SetToolTipString("Maximum value of y in linear scale.")143 self.sizer4.Add(self.ymax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)144 self.ymax.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)145 self.ymax.Bind(wx.EVT_TEXT_ENTER, self._onTextEnter)146 147 #Set chisqr result into TextCtrl148 ix = 0149 iy = 1150 self.text1_1 = wx.StaticText(self, -1, 'Chi2/dof', style=wx.ALIGN_LEFT)151 self.sizer1.Add(self.text1_1,(iy,ix),(1,1),\152 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)153 ix += 1154 self.tcChi = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))155 self.tcChi.SetToolTipString("Chi^2 over degrees of freedom.")156 self.sizer1.Add(self.tcChi,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)157 ix +=2158 self.sizer1.Add(self.btFit,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)159 ix+= 1160 self.sizer1.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)161 ix= 1162 iy+=1163 self.sizer1.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)164 # contains link between model ,all its parameters, and panel organization165 self.parameters=[]166 self.fixed_param=[]167 #contains link between a model and selected parameters to fit168 self.param_toFit=[]169 # model on which the fit would be performed170 self.model=None171 # preview selected model name172 173 174 #dictionary of model name and model class175 self.model_list_box={}176 177 self.data = data178 self.vbox.Layout()179 self.vbox.Fit(self)180 self.SetSizer(self.vbox)181 self.SetScrollbars(20,20,55,40)182 self.Centre()183 184 185 34 186 35 def compute_chisqr(self): -
sansview/perspectives/fitting/fitpanel.py
r32d802f r26bf293 1 1 import wx 2 import wx.aui 2 3 import wx.lib 3 4 import numpy … … 7 8 8 9 9 10 class FitPanel(wx.Panel):10 class FitPanel(wx.aui.AuiNotebook): 11 #class FitPanel(wx.aui.AuiNotebook,wx.panel): 11 12 """ 12 13 FitPanel class contains fields allowing to fit models and data … … 20 21 window_caption = "Fit Panel " 21 22 CENTER_PANE = True 22 23 24 23 def __init__(self, parent, *args, **kwargs): 25 wx.Panel.__init__(self, parent, *args, **kwargs) 24 25 wx.aui.AuiNotebook.__init__(self,parent,-1, style=wx.aui.AUI_NB_SCROLL_BUTTONS ) 26 26 27 self.manager=None 27 28 self.parent=parent 28 29 self.event_owner=None 29 #self.menu_mng = models.ModelManager()30 self.nb = wx.Notebook(self)31 self. sizer = wx.BoxSizer()32 self.sizer.Add(self.nb, 1, wx.EXPAND) 30 31 pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE 32 self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.onClosePage) 33 33 34 #Creating an initial page for simultaneous fitting 34 35 from simfitpage import SimultaneousFitPage 35 self.sim_page = SimultaneousFitPage(self .nb, -1)36 37 #self.fit_panel.add_page(self.sim_page,"Simultaneous Fit")38 self.nb.AddPage(self.sim_page,"Simultaneous Fit") 36 self.sim_page = SimultaneousFitPage(self, -1) 37 self.AddPage(self.sim_page,"Simultaneous Fit") 38 39 39 40 40 41 #dictionary of miodel {model class name, model class} … … 50 51 self.count=0 51 52 #updating the panel 52 self.nb.Update() 53 self.SetSizer(self.sizer) 54 self.sizer.Fit(self) 53 self.Update() 55 54 self.Center() 56 55 def onClosePage(self, event): 56 self.ToggleWindowStyle(wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB) 57 print "went here",self.get_current_page(), self.GetPage(0) 58 #event.Skip() 59 if self.GetPageCount() <= 2: 60 print "wente here" 61 62 # Prevent last tab from being closed 63 self.ToggleWindowStyle(~wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB) 64 65 66 67 57 68 58 69 … … 86 97 if self.fit_page_name != name: 87 98 self.count +=1 99 88 100 if data.__class__.__name__=='Data2D': 89 101 from fitpage2D import FitPage2D 90 panel = FitPage2D(self .nb,data, -1)102 panel = FitPage2D(self,data, -1) 91 103 92 104 else: 93 105 94 106 from fitpage1D import FitPage1D 95 panel = FitPage1D(self .nb,data, -1)107 panel = FitPage1D(self,data, -1) 96 108 m_name= "M"+str(self.count) 97 109 panel.set_manager(self.manager) 98 110 panel.set_owner(self.event_owner) 99 111 100 self. nb.AddPage(page=panel,text=name,select=True)112 self.AddPage(page=panel,caption=name,select=True) 101 113 panel.populate_box( self.model_list_box) 102 114 self.fit_page_name = name … … 112 124 """ 113 125 from modelpage import ModelPage 114 panel = ModelPage(self.nb,model,page_title, -1) 126 print "fitpanel model", model 127 panel = ModelPage(self,model,page_title, -1) 115 128 panel.set_manager(self.manager) 116 129 panel.set_owner(self.event_owner) 117 #self.nb.AddPage(page=panel,text=page_title,select=True) 118 self.nb.AddPage(page=panel,text="Model",select=True) 130 self.AddPage(page=panel,caption="Model",select=True) 119 131 panel.populate_box( self.model_list_box) 120 132 self.draw_model_name=page_title 121 self.model_page_number=self. nb.GetSelection()122 self.model_page=self. nb.GetPage(self.nb.GetSelection())133 self.model_page_number=self.GetSelection() 134 self.model_page=self.GetPage(self.GetSelection()) 123 135 124 136 … … 150 162 self.model_page.select_model(model, page_title) 151 163 152 def get_notebook(self): 153 """ 154 @return self.nb: return its own notebook mostly used by fitting module 155 """ 156 return self.nb 164 def get_current_page(self): 165 """ 166 @return the current page selected 167 """ 168 #return self.nb.GetCurrentPage() 169 return self.GetPage(self.GetSelection() ) 170 157 171 158 def get_page(self, n): 159 """ 160 @return page at position n 161 @param n: page number 162 """ 163 return self.nb.GetPage(n) 164 165 166 def get_page_count(self): 167 """ @return number total of pages contained in notebook""" 168 return self.nb.GetPageCount() 169 170 171 def get_current_page(self): 172 """ 173 @return the current page selected 174 """ 175 return self.nb.GetCurrentPage() 176 177 178 def get_selected_page(self): 179 """ @return the page just selected by the user """ 180 return self.nb.GetPage(self.nb.GetSelection()) 181 182 183 def get_page_number(self): 184 return self.nb.GetSelection() 185 186 def onClose(self, page=None,page_number=None): 172 def old_onClose(self, page=None,page_number=None): 187 173 """ 188 174 close the current page except the simpage. remove each check box link to the model -
sansview/perspectives/fitting/fitting.py
r1374fbe4 r26bf293 286 286 # print "fitting: single fit", name, result.pvec[i] 287 287 i += 1 288 # print "fitting result : chisqr",result.fitness 289 # print "fitting result : pvec",result.pvec 290 # print "fitting result : stderr",result.stderr 288 print "fitting result : chisqr",result.fitness 289 print "fitting result : pvec",result.pvec 290 print "fitting result : stderr",result.stderr 291 print "xmin xmax ymin , ymax",qmin, qmax, ymin, ymax 291 292 292 293 cpage.onsetValues(result.fitness, result.pvec,result.stderr) … … 320 321 if model.name == model_name: 321 322 small_out.append(p.value ) 322 if p.stderr ==None: 323 small_cov.append(0) 324 else: 325 small_cov.append(p.stderr) 323 small_cov.append(p.stderr) 326 324 model.setParam(param_name,p.value) 327 325 # Display result on each page … … 333 331 334 332 335 def _on_single_fit(self,id=None,qmin=None,qmax=None ,ymin=None,ymax=None):333 def _on_single_fit(self,id=None,qmin=None,qmax=None): 336 334 """ 337 335 perform fit for the current page and return chisqr,out and cov … … 362 360 model=list[0] 363 361 smearer= value.get_smearer() 362 print "single fit", model, smearer 364 363 #Create list of parameters for fitting used 365 364 pars=[] … … 381 380 self.schedule_for_fit( 0,value) 382 381 except: 383 #raise384 wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value))382 raise 383 #wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value)) 385 384 return 386 385 # make sure to keep an alphabetic order … … 397 396 qmin=qmin, 398 397 qmax=qmax, 399 ymin= ymin, 400 ymax= ymax, 398 401 399 completefn=self._single_fit_completed, 402 400 updatefn=None) … … 409 407 410 408 except: 411 #raise409 raise 412 410 wx.PostEvent(self.parent, StatusEvent(status="Single Fit error: %s" % sys.exc_value)) 413 411 return … … 519 517 name = evt.name 520 518 521 sim_page=self.fit_panel. get_page(0)519 sim_page=self.fit_panel.GetPage(0) 522 520 current_pg = self.fit_panel.get_current_page() 523 selected_page = self.fit_panel.get_selected_page()524 521 if current_pg != sim_page: 525 522 current_pg.set_panel(model) … … 562 559 @param currpage: page in a dictionary referring to some data 563 560 """ 564 if self.fit_panel. get_page_count() >1:561 if self.fit_panel.GetPageCount() >1: 565 562 for page in self.page_finder.iterkeys(): 566 563 if page==currpage : … … 569 566 model=list[0] 570 567 break 571 568 print "model in fitting",model 572 569 if data!=None and data.__class__.__name__ != 'Data2D': 573 570 theory = Theory1D(x=[], y=[]) … … 638 635 639 636 theory.data = numpy.zeros((len(data.y_bins),len(data.x_bins))) 640 for i in range(len(data. x_bins)):641 if data. x_bins[i]>= qmin and data.x_bins[i]<= qmax:642 for j in range(len(data. y_bins)):643 if data. y_bins[j]>= ymin and data.y_bins[j]<= ymax:644 theory.data[j][i]=model.runXY([data.x_bins[ i],data.y_bins[j]])645 637 for i in range(len(data.y_bins)): 638 if data.y_bins[i]>= ymin and data.y_bins[i]<= ymax: 639 for j in range(len(data.x_bins)): 640 if data.x_bins[i]>= qmin and data.x_bins[i]<= qmax: 641 theory.data[j][i]=model.runXY([data.x_bins[j],data.y_bins[i]]) 642 646 643 #print "fitting : plot_helper:", theory.image 647 644 #print data.image … … 676 673 self.fit_panel.add_model_page(model,description,name,topmenu=True) 677 674 678 def draw_model(self,model,name ,d escription=None,enable1D=True, enable2D=False,675 def draw_model(self,model,name ,data=None,description=None,enable1D=True, enable2D=False, 679 676 qmin=DEFAULT_QMIN, qmax=DEFAULT_QMAX, qstep=DEFAULT_NPTS): 680 677 """ 681 678 draw model with default data value 682 679 """ 680 if data !=None: 681 print "qmin qmax",qmin, qmax 682 self.redraw_model(qmin,qmax) 683 return 683 684 self._draw_model2D(model=model, 684 685 description=model.description, … … 741 742 742 743 def complete(self, output, elapsed, model, qmin, qmax,qstep=DEFAULT_NPTS): 743 744 744 745 wx.PostEvent(self.parent, StatusEvent(status="Calc \ 745 746 complete in %g sec" % elapsed)) -
sansview/perspectives/fitting/modelpage.py
r68dada4 r26bf293 5 5 import copy 6 6 7 7 8 from sans.guicomm.events import StatusEvent 9 from sans.guiframe.utils import format_number 8 10 (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() 9 11 _BOX_WIDTH = 80 10 12 11 def format_number(value, high=False): 12 """ 13 Return a float in a standardized, human-readable formatted string 14 """ 15 try: 16 value = float(value) 17 except: 18 print "returning 0" 19 return "0" 20 21 if high: 22 return "%-6.4g" % value 23 else: 24 return "%-5.3g" % value 25 26 13 14 15 27 16 class ModelPage(wx.ScrolledWindow): 28 17 """ … … 44 33 Initialization of the Panel 45 34 """ 46 #self.scroll = wx.ScrolledWindow(self) 35 # model on which the fit would be performed 36 self.model=model 37 #list of dispersion paramaters 38 self.disp_list=self.model.getDispParamList() 47 39 self.manager = None 48 40 self.parent = parent 49 self.event_owner=None 41 self.event_owner = None 42 # this panel does contain data .existing data allow a different drawing 43 #on set_model parameters 44 self.data=None 50 45 #panel interface 51 46 self.vbox = wx.BoxSizer(wx.VERTICAL) 52 self.sizer3 = wx.GridBagSizer(5,5) 53 self.sizer1 = wx.GridBagSizer(5,5) 54 self.sizer2 = wx.GridBagSizer(5,5) 47 self.sizer10 = wx.GridBagSizer(5,5) 48 self.sizer9 = wx.GridBagSizer(5,5) 49 self.sizer8 = wx.GridBagSizer(5,5) 50 self.sizer7 = wx.GridBagSizer(5,5) 51 self.sizer6 = wx.GridBagSizer(5,5) 52 self.sizer5 = wx.GridBagSizer(5,5) 55 53 self.sizer4 = wx.GridBagSizer(5,5) 56 self.sizer5 = wx.GridBagSizer(5,5) 57 self.static_line_1 = wx.StaticLine(self, -1) 54 55 #model selection 56 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 57 self.vbox.Add(self.sizer4) 58 #model paramaters layer 59 self.vbox.Add(self.sizer5) 60 #polydispersion selected 61 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 62 self.vbox.Add(self.sizer6) 63 #combox box for type of dispersion 64 self.vbox.Add(self.sizer7) 65 #dispersion parameters layer 66 self.vbox.Add(self.sizer8) 67 # plotting range 68 self.vbox.Add(self.sizer9) 69 #close layer 70 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 71 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 72 self.vbox.Add(self.sizer10) 73 74 75 #------------------ sizer 4 draw------------------------ 76 # model on which the fit would be performed 77 self.model=model 78 79 # define combox box 58 80 self.modelbox = wx.ComboBox(self, -1) 81 # preview selected model name 82 self.prevmodel_name=name 83 #print "model view prev_model",name 84 self.modelbox.SetValue(self.prevmodel_name) 85 #enable model 2D draw 86 self.enable2D= False 87 #filling sizer2 88 ix = 0 89 iy = 1 90 self.sizer4.Add(wx.StaticText(self,-1,'Model'),(iy,ix),(1,1)\ 91 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 92 ix += 1 93 self.sizer4.Add(self.modelbox,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 94 ix += 1 59 95 id = wx.NewId() 60 self.vbox.Add(self.sizer3) 61 self.vbox.Add(self.sizer1) 62 self.vbox.Add(self.sizer2) 63 self.vbox.Add(self.static_line_1, 0, wx.EXPAND, 0) 64 self.vbox.Add(self.sizer5) 65 self.vbox.Add(self.sizer4) 66 67 id = wx.NewId() 68 self.btClose =wx.Button(self,id,'Close') 69 self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id) 70 self.btClose.SetToolTipString("Close page.") 71 ix = 1 72 iy = 1 73 self.sizer4.Add(wx.StaticText(self, -1, 'Min'),(iy, ix),(1,1),\ 74 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 75 ix += 1 76 self.sizer4.Add(wx.StaticText(self, -1, 'Max'),(iy, ix),(1,1),\ 77 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 78 ix += 1 79 self.sizer4.Add(wx.StaticText(self, -1, 'Npts'),(iy, ix),(1,1),\ 80 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 81 ix = 0 82 iy += 1 83 self.sizer4.Add(wx.StaticText(self, -1, 'x range'),(iy, ix),(1,1),\ 84 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 85 ## Q range 86 self.qmin= 0.001 87 self.qmax= 0.1 96 self.model_view =wx.Button(self,id,'View 2D') 97 self.model_view.Bind(wx.EVT_BUTTON, self.onModel2D,id=id) 98 self.model_view.SetToolTipString("View model in 2D") 99 self.sizer4.Add(self.model_view,(iy,ix),(1,1),\ 100 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 101 self.model_view.SetFocus() 102 #----------sizer6------------------------------------------------- 103 self.disable_disp = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP) 104 self.enable_disp = wx.RadioButton(self, -1, 'Yes', (10, 30)) 105 self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.disable_disp.GetId()) 106 self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.enable_disp.GetId()) 107 ix= 0 108 iy=1 109 self.sizer6.Add(wx.StaticText(self,-1,'Polydispersity: '),(iy,ix),(1,1)\ 110 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 111 ix += 1 112 self.sizer6.Add(self.enable_disp ,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 113 ix += 1 114 self.sizer6.Add(self.disable_disp ,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 115 ix =0 116 iy+=1 117 self.sizer6.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 118 119 120 #---------sizer 9 draw---------------------------------------- 121 122 ## Q range 123 self.qmin_x= 0.001 124 self.qmax_x= 0.1 88 125 self.num_points= 100 89 126 90 ix += 1 91 self.xmin = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 92 self.xmin.SetValue(format_number(self.qmin)) 93 self.xmin.SetToolTipString("Minimun value of x in linear scale.") 94 self.xmin.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 95 self.xmin.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) 96 self.sizer4.Add(self.xmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 97 98 99 ix += 1 100 self.xmax = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 101 self.xmax.SetValue(format_number(self.qmax)) 102 self.xmax.SetToolTipString("Maximum value of x in linear scale.") 103 self.xmax.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 104 self.xmax.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) 105 self.sizer4.Add(self.xmax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 106 ix += 1 127 128 self.qmin = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 129 self.qmin.SetValue(format_number(self.qmin_x)) 130 self.qmin.SetToolTipString("Minimun value of x in linear scale.") 131 self.qmin.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 132 self.qmin.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) 133 134 self.qmax = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 135 self.qmax.SetValue(format_number(self.qmax_x)) 136 self.qmax.SetToolTipString("Maximum value of x in linear scale.") 137 self.qmax.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 138 self.qmax.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) 139 140 107 141 self.npts = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 108 142 self.npts.SetValue(format_number(self.num_points)) … … 111 145 self.npts.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) 112 146 113 self.sizer4.Add(self.npts,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 147 ix = 0 148 iy = 1 149 self.sizer9.Add(wx.StaticText(self, -1, 'Plotting Range'),(iy, ix),(1,1),\ 150 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 151 ix += 1 152 self.sizer9.Add(wx.StaticText(self, -1, 'Min'),(iy, ix),(1,1),\ 153 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 154 ix += 1 155 self.sizer9.Add(wx.StaticText(self, -1, 'Max'),(iy, ix),(1,1),\ 156 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 157 ix += 1 158 self.sizer9.Add(wx.StaticText(self, -1, 'Npts'),(iy, ix),(1,1),\ 159 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 114 160 ix = 0 115 161 iy += 1 116 self.sizer4.Add((20,20),(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 117 ix +=3 118 self.sizer4.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 119 ix = 0 120 iy = 1 121 self.sizer3.Add(wx.StaticText(self,-1,'Model'),(iy,ix),(1,1)\ 122 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 123 ix += 1 124 self.sizer3.Add(self.modelbox,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 125 #ix = 0 126 #iy += 1 127 ix += 1 162 self.sizer9.Add(wx.StaticText(self, -1, 'x range'),(iy, ix),(1,1),\ 163 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 164 ix += 1 165 self.sizer9.Add(self.qmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 166 ix += 1 167 self.sizer9.Add(self.qmax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 168 ix += 1 169 self.sizer9.Add(self.npts,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 170 171 ix =0 172 iy+=1 173 self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 174 #----------sizer 10 draw------------------------------------------------------ 128 175 id = wx.NewId() 129 self.model_view =wx.Button(self,id,'View 2D') 130 self.model_view.Bind(wx.EVT_BUTTON, self.onModel2D,id=id) 131 self.model_view.SetToolTipString("View model in 2D") 132 self.sizer3.Add(self.model_view,(iy,ix),(1,1),\ 133 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 176 self.btClose =wx.Button(self,id,'Close') 177 self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id) 178 self.btClose.SetToolTipString("Close page.") 179 180 ix= 3 181 iy= 1 182 self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 183 ix +=1 184 self.sizer10.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 185 ix =0 186 iy+=1 187 self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 188 134 189 # contains link between model ,all its parameters, and panel organization 135 190 self.parameters=[] 191 self.fixed_param=[] 136 192 #contains link between a model and selected parameters to fit 137 193 self.param_toFit=[] 138 # model on which the fit would be performed 139 self.model=model 140 try: 141 #print"init modelpage",model.name 142 self.set_panel(model) 143 except: 144 raise 145 # preview selected model name 146 self.prevmodel_name=name 147 #print "model view prev_model",name 148 self.modelbox.SetValue(self.prevmodel_name) 149 # flag to check if the user has selected a new model in the combox box 150 self.model_hasChanged=False 194 151 195 #dictionary of model name and model class 152 196 self.model_list_box={} 153 154 #enable model 2D draw 155 self.enable2D= False 156 # Data1D to make a deep comparison between 2 Data1D for checking data 157 #change 197 #Draw initial panel 198 if self.model!=None: 199 self.set_panel(self.model) 200 201 202 158 203 self.vbox.Layout() 159 204 self.vbox.Fit(self) 160 161 205 self.SetSizer(self.vbox) 162 206 self.SetScrollbars(20,20,55,40) 163 207 164 208 self.Centre() 165 166 def set_range(self, qmin, qmax, npts): 167 """ 168 Set the range for the plotted models 169 @param qmin: minimum Q 170 @param qmax: maximum Q 171 @param npts: number of Q bins 172 """ 173 # Set the data members 174 self.qmin = qmin 175 self.qmax = qmax 176 self.num_points = npts 177 178 # Set the controls 179 self.xmin.SetValue(format_number(self.qmin)) 180 self.xmax.SetValue(format_number(self.qmax)) 181 self.npts.SetValue(format_number(self.num_points)) 182 183 def onClose(self,event): 184 """ close the page associated with this panel""" 185 self.GrandParent.onClose() 209 self.Layout() 210 self.parent.GetSizer().Layout() 186 211 187 212 def set_owner(self,owner): … … 198 223 @param manager: instance of plugin fitting 199 224 """ 200 self.manager = manager 201 202 def onModel2D(self, event): 203 """ 204 call manager to plot model in 2D 205 """ 206 # If the 2D display is not currently enabled, plot the model in 2D 207 # and set the enable2D flag. 208 if self.enable2D==False: 209 self.enable2D=True 210 self._draw_model() 211 212 else: 213 print "enable is true:",self.enable2D 214 #self.manager.parent. show_panel(147) 215 self.manager.show_panel2D( id=None ) 216 #self.manager.menu1.Append(event_id, new_panel.window_caption, 217 # "Show %s plot panel" % new_panel.window_caption) 218 225 self.manager = manager 226 219 227 def populate_box(self, dict): 220 228 """ … … 230 238 name = item.name 231 239 list_name.append(name) 232 list_name.sort() 240 list_name.sort() 241 233 242 for name in list_name: 234 243 self.modelbox.Insert(name,int(id)) … … 236 245 wx.EVT_COMBOBOX(self.modelbox,-1, self._on_select_model) 237 246 return 0 247 248 249 def Set_DipersParam(self, event): 250 if self.enable_disp.GetValue(): 251 if len(self.disp_list)==0: 252 ix=0 253 iy=1 254 self.sizer8.Clear(True) 255 model_disp = wx.StaticText(self, -1, 'No PolyDispersity for this model') 256 self.sizer7.Add(model_disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 257 self.vbox.Layout() 258 self.SetScrollbars(20,20,55,40) 259 self.Layout() 260 self.parent.GetSizer().Layout() 261 return 262 else: 263 self.sizer8.Clear(True) 264 self.populate_disp_box() 265 self.set_panel_dispers(self.disp_list) 266 self.vbox.Layout() 267 self.SetScrollbars(20,20,55,40) 268 self.Layout() 269 self.parent.GetSizer().Layout() 270 else: 271 self.sizer7.Clear(True) 272 self.sizer8.Clear(True) 273 self.vbox.Layout() 274 self.SetScrollbars(20,20,55,40) 275 self.Layout() 276 self.parent.GetSizer().Layout() 277 278 def populate_disp_box(self): 279 self.sizer7.Clear(True) 280 if len(self.disp_list)>0: 281 ix=0 282 iy=1 283 model_disp = wx.StaticText(self, -1, 'Model Disp') 284 self.sizer7.Add(model_disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 285 ix += 1 286 # set up the combox box 287 id = 0 288 self.disp_box = wx.ComboBox(self, -1) 289 self.disp_box.SetValue("Gaussian") 290 self.disp_box.Insert("Gaussian",int(id)) 291 wx.EVT_COMBOBOX(self.disp_box,-1, self._on_select_Disp) 292 self.sizer7.Add(self.disp_box,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 293 294 def set_range(self, qmin_x, qmax_x, npts): 295 """ 296 Set the range for the plotted models 297 @param qmin: minimum Q 298 @param qmax: maximum Q 299 @param npts: number of Q bins 300 """ 301 # Set the data members 302 self.qmin_x = qmin_x 303 self.qmax_x = qmax_x 304 self.num_points = npts 305 306 # Set the controls 307 self.qmin.SetValue(format_number(self.qmin_x)) 308 self.qmax.SetValue(format_number(self.qmax_x)) 309 self.npts.SetValue(format_number(self.num_points)) 310 def checkFitRange(self): 311 """ 312 Check the validity of fitting range 313 @note: qmin should always be less than qmax or else each control box 314 background is colored in pink. 315 """ 316 317 flag = True 318 valueMin = self.qmin.GetValue() 319 valueMax = self.qmax.GetValue() 320 # Check for possible values entered 321 #print "fitpage: checkfitrange:",valueMin,valueMax 322 try: 323 if (float(valueMax)> float(valueMin)): 324 self.qmax.SetBackgroundColour(wx.WHITE) 325 self.qmin.SetBackgroundColour(wx.WHITE) 326 else: 327 flag = False 328 self.qmin.SetBackgroundColour("pink") 329 self.qmax.SetBackgroundColour("pink") 330 except: 331 flag = False 332 self.qmin.SetBackgroundColour("pink") 333 self.qmax.SetBackgroundColour("pink") 334 335 self.qmin.Refresh() 336 self.qmax.Refresh() 337 return flag 338 339 340 341 def onClose(self,event): 342 """ close the page associated with this panel""" 343 self.parent.onClose() 344 345 346 347 def onModel2D(self, event): 348 """ 349 call manager to plot model in 2D 350 """ 351 # If the 2D display is not currently enabled, plot the model in 2D 352 # and set the enable2D flag. 353 if self.enable2D==False: 354 self.enable2D=True 355 self._draw_model() 356 357 else: 358 print "enable is true:",self.enable2D 359 #self.manager.parent. show_panel(147) 360 self.manager.show_panel2D( id=None ) 361 #self.manager.menu1.Append(event_id, new_panel.window_caption, 362 # "Show %s plot panel" % new_panel.window_caption) 363 238 364 239 365 def select_model(self, model, name): … … 254 380 if items[i]==name: 255 381 self.modelbox.SetSelection(i) 256 382 383 384 def _on_select_Disp(self,event): 385 """ 386 allow selecting different dispersion 387 self.disp_list should change type later .now only gaussian 388 """ 389 type = "Gaussian" 390 if type ==event.GetString(): 391 self.set_panel_dispers( self.disp_list,type ) 392 257 393 def _on_select_model(self,event): 258 394 """ … … 260 396 post an event to its owner to draw an appropriate theory 261 397 """ 262 self.model_view.SetFocus() 398 self.disable_disp.SetValue(True) 399 self.sizer8.Clear(True) 400 self.sizer7.Clear(True) 401 self.vbox.Layout() 402 self.SetScrollbars(20,20,55,40) 403 self.Layout() 404 self.parent.GetSizer().Layout() 263 405 for item in self.model_list_box.itervalues(): 264 406 name = item.__name__ … … 298 440 @param model: the model selected in combo box for fitting purpose 299 441 """ 300 301 self.sizer2.Clear(True) 302 self.sizer1.Clear(True) 442 print "set_panel", model 303 443 self.sizer5.Clear(True) 304 444 self.parameters = [] 305 445 self.param_toFit=[] 446 self.fixed_param=[] 306 447 self.model = model 307 448 keys = self.model.getParamList() 449 #list of dispersion paramaters 450 self.disp_list=self.model.getDispParamList() 451 308 452 keys.sort() 309 description=None 310 if hasattr(self.model,'description'): 311 description =model.description 312 disp_list=self.model.getDispParamList() 313 ip=0 314 iq=1 315 if len(disp_list)>0: 316 disp = wx.StaticText(self, -1, 'Dispersion') 317 self.sizer5.Add(disp,( iq, ip),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 318 ip += 1 319 values = wx.StaticText(self, -1, 'Values') 320 self.sizer5.Add(values,( iq, ip),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 321 322 disp_list.sort() 323 #print "went here",self.model.name,model.description 453 ik=0 454 im=1 455 324 456 iy = 1 325 457 ix = 0 326 self.cb0 = wx.StaticText(self, -1,'Model Description:') 327 self.sizer1.Add(self.cb0,(iy, ix),(1,1),\ 328 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 329 iy += 1 330 331 self.cb01 = wx.StaticText(self, -1,str(description),style=wx.ALIGN_LEFT) 332 self.cb01.Wrap(400) 333 #self.cb01 = wx.StaticText(self, -1,str(description),(45, 25),style=wx.ALIGN_LEFT) 334 335 self.sizer1.Add(self.cb01,(iy, ix),(1,1),\ 336 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 337 ix = 0 338 iy = 1 339 self.cb1 = wx.StaticText(self, -1,'Parameters') 340 self.sizer2.Add(self.cb1,(iy, ix),(1,1),\ 458 self.cb1 = wx.CheckBox(self, -1,"Select all", (10, 10)) 459 if self.data!=None: 460 wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param) 461 self.cb1.SetValue(False) 462 else: 463 self.cb1.Disable() 464 self.cb1.Hide() 465 466 self.sizer5.Add(self.cb1,(iy, ix),(1,1),\ 341 467 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 342 468 ix +=1 343 469 self.text2_2 = wx.StaticText(self, -1, 'Values') 344 self.sizer 2.Add(self.text2_2,(iy, ix),(1,1),\470 self.sizer5.Add(self.text2_2,(iy, ix),(1,1),\ 345 471 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 472 ix +=2 473 self.text2_3 = wx.StaticText(self, -1, 'Errors') 474 self.sizer5.Add(self.text2_3,(iy, ix),(1,1),\ 475 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 476 self.text2_3.Hide() 346 477 ix +=1 347 478 self.text2_4 = wx.StaticText(self, -1, 'Units') 348 self.sizer 2.Add(self.text2_4,(iy, ix),(1,1),\479 self.sizer5.Add(self.text2_4,(iy, ix),(1,1),\ 349 480 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 350 481 self.text2_4.Hide() 482 disp_list=self.model.getDispParamList() 351 483 for item in keys: 352 484 if not item in disp_list: 353 485 iy += 1 354 486 ix = 0 355 cb=wx.StaticText(self, -1, item) 356 self.sizer2.Add( cb,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 487 488 cb = wx.CheckBox(self, -1, item, (10, 10)) 489 if self.data!=None: 490 cb.SetValue(False) 491 wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) 492 else: 493 cb.Disable() 494 self.sizer5.Add( cb,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 495 357 496 ix += 1 358 497 value= self.model.getParam(item) … … 360 499 ctl1.SetValue(str (format_number(value))) 361 500 ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 362 ctl1.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) 363 self.sizer2.Add(ctl1, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 501 ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) 502 self.sizer5.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) 503 504 ix += 1 505 text2=wx.StaticText(self, -1, '+/-') 506 self.sizer5.Add(text2,(iy, ix),(1,1),\ 507 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 508 text2.Hide() 509 ix += 1 510 ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) 511 self.sizer5.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 512 ctl2.Hide() 364 513 ix +=1 365 366 514 # Units 367 515 try: … … 369 517 except: 370 518 units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) 371 self.sizer2.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 372 else: 373 ip = 0 374 iq += 1 375 cb=wx.StaticText(self, -1, item) 376 self.sizer5.Add( cb,( iq, ip),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 377 wx.EVT_CHECKBOX(self, cb.GetId(), self._on_select_model) 519 self.sizer5.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 520 521 self.parameters.append([cb,ctl1,text2,ctl2]) 378 522 379 ip += 1380 value= self.model.getParam(item)381 ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER)382 ctl1.SetValue(str (format_number(value)))383 ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)384 ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter)385 self.sizer5.Add(ctl1, (iq,ip),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)386 #save data387 self.parameters.append([cb,ctl1])388 523 iy+=1 389 self.sizer 2.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)524 self.sizer5.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 390 525 391 526 #Display units text on panel … … 396 531 else: 397 532 self.text2_4.Hide() 533 #Disable or enable fit button 534 """ 535 if not (len(self.param_toFit ) >0): 536 self.qmin.Disable() 537 self.qmax.Disable() 538 else: 539 self.qmin.Enable() 540 self.qmax.Enable() 541 """ 398 542 self.vbox.Layout() 399 543 self.SetScrollbars(20,20,55,40) 400 401 self.GrandParent.GetSizer().Layout() 402 544 self.Layout() 545 self.parent.GetSizer().Layout() 546 547 548 def set_panel_dispers(self, disp_list, type="Gaussian" ): 549 550 551 552 ix=0 553 iy=1 554 ### this will become a separate method 555 if type== "Gaussian" : 556 557 disp = wx.StaticText(self, -1, 'Dispersion') 558 self.sizer8.Add(disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 559 ix += 1 560 values = wx.StaticText(self, -1, 'Values') 561 self.sizer8.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 562 ix +=2 563 self.text2_3 = wx.StaticText(self, -1, 'Errors') 564 self.sizer8.Add(self.text2_3,(iy, ix),(1,1),\ 565 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 566 self.text2_3.Hide() 567 568 ix += 1 569 npts = wx.StaticText(self, -1, 'Npts') 570 self.sizer8.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 571 ix += 1 572 nsigmas = wx.StaticText(self, -1, 'Nsigmas') 573 self.sizer8.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 574 575 disp_list.sort() 576 #print disp_list,self.model.fixed,self.model.dispersion 577 for item in self.model.dispersion.keys(): 578 name1=item+".width" 579 name2=item+".npts" 580 name3=item+".nsigmas" 581 iy += 1 582 for p in self.model.dispersion[item].keys(): 583 #print "name 1 2 3", name1, name2, name3 584 if p=="width": 585 ix = 0 586 cb = wx.CheckBox(self, -1, name1, (10, 10)) 587 if self.data !=None: 588 cb.SetValue(False) 589 wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) 590 else: 591 cb.Disable() 592 self.sizer8.Add( cb,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 593 ix = 1 594 value= self.model.getParam(name1) 595 ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) 596 ctl1.SetValue(str (format_number(value))) 597 ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 598 ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) 599 self.sizer8.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) 600 601 ix = 2 602 text2=wx.StaticText(self, -1, '+/-') 603 self.sizer8.Add(text2,(iy, ix),(1,1),\ 604 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 605 text2.Hide() 606 ix = 3 607 ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) 608 self.sizer8.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 609 ctl2.Hide() 610 611 self.parameters.append([cb,ctl1,text2,ctl2]) 612 613 elif p=="npts": 614 ix =4 615 value= self.model.getParam(name2) 616 Tctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER) 617 Tctl.SetValue(str (format_number(value))) 618 Tctl.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 619 Tctl.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) 620 self.sizer8.Add(Tctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 621 self.fixed_param.append([name2, Tctl]) 622 elif p=="nsigmas": 623 ix =5 624 value= self.model.getParam(name3) 625 Tctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER) 626 Tctl.SetValue(str (format_number(value))) 627 Tctl.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 628 Tctl.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) 629 self.sizer8.Add(Tctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 630 self.fixed_param.append([name3, Tctl]) 631 632 633 634 403 635 404 636 def _onparamEnter(self,event): … … 412 644 # Flag to register when a parameter has changed. 413 645 is_modified = False 646 for item in self.fixed_param: 647 try: 648 name=str(item[0]) 649 value= float(item[1].GetValue()) 650 #print "model para", name,value,self.model.getParam(name) 651 # If the value of the parameter has changed, 652 # update the model and set the is_modified flag 653 if value != self.model.getParam(name): 654 #print "went hereee" 655 self.model.setParam(name,value) 656 is_modified = True 657 658 except: 659 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 660 "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) 661 414 662 for item in self.parameters: 415 663 try: 416 664 name=str(item[0].GetLabelText()) 417 665 value= float(item[1].GetValue()) 666 #print " fittable model para", name,value 418 667 # If the value of the parameter has changed, 419 668 # update the model and set the is_modified flag 420 669 if value != self.model.getParam(name): 670 #print "went here", name,value 421 671 self.model.setParam(name,value) 422 672 is_modified = True 423 673 except: 424 wx.PostEvent(self.parent. GrandParent, StatusEvent(status=\674 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 425 675 "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) 426 676 … … 428 678 # If qmin and qmax have been modified, update qmin and qmax and 429 679 # set the is_modified flag to True 430 if float(self. xmin.GetValue()) != self.qmin:431 self.qmin = float(self.xmin.GetValue())680 if float(self.qmin.GetValue()) != self.qmin_x: 681 self.qmin_x = float(self.qmin.GetValue()) 432 682 is_modified = True 433 if float(self. xmax.GetValue()) != self.qmax:434 self.qmax = float(self.xmax.GetValue())683 if float(self.qmax.GetValue()) != self.qmax_x: 684 self.qmax_x = float(self.qmax.GetValue()) 435 685 is_modified = True 436 686 … … 450 700 [Note to coder: This way future changes will be done in only one place.] 451 701 """ 702 #print "_draw_model",self.model 452 703 if name==None: 453 704 name= self.model.name 454 self.manager.draw_model(self.model, name, 455 qmin=self.qmin, qmax=self.qmax, 705 706 self.manager.draw_model(self.model, name, data=self.data, 707 qmin=self.qmin_x, qmax=self.qmax_x, 456 708 qstep= self.num_points, 457 709 enable2D=self.enable2D) … … 462 714 enable2D=self.enable2D) 463 715 """ 464 465 466 716 def select_param(self,event): 717 pass 718 def select_all_param(self,event): 719 pass 720 721 -
sansview/perspectives/fitting/old_fitpage1D.py
rc80c06f r26bf293 5 5 import copy 6 6 import sans.models.dispersion_models 7 from sans.guicomm.events import StatusEvent 8 from modelpage import ModelPage 9 from modelpage import format_number 7 from sans.guicomm.events import StatusEvent 10 8 (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() 11 9 _BOX_WIDTH = 80 12 10 11 def format_number(value, high=False): 12 """ 13 Return a float in a standardized, human-readable formatted string 14 """ 15 try: 16 value = float(value) 17 except: 18 print "returning 0" 19 return "0" 20 21 if high: 22 return "%-6.4g" % value 23 else: 24 return "%-5.3g" % value 13 25 14 26 from modelpage import format_number 27 from modelpage import ModelPage 15 28 class FitPage1D(ModelPage): 16 29 """ … … 39 52 #panel interface 40 53 self.vbox = wx.BoxSizer(wx.VERTICAL) 41 self.sizer10 = wx.GridBagSizer(5,5)42 self.sizer9 = wx.GridBagSizer(5,5)43 self.sizer8 = wx.GridBagSizer(5,5)44 self.sizer7 = wx.GridBagSizer(5,5)45 54 self.sizer6 = wx.GridBagSizer(5,5) 46 55 self.sizer5 = wx.GridBagSizer(5,5) … … 49 58 self.sizer2 = wx.GridBagSizer(5,5) 50 59 self.sizer1 = wx.GridBagSizer(5,5) 51 # Add layer 52 #data info layer 53 self.vbox.Add(self.sizer1) 54 #data range 55 self.vbox.Add(self.sizer2) 56 #instrument smearing selection layer 57 self.vbox.Add(self.sizer3) 58 #model selection 59 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 60 self.vbox.Add(self.sizer4) 61 #model paramaters layer 62 self.vbox.Add(self.sizer5) 63 #polydispersion selected 64 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 65 self.vbox.Add(self.sizer6) 66 #combox box for type of dispersion 67 self.vbox.Add(self.sizer7) 68 #dispersion parameters layer 69 self.vbox.Add(self.sizer8) 70 #fit info layer 71 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 72 self.vbox.Add(self.sizer9) 73 #close layer 74 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 75 self.vbox.Add(self.sizer10) 76 77 #---------sizer 1 draw-------------------------------- 60 61 78 62 self.DataSource =wx.StaticText(self, -1,str(data.name)) 79 63 self.smearer_box = wx.ComboBox(self, -1) … … 90 74 self.smearer_box.Insert(str(v),i) 91 75 i+=1 92 93 # Minimum value of data 94 self.data_min = wx.StaticText(self, -1,str(format_number(numpy.min(data.x)))) 95 # Maximum value of data 96 self.data_max = wx.StaticText(self, -1,str(format_number(numpy.max(data.x)))) 97 #Filing the sizer containing data related fields 76 self.modelbox = wx.ComboBox(self, -1) 77 id = wx.NewId() 78 self.btFit =wx.Button(self,id,'Fit') 79 self.btFit.Bind(wx.EVT_BUTTON, self.onFit,id=id) 80 self.btFit.SetToolTipString("Perform fit.") 81 self.static_line_1 = wx.StaticLine(self, -1) 82 83 self.vbox.Add(self.sizer3) 84 self.vbox.Add(self.sizer2) 85 self.vbox.Add(self.static_line_1, 0, wx.EXPAND, 0) 86 self.vbox.Add(self.sizer5) 87 self.vbox.Add(self.sizer6) 88 self.vbox.Add(self.sizer4) 89 self.vbox.Add(self.sizer1) 90 91 id = wx.NewId() 92 self.btClose =wx.Button(self,id,'Close') 93 self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id) 94 self.btClose.SetToolTipString("Close page.") 98 95 ix = 0 99 96 iy = 1 100 self.sizer 1.Add(wx.StaticText(self, -1, 'Data Source Name : '),(iy,ix),\97 self.sizer3.Add(wx.StaticText(self, -1, 'Data Source Name : '),(iy,ix),\ 101 98 (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 102 103 99 ix += 1 104 self.sizer1.Add(self.DataSource,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 105 106 #---------sizer 2 draw-------------------------------- 100 self.sizer3.Add(self.DataSource,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 101 ix += 1 102 self.sizer3.Add((20,20),(iy,ix),(1,1),wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE,0) 103 ix = 0 104 iy += 1 105 self.sizer3.Add(wx.StaticText(self,-1,'Instrument Smearing'),(iy,ix),(1,1)\ 106 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 107 ix += 1 108 self.sizer3.Add(self.smearer_box,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 109 110 ix = 0 111 iy += 1 112 self.sizer3.Add(wx.StaticText(self,-1,'Model'),(iy,ix),(1,1)\ 113 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 114 ix += 1 115 self.sizer3.Add(self.modelbox,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 116 107 117 ix = 0 108 118 iy = 1 109 119 #set maximum range for x in linear scale 110 120 self.text4_3 = wx.StaticText(self, -1, 'Maximum Data Range(Linear)', style=wx.ALIGN_LEFT) 111 self.sizer 2.Add(self.text4_3,(iy,ix),(1,1),\121 self.sizer4.Add(self.text4_3,(iy,ix),(1,1),\ 112 122 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 123 ix += 1 124 self.sizer4.Add(wx.StaticText(self, -1, 'Min'),(iy, ix),(1,1),\ 125 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 113 126 ix += 2 114 self.sizer2.Add(wx.StaticText(self, -1, 'Min :'),(iy, ix),(1,1),\ 115 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 116 ix += 1 117 self.sizer2.Add(self.data_min,(iy, ix),(1,1),\ 118 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 119 ix += 1 120 self.sizer2.Add(wx.StaticText(self, -1, 'Max : '),(iy, ix),(1,1),\ 121 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 122 ix += 1 123 self.sizer2.Add(self.data_max,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 124 125 #----sizer 3 draw-------------------------------- 126 ix = 0 127 iy = 1 128 self.sizer3.Add(wx.StaticText(self,-1,'Instrument Smearing'),(iy,ix),(1,1)\ 129 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 130 ix += 1 131 self.sizer3.Add(self.smearer_box,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 132 ix =0 133 iy+=1 134 self.sizer3.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 135 136 #------------------ sizer 4 draw------------------------ 137 self.modelbox = wx.ComboBox(self, -1) 138 139 #filling sizer2 140 ix = 0 141 iy = 1 142 self.sizer4.Add(wx.StaticText(self,-1,'Model'),(iy,ix),(1,1)\ 143 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 144 ix += 1 145 self.sizer4.Add(self.modelbox,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 146 147 #----------sizer6------------------------------------------------- 148 self.disable_disp = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP) 149 self.enable_disp = wx.RadioButton(self, -1, 'Yes', (10, 30)) 150 self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.disable_disp.GetId()) 151 self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.enable_disp.GetId()) 152 ix= 0 153 iy=1 154 self.sizer6.Add(wx.StaticText(self,-1,'Polydispersity: '),(iy,ix),(1,1)\ 155 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 156 ix += 1 157 self.sizer6.Add(self.enable_disp ,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 158 ix += 1 159 self.sizer6.Add(self.disable_disp ,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 160 ix =0 161 iy+=1 162 self.sizer6.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 163 164 165 #---------sizer 9 draw---------------------------------------- 166 self.tcChi = wx.StaticText(self, -1, str(0), style=wx.ALIGN_LEFT) 167 self.tcChi.Hide() 168 self.text1_1 = wx.StaticText(self, -1, 'Chi2/dof', style=wx.ALIGN_LEFT) 169 self.text1_1.Hide() 170 171 id = wx.NewId() 172 self.btFit =wx.Button(self,id,'Fit') 173 self.btFit.Bind(wx.EVT_BUTTON, self.onFit,id=id) 174 self.btFit.SetToolTipString("Perform fit.") 175 ## Q range 176 self.qmin= 0.001 177 self.qmax= 0.1 178 self.num_points= 100 179 180 181 self.xmin = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 182 self.xmin.SetValue(format_number(self.qmin)) 183 self.xmin.SetToolTipString("Minimun value of x in linear scale.") 184 self.xmin.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 185 self.xmin.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) 186 self.xmin.Disable() 187 188 self.xmax = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 189 self.xmax.SetValue(format_number(self.qmax)) 190 self.xmax.SetToolTipString("Maximum value of x in linear scale.") 191 self.xmax.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 192 self.xmax.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) 193 self.xmax.Disable() 194 195 self.npts = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 196 self.npts.SetValue(format_number(self.num_points)) 197 self.npts.SetToolTipString("Number of point to plot.") 198 self.npts.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 199 self.npts.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) 200 self.npts.Disable() 201 ix = 0 202 iy = 1 203 self.sizer9.Add(wx.StaticText(self, -1, 'Fitting Range'),(iy, ix),(1,1),\ 204 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 205 ix += 1 206 self.sizer9.Add(wx.StaticText(self, -1, 'Min'),(iy, ix),(1,1),\ 207 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 208 ix += 1 209 self.sizer9.Add(wx.StaticText(self, -1, 'Max'),(iy, ix),(1,1),\ 210 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 211 ix += 1 212 self.sizer9.Add(wx.StaticText(self, -1, 'Npts'),(iy, ix),(1,1),\ 127 self.sizer4.Add(wx.StaticText(self, -1, 'Max'),(iy, ix),(1,1),\ 213 128 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 214 129 ix = 0 215 130 iy += 1 216 self.sizer 9.Add(wx.StaticText(self, -1, 'x range'),(iy, ix),(1,1),\131 self.sizer4.Add(wx.StaticText(self, -1, 'x range'),(iy, ix),(1,1),\ 217 132 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 218 133 ix += 1 219 self.sizer9.Add(self.xmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 220 ix += 1 221 self.sizer9.Add(self.xmax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 222 ix += 1 223 self.sizer9.Add(self.npts,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 134 self.xmin = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 135 self.xmin.SetValue(format_number(numpy.min(data.x))) 136 self.xmin.SetToolTipString("Minimun value of x in linear scale.") 137 self.xmin.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter) 138 self.xmin.Bind(wx.EVT_TEXT_ENTER, self._onTextEnter) 139 self.xmin.Disable() 140 self.sizer4.Add(self.xmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 141 142 143 ix += 2 144 self.xmax = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 145 self.xmax.SetValue(format_number(numpy.max(data.x))) 146 self.xmax.SetToolTipString("Maximum value of x in linear scale.") 147 self.xmax.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter) 148 self.xmax.Bind(wx.EVT_TEXT_ENTER, self._onTextEnter) 149 self.xmax.Disable() 150 self.sizer4.Add(self.xmax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 151 ix =0 152 iy+=1 153 self.sizer4.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 154 #Set chisqr result into TextCtrl 224 155 ix = 0 225 iy += 1 226 self.sizer9.Add(self.text1_1,(iy,ix),(1,1),\ 156 iy = 1 157 158 self.text1_1 = wx.StaticText(self, -1, 'Chi2/dof', style=wx.ALIGN_LEFT) 159 #self.sizer1.Add(self.text1_1,1) 160 self.sizer1.Add(self.text1_1,(iy,ix),(1,1),\ 227 161 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 228 162 ix += 1 229 self.sizer9.Add(self.tcChi,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 163 self.tcChi = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 164 self.tcChi.SetToolTipString("Chi^2 over degrees of freedom.") 165 #self.sizer1.Add(self.tcChi, 1, wx.R | wx.BOTTOM , 5) 166 self.sizer1.Add(self.tcChi,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 230 167 ix +=2 231 self.sizer9.Add(self.btFit,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 232 ix =0 233 iy+=1 234 self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 235 #----------sizer 10 draw------------------------------------------------------ 236 id = wx.NewId() 237 self.btClose =wx.Button(self,id,'Close') 238 self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id) 239 self.btClose.SetToolTipString("Close page.") 240 241 ix= 3 242 iy= 1 243 self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 244 ix +=1 245 self.sizer10.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 246 ix =0 168 #self.sizer1.Add(self.btFit, 1, wx.LEFT | wx.BOTTOM , 5) 169 self.sizer1.Add(self.btFit,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 170 ix+= 2 171 self.sizer1.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 172 #self.sizer1.Add( self.btClose,1, wx.LEFT | wx.BOTTOM , 5) 173 self.tcChi.Disable() 174 ix= 0 247 175 iy+=1 248 self.sizer1 0.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)249 176 self.sizer1.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 177 #self.sizer1.Add((20,20), 0) 250 178 # contains link between model ,all its parameters, and panel organization 251 179 self.parameters=[] … … 270 198 self.Layout() 271 199 self.GrandParent.GetSizer().Layout() 272 273 200 201 202 203 204 205 274 206 def compute_chisqr(self): 275 207 """ @param fn: function that return model value … … 296 228 if numpy.isfinite(item): 297 229 sum +=item 298 self.tcChi.Set Label(format_number(math.fabs(sum)))230 self.tcChi.SetValue(format_number(math.fabs(sum))) 299 231 except: 300 232 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 301 233 "Chisqr cannot be compute: %s"% sys.exc_value)) 302 234 235 236 def onFit(self,event): 237 """ signal for fitting""" 238 239 flag=self.checkFitRange() 240 self.set_manager(self.manager) 241 242 qmin=float(self.xmin.GetValue()) 243 qmax =float( self.xmax.GetValue()) 244 if len(self.param_toFit) >0 and flag==True: 245 self.manager.schedule_for_fit( value=1,fitproblem =None) 246 self.manager._on_single_fit(qmin=qmin,qmax=qmax) 247 else: 248 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 249 "Select at least on parameter to fit ")) 250 251 303 252 def _on_select_model(self,event): 304 253 """ … … 321 270 except: 322 271 raise #ValueError,"model.name is not equal to model class name" 323 break 324 def onFit(self,event): 325 """ signal for fitting""" 326 327 flag=self.checkFitRange() 328 self.set_manager(self.manager) 329 330 qmin=float(self.xmin.GetValue()) 331 qmax =float( self.xmax.GetValue()) 332 if len(self.param_toFit) >0 and flag==True: 333 self.manager.schedule_for_fit( value=1,fitproblem =None) 334 self.manager._on_single_fit(qmin=qmin,qmax=qmax) 335 else: 336 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 337 "Select at least on parameter to fit ")) 338 339 272 break 273 340 274 def _onTextEnter(self,event): 341 275 """ … … 354 288 "Drawing Error:wrong value entered %s"% sys.exc_value)) 355 289 356 290 def checkFitRange(self): 291 """ 292 Check the validity of fitting range 293 @note: xmin should always be less than xmax or else each control box 294 background is colored in pink. 295 """ 296 297 flag = True 298 valueMin = self.xmin.GetValue() 299 valueMax = self.xmax.GetValue() 300 # Check for possible values entered 301 #print "fitpage: checkfitrange:",valueMin,valueMax 302 try: 303 if (float(valueMax)> float(valueMin)): 304 self.xmax.SetBackgroundColour(wx.WHITE) 305 self.xmin.SetBackgroundColour(wx.WHITE) 306 else: 307 flag = False 308 self.xmin.SetBackgroundColour("pink") 309 self.xmax.SetBackgroundColour("pink") 310 except: 311 flag = False 312 self.xmin.SetBackgroundColour("pink") 313 self.xmax.SetBackgroundColour("pink") 314 315 self.xmin.Refresh() 316 self.xmax.Refresh() 317 return flag 318 319 357 320 358 321 def get_param_list(self): … … 368 331 raise ValueError,"missing parameter to fit" 369 332 370 371 372 def old_set_panel(self,model): 333 334 def set_panel(self,model): 373 335 """ 374 336 Build the panel from the model content 375 337 @param model: the model selected in combo box for fitting purpose 376 338 """ 339 self.sizer2.Clear(True) 377 340 self.sizer5.Clear(True) 341 self.sizer6.Clear(True) 378 342 self.parameters = [] 379 343 self.param_toFit=[] … … 382 346 #print "fitpage1D : dispersion list",self.model.getDispParamList() 383 347 keys.sort() 348 disp_list=self.model.getDispParamList() 349 fixed=self.model.fixed 350 print "fixed",fixed 351 #model.setParam("scale", 2) 352 #print "model sphere scale fixed?", self.model.is_fittable("scale") 353 ip=0 354 iq=1 355 384 356 ik=0 385 357 im=1 386 358 if len(disp_list)>0: 359 disp = wx.StaticText(self, -1, 'Dispersion') 360 self.sizer5.Add(disp,( iq, ip),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 361 ip += 1 362 values = wx.StaticText(self, -1, 'Values') 363 self.sizer5.Add(values,( iq, ip),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 364 365 disp_list.sort() 387 366 iy = 1 388 367 ix = 0 389 368 self.cb1 = wx.CheckBox(self, -1,"Select all", (10, 10)) 390 369 wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param) 391 self.sizer 5.Add(self.cb1,(iy, ix),(1,1),\370 self.sizer2.Add(self.cb1,(iy, ix),(1,1),\ 392 371 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 393 372 ix +=1 394 373 self.text2_2 = wx.StaticText(self, -1, 'Values') 395 self.sizer 5.Add(self.text2_2,(iy, ix),(1,1),\374 self.sizer2.Add(self.text2_2,(iy, ix),(1,1),\ 396 375 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 397 376 ix +=2 398 377 self.text2_3 = wx.StaticText(self, -1, 'Errors') 399 self.sizer 5.Add(self.text2_3,(iy, ix),(1,1),\378 self.sizer2.Add(self.text2_3,(iy, ix),(1,1),\ 400 379 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 401 380 self.text2_3.Hide() 402 381 ix +=1 403 382 self.text2_4 = wx.StaticText(self, -1, 'Units') 404 self.sizer 5.Add(self.text2_4,(iy, ix),(1,1),\383 self.sizer2.Add(self.text2_4,(iy, ix),(1,1),\ 405 384 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 406 385 self.text2_4.Hide() 407 disp_list=self.model.getDispParamList() 386 #print "keys", keys 387 #print "disp_list", disp_list 388 #print "fix_list",fixed 408 389 for item in keys: 409 390 if not item in disp_list: … … 413 394 cb = wx.CheckBox(self, -1, item, (10, 10)) 414 395 cb.SetValue(False) 415 self.sizer 5.Add( cb,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)396 self.sizer2.Add( cb,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 416 397 wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) 417 398 … … 422 403 ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 423 404 ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) 424 self.sizer 5.Add(ctl1, (iy,ix),(1,1), wx.EXPAND)405 self.sizer2.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) 425 406 426 407 ix += 1 427 408 text2=wx.StaticText(self, -1, '+/-') 428 self.sizer 5.Add(text2,(iy, ix),(1,1),\409 self.sizer2.Add(text2,(iy, ix),(1,1),\ 429 410 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 430 411 text2.Hide() 431 412 ix += 1 432 413 ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) 433 self.sizer 5.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)414 self.sizer2.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 434 415 ctl2.Hide() 435 416 ix +=1 … … 439 420 except: 440 421 units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) 441 self.sizer5.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 442 """ 422 self.sizer2.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 443 423 else: 444 if notitem in fixed:424 if item in fixed: 445 425 ip = 0 446 426 iq += 1 … … 472 452 im += 1 473 453 #save data 474 """454 475 455 self.parameters.append([cb,ctl1,text2,ctl2]) 476 456 477 457 iy+=1 478 self.sizer 5.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)458 self.sizer2.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 479 459 480 460 #Display units text on panel … … 523 503 self.set_model_parameter() 524 504 525 505 def set_model_parameter(self): 506 if len(self.parameters) !=0 and self.model !=None: 507 # Flag to register when a parameter has changed. 508 is_modified = False 509 for item in self.fixed_param: 510 511 try: 512 name=str(item[0]) 513 value= float(item[1].GetValue()) 514 # print "model para", name,value 515 # If the value of the parameter has changed, 516 # update the model and set the is_modified flag 517 if value != self.model.getParam(name): 518 self.model.setParam(name,value) 519 is_modified = True 520 except: 521 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 522 "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) 523 524 for item in self.parameters: 525 # print "paramters",str(item[0].GetLabelText()) 526 try: 527 name=str(item[0].GetLabelText()) 528 value= float(item[1].GetValue()) 529 # print "model para", name,value 530 # If the value of the parameter has changed, 531 # update the model and set the is_modified flag 532 if value != self.model.getParam(name): 533 self.model.setParam(name,value) 534 is_modified = True 535 except: 536 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 537 "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) 538 539 # Here we should check whether the boundaries have been modified. 540 # If qmin and qmax have been modified, update qmin and qmax and 541 # set the is_modified flag to True 542 if float(self.xmin.GetValue()) != self.qmin: 543 self.qmin = float(self.xmin.GetValue()) 544 is_modified = True 545 if float(self.xmax.GetValue()) != self.qmax: 546 self.qmax = float(self.xmax.GetValue()) 547 is_modified = True 548 549 if is_modified: 550 self.manager.redraw_model(qmin=self.qmin, qmax=self.qmax) 551 526 552 def select_all_param(self,event): 527 553 """ -
sansview/perspectives/fitting/old_fitpanel.py
rc80c06f r26bf293 1 1 import wx 2 import wx.aui3 2 import wx.lib 4 3 import numpy … … 8 7 9 8 10 class FitPanel(wx.aui.AuiNotebook):11 #class FitPanel(wx.aui.AuiNotebook,wx.panel):9 10 class FitPanel(wx.Panel): 12 11 """ 13 12 FitPanel class contains fields allowing to fit models and data … … 21 20 window_caption = "Fit Panel " 22 21 CENTER_PANE = True 22 23 23 24 def __init__(self, parent, *args, **kwargs): 24 25 wx.aui.AuiNotebook.__init__(self,parent,-1, style=wx.aui.AUI_NB_SCROLL_BUTTONS ) 26 25 wx.Panel.__init__(self, parent, *args, **kwargs) 27 26 self.manager=None 28 27 self.parent=parent 29 28 self.event_owner=None 30 31 pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE32 self. Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.onClosePage)33 29 #self.menu_mng = models.ModelManager() 30 self.nb = wx.Notebook(self) 31 self.sizer = wx.BoxSizer() 32 self.sizer.Add(self.nb, 1, wx.EXPAND) 34 33 #Creating an initial page for simultaneous fitting 35 34 from simfitpage import SimultaneousFitPage 36 self.sim_page = SimultaneousFitPage(self , -1)37 self.AddPage(self.sim_page,"Simultaneous Fit")38 39 35 self.sim_page = SimultaneousFitPage(self.nb, -1) 36 37 #self.fit_panel.add_page(self.sim_page,"Simultaneous Fit") 38 self.nb.AddPage(self.sim_page,"Simultaneous Fit") 40 39 41 40 #dictionary of miodel {model class name, model class} … … 51 50 self.count=0 52 51 #updating the panel 53 self.Update() 52 self.nb.Update() 53 self.SetSizer(self.sizer) 54 self.sizer.Fit(self) 54 55 self.Center() 55 def onClosePage(self, event): 56 self.ToggleWindowStyle(wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB) 57 print "went here",self.get_current_page(), self.GetPage(0) 58 #event.Skip() 59 if self.GetPageCount() <= 2: 60 print "wente here" 61 62 # Prevent last tab from being closed 63 self.ToggleWindowStyle(~wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB) 64 65 66 67 56 68 57 69 58 … … 99 88 if data.__class__.__name__=='Data2D': 100 89 from fitpage2D import FitPage2D 101 panel = FitPage2D(self ,data, -1)90 panel = FitPage2D(self.nb,data, -1) 102 91 103 92 else: 104 93 105 94 from fitpage1D import FitPage1D 106 panel = FitPage1D(self ,data, -1)95 panel = FitPage1D(self.nb,data, -1) 107 96 m_name= "M"+str(self.count) 108 97 panel.set_manager(self.manager) 109 98 panel.set_owner(self.event_owner) 110 99 111 self. AddPage(page=panel,caption=name,select=True)100 self.nb.AddPage(page=panel,text=name,select=True) 112 101 panel.populate_box( self.model_list_box) 113 102 self.fit_page_name = name … … 123 112 """ 124 113 from modelpage import ModelPage 125 panel = ModelPage(self ,model,page_title, -1)114 panel = ModelPage(self.nb,model,page_title, -1) 126 115 panel.set_manager(self.manager) 127 116 panel.set_owner(self.event_owner) 128 self.AddPage(page=panel,caption="Model",select=True) 117 #self.nb.AddPage(page=panel,text=page_title,select=True) 118 self.nb.AddPage(page=panel,text="Model",select=True) 129 119 panel.populate_box( self.model_list_box) 130 120 self.draw_model_name=page_title 131 self.model_page_number=self. GetSelection()132 self.model_page=self. GetPage(self.GetSelection())121 self.model_page_number=self.nb.GetSelection() 122 self.model_page=self.nb.GetPage(self.nb.GetSelection()) 133 123 134 124 … … 160 150 self.model_page.select_model(model, page_title) 161 151 152 def get_notebook(self): 153 """ 154 @return self.nb: return its own notebook mostly used by fitting module 155 """ 156 return self.nb 157 158 def get_page(self, n): 159 """ 160 @return page at position n 161 @param n: page number 162 """ 163 return self.nb.GetPage(n) 164 165 166 def get_page_count(self): 167 """ @return number total of pages contained in notebook""" 168 return self.nb.GetPageCount() 169 170 162 171 def get_current_page(self): 163 172 """ 164 173 @return the current page selected 165 174 """ 166 #return self.nb.GetCurrentPage() 167 return self.GetPage(self.GetSelection() ) 168 169 170 def old_onClose(self, page=None,page_number=None): 175 return self.nb.GetCurrentPage() 176 177 178 def get_selected_page(self): 179 """ @return the page just selected by the user """ 180 return self.nb.GetPage(self.nb.GetSelection()) 181 182 183 def get_page_number(self): 184 return self.nb.GetSelection() 185 186 def onClose(self, page=None,page_number=None): 171 187 """ 172 188 close the current page except the simpage. remove each check box link to the model -
sansview/perspectives/fitting/old_fitting.py
rc80c06f r26bf293 8 8 from sans.guicomm.events import NewPlotEvent, StatusEvent 9 9 from sans.guicomm.events import EVT_SLICER_PANEL,EVT_MODEL2D_PANEL 10 from sans.guiframe.model_thread import Calc2D 11 from sans.guiframe.calcthread import CalcThread 12 10 13 11 14 from sans.fit.AbstractFitEngine import Model,Data,FitData1D,FitData2D … … 320 323 if model.name == model_name: 321 324 small_out.append(p.value ) 322 small_cov.append(p.stderr) 325 if p.stderr ==None: 326 small_cov.append(0) 327 else: 328 small_cov.append(p.stderr) 323 329 model.setParam(param_name,p.value) 324 330 # Display result on each page … … 359 365 model=list[0] 360 366 smearer= value.get_smearer() 361 print "single fit", model, smearer362 367 #Create list of parameters for fitting used 363 368 pars=[] … … 379 384 self.schedule_for_fit( 0,value) 380 385 except: 381 raise382 #wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value))386 #raise 387 wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value)) 383 388 return 384 389 # make sure to keep an alphabetic order … … 407 412 408 413 except: 409 raise414 #raise 410 415 wx.PostEvent(self.parent, StatusEvent(status="Single Fit error: %s" % sys.exc_value)) 411 416 return … … 517 522 name = evt.name 518 523 519 sim_page=self.fit_panel. GetPage(0)524 sim_page=self.fit_panel.get_page(0) 520 525 current_pg = self.fit_panel.get_current_page() 526 selected_page = self.fit_panel.get_selected_page() 521 527 if current_pg != sim_page: 522 528 current_pg.set_panel(model) … … 559 565 @param currpage: page in a dictionary referring to some data 560 566 """ 561 if self.fit_panel. GetPageCount() >1:567 if self.fit_panel.get_page_count() >1: 562 568 for page in self.page_finder.iterkeys(): 563 569 if page==currpage : … … 635 641 636 642 theory.data = numpy.zeros((len(data.y_bins),len(data.x_bins))) 637 for i in range(len(data. y_bins)):638 if data. y_bins[i]>= ymin and data.y_bins[i]<= ymax:639 for j in range(len(data. x_bins)):640 if data. x_bins[i]>= qmin and data.x_bins[i]<= qmax:641 theory.data[j][i]=model.runXY([data.x_bins[ j],data.y_bins[i]])642 643 for i in range(len(data.x_bins)): 644 if data.x_bins[i]>= qmin and data.x_bins[i]<= qmax: 645 for j in range(len(data.y_bins)): 646 if data.y_bins[j]>= ymin and data.y_bins[j]<= ymax: 647 theory.data[j][i]=model.runXY([data.x_bins[i],data.y_bins[j]]) 648 643 649 #print "fitting : plot_helper:", theory.image 644 650 #print data.image … … 673 679 self.fit_panel.add_model_page(model,description,name,topmenu=True) 674 680 675 def draw_model(self,model,name ,d ata=None,description=None,enable1D=True, enable2D=False,681 def draw_model(self,model,name ,description=None,enable1D=True, enable2D=False, 676 682 qmin=DEFAULT_QMIN, qmax=DEFAULT_QMAX, qstep=DEFAULT_NPTS): 677 683 """ 678 684 draw model with default data value 679 685 """ 680 if data !=None:681 self.redraw_model(qmin,qmax)682 return683 686 self._draw_model2D(model=model, 684 687 description=model.description, … … 741 744 742 745 def complete(self, output, elapsed, model, qmin, qmax,qstep=DEFAULT_NPTS): 743 746 744 747 wx.PostEvent(self.parent, StatusEvent(status="Calc \ 745 748 complete in %g sec" % elapsed)) … … 794 797 self.model= model 795 798 if enable2D: 796 from model_thread import Calc2D799 797 800 self.calc_thread = Calc2D(parent =self.parent,x=x, 798 801 y=y,model= self.model, -
sansview/perspectives/fitting/old_modelpage.py
rc80c06f r26bf293 4 4 import numpy 5 5 import copy 6 7 6 8 7 from sans.guicomm.events import StatusEvent … … 25 24 return "%-5.3g" % value 26 25 27 26 28 27 class ModelPage(wx.ScrolledWindow): 29 28 """ … … 46 45 """ 47 46 #self.scroll = wx.ScrolledWindow(self) 48 49 47 self.manager = None 50 48 self.parent = parent 51 self.event_owner = None 52 # this panel does contain data .existing data allow a different drawing 53 #on set_model parameters 54 self.data=None 49 self.event_owner=None 55 50 #panel interface 56 51 self.vbox = wx.BoxSizer(wx.VERTICAL) 57 self.sizer10 = wx.GridBagSizer(5,5) 58 self.sizer9 = wx.GridBagSizer(5,5) 59 self.sizer8 = wx.GridBagSizer(5,5) 60 self.sizer7 = wx.GridBagSizer(5,5) 61 self.sizer6 = wx.GridBagSizer(5,5) 52 self.sizer3 = wx.GridBagSizer(5,5) 53 self.sizer1 = wx.GridBagSizer(5,5) 54 self.sizer2 = wx.GridBagSizer(5,5) 55 self.sizer4 = wx.GridBagSizer(5,5) 62 56 self.sizer5 = wx.GridBagSizer(5,5) 63 self.sizer4 = wx.GridBagSizer(5,5) 64 65 #model selection 66 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 57 self.static_line_1 = wx.StaticLine(self, -1) 58 self.modelbox = wx.ComboBox(self, -1) 59 id = wx.NewId() 60 self.vbox.Add(self.sizer3) 61 self.vbox.Add(self.sizer1) 62 self.vbox.Add(self.sizer2) 63 self.vbox.Add(self.static_line_1, 0, wx.EXPAND, 0) 64 self.vbox.Add(self.sizer5) 67 65 self.vbox.Add(self.sizer4) 68 #model paramaters layer 69 self.vbox.Add(self.sizer5) 70 #polydispersion selected 71 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 72 self.vbox.Add(self.sizer6) 73 #combox box for type of dispersion 74 self.vbox.Add(self.sizer7) 75 #dispersion parameters layer 76 self.vbox.Add(self.sizer8) 77 # plotting range 78 self.vbox.Add(self.sizer9) 79 #close layer 80 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 81 self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) 82 self.vbox.Add(self.sizer10) 83 84 85 #------------------ sizer 4 draw------------------------ 86 self.modelbox = wx.ComboBox(self, -1) 87 # preview selected model name 88 self.prevmodel_name=name 89 #print "model view prev_model",name 90 self.modelbox.SetValue(self.prevmodel_name) 91 #filling sizer2 66 67 id = wx.NewId() 68 self.btClose =wx.Button(self,id,'Close') 69 self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id) 70 self.btClose.SetToolTipString("Close page.") 71 ix = 1 72 iy = 1 73 self.sizer4.Add(wx.StaticText(self, -1, 'Min'),(iy, ix),(1,1),\ 74 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 75 ix += 1 76 self.sizer4.Add(wx.StaticText(self, -1, 'Max'),(iy, ix),(1,1),\ 77 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 78 ix += 1 79 self.sizer4.Add(wx.StaticText(self, -1, 'Npts'),(iy, ix),(1,1),\ 80 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 92 81 ix = 0 93 iy = 1 94 self.sizer4.Add(wx.StaticText(self,-1,'Model'),(iy,ix),(1,1)\ 95 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 96 ix += 1 97 self.sizer4.Add(self.modelbox,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 98 ix += 1 99 id = wx.NewId() 100 self.model_view =wx.Button(self,id,'View 2D') 101 self.model_view.Bind(wx.EVT_BUTTON, self.onModel2D,id=id) 102 self.model_view.SetToolTipString("View model in 2D") 103 self.sizer4.Add(self.model_view,(iy,ix),(1,1),\ 104 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 105 self.model_view.SetFocus() 106 #----------sizer6------------------------------------------------- 107 self.disable_disp = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP) 108 self.enable_disp = wx.RadioButton(self, -1, 'Yes', (10, 30)) 109 self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.disable_disp.GetId()) 110 self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.enable_disp.GetId()) 111 ix= 0 112 iy=1 113 self.sizer6.Add(wx.StaticText(self,-1,'Polydispersity: '),(iy,ix),(1,1)\ 114 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 115 ix += 1 116 self.sizer6.Add(self.enable_disp ,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 117 ix += 1 118 self.sizer6.Add(self.disable_disp ,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 119 ix =0 120 iy+=1 121 self.sizer6.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 122 123 124 #---------sizer 9 draw---------------------------------------- 125 126 ## Q range 82 iy += 1 83 self.sizer4.Add(wx.StaticText(self, -1, 'x range'),(iy, ix),(1,1),\ 84 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 85 ## Q range 127 86 self.qmin= 0.001 128 87 self.qmax= 0.1 129 88 self.num_points= 100 130 89 131 90 ix += 1 132 91 self.xmin = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 133 92 self.xmin.SetValue(format_number(self.qmin)) … … 135 94 self.xmin.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 136 95 self.xmin.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) 137 self.xmin.Disable() 138 96 self.sizer4.Add(self.xmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 97 98 99 ix += 1 139 100 self.xmax = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 140 101 self.xmax.SetValue(format_number(self.qmax)) … … 142 103 self.xmax.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 143 104 self.xmax.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) 144 self. xmax.Disable()145 105 self.sizer4.Add(self.xmax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 106 ix += 1 146 107 self.npts = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 147 108 self.npts.SetValue(format_number(self.num_points)) … … 149 110 self.npts.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 150 111 self.npts.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) 151 self.npts.Disable() 152 ix = 0 153 iy = 1 154 self.sizer9.Add(wx.StaticText(self, -1, 'Plotting Range'),(iy, ix),(1,1),\ 155 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 156 ix += 1 157 self.sizer9.Add(wx.StaticText(self, -1, 'Min'),(iy, ix),(1,1),\ 158 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 159 ix += 1 160 self.sizer9.Add(wx.StaticText(self, -1, 'Max'),(iy, ix),(1,1),\ 161 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 162 ix += 1 163 self.sizer9.Add(wx.StaticText(self, -1, 'Npts'),(iy, ix),(1,1),\ 164 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 112 113 self.sizer4.Add(self.npts,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 165 114 ix = 0 166 115 iy += 1 167 self.sizer9.Add(wx.StaticText(self, -1, 'x range'),(iy, ix),(1,1),\ 168 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 169 ix += 1 170 self.sizer9.Add(self.xmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 171 ix += 1 172 self.sizer9.Add(self.xmax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 173 ix += 1 174 self.sizer9.Add(self.npts,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 175 176 ix =0 177 iy+=1 178 self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 179 #----------sizer 10 draw------------------------------------------------------ 116 self.sizer4.Add((20,20),(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 117 ix +=3 118 self.sizer4.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 119 ix = 0 120 iy = 1 121 self.sizer3.Add(wx.StaticText(self,-1,'Model'),(iy,ix),(1,1)\ 122 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 123 ix += 1 124 self.sizer3.Add(self.modelbox,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 125 #ix = 0 126 #iy += 1 127 ix += 1 180 128 id = wx.NewId() 181 self.btClose =wx.Button(self,id,'Close') 182 self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id) 183 self.btClose.SetToolTipString("Close page.") 184 185 ix= 3 186 iy= 1 187 self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 188 ix +=1 189 self.sizer10.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 190 ix =0 191 iy+=1 192 self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 193 129 self.model_view =wx.Button(self,id,'View 2D') 130 self.model_view.Bind(wx.EVT_BUTTON, self.onModel2D,id=id) 131 self.model_view.SetToolTipString("View model in 2D") 132 self.sizer3.Add(self.model_view,(iy,ix),(1,1),\ 133 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 194 134 # contains link between model ,all its parameters, and panel organization 195 135 self.parameters=[] 196 self.fixed_param=[]197 136 #contains link between a model and selected parameters to fit 198 137 self.param_toFit=[] 199 138 # model on which the fit would be performed 200 self.model=None 139 self.model=model 140 try: 141 #print"init modelpage",model.name 142 self.set_panel(model) 143 except: 144 raise 145 # preview selected model name 146 self.prevmodel_name=name 147 #print "model view prev_model",name 148 self.modelbox.SetValue(self.prevmodel_name) 149 # flag to check if the user has selected a new model in the combox box 150 self.model_hasChanged=False 201 151 #dictionary of model name and model class 202 152 self.model_list_box={} 203 153 204 # # Q range205 self. qmin= 0.001206 self.qmax= 0.1207 154 #enable model 2D draw 155 self.enable2D= False 156 # Data1D to make a deep comparison between 2 Data1D for checking data 157 #change 208 158 self.vbox.Layout() 209 159 self.vbox.Fit(self) 160 210 161 self.SetSizer(self.vbox) 211 162 self.SetScrollbars(20,20,55,40) 212 163 213 164 self.Centre() 214 self.Layout() 215 self.GrandParent.GetSizer().Layout() 165 166 def set_range(self, qmin, qmax, npts): 167 """ 168 Set the range for the plotted models 169 @param qmin: minimum Q 170 @param qmax: maximum Q 171 @param npts: number of Q bins 172 """ 173 # Set the data members 174 self.qmin = qmin 175 self.qmax = qmax 176 self.num_points = npts 177 178 # Set the controls 179 self.xmin.SetValue(format_number(self.qmin)) 180 self.xmax.SetValue(format_number(self.qmax)) 181 self.npts.SetValue(format_number(self.num_points)) 182 183 def onClose(self,event): 184 """ close the page associated with this panel""" 185 self.GrandParent.onClose() 216 186 217 187 def set_owner(self,owner): … … 228 198 @param manager: instance of plugin fitting 229 199 """ 230 self.manager = manager 231 200 self.manager = manager 201 202 def onModel2D(self, event): 203 """ 204 call manager to plot model in 2D 205 """ 206 # If the 2D display is not currently enabled, plot the model in 2D 207 # and set the enable2D flag. 208 if self.enable2D==False: 209 self.enable2D=True 210 self._draw_model() 211 212 else: 213 print "enable is true:",self.enable2D 214 #self.manager.parent. show_panel(147) 215 self.manager.show_panel2D( id=None ) 216 #self.manager.menu1.Append(event_id, new_panel.window_caption, 217 # "Show %s plot panel" % new_panel.window_caption) 218 232 219 def populate_box(self, dict): 233 220 """ … … 243 230 name = item.name 244 231 list_name.append(name) 245 list_name.sort() 246 232 list_name.sort() 247 233 for name in list_name: 248 234 self.modelbox.Insert(name,int(id)) … … 250 236 wx.EVT_COMBOBOX(self.modelbox,-1, self._on_select_model) 251 237 return 0 252 253 254 def Set_DipersParam(self, event):255 if self.enable_disp.GetValue():256 self.set_panel_dispers()257 else:258 self.sizer7.Clear(True)259 self.sizer8.Clear(True)260 261 def set_range(self, qmin, qmax, npts):262 """263 Set the range for the plotted models264 @param qmin: minimum Q265 @param qmax: maximum Q266 @param npts: number of Q bins267 """268 # Set the data members269 self.qmin = qmin270 self.qmax = qmax271 self.num_points = npts272 273 # Set the controls274 self.xmin.SetValue(format_number(self.qmin))275 self.xmax.SetValue(format_number(self.qmax))276 self.npts.SetValue(format_number(self.num_points))277 def checkFitRange(self):278 """279 Check the validity of fitting range280 @note: xmin should always be less than xmax or else each control box281 background is colored in pink.282 """283 284 flag = True285 valueMin = self.xmin.GetValue()286 valueMax = self.xmax.GetValue()287 # Check for possible values entered288 #print "fitpage: checkfitrange:",valueMin,valueMax289 try:290 if (float(valueMax)> float(valueMin)):291 self.xmax.SetBackgroundColour(wx.WHITE)292 self.xmin.SetBackgroundColour(wx.WHITE)293 else:294 flag = False295 self.xmin.SetBackgroundColour("pink")296 self.xmax.SetBackgroundColour("pink")297 except:298 flag = False299 self.xmin.SetBackgroundColour("pink")300 self.xmax.SetBackgroundColour("pink")301 302 self.xmin.Refresh()303 self.xmax.Refresh()304 return flag305 306 307 308 def onClose(self,event):309 """ close the page associated with this panel"""310 self.GrandParent.onClose()311 312 313 314 def onModel2D(self, event):315 """316 call manager to plot model in 2D317 """318 # If the 2D display is not currently enabled, plot the model in 2D319 # and set the enable2D flag.320 if self.enable2D==False:321 self.enable2D=True322 self._draw_model()323 324 else:325 print "enable is true:",self.enable2D326 #self.manager.parent. show_panel(147)327 self.manager.show_panel2D( id=None )328 #self.manager.menu1.Append(event_id, new_panel.window_caption,329 # "Show %s plot panel" % new_panel.window_caption)330 331 238 332 239 def select_model(self, model, name): … … 353 260 post an event to its owner to draw an appropriate theory 354 261 """ 355 262 self.model_view.SetFocus() 356 263 for item in self.model_list_box.itervalues(): 357 264 name = item.__name__ … … 391 298 @param model: the model selected in combo box for fitting purpose 392 299 """ 300 301 self.sizer2.Clear(True) 302 self.sizer1.Clear(True) 393 303 self.sizer5.Clear(True) 394 304 self.parameters = [] … … 396 306 self.model = model 397 307 keys = self.model.getParamList() 398 #print "fitpage1D : dispersion list",self.model.getDispParamList()399 308 keys.sort() 400 ik=0 401 im=1 402 309 description=None 310 if hasattr(self.model,'description'): 311 description =model.description 312 disp_list=self.model.getDispParamList() 313 ip=0 314 iq=1 315 if len(disp_list)>0: 316 disp = wx.StaticText(self, -1, 'Dispersion') 317 self.sizer5.Add(disp,( iq, ip),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 318 ip += 1 319 values = wx.StaticText(self, -1, 'Values') 320 self.sizer5.Add(values,( iq, ip),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 321 322 disp_list.sort() 323 #print "went here",self.model.name,model.description 403 324 iy = 1 404 325 ix = 0 405 self.cb1 = wx.CheckBox(self, -1,"Select all", (10, 10)) 406 if self.data!=None: 407 wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param) 408 self.cb1.SetValue(False) 409 else: 410 self.cb1.Disable() 411 self.cb1.Hide() 412 413 self.sizer5.Add(self.cb1,(iy, ix),(1,1),\ 326 self.cb0 = wx.StaticText(self, -1,'Model Description:') 327 self.sizer1.Add(self.cb0,(iy, ix),(1,1),\ 328 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 329 iy += 1 330 331 self.cb01 = wx.StaticText(self, -1,str(description),style=wx.ALIGN_LEFT) 332 self.cb01.Wrap(400) 333 #self.cb01 = wx.StaticText(self, -1,str(description),(45, 25),style=wx.ALIGN_LEFT) 334 335 self.sizer1.Add(self.cb01,(iy, ix),(1,1),\ 336 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 337 ix = 0 338 iy = 1 339 self.cb1 = wx.StaticText(self, -1,'Parameters') 340 self.sizer2.Add(self.cb1,(iy, ix),(1,1),\ 414 341 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 415 342 ix +=1 416 343 self.text2_2 = wx.StaticText(self, -1, 'Values') 417 self.sizer 5.Add(self.text2_2,(iy, ix),(1,1),\344 self.sizer2.Add(self.text2_2,(iy, ix),(1,1),\ 418 345 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 419 ix +=2420 self.text2_3 = wx.StaticText(self, -1, 'Errors')421 self.sizer5.Add(self.text2_3,(iy, ix),(1,1),\422 wx.EXPAND|wx.ADJUST_MINSIZE, 0)423 self.text2_3.Hide()424 346 ix +=1 425 347 self.text2_4 = wx.StaticText(self, -1, 'Units') 426 self.sizer 5.Add(self.text2_4,(iy, ix),(1,1),\348 self.sizer2.Add(self.text2_4,(iy, ix),(1,1),\ 427 349 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 428 350 self.text2_4.Hide() 429 disp_list=self.model.getDispParamList()430 351 for item in keys: 431 352 if not item in disp_list: 432 353 iy += 1 433 354 ix = 0 434 435 cb = wx.CheckBox(self, -1, item, (10, 10)) 436 if self.data!=None: 437 cb.SetValue(False) 438 wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) 439 else: 440 cb.Disable() 441 self.sizer5.Add( cb,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 442 355 cb=wx.StaticText(self, -1, item) 356 self.sizer2.Add( cb,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 443 357 ix += 1 444 358 value= self.model.getParam(item) … … 446 360 ctl1.SetValue(str (format_number(value))) 447 361 ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 448 ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) 449 self.sizer5.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) 362 ctl1.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) 363 self.sizer2.Add(ctl1, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 364 ix +=1 450 365 451 ix += 1452 text2=wx.StaticText(self, -1, '+/-')453 self.sizer5.Add(text2,(iy, ix),(1,1),\454 wx.EXPAND|wx.ADJUST_MINSIZE, 0)455 text2.Hide()456 ix += 1457 ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER)458 self.sizer5.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)459 ctl2.Hide()460 ix +=1461 366 # Units 462 367 try: … … 464 369 except: 465 370 units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) 466 self.sizer5.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 467 468 self.parameters.append([cb,ctl1,text2,ctl2]) 371 self.sizer2.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 372 else: 373 ip = 0 374 iq += 1 375 cb=wx.StaticText(self, -1, item) 376 self.sizer5.Add( cb,( iq, ip),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 377 wx.EVT_CHECKBOX(self, cb.GetId(), self._on_select_model) 469 378 379 ip += 1 380 value= self.model.getParam(item) 381 ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) 382 ctl1.SetValue(str (format_number(value))) 383 ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) 384 ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) 385 self.sizer5.Add(ctl1, (iq,ip),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 386 #save data 387 self.parameters.append([cb,ctl1]) 470 388 iy+=1 471 self.sizer 5.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)389 self.sizer2.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 472 390 473 391 #Display units text on panel … … 478 396 else: 479 397 self.text2_4.Hide() 480 #Disable or enable fit button481 482 if not (len(self.param_toFit ) >0):483 self.xmin.Disable()484 self.xmax.Disable()485 else:486 self.xmin.Enable()487 self.xmax.Enable()488 489 398 self.vbox.Layout() 490 399 self.SetScrollbars(20,20,55,40) 491 self.Layout()400 492 401 self.GrandParent.GetSizer().Layout() 493 494 402 495 def set_panel_dispers(self):496 self.sizer7.Clear(True)497 self.sizer8.Clear(True)498 disp_list=self.model.getDispParamList()499 ix=0500 iy=1501 if len(disp_list)>0:502 model_disp = wx.StaticText(self, -1, 'Model Disp')503 self.sizer7.Add(model_disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)504 ix += 1505 self.disp_box = wx.ComboBox(self, -1)506 self.sizer7.Add(self.disp_box,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)507 ix = 0508 iy = 1509 disp = wx.StaticText(self, -1, 'Dispersion')510 self.sizer8.Add(disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)511 ix += 1512 values = wx.StaticText(self, -1, 'Values')513 self.sizer8.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)514 ix += 1515 npts = wx.StaticText(self, -1, 'Npts')516 self.sizer8.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)517 ix += 1518 nsigmas = wx.StaticText(self, -1, 'Nsigmas')519 self.sizer8.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)520 521 disp_list.sort()522 print disp_list,self.model.fixed523 for item in disp_list:524 if item in self.model.fixed:525 ix = 0526 iy += 1527 cb = wx.CheckBox(self, -1, item, (10, 10))528 if self.data !=None:529 cb.SetValue(False)530 wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param)531 else:532 cb.Disable()533 self.sizer7.Add( cb,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)534 535 536 ix += 1537 value= self.model.getParam(item)538 ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER)539 ctl1.SetValue(str (format_number(value)))540 ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)541 ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter)542 self.sizer7.Add(ctl1, (iy,ix),(1,1), wx.EXPAND)543 544 self.parameters.append([cb,ctl1])545 iy+= 1546 self.vbox.Layout()547 self.SetScrollbars(20,20,55,40)548 self.Layout()549 self.GrandParent.GetSizer().Layout()550 551 403 552 404 def _onparamEnter(self,event): … … 600 452 if name==None: 601 453 name= self.model.name 602 self.manager.draw_model(self.model, name, data=self.data,454 self.manager.draw_model(self.model, name, 603 455 qmin=self.qmin, qmax=self.qmax, 604 456 qstep= self.num_points, … … 610 462 enable2D=self.enable2D) 611 463 """ 612 def select_param(self,event): 613 pass 614 def select_all_param(self,event): 615 pass 616 617 464 465 466
Note: See TracChangeset
for help on using the changeset viewer.