[c77d859] | 1 | import sys |
---|
| 2 | import wx |
---|
| 3 | import wx.lib.newevent |
---|
| 4 | import numpy |
---|
| 5 | import copy |
---|
| 6 | import math |
---|
| 7 | from sans.models.dispersion_models import ArrayDispersion, GaussianDispersion |
---|
| 8 | |
---|
| 9 | from sans.guicomm.events import StatusEvent |
---|
[69bee6d] | 10 | from sans.guiframe.utils import format_number,check_float |
---|
[77e23a2] | 11 | |
---|
[b787e68c] | 12 | ## event to post model to fit to fitting plugins |
---|
[c77d859] | 13 | (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() |
---|
[b787e68c] | 14 | |
---|
| 15 | ## event to know the selected fit engine |
---|
[77e23a2] | 16 | (FitterTypeEvent, EVT_FITTER_TYPE) = wx.lib.newevent.NewEvent() |
---|
[c77d859] | 17 | _BOX_WIDTH = 80 |
---|
| 18 | |
---|
| 19 | import basepage |
---|
| 20 | from basepage import BasicPage |
---|
[b787e68c] | 21 | from basepage import PageInfoEvent |
---|
[c77d859] | 22 | |
---|
| 23 | |
---|
| 24 | class FitPage(BasicPage): |
---|
| 25 | """ |
---|
| 26 | FitPanel class contains fields allowing to display results when |
---|
| 27 | fitting a model and one data |
---|
| 28 | @note: For Fit to be performed the user should check at least one parameter |
---|
| 29 | on fit Panel window. |
---|
| 30 | |
---|
| 31 | """ |
---|
[cfc0913] | 32 | def __init__(self,parent, page_info): |
---|
| 33 | BasicPage.__init__(self, parent, page_info) |
---|
[c77d859] | 34 | """ |
---|
| 35 | Initialization of the Panel |
---|
| 36 | """ |
---|
| 37 | ## fit page does not content npts txtcrtl |
---|
| 38 | self.npts=None |
---|
| 39 | ## if no dispersity parameters is avaible |
---|
| 40 | self.text_disp_1=None |
---|
[dcf29d7] | 41 | ## default fitengine type |
---|
[707436d] | 42 | self.engine_type = None |
---|
[b787e68c] | 43 | ## draw sizer |
---|
[c77d859] | 44 | self._fill_datainfo_sizer() |
---|
| 45 | self._fill_model_sizer( self.sizer1) |
---|
[cfc0913] | 46 | self._fill_range_sizer() |
---|
[87fbc60] | 47 | self._on_select_model(event=None) |
---|
[b787e68c] | 48 | |
---|
[cfc0913] | 49 | ## to update the panel according to the fit engine type selected |
---|
[77e23a2] | 50 | self.Bind(EVT_FITTER_TYPE,self._on_engine_change) |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | def _on_engine_change(self, event): |
---|
| 54 | """ |
---|
| 55 | get an event containing the current name of the fit engine type |
---|
| 56 | @param event: FitterTypeEvent containing the name of the current engine |
---|
| 57 | """ |
---|
[dcf29d7] | 58 | self.engine_type = event.type |
---|
| 59 | |
---|
[77e23a2] | 60 | if len(self.parameters)==0: |
---|
| 61 | return |
---|
| 62 | for item in self.parameters: |
---|
| 63 | if event.type =="scipy": |
---|
[60132ef] | 64 | item[5].SetValue("") |
---|
[77e23a2] | 65 | item[5].Hide() |
---|
[60132ef] | 66 | item[6].SetValue("") |
---|
[77e23a2] | 67 | item[6].Hide() |
---|
| 68 | self.text2_min.Hide() |
---|
| 69 | self.text2_max.Hide() |
---|
| 70 | else: |
---|
| 71 | item[5].Show(True) |
---|
| 72 | item[6].Show(True) |
---|
| 73 | self.text2_min.Show(True) |
---|
| 74 | self.text2_max.Show(True) |
---|
| 75 | |
---|
| 76 | self.sizer3.Layout() |
---|
| 77 | self.SetScrollbars(20,20,200,100) |
---|
[c77d859] | 78 | |
---|
| 79 | |
---|
| 80 | def _fill_range_sizer(self): |
---|
| 81 | """ |
---|
| 82 | Fill the sizer containing the plotting range |
---|
| 83 | add access to npts |
---|
| 84 | """ |
---|
[1ae3fe1] | 85 | sizer_fit = wx.GridSizer(1, 1,0, 0) |
---|
[c77d859] | 86 | |
---|
| 87 | self.btFit = wx.Button(self,wx.NewId(),'Fit') |
---|
| 88 | self.btFit.Bind(wx.EVT_BUTTON, self._onFit,id= self.btFit.GetId()) |
---|
| 89 | self.btFit.SetToolTipString("Perform fit.") |
---|
[2d5f7a1] | 90 | |
---|
[c77d859] | 91 | |
---|
| 92 | sizer_fit.Add((5,5),1, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
[1ae3fe1] | 93 | sizer_fit.Add(self.btFit,0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
[c77d859] | 94 | |
---|
| 95 | sizer_smearer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 96 | #Filling the sizer containing instruments smearing info. |
---|
| 97 | self.disable_smearer = wx.RadioButton(self, -1, 'No', style=wx.RB_GROUP) |
---|
| 98 | self.enable_smearer = wx.RadioButton(self, -1, 'Yes') |
---|
| 99 | self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.disable_smearer.GetId()) |
---|
| 100 | self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.enable_smearer.GetId()) |
---|
| 101 | |
---|
| 102 | sizer_smearer.Add(wx.StaticText(self,-1,'Instrument Smearing? ')) |
---|
| 103 | sizer_smearer.Add((10, 10)) |
---|
| 104 | sizer_smearer.Add( self.enable_smearer ) |
---|
| 105 | sizer_smearer.Add((10,10)) |
---|
| 106 | sizer_smearer.Add( self.disable_smearer ) |
---|
| 107 | |
---|
[7b0fd65] | 108 | #Display Chi^2/dof |
---|
| 109 | sizer_smearer.Add((70,10)) |
---|
| 110 | box_description= wx.StaticBox(self, -1,'Chi2/dof') |
---|
| 111 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
[2a5bba7] | 112 | boxsizer1.SetMinSize((60,-1)) |
---|
[7b0fd65] | 113 | self.tcChi = wx.StaticText(self, -1, "-", style=wx.ALIGN_LEFT) |
---|
| 114 | boxsizer1.Add( self.tcChi ) |
---|
| 115 | sizer_smearer.Add( boxsizer1 ) |
---|
| 116 | |
---|
| 117 | #Set sizer for Fitting section |
---|
[45bf0ede] | 118 | self._set_range_sizer( title="Fitting", |
---|
[c77d859] | 119 | object1=sizer_smearer, object= sizer_fit) |
---|
[7b0fd65] | 120 | |
---|
[c77d859] | 121 | |
---|
| 122 | def _fill_datainfo_sizer(self): |
---|
| 123 | """ |
---|
| 124 | fill sizer 0 with data info |
---|
| 125 | """ |
---|
| 126 | self.sizer0.Clear(True) |
---|
| 127 | ## no loaded data , don't fill the sizer |
---|
| 128 | if self.data== None: |
---|
| 129 | self.sizer0.Layout() |
---|
| 130 | return |
---|
| 131 | |
---|
[fa58441] | 132 | box_description= wx.StaticBox(self, -1, 'Data') |
---|
[c77d859] | 133 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 134 | #---------------------------------------------------------- |
---|
| 135 | sizer_data = wx.GridSizer(3, 3,5, 5) |
---|
| 136 | #Filling the sizer containing data related fields |
---|
| 137 | DataSource =wx.StaticText(self, -1,str(self.data.name)) |
---|
| 138 | |
---|
[fa58441] | 139 | sizer_data.Add(wx.StaticText(self, -1, 'Source Name : ')) |
---|
[c77d859] | 140 | sizer_data.Add(DataSource ) |
---|
[2a5bba7] | 141 | sizer_data.Add( (0,5) ) |
---|
[c77d859] | 142 | |
---|
| 143 | #---------sizer 2 draw-------------------------------- |
---|
| 144 | #set maximum range for x in linear scale |
---|
| 145 | if not hasattr(self.data,"data"): #Display only for 1D data fit |
---|
| 146 | # Minimum value of data |
---|
[b5e98540] | 147 | #data_min = str(format_number(numpy.min(self.data.x))) |
---|
| 148 | data_min = str((numpy.min(self.data.x))) |
---|
[c77d859] | 149 | # Maximum value of data |
---|
[b5e98540] | 150 | # data_max = str(format_number(numpy.max(self.data.x))) |
---|
| 151 | data_max = str((numpy.max(self.data.x))) |
---|
[7b0fd65] | 152 | text4_3 = wx.StaticText(self, -1, 'Total Q Range (1/A)', |
---|
[c77d859] | 153 | style=wx.ALIGN_LEFT) |
---|
| 154 | sizer_data.Add( text4_3 ) |
---|
| 155 | sizer_data.Add(wx.StaticText(self, -1, "Min : %s"%data_min)) |
---|
[2a5bba7] | 156 | |
---|
[c77d859] | 157 | sizer_data.Add(wx.StaticText(self, -1, "Max : %s"%data_max)) |
---|
| 158 | |
---|
| 159 | else: |
---|
| 160 | radius_min= 0 |
---|
| 161 | x= numpy.max(self.data.xmin, self.data.xmax) |
---|
| 162 | y= numpy.max(self.data.ymin, self.data.ymax) |
---|
| 163 | radius_max = math.sqrt(x*x + y*y) |
---|
[b5e98540] | 164 | |
---|
| 165 | #For qmin and qmax, do not use format_number.(If do, qmin and max could be different from what is in the data.) |
---|
[c77d859] | 166 | # Minimum value of data |
---|
[b5e98540] | 167 | #data_min = str(format_number(radius_min)) |
---|
| 168 | data_min = str((radius_min)) |
---|
[c77d859] | 169 | # Maximum value of data |
---|
[b5e98540] | 170 | #data_max = str(format_number(radius_max)) |
---|
| 171 | data_max = str((radius_max)) |
---|
[7b0fd65] | 172 | text4_3 = wx.StaticText(self, -1, 'Total Q Range (1/A)', |
---|
[c77d859] | 173 | style=wx.ALIGN_LEFT) |
---|
| 174 | sizer_data.Add( text4_3 ) |
---|
| 175 | sizer_data.Add(wx.StaticText(self, -1, "Min : %s"%data_min)) |
---|
| 176 | sizer_data.Add(wx.StaticText(self, -1, "Max : %s"%data_max)) |
---|
| 177 | |
---|
| 178 | boxsizer1.Add(sizer_data) |
---|
| 179 | #------------------------------------------------------------ |
---|
| 180 | self.sizer0.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 181 | self.sizer0.Layout() |
---|
| 182 | |
---|
| 183 | self.qmin_x= data_min |
---|
| 184 | self.qmax_x= data_max |
---|
| 185 | |
---|
[7b0fd65] | 186 | |
---|
[c77d859] | 187 | def _fill_model_sizer(self, sizer): |
---|
| 188 | """ |
---|
| 189 | fill sizer containing model info |
---|
| 190 | """ |
---|
[87fbc60] | 191 | |
---|
[c77d859] | 192 | ## class base method to add view 2d button |
---|
[7b0fd65] | 193 | self._set_model_sizer(sizer=sizer, title="Model",object=None ) |
---|
| 194 | |
---|
[c77d859] | 195 | |
---|
| 196 | def _set_sizer_gaussian(self): |
---|
| 197 | """ |
---|
| 198 | draw sizer with gaussian dispersity parameters |
---|
| 199 | """ |
---|
| 200 | self.fittable_param=[] |
---|
| 201 | self.fixed_param=[] |
---|
[60132ef] | 202 | self.orientation_params_disp=[] |
---|
| 203 | |
---|
[c77d859] | 204 | self.sizer4_4.Clear(True) |
---|
| 205 | |
---|
| 206 | if self.model==None: |
---|
| 207 | ##no model is selected |
---|
| 208 | return |
---|
| 209 | if not self.enable_disp.GetValue(): |
---|
| 210 | ## the user didn't select dispersity display |
---|
| 211 | return |
---|
[376916c] | 212 | |
---|
| 213 | self._reset_dispersity() |
---|
| 214 | # Create the dispersion objects |
---|
| 215 | for item in self.model.dispersion.keys(): |
---|
| 216 | disp_model = GaussianDispersion() |
---|
| 217 | self._disp_obj_dict[item] = disp_model |
---|
| 218 | self.model.set_dispersion(item, disp_model) |
---|
| 219 | |
---|
[c77d859] | 220 | ix=0 |
---|
| 221 | iy=1 |
---|
| 222 | disp = wx.StaticText(self, -1, 'Names') |
---|
| 223 | self.sizer4_4.Add(disp,( iy, ix),(1,1), |
---|
| 224 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 225 | ix += 1 |
---|
| 226 | values = wx.StaticText(self, -1, 'Values') |
---|
| 227 | self.sizer4_4.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 228 | ix +=2 |
---|
| 229 | self.text_disp_1 = wx.StaticText(self, -1, 'Errors') |
---|
| 230 | self.sizer4_4.Add( self.text_disp_1,(iy, ix),(1,1),\ |
---|
| 231 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 232 | self.text_disp_1.Hide() |
---|
| 233 | ix += 1 |
---|
| 234 | npts = wx.StaticText(self, -1, 'Npts') |
---|
| 235 | self.sizer4_4.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 236 | ix += 1 |
---|
| 237 | nsigmas = wx.StaticText(self, -1, 'Nsigmas') |
---|
| 238 | self.sizer4_4.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 239 | |
---|
| 240 | for item in self.model.dispersion.keys(): |
---|
[780d095] | 241 | if not item in self.model.orientation_params: |
---|
| 242 | self.disp_cb_dict[item]= None |
---|
| 243 | name1=item+".width" |
---|
| 244 | name2=item+".npts" |
---|
| 245 | name3=item+".nsigmas" |
---|
| 246 | iy += 1 |
---|
| 247 | for p in self.model.dispersion[item].keys(): |
---|
| 248 | |
---|
| 249 | if p=="width": |
---|
| 250 | ix = 0 |
---|
| 251 | cb = wx.CheckBox(self, -1, name1, (10, 10)) |
---|
| 252 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 253 | self.sizer4_4.Add( cb,( iy, ix),(1,1), |
---|
| 254 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 255 | ix = 1 |
---|
| 256 | value= self.model.getParam(name1) |
---|
| 257 | ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
[c77d859] | 258 | style=wx.TE_PROCESS_ENTER) |
---|
[780d095] | 259 | ctl1.SetValue(str (format_number(value))) |
---|
| 260 | ctl1.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
| 261 | ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 262 | ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
| 263 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1),wx.EXPAND) |
---|
| 264 | ## text to show error sign |
---|
| 265 | ix = 2 |
---|
| 266 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 267 | self.sizer4_4.Add(text2,(iy, ix),(1,1), |
---|
| 268 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 269 | text2.Hide() |
---|
| 270 | ## txtcrtl to add error from fit |
---|
| 271 | ix = 3 |
---|
| 272 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 273 | self.sizer4_4.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 274 | ctl2.Hide() |
---|
| 275 | self.fittable_param.append([cb,name1,ctl1,text2, |
---|
| 276 | ctl2, None, None,None]) |
---|
| 277 | elif p=="npts": |
---|
| 278 | ix = 4 |
---|
| 279 | value= self.model.getParam(name2) |
---|
| 280 | Tctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 281 | style=wx.TE_PROCESS_ENTER) |
---|
| 282 | |
---|
| 283 | Tctl.SetValue(str (format_number(value))) |
---|
| 284 | Tctl.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
| 285 | Tctl.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 286 | Tctl.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
| 287 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
| 288 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 289 | self.fixed_param.append([None,name2, Tctl,None,None, |
---|
| 290 | None, None,None]) |
---|
| 291 | elif p=="nsigmas": |
---|
| 292 | ix = 5 |
---|
| 293 | value= self.model.getParam(name3) |
---|
| 294 | Tctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 295 | style=wx.TE_PROCESS_ENTER) |
---|
| 296 | Tctl.SetValue(str (format_number(value))) |
---|
| 297 | Tctl.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
| 298 | Tctl.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 299 | Tctl.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
| 300 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
| 301 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 302 | ix +=1 |
---|
| 303 | self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
| 304 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 305 | |
---|
| 306 | self.fixed_param.append([None,name3, Tctl |
---|
| 307 | ,None,None, None, None,None]) |
---|
| 308 | ix =0 |
---|
| 309 | iy +=1 |
---|
| 310 | self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 311 | for item in self.model.dispersion.keys(): |
---|
| 312 | if item in self.model.orientation_params: |
---|
| 313 | self.disp_cb_dict[item]= None |
---|
| 314 | name1=item+".width" |
---|
| 315 | name2=item+".npts" |
---|
| 316 | name3=item+".nsigmas" |
---|
| 317 | iy += 1 |
---|
| 318 | for p in self.model.dispersion[item].keys(): |
---|
| 319 | |
---|
| 320 | if p=="width": |
---|
| 321 | ix = 0 |
---|
| 322 | cb = wx.CheckBox(self, -1, name1, (10, 10)) |
---|
| 323 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 324 | self.sizer4_4.Add( cb,( iy, ix),(1,1), |
---|
| 325 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 326 | if self.data.__class__.__name__ =="Data2D": |
---|
| 327 | cb.Enable() |
---|
| 328 | else: |
---|
| 329 | cb.Disable() |
---|
| 330 | ix = 1 |
---|
| 331 | value= self.model.getParam(name1) |
---|
| 332 | ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
[c77d859] | 333 | style=wx.TE_PROCESS_ENTER) |
---|
[780d095] | 334 | ctl1.SetValue(str (format_number(value))) |
---|
| 335 | if self.data.__class__.__name__ =="Data2D": |
---|
| 336 | ctl1.Enable() |
---|
| 337 | else: |
---|
| 338 | ctl1.Disable() |
---|
| 339 | ctl1.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
| 340 | ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 341 | ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
| 342 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1),wx.EXPAND) |
---|
| 343 | ## text to show error sign |
---|
| 344 | ix = 2 |
---|
| 345 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 346 | self.sizer4_4.Add(text2,(iy, ix),(1,1), |
---|
| 347 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 348 | text2.Hide() |
---|
| 349 | ## txtcrtl to add error from fit |
---|
| 350 | ix = 3 |
---|
| 351 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 352 | self.sizer4_4.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 353 | ctl2.Hide() |
---|
| 354 | if self.data.__class__.__name__ =="Data2D": |
---|
| 355 | ctl2.Enable() |
---|
| 356 | else: |
---|
| 357 | ctl2.Disable() |
---|
| 358 | self.fittable_param.append([cb,name1,ctl1,text2, |
---|
| 359 | ctl2, None, None,None]) |
---|
[60132ef] | 360 | self.orientation_params_disp.append([cb,name1,ctl1,text2, |
---|
[780d095] | 361 | ctl2, None, None,None]) |
---|
| 362 | elif p=="npts": |
---|
| 363 | ix = 4 |
---|
| 364 | value= self.model.getParam(name2) |
---|
| 365 | Tctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 366 | style=wx.TE_PROCESS_ENTER) |
---|
| 367 | |
---|
| 368 | Tctl.SetValue(str (format_number(value))) |
---|
| 369 | if self.data.__class__.__name__ =="Data2D": |
---|
| 370 | Tctl.Enable() |
---|
| 371 | else: |
---|
| 372 | Tctl.Disable() |
---|
| 373 | Tctl.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
| 374 | Tctl.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 375 | Tctl.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
| 376 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
| 377 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 378 | self.fixed_param.append([None,name2, Tctl,None,None, |
---|
| 379 | None, None,None]) |
---|
[60132ef] | 380 | self.orientation_params_disp.append([None,name2, Tctl,None,None, |
---|
[780d095] | 381 | None, None,None]) |
---|
| 382 | elif p=="nsigmas": |
---|
| 383 | ix = 5 |
---|
| 384 | value= self.model.getParam(name3) |
---|
| 385 | Tctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
| 386 | style=wx.TE_PROCESS_ENTER) |
---|
| 387 | Tctl.SetValue(str (format_number(value))) |
---|
| 388 | if self.data.__class__.__name__ =="Data2D": |
---|
| 389 | Tctl.Enable() |
---|
| 390 | else: |
---|
| 391 | Tctl.Disable() |
---|
| 392 | Tctl.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
| 393 | Tctl.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 394 | Tctl.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
| 395 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
| 396 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 397 | ix +=1 |
---|
| 398 | self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
| 399 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 400 | self.fixed_param.append([None,name3, Tctl |
---|
| 401 | ,None,None, None, None,None]) |
---|
[60132ef] | 402 | self.orientation_params_disp.append([None,name3, Tctl |
---|
[780d095] | 403 | ,None,None, None, None,None]) |
---|
| 404 | |
---|
[c77d859] | 405 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
| 406 | " Selected Distribution: Gaussian")) |
---|
| 407 | ix =0 |
---|
| 408 | iy +=1 |
---|
| 409 | self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 410 | self.sizer4_4.Layout() |
---|
| 411 | self.sizer4.Layout() |
---|
| 412 | self.SetScrollbars(20,20,200,100) |
---|
[0a518e4c] | 413 | |
---|
[c77d859] | 414 | |
---|
| 415 | def _onFit(self, event): |
---|
| 416 | """ |
---|
| 417 | Allow to fit |
---|
| 418 | """ |
---|
[1ae3fe1] | 419 | #self.btFit.SetLabel("Stop") |
---|
[c77d859] | 420 | from sans.guiframe.utils import check_value |
---|
| 421 | flag = check_value( self.qmin, self.qmax) |
---|
| 422 | |
---|
| 423 | if not flag: |
---|
| 424 | msg= "Fitting range invalid" |
---|
| 425 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
| 426 | return |
---|
| 427 | |
---|
| 428 | if len(self.param_toFit) <= 0: |
---|
| 429 | msg= "Select at least one parameter to fit" |
---|
| 430 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
| 431 | return |
---|
| 432 | |
---|
| 433 | self.qmin_x=float(self.qmin.GetValue()) |
---|
| 434 | self.qmax_x =float( self.qmax.GetValue()) |
---|
[6f023e8] | 435 | self.manager._reset_schedule_problem( value=0) |
---|
[ca7a626] | 436 | self.manager.schedule_for_fit( value=1,page=self,fitproblem =None) |
---|
| 437 | self.manager.set_fit_range(page= self,qmin= self.qmin_x, qmax= self.qmax_x) |
---|
[c77d859] | 438 | #single fit |
---|
[ca7a626] | 439 | self.manager.onFit() |
---|
[c77d859] | 440 | |
---|
| 441 | self.sizer5.Layout() |
---|
| 442 | self.SetScrollbars(20,20,55,40) |
---|
| 443 | |
---|
| 444 | |
---|
| 445 | def _on_select_model(self, event): |
---|
| 446 | """ |
---|
| 447 | call back for model selection |
---|
| 448 | """ |
---|
[59a7f2d] | 449 | self._on_select_model_helper() |
---|
[c77d859] | 450 | self.set_model_param_sizer(self.model) |
---|
| 451 | try: |
---|
| 452 | self.compute_chisqr() |
---|
| 453 | except: |
---|
| 454 | ## error occured on chisqr computation |
---|
| 455 | pass |
---|
[3b605bb] | 456 | self.enable_disp.SetValue(False) |
---|
| 457 | self.disable_disp.SetValue(True) |
---|
| 458 | self._set_dipers_Param(event=None) |
---|
| 459 | |
---|
| 460 | evt = ModelEventbox(model=self.model) |
---|
| 461 | wx.PostEvent(self.event_owner, evt) |
---|
| 462 | |
---|
[a074145] | 463 | |
---|
[dd5949d] | 464 | def _onparamEnter(self,event): |
---|
| 465 | """ |
---|
| 466 | when enter value on panel redraw model according to changed |
---|
| 467 | """ |
---|
[69bee6d] | 468 | tcrtl= event.GetEventObject() |
---|
| 469 | if check_float(tcrtl): |
---|
| 470 | self._onparamEnter_helper() |
---|
| 471 | self.compute_chisqr() |
---|
| 472 | else: |
---|
| 473 | msg= "Cannot Plot :Must enter a number!!! " |
---|
| 474 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 475 | return |
---|
[cfc0913] | 476 | |
---|
[a074145] | 477 | def reset_page(self, state): |
---|
| 478 | """ |
---|
| 479 | reset the state |
---|
| 480 | """ |
---|
| 481 | self.reset_page_helper(state) |
---|
| 482 | evt = ModelEventbox(model=self.model) |
---|
| 483 | wx.PostEvent(self.event_owner, evt) |
---|
| 484 | |
---|
| 485 | |
---|
[2140e68] | 486 | def get_range(self): |
---|
| 487 | """ |
---|
| 488 | return the fitting range |
---|
| 489 | """ |
---|
[c9a4377] | 490 | return float(self.qmin_x) , float(self.qmax_x) |
---|
[c77d859] | 491 | |
---|
| 492 | def get_param_list(self): |
---|
| 493 | """ |
---|
| 494 | @return self.param_toFit: list containing references to TextCtrl |
---|
| 495 | checked.Theses TextCtrl will allow reference to parameters to fit. |
---|
| 496 | @raise: if return an empty list of parameter fit will nnote work |
---|
| 497 | properly so raise ValueError,"missing parameter to fit" |
---|
| 498 | """ |
---|
| 499 | if self.param_toFit !=[]: |
---|
| 500 | return self.param_toFit |
---|
| 501 | else: |
---|
| 502 | raise ValueError,"missing parameter to fit" |
---|
| 503 | |
---|
| 504 | def onsetValues(self,chisqr, out,cov): |
---|
| 505 | """ |
---|
| 506 | Build the panel from the fit result |
---|
| 507 | @param chisqr:Value of the goodness of fit metric |
---|
| 508 | @param out:list of parameter with the best value found during fitting |
---|
| 509 | @param cov:Covariance matrix |
---|
| 510 | |
---|
| 511 | """ |
---|
| 512 | self.tcChi.SetLabel(format_number(chisqr)) |
---|
| 513 | params = {} |
---|
| 514 | is_modified = False |
---|
| 515 | has_error = False |
---|
[0a518e4c] | 516 | self.text2_3.Hide() |
---|
| 517 | if self.text_disp_1 !=None: |
---|
| 518 | self.text_disp_1.Hide() |
---|
[c77d859] | 519 | #set the panel when fit result are float not list |
---|
| 520 | if out.__class__==numpy.float64: |
---|
| 521 | self.param_toFit[0][2].SetValue(format_number(out)) |
---|
| 522 | self.param_toFit[0][2].Refresh() |
---|
[0a518e4c] | 523 | |
---|
| 524 | self.param_toFit[0][4].Clear() |
---|
| 525 | self.param_toFit[0][4].Hide() |
---|
[c77d859] | 526 | if cov !=None : |
---|
| 527 | self.text2_3.Show(True) |
---|
[0a518e4c] | 528 | if self.text_disp_1 !=None: |
---|
[c77d859] | 529 | self.text_disp_1.Show(True) |
---|
[69bee6d] | 530 | if cov[0]==None: |
---|
| 531 | self.param_toFit[0][3].Hide() |
---|
| 532 | self.param_toFit[0][4].Clear() |
---|
| 533 | self.param_toFit[0][4].Hide() |
---|
| 534 | self.param_toFit[0][4].Refresh() |
---|
| 535 | else: |
---|
| 536 | self.param_toFit[0][3].Show(True) |
---|
| 537 | self.param_toFit[0][4].Clear() |
---|
| 538 | self.param_toFit[0][4].SetValue(format_number(cov[0])) |
---|
| 539 | self.param_toFit[0][4].Show(True) |
---|
| 540 | self.param_toFit[0][4].Refresh() |
---|
[c77d859] | 541 | else: |
---|
| 542 | i=0 |
---|
| 543 | j=0 |
---|
| 544 | #Set the panel when fit result are list |
---|
| 545 | for item in self.param_toFit: |
---|
[0a518e4c] | 546 | ## reset error value to initial state |
---|
| 547 | item[4].Clear() |
---|
| 548 | item[4].Hide() |
---|
| 549 | item[4].Refresh() |
---|
[c77d859] | 550 | if( out != None ) and len(out)<=len(self.param_toFit)and i < len(out): |
---|
| 551 | item[2].SetValue(format_number(self.model.getParam(item[1]))) |
---|
| 552 | item[2].Refresh() |
---|
| 553 | if(cov !=None)and len(cov)<=len(self.param_toFit)and i < len(cov): |
---|
| 554 | self.text2_3.Show(True) |
---|
| 555 | if self.text_disp_1!=None: |
---|
| 556 | self.text_disp_1.Show(True) |
---|
| 557 | item[3].Show(True) |
---|
| 558 | item[4].Clear() |
---|
| 559 | for j in range(len(out)): |
---|
| 560 | if out[j]==self.model.getParam(item[1]): |
---|
| 561 | break |
---|
[69bee6d] | 562 | ## unable to compare cov[j]==numpy.nan so switch to None |
---|
| 563 | if cov[j]==None: |
---|
| 564 | item[3].Hide() |
---|
| 565 | item[4].Refresh() |
---|
| 566 | item[4].Clear() |
---|
| 567 | item[4].Hide() |
---|
| 568 | else: |
---|
| 569 | item[4].SetValue(format_number(cov[j])) |
---|
| 570 | item[4].Refresh() |
---|
| 571 | item[4].Show(True) |
---|
[c77d859] | 572 | i+=1 |
---|
| 573 | |
---|
| 574 | self.sizer3.Layout() |
---|
| 575 | self.sizer4.Layout() |
---|
| 576 | self.SetScrollbars(20,20,200,100) |
---|
| 577 | |
---|
| 578 | |
---|
| 579 | |
---|
| 580 | def onSmear(self, event): |
---|
| 581 | """ |
---|
| 582 | Create a smear object that will change the way residuals |
---|
| 583 | are compute when fitting |
---|
| 584 | """ |
---|
| 585 | smear =None |
---|
| 586 | msg="" |
---|
| 587 | if self.enable_smearer.GetValue(): |
---|
| 588 | from DataLoader.qsmearing import smear_selection |
---|
[2140e68] | 589 | smear = smear_selection( self.data ) |
---|
[c77d859] | 590 | if hasattr(self.data,"dxl"): |
---|
| 591 | msg= ": Resolution smearing parameters" |
---|
| 592 | if hasattr(self.data,"dxw"): |
---|
| 593 | msg= ": Slit smearing parameters" |
---|
| 594 | if smear ==None: |
---|
| 595 | wx.PostEvent(self.manager.parent, StatusEvent(status=\ |
---|
| 596 | "Data contains no smearing information")) |
---|
| 597 | else: |
---|
| 598 | wx.PostEvent(self.manager.parent, StatusEvent(status=\ |
---|
| 599 | "Data contains smearing information %s"%msg)) |
---|
[fb8daaaf] | 600 | ## set smearing value whether or not the data contain the smearing info |
---|
| 601 | self.manager.set_smearer(smear, qmin= float(self.qmin_x), |
---|
[875f1a2] | 602 | qmax= float(self.qmax_x)) |
---|
| 603 | ##Calculate chi2 |
---|
| 604 | self.compute_chisqr() |
---|
[cfc0913] | 605 | ## save the state enable smearing |
---|
| 606 | self.save_current_state() |
---|
[b787e68c] | 607 | |
---|
[dd5949d] | 608 | |
---|
[c77d859] | 609 | def compute_chisqr2D(self): |
---|
| 610 | """ |
---|
| 611 | compute chi square given a model and data 2D and set the value |
---|
| 612 | to the tcChi txtcrl |
---|
| 613 | """ |
---|
| 614 | from sans.guiframe.utils import check_value |
---|
| 615 | flag = check_value( self.qmin, self.qmax) |
---|
[9cb364a] | 616 | err_image = self.data.err_data |
---|
[7b78bb6] | 617 | if err_image==[] or err_image==None: |
---|
| 618 | err_image= numpy.zeros(len(self.data.x_bins),len(self.data.y_bins)) |
---|
| 619 | |
---|
| 620 | err_image[err_image==0]=1 |
---|
[c77d859] | 621 | res=[] |
---|
| 622 | if flag== True: |
---|
| 623 | try: |
---|
| 624 | self.qmin_x = float(self.qmin.GetValue()) |
---|
| 625 | self.qmax_x = float(self.qmax.GetValue()) |
---|
| 626 | for i in range(len(self.data.x_bins)): |
---|
| 627 | for j in range(len(self.data.y_bins)): |
---|
| 628 | #Check the range containing data between self.qmin_x and self.qmax_x |
---|
[7b78bb6] | 629 | value = math.pow(self.data.x_bins[i],2)+ math.pow(self.data.y_bins[j],2) |
---|
| 630 | if value >= math.pow(self.qmin_x,2) and value <= math.pow(self.qmax_x,2): |
---|
[2a5bba7] | 631 | |
---|
[7b78bb6] | 632 | temp = [self.data.x_bins[i],self.data.y_bins[j]] |
---|
[9cb364a] | 633 | error= err_image[j][i] |
---|
[7b78bb6] | 634 | chisqrji = (self.data.data[j][i]- self.model.runXY(temp ))/error |
---|
| 635 | #Vector containing residuals |
---|
| 636 | res.append( math.pow(chisqrji,2) ) |
---|
[2a5bba7] | 637 | |
---|
[c77d859] | 638 | # compute sum of residual |
---|
| 639 | sum=0 |
---|
| 640 | for item in res: |
---|
| 641 | if numpy.isfinite(item): |
---|
| 642 | sum +=item |
---|
| 643 | self.tcChi.SetLabel(format_number(math.fabs(sum/ len(res)))) |
---|
| 644 | except: |
---|
| 645 | wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ |
---|
| 646 | "Chisqr cannot be compute: %s"% sys.exc_value)) |
---|
| 647 | return |
---|
| 648 | |
---|
| 649 | |
---|
| 650 | def compute_chisqr(self): |
---|
| 651 | """ |
---|
| 652 | compute chi square given a model and data 1D and set the value |
---|
| 653 | to the tcChi txtcrl |
---|
| 654 | """ |
---|
| 655 | from sans.guiframe.utils import check_value |
---|
| 656 | flag = check_value( self.qmin, self.qmax) |
---|
| 657 | |
---|
| 658 | if flag== True: |
---|
| 659 | try: |
---|
| 660 | if hasattr(self.data,"data"): |
---|
| 661 | self.compute_chisqr2D() |
---|
| 662 | return |
---|
| 663 | else: |
---|
| 664 | self.qmin_x = float(self.qmin.GetValue()) |
---|
| 665 | self.qmax_x = float(self.qmax.GetValue()) |
---|
| 666 | # return residuals within self.qmin_x and self.qmax_x |
---|
[60d6c23] | 667 | x,y = [numpy.asarray(v) for v in (self.data.x,self.data.y)] |
---|
| 668 | |
---|
| 669 | if self.data.dy==None: |
---|
| 670 | dy= numpy.zeros(len(y)) |
---|
| 671 | else: |
---|
| 672 | dy= numpy.asarray(self.data.dy) |
---|
| 673 | dy[dy==0]=1 |
---|
[c77d859] | 674 | if self.qmin_x==None and self.qmax_x==None: |
---|
| 675 | fx =numpy.asarray([self.model.run(v) for v in x]) |
---|
| 676 | temp=(y - fx)/dy |
---|
| 677 | res= temp*temp |
---|
| 678 | else: |
---|
| 679 | idx = (x>= self.qmin_x) & (x <=self.qmax_x) |
---|
| 680 | fx = numpy.asarray([self.model.run(item)for item in x[idx ]]) |
---|
| 681 | temp=(y[idx] - fx)/dy[idx] |
---|
| 682 | res= temp*temp |
---|
| 683 | #sum of residuals |
---|
| 684 | sum=0 |
---|
| 685 | for item in res: |
---|
| 686 | if numpy.isfinite(item): |
---|
| 687 | sum +=item |
---|
| 688 | self.tcChi.SetLabel(format_number(math.fabs(sum/ len(res)))) |
---|
| 689 | except: |
---|
| 690 | wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ |
---|
| 691 | "Chisqr cannot be compute: %s"% sys.exc_value)) |
---|
| 692 | return |
---|
| 693 | |
---|
| 694 | |
---|
| 695 | def select_all_param(self,event): |
---|
| 696 | """ |
---|
| 697 | set to true or false all checkBox given the main checkbox value cb1 |
---|
| 698 | """ |
---|
| 699 | self.param_toFit=[] |
---|
[cfc0913] | 700 | |
---|
[c77d859] | 701 | if self.parameters !=[]: |
---|
[998b6b8] | 702 | if self.cb1.GetValue(): |
---|
[c77d859] | 703 | for item in self.parameters: |
---|
| 704 | item[0].SetValue(True) |
---|
| 705 | self.param_toFit.append(item ) |
---|
| 706 | if len(self.fittable_param)>0: |
---|
| 707 | for item in self.fittable_param: |
---|
| 708 | item[0].SetValue(True) |
---|
| 709 | self.param_toFit.append(item ) |
---|
| 710 | else: |
---|
| 711 | for item in self.parameters: |
---|
| 712 | item[0].SetValue(False) |
---|
| 713 | for item in self.fittable_param: |
---|
| 714 | item[0].SetValue(False) |
---|
| 715 | self.param_toFit=[] |
---|
[60132ef] | 716 | |
---|
[cfc0913] | 717 | self.save_current_state() |
---|
| 718 | |
---|
[c77d859] | 719 | |
---|
| 720 | |
---|
| 721 | def select_param(self,event): |
---|
| 722 | """ |
---|
| 723 | Select TextCtrl checked for fitting purpose and stores them |
---|
| 724 | in self.param_toFit=[] list |
---|
| 725 | """ |
---|
| 726 | self.param_toFit=[] |
---|
| 727 | for item in self.parameters: |
---|
| 728 | #Select parameters to fit for list of primary parameters |
---|
[998b6b8] | 729 | if item[0].GetValue(): |
---|
[c77d859] | 730 | if not (item in self.param_toFit): |
---|
| 731 | self.param_toFit.append(item ) |
---|
| 732 | else: |
---|
| 733 | #remove parameters from the fitting list |
---|
| 734 | if item in self.param_toFit: |
---|
| 735 | self.param_toFit.remove(item) |
---|
| 736 | #Select parameters to fit for list of fittable parameters with dispersion |
---|
| 737 | for item in self.fittable_param: |
---|
[998b6b8] | 738 | if item[0].GetValue(): |
---|
[c77d859] | 739 | if not (item in self.param_toFit): |
---|
| 740 | self.param_toFit.append(item) |
---|
| 741 | else: |
---|
| 742 | #remove parameters from the fitting list |
---|
| 743 | if item in self.param_toFit: |
---|
| 744 | self.param_toFit.remove(item) |
---|
| 745 | #Set the value of checkbox that selected every checkbox or not |
---|
| 746 | if len(self.parameters)+len(self.fittable_param) ==len(self.param_toFit): |
---|
| 747 | self.cb1.SetValue(True) |
---|
| 748 | else: |
---|
| 749 | self.cb1.SetValue(False) |
---|
[cfc0913] | 750 | ## save current state of the page |
---|
| 751 | self.save_current_state() |
---|
| 752 | |
---|
[c77d859] | 753 | |
---|
| 754 | |
---|
[77e23a2] | 755 | def set_model_param_sizer(self, model): |
---|
[c77d859] | 756 | """ |
---|
| 757 | Build the panel from the model content |
---|
| 758 | @param model: the model selected in combo box for fitting purpose |
---|
| 759 | """ |
---|
| 760 | self.sizer3.Clear(True) |
---|
| 761 | self.parameters = [] |
---|
| 762 | self.param_toFit=[] |
---|
| 763 | self.fittable_param=[] |
---|
| 764 | self.fixed_param=[] |
---|
[780d095] | 765 | self.orientation_params=[] |
---|
[60132ef] | 766 | self.orientation_params_disp=[] |
---|
[c77d859] | 767 | |
---|
| 768 | if model ==None: |
---|
| 769 | self.sizer3.Layout() |
---|
| 770 | self.SetScrollbars(20,20,200,100) |
---|
| 771 | return |
---|
[707436d] | 772 | ## the panel is drawn using the current value of the fit engine |
---|
| 773 | if self.engine_type==None and self.manager !=None: |
---|
| 774 | self.engine_type= self.manager._return_engine_type() |
---|
| 775 | |
---|
[c77d859] | 776 | box_description= wx.StaticBox(self, -1,str("Model Parameters")) |
---|
| 777 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 778 | sizer = wx.GridBagSizer(5,5) |
---|
| 779 | ## save the current model |
---|
| 780 | self.model = model |
---|
| 781 | |
---|
| 782 | keys = self.model.getParamList() |
---|
| 783 | #list of dispersion paramaters |
---|
| 784 | self.disp_list=self.model.getDispParamList() |
---|
| 785 | |
---|
| 786 | keys.sort() |
---|
| 787 | |
---|
| 788 | iy = 1 |
---|
| 789 | ix = 0 |
---|
| 790 | self.cb1 = wx.CheckBox(self, -1,"Select all", (10, 10)) |
---|
| 791 | wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param) |
---|
| 792 | self.cb1.SetValue(False) |
---|
| 793 | |
---|
| 794 | sizer.Add(self.cb1,(iy, ix),(1,1),\ |
---|
| 795 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 796 | ix +=1 |
---|
| 797 | self.text2_2 = wx.StaticText(self, -1, 'Values') |
---|
| 798 | sizer.Add(self.text2_2,(iy, ix),(1,1),\ |
---|
| 799 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 800 | ix +=2 |
---|
| 801 | self.text2_3 = wx.StaticText(self, -1, 'Errors') |
---|
| 802 | sizer.Add(self.text2_3,(iy, ix),(1,1),\ |
---|
| 803 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 804 | self.text2_3.Hide() |
---|
| 805 | ix +=1 |
---|
| 806 | self.text2_min = wx.StaticText(self, -1, 'Min') |
---|
| 807 | sizer.Add(self.text2_min,(iy, ix),(1,1),\ |
---|
| 808 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 809 | self.text2_min.Hide() |
---|
| 810 | ix +=1 |
---|
| 811 | self.text2_max = wx.StaticText(self, -1, 'Max') |
---|
| 812 | sizer.Add(self.text2_max,(iy, ix),(1,1),\ |
---|
| 813 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 814 | self.text2_max.Hide() |
---|
| 815 | ix += 1 |
---|
[27c5c26] | 816 | self.text2_4 = wx.StaticText(self, -1, '[Units]') |
---|
[c77d859] | 817 | sizer.Add(self.text2_4,(iy, ix),(1,1),\ |
---|
| 818 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 819 | self.text2_4.Hide() |
---|
[dcf29d7] | 820 | if self.engine_type=="park": |
---|
| 821 | self.text2_max.Show(True) |
---|
| 822 | self.text2_min.Show(True) |
---|
[c77d859] | 823 | |
---|
| 824 | for item in keys: |
---|
[780d095] | 825 | if not item in self.disp_list and not item in self.model.orientation_params: |
---|
[c77d859] | 826 | iy += 1 |
---|
| 827 | ix = 0 |
---|
| 828 | ## add parameters name with checkbox for selecting to fit |
---|
| 829 | cb = wx.CheckBox(self, -1, item ) |
---|
| 830 | cb.SetValue(False) |
---|
| 831 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 832 | sizer.Add( cb,( iy, ix),(1,1), |
---|
| 833 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 834 | ## add parameter value |
---|
| 835 | ix += 1 |
---|
| 836 | value= self.model.getParam(item) |
---|
| 837 | ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 838 | style=wx.TE_PROCESS_ENTER) |
---|
| 839 | |
---|
[77e23a2] | 840 | ctl1.SetValue(format_number(value)) |
---|
| 841 | ctl1.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
[c77d859] | 842 | ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 843 | ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
| 844 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 845 | ## text to show error sign |
---|
| 846 | ix += 1 |
---|
| 847 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 848 | sizer.Add(text2,(iy, ix),(1,1),\ |
---|
| 849 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 850 | text2.Hide() |
---|
| 851 | ## txtcrtl to add error from fit |
---|
| 852 | ix += 1 |
---|
| 853 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 854 | sizer.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 855 | ctl2.Hide() |
---|
| 856 | |
---|
[77e23a2] | 857 | param_min, param_max= self.model.details[item][1:] |
---|
[c77d859] | 858 | ix += 1 |
---|
| 859 | ctl3 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER) |
---|
[60132ef] | 860 | ctl3.SetValue(str(param_min)) |
---|
[77e23a2] | 861 | ctl3.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
[c77d859] | 862 | ctl3.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 863 | ctl3.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
| 864 | sizer.Add(ctl3, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 865 | ctl3.Hide() |
---|
[77e23a2] | 866 | |
---|
[c77d859] | 867 | ix += 1 |
---|
| 868 | ctl4 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER) |
---|
[77e23a2] | 869 | ctl4.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
[c77d859] | 870 | ctl4.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 871 | ctl4.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
| 872 | sizer.Add(ctl4, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[60132ef] | 873 | ctl4.SetValue(str(param_max)) |
---|
[c77d859] | 874 | ctl4.Hide() |
---|
[dcf29d7] | 875 | |
---|
| 876 | if self.engine_type=="park": |
---|
| 877 | ctl3.Show(True) |
---|
| 878 | ctl4.Show(True) |
---|
| 879 | |
---|
[c77d859] | 880 | ix +=1 |
---|
| 881 | # Units |
---|
| 882 | try: |
---|
| 883 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
| 884 | except: |
---|
| 885 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
| 886 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 887 | |
---|
| 888 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 889 | self.parameters.append([cb,item, ctl1, |
---|
| 890 | text2,ctl2, ctl3, ctl4,None]) |
---|
[2d5f7a1] | 891 | |
---|
[c77d859] | 892 | iy+=1 |
---|
[2a5bba7] | 893 | sizer.Add((10,10),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[780d095] | 894 | for item in self.model.orientation_params: |
---|
| 895 | if not item in self.disp_list : |
---|
| 896 | iy += 1 |
---|
| 897 | ix = 0 |
---|
| 898 | ## add parameters name with checkbox for selecting to fit |
---|
| 899 | cb = wx.CheckBox(self, -1, item ) |
---|
| 900 | cb.SetValue(False) |
---|
| 901 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 902 | if self.data.__class__.__name__ =="Data2D": |
---|
| 903 | cb.Enable() |
---|
| 904 | else: |
---|
| 905 | cb.Disable() |
---|
| 906 | sizer.Add( cb,( iy, ix),(1,1), |
---|
| 907 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 908 | ## add parameter value |
---|
| 909 | ix += 1 |
---|
| 910 | value= self.model.getParam(item) |
---|
| 911 | ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 912 | style=wx.TE_PROCESS_ENTER) |
---|
| 913 | |
---|
| 914 | ctl1.SetValue(format_number(value)) |
---|
| 915 | if self.data.__class__.__name__ =="Data2D": |
---|
| 916 | ctl1.Enable() |
---|
| 917 | else: |
---|
| 918 | ctl1.Disable() |
---|
| 919 | ctl1.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
| 920 | ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 921 | ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
| 922 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 923 | ## text to show error sign |
---|
| 924 | ix += 1 |
---|
| 925 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 926 | sizer.Add(text2,(iy, ix),(1,1),\ |
---|
| 927 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 928 | text2.Hide() |
---|
| 929 | ## txtcrtl to add error from fit |
---|
| 930 | ix += 1 |
---|
| 931 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 932 | sizer.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 933 | ctl2.Hide() |
---|
| 934 | if self.data.__class__.__name__ =="Data2D": |
---|
| 935 | ctl1.Enable() |
---|
| 936 | else: |
---|
| 937 | ctl1.Disable() |
---|
| 938 | param_min, param_max= self.model.details[item][1:] |
---|
| 939 | ix += 1 |
---|
| 940 | ctl3 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER) |
---|
[875f1a2] | 941 | ctl3.SetValue(str(param_min)) |
---|
[780d095] | 942 | ctl3.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
| 943 | ctl3.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 944 | ctl3.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
| 945 | sizer.Add(ctl3, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 946 | ctl3.Hide() |
---|
| 947 | if self.data.__class__.__name__ =="Data2D": |
---|
| 948 | ctl3.Enable() |
---|
| 949 | else: |
---|
| 950 | ctl3.Disable() |
---|
| 951 | |
---|
| 952 | ix += 1 |
---|
| 953 | ctl4 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER) |
---|
| 954 | ctl4.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) |
---|
| 955 | ctl4.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter) |
---|
| 956 | ctl4.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter) |
---|
| 957 | sizer.Add(ctl4, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[875f1a2] | 958 | ctl4.SetValue(str(param_max)) |
---|
[780d095] | 959 | ctl4.Hide() |
---|
| 960 | if self.data.__class__.__name__ =="Data2D": |
---|
| 961 | ctl4.Enable() |
---|
| 962 | else: |
---|
| 963 | ctl4.Disable() |
---|
| 964 | if self.engine_type=="park": |
---|
| 965 | ctl3.Show(True) |
---|
| 966 | ctl4.Show(True) |
---|
| 967 | |
---|
| 968 | ix +=1 |
---|
| 969 | # Units |
---|
| 970 | try: |
---|
| 971 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
| 972 | except: |
---|
| 973 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
| 974 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 975 | |
---|
| 976 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 977 | self.parameters.append([cb,item, ctl1, |
---|
| 978 | text2,ctl2, ctl3, ctl4,None]) |
---|
| 979 | self.orientation_params.append([cb,item, ctl1, |
---|
| 980 | text2,ctl2, ctl3, ctl4,None]) |
---|
| 981 | |
---|
| 982 | iy+=1 |
---|
| 983 | sizer.Add((10,10),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[c77d859] | 984 | |
---|
| 985 | #Display units text on panel |
---|
| 986 | for item in keys: |
---|
| 987 | if self.model.details[item][0]!='': |
---|
| 988 | self.text2_4.Show() |
---|
| 989 | break |
---|
| 990 | else: |
---|
| 991 | self.text2_4.Hide() |
---|
| 992 | |
---|
| 993 | boxsizer1.Add(sizer) |
---|
| 994 | |
---|
| 995 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 996 | self.sizer3.Layout() |
---|
| 997 | self.SetScrollbars(20,20,200,100) |
---|
| 998 | |
---|
| 999 | |
---|
| 1000 | |
---|
| 1001 | |
---|
| 1002 | class HelpWindow(wx.Frame): |
---|
| 1003 | def __init__(self, parent, id, title): |
---|
| 1004 | wx.Frame.__init__(self, parent, id, title, size=(570, 400)) |
---|
| 1005 | |
---|
| 1006 | from sans.models.CylinderModel import CylinderModel |
---|
| 1007 | model = CylinderModel() |
---|
[2d5f7a1] | 1008 | |
---|
[c77d859] | 1009 | from danse.common.plottools.plottables import Data1D |
---|
| 1010 | data= Data1D(x=[1,2], y=[3,4], dy=[0.1, 0,1]) |
---|
| 1011 | |
---|
[cfc0913] | 1012 | from fitpanel import PageInfo |
---|
[c77d859] | 1013 | myinfo = PageInfo(self, model, data=data ) |
---|
| 1014 | |
---|
| 1015 | ## add data |
---|
| 1016 | |
---|
| 1017 | from models import ModelList |
---|
| 1018 | mylist= ModelList() |
---|
| 1019 | |
---|
| 1020 | from sans.models.SphereModel import SphereModel |
---|
| 1021 | from sans.models.SquareWellStructure import SquareWellStructure |
---|
| 1022 | from sans.models.DebyeModel import DebyeModel |
---|
| 1023 | from sans.models.LineModel import LineModel |
---|
| 1024 | name= "shapes" |
---|
| 1025 | list1= [SphereModel] |
---|
| 1026 | mylist.set_list( name, list1) |
---|
| 1027 | |
---|
| 1028 | name= "Shape-independent" |
---|
| 1029 | list1= [DebyeModel] |
---|
| 1030 | mylist.set_list( name, list1) |
---|
| 1031 | |
---|
| 1032 | name= "Structure Factors" |
---|
| 1033 | list1= [SquareWellStructure] |
---|
| 1034 | mylist.set_list( name, list1) |
---|
| 1035 | |
---|
| 1036 | name= "Added models" |
---|
| 1037 | list1= [LineModel] |
---|
| 1038 | mylist.set_list( name, list1) |
---|
| 1039 | |
---|
| 1040 | myinfo.model_list_box = mylist.get_list() |
---|
| 1041 | |
---|
| 1042 | self.page = FitPage(self, myinfo) |
---|
| 1043 | |
---|
| 1044 | |
---|
| 1045 | |
---|
| 1046 | self.Centre() |
---|
| 1047 | self.Show(True) |
---|
| 1048 | |
---|
| 1049 | |
---|
| 1050 | |
---|
| 1051 | if __name__=="__main__": |
---|
| 1052 | app = wx.App() |
---|
| 1053 | HelpWindow(None, -1, 'HelpWindow') |
---|
| 1054 | app.MainLoop() |
---|
| 1055 | |
---|