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