[ed2ea6a] | 1 | import sys |
---|
| 2 | import wx |
---|
| 3 | import wx.lib |
---|
| 4 | import numpy |
---|
| 5 | import copy |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | from sans.guicomm.events import StatusEvent |
---|
| 9 | from sans.guiframe.utils import format_number |
---|
| 10 | (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() |
---|
| 11 | _BOX_WIDTH = 80 |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | class ModelPage(wx.ScrolledWindow): |
---|
| 17 | """ |
---|
| 18 | FitPanel class contains fields allowing to display results when |
---|
| 19 | fitting a model and one data |
---|
| 20 | @note: For Fit to be performed the user should check at least one parameter |
---|
| 21 | on fit Panel window. |
---|
| 22 | |
---|
| 23 | """ |
---|
| 24 | ## Internal name for the AUI manager |
---|
| 25 | window_name = "Fit page" |
---|
| 26 | ## Title to appear on top of the window |
---|
| 27 | window_caption = "Fit Page" |
---|
| 28 | name="" |
---|
| 29 | def __init__(self, parent,model,name, *args, **kwargs): |
---|
| 30 | wx.ScrolledWindow.__init__(self, parent, *args, **kwargs) |
---|
| 31 | """ |
---|
| 32 | Initialization of the Panel |
---|
| 33 | """ |
---|
| 34 | # model on which the fit would be performed |
---|
| 35 | self.model=model |
---|
| 36 | self.back_up_model= model.clone() |
---|
| 37 | #list of dispersion paramaters |
---|
| 38 | self.disp_list=[] |
---|
| 39 | try: |
---|
| 40 | self.disp_list=self.model.getDispParamList() |
---|
| 41 | except: |
---|
| 42 | pass |
---|
| 43 | self.manager = None |
---|
| 44 | self.parent = parent |
---|
| 45 | self.event_owner = None |
---|
| 46 | # this panel does contain data .existing data allow a different drawing |
---|
| 47 | #on set_model parameters |
---|
| 48 | self.data=None |
---|
| 49 | #panel interface |
---|
| 50 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
| 51 | self.sizer11 = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 52 | self.sizer10 = wx.GridBagSizer(5,5) |
---|
| 53 | self.sizer9 = wx.GridBagSizer(5,5) |
---|
| 54 | self.sizer8 = wx.GridBagSizer(5,5) |
---|
| 55 | self.sizer7 = wx.GridBagSizer(5,5) |
---|
| 56 | self.sizer6 = wx.GridBagSizer(5,5) |
---|
| 57 | self.sizer5 = wx.GridBagSizer(5,5) |
---|
| 58 | self.sizer4 = wx.GridBagSizer(5,5) |
---|
| 59 | |
---|
| 60 | #model selection |
---|
| 61 | self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) |
---|
| 62 | self.vbox.Add(self.sizer4) |
---|
| 63 | #model description |
---|
| 64 | self.vbox.Add(self.sizer11) |
---|
| 65 | #model paramaters layer |
---|
| 66 | self.vbox.Add(self.sizer5) |
---|
| 67 | #polydispersion selected |
---|
| 68 | self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) |
---|
| 69 | self.vbox.Add(self.sizer6) |
---|
| 70 | #combox box for type of dispersion |
---|
| 71 | self.vbox.Add(self.sizer7) |
---|
| 72 | #dispersion parameters layer |
---|
| 73 | self.vbox.Add(self.sizer8) |
---|
| 74 | # plotting range |
---|
| 75 | self.vbox.Add(self.sizer9) |
---|
| 76 | #close layer |
---|
| 77 | self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) |
---|
| 78 | self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) |
---|
| 79 | self.vbox.Add(self.sizer10) |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | #------------------ sizer 4 draw------------------------ |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | # define combox box |
---|
| 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 | #enable model 2D draw |
---|
| 92 | self.enable2D= False |
---|
| 93 | #filling sizer2 |
---|
| 94 | ix = 0 |
---|
| 95 | iy = 1 |
---|
| 96 | self.sizer4.Add(wx.StaticText(self,-1,'Model'),(iy,ix),(1,1)\ |
---|
| 97 | , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 98 | ix += 1 |
---|
| 99 | self.sizer4.Add(self.modelbox,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 100 | ix += 1 |
---|
| 101 | id = wx.NewId() |
---|
| 102 | self.model_view =wx.Button(self,id,'View 2D') |
---|
| 103 | self.model_view.Bind(wx.EVT_BUTTON, self.onModel2D,id=id) |
---|
| 104 | self.model_view.SetToolTipString("View model in 2D") |
---|
| 105 | |
---|
| 106 | self.sizer4.Add(self.model_view,(iy,ix),(1,1),\ |
---|
| 107 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 108 | |
---|
| 109 | self.model_view.Enable() |
---|
| 110 | self.model_view.SetFocus() |
---|
| 111 | |
---|
| 112 | ix = 0 |
---|
| 113 | iy += 1 |
---|
| 114 | self.sizer4.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 115 | |
---|
| 116 | #----------sizer6------------------------------------------------- |
---|
| 117 | self.disable_disp = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP) |
---|
| 118 | self.enable_disp = wx.RadioButton(self, -1, 'Yes', (10, 30)) |
---|
| 119 | self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.disable_disp.GetId()) |
---|
| 120 | self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.enable_disp.GetId()) |
---|
| 121 | ix= 0 |
---|
| 122 | iy=1 |
---|
| 123 | self.sizer6.Add(wx.StaticText(self,-1,'Polydispersity: '),(iy,ix),(1,1)\ |
---|
| 124 | , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 125 | ix += 1 |
---|
| 126 | self.sizer6.Add(self.enable_disp ,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 127 | ix += 1 |
---|
| 128 | self.sizer6.Add(self.disable_disp ,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 129 | ix =0 |
---|
| 130 | iy+=1 |
---|
| 131 | self.sizer6.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | #---------sizer 9 draw---------------------------------------- |
---|
| 135 | |
---|
| 136 | ## Q range |
---|
| 137 | self.qmin_x= 0.001 |
---|
| 138 | self.qmax_x= 0.1 |
---|
| 139 | self.num_points= 100 |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | self.qmin = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
| 143 | self.qmin.SetValue(format_number(self.qmin_x)) |
---|
| 144 | self.qmin.SetToolTipString("Minimun value of Q in linear scale.") |
---|
| 145 | self.qmin.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 146 | self.qmin.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
| 147 | |
---|
| 148 | self.qmax = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
| 149 | self.qmax.SetValue(format_number(self.qmax_x)) |
---|
| 150 | self.qmax.SetToolTipString("Maximum value of Q in linear scale.") |
---|
| 151 | self.qmax.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 152 | self.qmax.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
| 153 | |
---|
| 154 | |
---|
| 155 | self.npts = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
| 156 | self.npts.SetValue(format_number(self.num_points)) |
---|
| 157 | self.npts.SetToolTipString("Number of point to plot.") |
---|
| 158 | self.npts.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 159 | self.npts.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter) |
---|
| 160 | |
---|
| 161 | ix = 0 |
---|
| 162 | iy = 1 |
---|
| 163 | self.sizer9.Add(wx.StaticText(self, -1, 'Plotting Range'),(iy, ix),(1,1),\ |
---|
| 164 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 165 | ix += 1 |
---|
| 166 | self.sizer9.Add(wx.StaticText(self, -1, 'Min'),(iy, ix),(1,1),\ |
---|
| 167 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 168 | ix += 1 |
---|
| 169 | self.sizer9.Add(wx.StaticText(self, -1, 'Max'),(iy, ix),(1,1),\ |
---|
| 170 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 171 | ix += 1 |
---|
| 172 | self.sizer9.Add(wx.StaticText(self, -1, 'Npts'),(iy, ix),(1,1),\ |
---|
| 173 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 174 | ix = 0 |
---|
| 175 | iy += 1 |
---|
| 176 | self.sizer9.Add(wx.StaticText(self, -1, 'Q range'),(iy, ix),(1,1),\ |
---|
| 177 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 178 | ix += 1 |
---|
| 179 | self.sizer9.Add(self.qmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 180 | ix += 1 |
---|
| 181 | self.sizer9.Add(self.qmax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 182 | ix += 1 |
---|
| 183 | self.sizer9.Add(self.npts,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 184 | |
---|
| 185 | ix =0 |
---|
| 186 | iy+=1 |
---|
| 187 | self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 188 | #----------sizer 10 draw------------------------------------------------------ |
---|
| 189 | id = wx.NewId() |
---|
| 190 | self.btClose =wx.Button(self,id,'Close') |
---|
| 191 | self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id) |
---|
| 192 | self.btClose.SetToolTipString("Close page.") |
---|
| 193 | |
---|
| 194 | ix= 3 |
---|
| 195 | iy= 1 |
---|
| 196 | self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 197 | ix +=1 |
---|
| 198 | self.sizer10.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 199 | ix =0 |
---|
| 200 | iy+=1 |
---|
| 201 | self.sizer10.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 202 | |
---|
| 203 | # contains link between model ,all its parameters, and panel organization |
---|
| 204 | self.parameters=[] |
---|
| 205 | self.fixed_param=[] |
---|
| 206 | self.fittable_param=[] |
---|
| 207 | self.polydisp= {} |
---|
| 208 | #contains link between a model and selected parameters to fit |
---|
| 209 | self.param_toFit=[] |
---|
| 210 | |
---|
| 211 | #dictionary of model name and model class |
---|
| 212 | self.model_list_box={} |
---|
| 213 | #Draw initial panel |
---|
| 214 | #-----sizer 11--------------------model description------ |
---|
| 215 | if self.model!=None: |
---|
| 216 | self.set_panel(self.model) |
---|
| 217 | self.theta_cb=None |
---|
| 218 | |
---|
| 219 | |
---|
| 220 | self.vbox.Layout() |
---|
| 221 | self.vbox.Fit(self) |
---|
| 222 | self.SetSizer(self.vbox) |
---|
| 223 | self.SetScrollbars(20,20,55,40) |
---|
| 224 | |
---|
| 225 | self.Centre() |
---|
| 226 | self.Layout() |
---|
| 227 | self.parent.GetSizer().Layout() |
---|
| 228 | def set_model_description(self, model): |
---|
| 229 | |
---|
| 230 | if model !=None and str(model.description)!=""and self.data==None: |
---|
| 231 | self.sizer11.Clear(True) |
---|
| 232 | self.box_description= wx.StaticBox(self, -1, 'Model Description') |
---|
| 233 | boxsizer1 = wx.StaticBoxSizer(self.box_description, wx.VERTICAL) |
---|
| 234 | boxsizer1.SetMinSize((320,20)) |
---|
| 235 | self.description = wx.StaticText(self,-1,str(model.description)) |
---|
| 236 | boxsizer1.Add(self.description, 0, wx.EXPAND) |
---|
| 237 | self.sizer11.Add(boxsizer1,1, wx.EXPAND | wx.ALL, 2) |
---|
| 238 | |
---|
| 239 | |
---|
| 240 | def set_owner(self,owner): |
---|
| 241 | """ |
---|
| 242 | set owner of fitpage |
---|
| 243 | @param owner: the class responsible of plotting |
---|
| 244 | """ |
---|
| 245 | self.event_owner=owner |
---|
| 246 | |
---|
| 247 | |
---|
| 248 | def set_manager(self, manager): |
---|
| 249 | """ |
---|
| 250 | set panel manager |
---|
| 251 | @param manager: instance of plugin fitting |
---|
| 252 | """ |
---|
| 253 | self.manager = manager |
---|
| 254 | |
---|
| 255 | def populate_box(self, dict): |
---|
| 256 | """ |
---|
| 257 | Populate each combox box of each page |
---|
| 258 | @param page: the page to populate |
---|
| 259 | """ |
---|
| 260 | id=0 |
---|
| 261 | self.model_list_box=dict |
---|
| 262 | list_name=[] |
---|
| 263 | for item in self.model_list_box.itervalues(): |
---|
| 264 | name = item.__name__ |
---|
| 265 | if hasattr(item, "name"): |
---|
| 266 | name = item.name |
---|
| 267 | list_name.append(name) |
---|
| 268 | list_name.sort() |
---|
| 269 | |
---|
| 270 | for name in list_name: |
---|
| 271 | self.modelbox.Insert(name,int(id)) |
---|
| 272 | id+=1 |
---|
| 273 | wx.EVT_COMBOBOX(self.modelbox,-1, self._on_select_model) |
---|
| 274 | return 0 |
---|
| 275 | |
---|
| 276 | |
---|
| 277 | def Set_DipersParam(self, event): |
---|
| 278 | if self.enable_disp.GetValue(): |
---|
| 279 | if len(self.disp_list)==0: |
---|
| 280 | ix=0 |
---|
| 281 | iy=1 |
---|
| 282 | self.fittable_param=[] |
---|
| 283 | self.fixed_param=[] |
---|
| 284 | self.sizer8.Clear(True) |
---|
| 285 | model_disp = wx.StaticText(self, -1, 'No PolyDispersity for this model') |
---|
| 286 | self.sizer7.Add(model_disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 287 | self.vbox.Layout() |
---|
| 288 | self.SetScrollbars(20,20,55,40) |
---|
| 289 | self.Layout() |
---|
| 290 | self.parent.GetSizer().Layout() |
---|
| 291 | return |
---|
| 292 | else: |
---|
| 293 | if self.data !=None and self.model !=None: # allow to recognize data panel from model panel |
---|
| 294 | |
---|
| 295 | |
---|
| 296 | self.cb1.SetValue(False) |
---|
| 297 | self.select_all_param_helper() |
---|
| 298 | |
---|
| 299 | self.populate_disp_box() |
---|
| 300 | self.set_panel_dispers(self.disp_list) |
---|
| 301 | |
---|
| 302 | else: |
---|
| 303 | if self.data !=None and self.model!=None: |
---|
| 304 | if self.cb1.GetValue(): |
---|
| 305 | self.select_all_param_helper() |
---|
| 306 | try: |
---|
| 307 | if self.back_up_model!=None: |
---|
| 308 | keys = self.back_up_model.getDispParamList() |
---|
| 309 | keys.sort() |
---|
| 310 | #disperse param into the initial state |
---|
| 311 | for item in keys: |
---|
| 312 | value= self.back_up_model.getParam(item) |
---|
| 313 | self.model.setParam(item, value) |
---|
| 314 | self._draw_model() |
---|
| 315 | except: |
---|
| 316 | pass |
---|
| 317 | |
---|
| 318 | self.fittable_param=[] |
---|
| 319 | self.fixed_param=[] |
---|
| 320 | self.sizer7.Clear(True) |
---|
| 321 | self.sizer8.Clear(True) |
---|
| 322 | self.vbox.Layout() |
---|
| 323 | self.SetScrollbars(20,20,55,40) |
---|
| 324 | self.Layout() |
---|
| 325 | self.parent.GetSizer().Layout() |
---|
| 326 | |
---|
| 327 | def populate_disp_box(self): |
---|
| 328 | self.sizer7.Clear(True) |
---|
| 329 | if len(self.disp_list)>0: |
---|
| 330 | ix=0 |
---|
| 331 | iy=1 |
---|
| 332 | model_disp = wx.StaticText(self, -1, 'Model Disp') |
---|
| 333 | self.sizer7.Add(model_disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 334 | ix += 1 |
---|
| 335 | # set up the combox box |
---|
| 336 | id = 0 |
---|
| 337 | import sans.models.dispersion_models |
---|
| 338 | self.polydisp= sans.models.dispersion_models.models |
---|
| 339 | self.disp_box = wx.ComboBox(self, -1) |
---|
| 340 | self.disp_box.SetValue("GaussianModel") |
---|
| 341 | for k,v in self.polydisp.iteritems(): |
---|
| 342 | if str(v)=="MyModel": |
---|
| 343 | self.disp_box.Insert("Select customized Model",id) |
---|
| 344 | else: |
---|
| 345 | self.disp_box.Insert(str(v),id) |
---|
| 346 | id+=1 |
---|
| 347 | wx.EVT_COMBOBOX(self.disp_box,-1, self._on_select_Disp) |
---|
| 348 | self.sizer7.Add(self.disp_box,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 349 | self.vbox.Layout() |
---|
| 350 | self.SetScrollbars(20,20,55,40) |
---|
| 351 | self.Layout() |
---|
| 352 | self.parent.GetSizer().Layout() |
---|
| 353 | |
---|
| 354 | |
---|
| 355 | def set_range(self, qmin_x, qmax_x, npts): |
---|
| 356 | """ |
---|
| 357 | Set the range for the plotted models |
---|
| 358 | @param qmin: minimum Q |
---|
| 359 | @param qmax: maximum Q |
---|
| 360 | @param npts: number of Q bins |
---|
| 361 | """ |
---|
| 362 | # Set the data members |
---|
| 363 | self.qmin_x = qmin_x |
---|
| 364 | self.qmax_x = qmax_x |
---|
| 365 | self.num_points = npts |
---|
| 366 | |
---|
| 367 | # Set the controls |
---|
| 368 | self.qmin.SetValue(format_number(self.qmin_x)) |
---|
| 369 | self.qmax.SetValue(format_number(self.qmax_x)) |
---|
| 370 | self.npts.SetValue(format_number(self.num_points)) |
---|
| 371 | def checkFitRange(self): |
---|
| 372 | """ |
---|
| 373 | Check the validity of fitting range |
---|
| 374 | @note: qmin should always be less than qmax or else each control box |
---|
| 375 | background is colored in pink. |
---|
| 376 | """ |
---|
| 377 | |
---|
| 378 | flag = True |
---|
| 379 | valueMin = self.qmin.GetValue() |
---|
| 380 | valueMax = self.qmax.GetValue() |
---|
| 381 | # Check for possible values entered |
---|
| 382 | #print "fitpage: checkfitrange:",valueMin,valueMax |
---|
| 383 | try: |
---|
| 384 | if (float(valueMax)> float(valueMin)): |
---|
| 385 | self.qmax.SetBackgroundColour(wx.WHITE) |
---|
| 386 | self.qmin.SetBackgroundColour(wx.WHITE) |
---|
| 387 | else: |
---|
| 388 | flag = False |
---|
| 389 | self.qmin.SetBackgroundColour("pink") |
---|
| 390 | self.qmax.SetBackgroundColour("pink") |
---|
| 391 | except: |
---|
| 392 | flag = False |
---|
| 393 | self.qmin.SetBackgroundColour("pink") |
---|
| 394 | self.qmax.SetBackgroundColour("pink") |
---|
| 395 | |
---|
| 396 | self.qmin.Refresh() |
---|
| 397 | self.qmax.Refresh() |
---|
| 398 | return flag |
---|
| 399 | |
---|
| 400 | |
---|
| 401 | |
---|
| 402 | def onClose(self,event): |
---|
| 403 | """ close the page associated with this panel""" |
---|
| 404 | self.parent.onClose() |
---|
| 405 | |
---|
| 406 | |
---|
| 407 | |
---|
| 408 | def onModel2D(self, event): |
---|
| 409 | """ |
---|
| 410 | call manager to plot model in 2D |
---|
| 411 | """ |
---|
| 412 | # If the 2D display is not currently enabled, plot the model in 2D |
---|
| 413 | # and set the enable2D flag. |
---|
| 414 | if self.enable2D==False: |
---|
| 415 | self.enable2D=True |
---|
| 416 | self._draw_model() |
---|
| 417 | self.model_view.Disable() |
---|
| 418 | |
---|
| 419 | |
---|
| 420 | def select_model(self, model, name): |
---|
| 421 | """ |
---|
| 422 | Select a new model |
---|
| 423 | @param model: model object |
---|
| 424 | """ |
---|
| 425 | self.model = model |
---|
| 426 | self.parent.model_page.name = name |
---|
| 427 | self.parent.draw_model_name = name |
---|
| 428 | |
---|
| 429 | print "select_model", self.name,model.__class__ |
---|
| 430 | self.set_panel(model) |
---|
| 431 | self._draw_model(name) |
---|
| 432 | |
---|
| 433 | # Select the model from the combo box |
---|
| 434 | items = self.modelbox.GetItems() |
---|
| 435 | for i in range(len(items)): |
---|
| 436 | print "model name",items[i],model.name, model.__class__.__name__ |
---|
| 437 | if items[i]==name: |
---|
| 438 | self.modelbox.SetSelection(i) |
---|
| 439 | |
---|
| 440 | |
---|
| 441 | def _on_select_Disp(self,event): |
---|
| 442 | """ |
---|
| 443 | allow selecting different dispersion |
---|
| 444 | self.disp_list should change type later .now only gaussian |
---|
| 445 | """ |
---|
| 446 | type =event.GetString() |
---|
| 447 | self.set_panel_dispers( self.disp_list,type ) |
---|
| 448 | |
---|
| 449 | def _on_select_model(self,event): |
---|
| 450 | """ |
---|
| 451 | react when a model is selected from page's combo box |
---|
| 452 | post an event to its owner to draw an appropriate theory |
---|
| 453 | """ |
---|
| 454 | self.disable_disp.SetValue(True) |
---|
| 455 | self.sizer8.Clear(True) |
---|
| 456 | self.sizer7.Clear(True) |
---|
| 457 | self.vbox.Layout() |
---|
| 458 | self.SetScrollbars(20,20,55,40) |
---|
| 459 | self.Layout() |
---|
| 460 | self.parent.GetSizer().Layout() |
---|
| 461 | for item in self.model_list_box.itervalues(): |
---|
| 462 | name = item.__name__ |
---|
| 463 | if hasattr(item, "name"): |
---|
| 464 | name = item.name |
---|
| 465 | if name ==event.GetString(): |
---|
| 466 | model=item() |
---|
| 467 | self.model= model |
---|
| 468 | self.set_panel(model) |
---|
| 469 | self.name= name |
---|
| 470 | self.model_view.SetFocus() |
---|
| 471 | self.parent.model_page.name=name |
---|
| 472 | self.parent.draw_model_name=name |
---|
| 473 | #self.manager.draw_model(model, name) |
---|
| 474 | #self.enable2D=False |
---|
| 475 | #self.model_view.Enable() |
---|
| 476 | self._draw_model(name) |
---|
| 477 | |
---|
| 478 | |
---|
| 479 | def get_model_box(self): |
---|
| 480 | """ return reference to combox box self.model""" |
---|
| 481 | return self.modelbox |
---|
| 482 | |
---|
| 483 | |
---|
| 484 | def get_param_list(self): |
---|
| 485 | """ |
---|
| 486 | @return self.param_toFit: list containing references to TextCtrl |
---|
| 487 | checked.Theses TextCtrl will allow reference to parameters to fit. |
---|
| 488 | @raise: if return an empty list of parameter fit will nnote work |
---|
| 489 | properly so raise ValueError,"missing parameter to fit" |
---|
| 490 | """ |
---|
| 491 | if self.param_toFit !=[]: |
---|
| 492 | return self.param_toFit |
---|
| 493 | else: |
---|
| 494 | raise ValueError,"missing parameter to fit" |
---|
| 495 | |
---|
| 496 | |
---|
| 497 | def set_panel(self,model): |
---|
| 498 | """ |
---|
| 499 | Build the panel from the model content |
---|
| 500 | @param model: the model selected in combo box for fitting purpose |
---|
| 501 | """ |
---|
| 502 | print "set_panel", model |
---|
| 503 | |
---|
| 504 | self.sizer5.Clear(True) |
---|
| 505 | self.parameters = [] |
---|
| 506 | self.param_toFit=[] |
---|
| 507 | self.fixed_param=[] |
---|
| 508 | self.model = model |
---|
| 509 | |
---|
| 510 | self.set_model_description( self.model) |
---|
| 511 | |
---|
| 512 | keys = self.model.getParamList() |
---|
| 513 | #list of dispersion paramaters |
---|
| 514 | self.disp_list=self.model.getDispParamList() |
---|
| 515 | |
---|
| 516 | keys.sort() |
---|
| 517 | ik=0 |
---|
| 518 | im=1 |
---|
| 519 | |
---|
| 520 | iy = 1 |
---|
| 521 | ix = 0 |
---|
| 522 | self.cb1 = wx.CheckBox(self, -1,"Select all", (10, 10)) |
---|
| 523 | if self.data!=None: |
---|
| 524 | wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param) |
---|
| 525 | self.cb1.SetValue(False) |
---|
| 526 | else: |
---|
| 527 | self.cb1.Disable() |
---|
| 528 | self.cb1.Hide() |
---|
| 529 | |
---|
| 530 | self.sizer5.Add(self.cb1,(iy, ix),(1,1),\ |
---|
| 531 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 532 | ix +=1 |
---|
| 533 | self.text2_2 = wx.StaticText(self, -1, 'Values') |
---|
| 534 | self.sizer5.Add(self.text2_2,(iy, ix),(1,1),\ |
---|
| 535 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 536 | ix +=2 |
---|
| 537 | self.text2_3 = wx.StaticText(self, -1, 'Errors') |
---|
| 538 | self.sizer5.Add(self.text2_3,(iy, ix),(1,1),\ |
---|
| 539 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 540 | self.text2_3.Hide() |
---|
| 541 | ix +=1 |
---|
| 542 | self.text2_4 = wx.StaticText(self, -1, 'Units') |
---|
| 543 | self.sizer5.Add(self.text2_4,(iy, ix),(1,1),\ |
---|
| 544 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 545 | self.text2_4.Hide() |
---|
| 546 | disp_list=self.model.getDispParamList() |
---|
| 547 | for item in keys: |
---|
| 548 | if not item in disp_list: |
---|
| 549 | iy += 1 |
---|
| 550 | ix = 0 |
---|
| 551 | |
---|
| 552 | cb = wx.CheckBox(self, -1, item, (10, 10)) |
---|
| 553 | if self.data!=None: |
---|
| 554 | cb.SetValue(False) |
---|
| 555 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 556 | else: |
---|
| 557 | cb.Disable() |
---|
| 558 | self.sizer5.Add( cb,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 559 | |
---|
| 560 | ix += 1 |
---|
| 561 | value= self.model.getParam(item) |
---|
| 562 | ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 563 | ctl1.SetValue(str (format_number(value))) |
---|
| 564 | ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 565 | ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
| 566 | self.sizer5.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 567 | |
---|
| 568 | ix += 1 |
---|
| 569 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 570 | self.sizer5.Add(text2,(iy, ix),(1,1),\ |
---|
| 571 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 572 | text2.Hide() |
---|
| 573 | ix += 1 |
---|
| 574 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 575 | self.sizer5.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 576 | ctl2.Hide() |
---|
| 577 | ix +=1 |
---|
| 578 | # Units |
---|
| 579 | try: |
---|
| 580 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
| 581 | except: |
---|
| 582 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
| 583 | self.sizer5.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 584 | |
---|
| 585 | self.parameters.append([cb,ctl1,text2,ctl2]) |
---|
| 586 | |
---|
| 587 | iy+=1 |
---|
| 588 | self.sizer5.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 589 | |
---|
| 590 | #Display units text on panel |
---|
| 591 | for item in keys: |
---|
| 592 | if self.model.details[item][0]!='': |
---|
| 593 | self.text2_4.Show() |
---|
| 594 | break |
---|
| 595 | else: |
---|
| 596 | self.text2_4.Hide() |
---|
| 597 | #Disable or enable fit button |
---|
| 598 | """ |
---|
| 599 | if not (len(self.param_toFit ) >0): |
---|
| 600 | self.qmin.Disable() |
---|
| 601 | self.qmax.Disable() |
---|
| 602 | else: |
---|
| 603 | self.qmin.Enable() |
---|
| 604 | self.qmax.Enable() |
---|
| 605 | """ |
---|
| 606 | self.vbox.Layout() |
---|
| 607 | self.SetScrollbars(20,20,55,40) |
---|
| 608 | self.Layout() |
---|
| 609 | self.parent.GetSizer().Layout() |
---|
| 610 | def _selectDlg(self): |
---|
| 611 | import os |
---|
| 612 | dlg = wx.FileDialog(self, "Choose a weight file", os.getcwd(), "", "*.*", wx.OPEN) |
---|
| 613 | path = None |
---|
| 614 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 615 | path = dlg.GetPath() |
---|
| 616 | dlg.Destroy() |
---|
| 617 | return path |
---|
| 618 | def read_file(self, path): |
---|
| 619 | try: |
---|
| 620 | if path==None: |
---|
| 621 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
| 622 | " Selected Distribution was not loaded: %s"%path)) |
---|
| 623 | return None, None |
---|
| 624 | input_f = open(path, 'r') |
---|
| 625 | buff = input_f.read() |
---|
| 626 | lines = buff.split('\n') |
---|
| 627 | |
---|
| 628 | angles = [] |
---|
| 629 | weights=[] |
---|
| 630 | for line in lines: |
---|
| 631 | toks = line.split() |
---|
| 632 | if len(toks)==2: |
---|
| 633 | try: |
---|
| 634 | angle = float(toks[0]) |
---|
| 635 | weight = float(toks[1]) |
---|
| 636 | except: |
---|
| 637 | # Skip non-data lines |
---|
| 638 | pass |
---|
| 639 | angles.append(angle) |
---|
| 640 | weights.append(weight) |
---|
| 641 | return numpy.array(angles), numpy.array(weights) |
---|
| 642 | except: |
---|
| 643 | raise |
---|
| 644 | |
---|
| 645 | def _draw_disp_theta(self): |
---|
| 646 | path = self._selectDlg() |
---|
| 647 | dispersion=None |
---|
| 648 | |
---|
| 649 | for key, value in self.polydisp.iteritems(): |
---|
| 650 | if value =="MyModel": |
---|
| 651 | disp_ph = key() |
---|
| 652 | disp_th = key() |
---|
| 653 | break |
---|
| 654 | values,weights = self.read_file(path) |
---|
| 655 | if values ==None and weights==None: |
---|
| 656 | return |
---|
| 657 | import math |
---|
| 658 | disp_ph.set_weights( values, weights) |
---|
| 659 | disp_th.set_weights( values, weights) |
---|
| 660 | |
---|
| 661 | if self.theta_cb !=None: |
---|
| 662 | angle= self.theta_cb.GetLabelText() |
---|
| 663 | n=0 |
---|
| 664 | self.disp_list=self.model.getDispParamList() |
---|
| 665 | if angle.lower().count("theta")>0: |
---|
| 666 | for param in self.model.getParamList(): |
---|
| 667 | if not param in self.disp_list and param.lower().count("theta")>0: |
---|
| 668 | self.model.set_dispersion(param, disp_th) |
---|
| 669 | self.model.dispersion[param]['npts'] = len(values) |
---|
| 670 | n+=1 |
---|
| 671 | |
---|
| 672 | if n ==0: |
---|
| 673 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
| 674 | " Model contains no theta distribution")) |
---|
| 675 | else: |
---|
| 676 | self._draw_model() |
---|
| 677 | def _draw_disp_Phi(self): |
---|
| 678 | path = self._selectDlg() |
---|
| 679 | dispersion=None |
---|
| 680 | |
---|
| 681 | for key, value in self.polydisp.iteritems(): |
---|
| 682 | if value =="MyModel": |
---|
| 683 | disp_ph = key() |
---|
| 684 | disp_th = key() |
---|
| 685 | break |
---|
| 686 | values,weights = self.read_file(path) |
---|
| 687 | if values ==None and weights==None: |
---|
| 688 | return |
---|
| 689 | import math |
---|
| 690 | disp_ph.set_weights( values, weights) |
---|
| 691 | disp_th.set_weights( values, weights) |
---|
| 692 | |
---|
| 693 | if self.theta_cb !=None: |
---|
| 694 | angle= self.theta_cb.GetLabelText() |
---|
| 695 | n=0 |
---|
| 696 | self.disp_list=self.model.getDispParamList() |
---|
| 697 | if angle.lower().count("theta")>0: |
---|
| 698 | for param in self.model.getParamList(): |
---|
| 699 | if not param in self.disp_list and param.lower().count("theta")>0: |
---|
| 700 | self.model.set_dispersion(param, disp_th) |
---|
| 701 | self.model.dispersion[param]['npts'] = len(values) |
---|
| 702 | n+=1 |
---|
| 703 | |
---|
| 704 | if n ==0: |
---|
| 705 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
| 706 | " Model contains no theta distribution")) |
---|
| 707 | else: |
---|
| 708 | self._draw_model() |
---|
| 709 | |
---|
| 710 | |
---|
| 711 | def select_disp_angle(self, event): |
---|
| 712 | if not self.phi_cb.GetValue(): |
---|
| 713 | return |
---|
| 714 | path = self._selectDlg() |
---|
| 715 | dispersion=None |
---|
| 716 | |
---|
| 717 | for key, value in self.polydisp.iteritems(): |
---|
| 718 | if value =="MyModel": |
---|
| 719 | disp_ph = key() |
---|
| 720 | disp_th = key() |
---|
| 721 | |
---|
| 722 | break |
---|
| 723 | try: |
---|
| 724 | values,weights = self.read_file(path) |
---|
| 725 | except: |
---|
| 726 | raise |
---|
| 727 | #print "values,weights",values,weights |
---|
| 728 | if values ==None and weights==None: |
---|
| 729 | return |
---|
| 730 | import math |
---|
| 731 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
| 732 | " Costumized Distribution: %s"% path)) |
---|
| 733 | |
---|
| 734 | disp_ph.set_weights( values, weights) |
---|
| 735 | disp_th.set_weights( values, weights) |
---|
| 736 | |
---|
| 737 | |
---|
| 738 | |
---|
| 739 | if self.theta_cb !=None: |
---|
| 740 | angle= self.phi_cb.GetLabelText() |
---|
| 741 | n=0 |
---|
| 742 | print "hello1",self.model.runXY([0.01,0.01]) |
---|
| 743 | self.disp_list=self.model.getDispParamList() |
---|
| 744 | name= "phi" |
---|
| 745 | if angle.lower().count(name)>0: |
---|
| 746 | for param in self.model.getParamList(): |
---|
| 747 | if not param in self.disp_list and param.lower().count(name)>0: |
---|
| 748 | self.model.set_dispersion(param, disp_th) |
---|
| 749 | print "para, th",param, disp_th |
---|
| 750 | #self.model.dispersion[param]['npts'] = len(values) |
---|
| 751 | n+=1 |
---|
| 752 | print "model dispers list",self.model.getDispParamList() |
---|
| 753 | if n ==0: |
---|
| 754 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
| 755 | " Model contains no %s distribution"%name)) |
---|
| 756 | else: |
---|
| 757 | print "hello2",self.model.runXY([0.01,0.01]) |
---|
| 758 | #self._draw_model() |
---|
| 759 | qmin=self.qmin_x |
---|
| 760 | qmax=self.qmax_x |
---|
| 761 | qstep= self.num_points |
---|
| 762 | x= numpy.linspace(start= -1*qmax, |
---|
| 763 | stop= qmax, |
---|
| 764 | num= qstep, |
---|
| 765 | endpoint=True ) |
---|
| 766 | y = numpy.linspace(start= -1*qmax, |
---|
| 767 | stop= qmax, |
---|
| 768 | num= qstep, |
---|
| 769 | endpoint=True ) |
---|
| 770 | output= numpy.zeros([len(x),len(y)]) |
---|
| 771 | for i_x in range(int(len(x))): |
---|
| 772 | for i_y in range(int(len(y))): |
---|
| 773 | if (x[i_x]*x[i_x]+y[i_y]*y[i_y]) \ |
---|
| 774 | < qmin * qmin: |
---|
| 775 | output[i_x] [i_y]=0 |
---|
| 776 | else: |
---|
| 777 | value = self.model.runXY([x[i_x], y[i_y]]) |
---|
| 778 | output[i_x] [i_y]=value |
---|
| 779 | print"modelpage", output |
---|
| 780 | self.manager.complete( output=output, elapsed=None, model=self.model, qmin=qmin, qmax=qmax,qstep=qstep) |
---|
| 781 | #self._draw_model() |
---|
| 782 | |
---|
| 783 | |
---|
| 784 | |
---|
| 785 | def set_panel_dispers(self, disp_list, type="GaussianModel" ): |
---|
| 786 | |
---|
| 787 | self.fittable_param=[] |
---|
| 788 | self.fixed_param=[] |
---|
| 789 | |
---|
| 790 | ix=0 |
---|
| 791 | iy=1 |
---|
| 792 | ### this will become a separate method |
---|
| 793 | if type== "Select customized Model": |
---|
| 794 | ix=0 |
---|
| 795 | iy=1 |
---|
| 796 | self.sizer8.Clear(True) |
---|
| 797 | disp1 = wx.StaticText(self, -1, 'Array Dispersion') |
---|
| 798 | self.sizer8.Add(disp1,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 799 | |
---|
| 800 | ix+=1 |
---|
| 801 | self.theta_cb = wx.CheckBox(self, -1,"Theta ", (10, 10)) |
---|
| 802 | wx.EVT_CHECKBOX(self, self.theta_cb.GetId(), self.select_disp_angle) |
---|
| 803 | self.sizer8.Add(self.theta_cb,(iy, ix),(1,1),\ |
---|
| 804 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 805 | ix+=1 |
---|
| 806 | self.phi_cb = wx.CheckBox(self, -1,"Phi", (10, 10)) |
---|
| 807 | wx.EVT_CHECKBOX(self, self.phi_cb.GetId(), self.select_disp_angle) |
---|
| 808 | self.sizer8.Add(self.phi_cb,(iy, ix),(1,1),\ |
---|
| 809 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 810 | |
---|
| 811 | ix =0 |
---|
| 812 | iy +=1 |
---|
| 813 | self.sizer8.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 814 | self.vbox.Layout() |
---|
| 815 | self.SetScrollbars(20,20,55,40) |
---|
| 816 | self.Layout() |
---|
| 817 | self.parent.GetSizer().Layout() |
---|
| 818 | |
---|
| 819 | if type== "GaussianModel" : |
---|
| 820 | |
---|
| 821 | self.sizer8.Clear(True) |
---|
| 822 | disp = wx.StaticText(self, -1, 'Dispersion') |
---|
| 823 | self.sizer8.Add(disp,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 824 | ix += 1 |
---|
| 825 | values = wx.StaticText(self, -1, 'Values') |
---|
| 826 | self.sizer8.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 827 | ix +=2 |
---|
| 828 | self.text2_3 = wx.StaticText(self, -1, 'Errors') |
---|
| 829 | self.sizer8.Add(self.text2_3,(iy, ix),(1,1),\ |
---|
| 830 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 831 | self.text2_3.Hide() |
---|
| 832 | |
---|
| 833 | ix += 1 |
---|
| 834 | npts = wx.StaticText(self, -1, 'Npts') |
---|
| 835 | self.sizer8.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 836 | ix += 1 |
---|
| 837 | nsigmas = wx.StaticText(self, -1, 'Nsigmas') |
---|
| 838 | self.sizer8.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 839 | |
---|
| 840 | disp_list.sort() |
---|
| 841 | print disp_list,self.model.dispersion |
---|
| 842 | for item in self.model.dispersion.keys(): |
---|
| 843 | name1=item+".width" |
---|
| 844 | name2=item+".npts" |
---|
| 845 | name3=item+".nsigmas" |
---|
| 846 | iy += 1 |
---|
| 847 | for p in self.model.dispersion[item].keys(): |
---|
| 848 | #print "name 1 2 3", name1, name2, name3 |
---|
| 849 | if p=="width": |
---|
| 850 | ix = 0 |
---|
| 851 | cb = wx.CheckBox(self, -1, name1, (10, 10)) |
---|
| 852 | if self.data !=None: |
---|
| 853 | cb.SetValue(False) |
---|
| 854 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 855 | else: |
---|
| 856 | cb.Disable() |
---|
| 857 | self.sizer8.Add( cb,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 858 | ix = 1 |
---|
| 859 | value= self.model.getParam(name1) |
---|
| 860 | ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 861 | ctl1.SetValue(str (format_number(value))) |
---|
| 862 | ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 863 | ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
| 864 | self.sizer8.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 865 | |
---|
| 866 | ix = 2 |
---|
| 867 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 868 | self.sizer8.Add(text2,(iy, ix),(1,1),\ |
---|
| 869 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 870 | text2.Hide() |
---|
| 871 | ix = 3 |
---|
| 872 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 873 | self.sizer8.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 874 | ctl2.Hide() |
---|
| 875 | self.fittable_param.append([cb,ctl1,text2,ctl2]) |
---|
| 876 | |
---|
| 877 | |
---|
| 878 | elif p=="npts": |
---|
| 879 | ix =4 |
---|
| 880 | value= self.model.getParam(name2) |
---|
| 881 | Tctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER) |
---|
| 882 | Tctl.SetValue(str (format_number(value))) |
---|
| 883 | Tctl.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 884 | Tctl.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
| 885 | self.sizer8.Add(Tctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 886 | self.fixed_param.append([name2, Tctl]) |
---|
| 887 | elif p=="nsigmas": |
---|
| 888 | ix =5 |
---|
| 889 | value= self.model.getParam(name3) |
---|
| 890 | Tctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER) |
---|
| 891 | Tctl.SetValue(str (format_number(value))) |
---|
| 892 | Tctl.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 893 | Tctl.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
| 894 | self.sizer8.Add(Tctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 895 | self.fixed_param.append([name3, Tctl]) |
---|
| 896 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
| 897 | " Selected Distribution: Gaussian")) |
---|
| 898 | ix =0 |
---|
| 899 | iy +=1 |
---|
| 900 | self.sizer8.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 901 | self.vbox.Layout() |
---|
| 902 | self.SetScrollbars(20,20,55,40) |
---|
| 903 | self.Layout() |
---|
| 904 | self.parent.GetSizer().Layout() |
---|
| 905 | |
---|
| 906 | |
---|
| 907 | |
---|
| 908 | |
---|
| 909 | def _onparamEnter(self,event): |
---|
| 910 | """ |
---|
| 911 | when enter value on panel redraw model according to changed |
---|
| 912 | """ |
---|
| 913 | self.set_model_parameter() |
---|
| 914 | |
---|
| 915 | def set_model_parameter(self): |
---|
| 916 | if len(self.parameters) !=0 and self.model !=None: |
---|
| 917 | # Flag to register when a parameter has changed. |
---|
| 918 | is_modified = False |
---|
| 919 | for item in self.fittable_param: |
---|
| 920 | try: |
---|
| 921 | name=str(item[0].GetLabelText()) |
---|
| 922 | value= float(item[1].GetValue()) |
---|
| 923 | #print "model para", name,value |
---|
| 924 | # If the value of the parameter has changed, |
---|
| 925 | # update the model and set the is_modified flag |
---|
| 926 | if value != self.model.getParam(name): |
---|
| 927 | #print "went hereee" |
---|
| 928 | self.model.setParam(name,value) |
---|
| 929 | |
---|
| 930 | is_modified = True |
---|
| 931 | |
---|
| 932 | except: |
---|
| 933 | raise |
---|
| 934 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
| 935 | "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) |
---|
| 936 | |
---|
| 937 | for item in self.fixed_param: |
---|
| 938 | try: |
---|
| 939 | name=str(item[0]) |
---|
| 940 | value= float(item[1].GetValue()) |
---|
| 941 | #print "model para", name,value,self.model.getParam(name) |
---|
| 942 | # If the value of the parameter has changed, |
---|
| 943 | # update the model and set the is_modified flag |
---|
| 944 | if value != self.model.getParam(name): |
---|
| 945 | #print "went hereee" |
---|
| 946 | self.model.setParam(name,value) |
---|
| 947 | is_modified = True |
---|
| 948 | |
---|
| 949 | except: |
---|
| 950 | raise |
---|
| 951 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
| 952 | "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) |
---|
| 953 | |
---|
| 954 | for item in self.parameters: |
---|
| 955 | try: |
---|
| 956 | name=str(item[0].GetLabelText()) |
---|
| 957 | value= float(item[1].GetValue()) |
---|
| 958 | #print " fittable model para", name,value |
---|
| 959 | # If the value of the parameter has changed, |
---|
| 960 | # update the model and set the is_modified flag |
---|
| 961 | if value != self.model.getParam(name): |
---|
| 962 | #print "went here", name,value |
---|
| 963 | self.model.setParam(name,value) |
---|
| 964 | is_modified = True |
---|
| 965 | except: |
---|
| 966 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
| 967 | "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) |
---|
| 968 | |
---|
| 969 | # Here we should check whether the boundaries have been modified. |
---|
| 970 | # If qmin and qmax have been modified, update qmin and qmax and |
---|
| 971 | # set the is_modified flag to True |
---|
| 972 | if float(self.qmin.GetValue()) != self.qmin_x: |
---|
| 973 | self.qmin_x = float(self.qmin.GetValue()) |
---|
| 974 | is_modified = True |
---|
| 975 | if float(self.qmax.GetValue()) != self.qmax_x: |
---|
| 976 | self.qmax_x = float(self.qmax.GetValue()) |
---|
| 977 | is_modified = True |
---|
| 978 | |
---|
| 979 | if float(self.npts.GetValue()) != self.num_points: |
---|
| 980 | self.num_points = float(self.npts.GetValue()) |
---|
| 981 | is_modified = True |
---|
| 982 | |
---|
| 983 | if is_modified: |
---|
| 984 | self._draw_model() |
---|
| 985 | |
---|
| 986 | def _draw_model(self, name=None): |
---|
| 987 | """ |
---|
| 988 | Method to draw or refresh a plotted model. |
---|
| 989 | The method will use the data member from the model page |
---|
| 990 | to build a call to the fitting perspective manager. |
---|
| 991 | |
---|
| 992 | [Note to coder: This way future changes will be done in only one place.] |
---|
| 993 | """ |
---|
| 994 | #print "_draw_model",self.model |
---|
| 995 | if name==None: |
---|
| 996 | name= self.model.name |
---|
| 997 | |
---|
| 998 | self.manager.draw_model(self.model, name, data=self.data, |
---|
| 999 | qmin=self.qmin_x, qmax=self.qmax_x, |
---|
| 1000 | qstep= self.num_points, |
---|
| 1001 | enable2D=self.enable2D) |
---|
| 1002 | |
---|
| 1003 | def select_param(self,event): |
---|
| 1004 | pass |
---|
| 1005 | def select_all_param(self,event): |
---|
| 1006 | pass |
---|
| 1007 | def select_all_param_helper(self): |
---|
| 1008 | """ |
---|
| 1009 | Allows selecting or delecting button |
---|
| 1010 | """ |
---|
| 1011 | self.param_toFit=[] |
---|
| 1012 | if self.parameters !=[]: |
---|
| 1013 | if self.cb1.GetValue()==True: |
---|
| 1014 | for item in self.parameters: |
---|
| 1015 | item[0].SetValue(True) |
---|
| 1016 | list= [item[0],item[1],item[2],item[3]] |
---|
| 1017 | self.param_toFit.append(list ) |
---|
| 1018 | if len(self.fittable_param)>0: |
---|
| 1019 | for item in self.fittable_param: |
---|
| 1020 | item[0].SetValue(True) |
---|
| 1021 | list= [item[0],item[1],item[2],item[3]] |
---|
| 1022 | self.param_toFit.append(list ) |
---|
| 1023 | else: |
---|
| 1024 | for item in self.parameters: |
---|
| 1025 | item[0].SetValue(False) |
---|
| 1026 | for item in self.fittable_param: |
---|
| 1027 | item[0].SetValue(False) |
---|
| 1028 | self.param_toFit=[] |
---|
| 1029 | |
---|
| 1030 | |
---|
| 1031 | |
---|