[d1e0473] | 1 | |
---|
| 2 | |
---|
[c77d859] | 3 | import sys |
---|
| 4 | import wx |
---|
| 5 | import wx.lib.newevent |
---|
| 6 | import numpy |
---|
| 7 | import copy |
---|
| 8 | import math |
---|
| 9 | from sans.models.dispersion_models import ArrayDispersion, GaussianDispersion |
---|
| 10 | |
---|
| 11 | from sans.guicomm.events import StatusEvent |
---|
[69bee6d] | 12 | from sans.guiframe.utils import format_number,check_float |
---|
[77e23a2] | 13 | |
---|
[b787e68c] | 14 | ## event to post model to fit to fitting plugins |
---|
[c77d859] | 15 | (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() |
---|
[b787e68c] | 16 | |
---|
| 17 | ## event to know the selected fit engine |
---|
[77e23a2] | 18 | (FitterTypeEvent, EVT_FITTER_TYPE) = wx.lib.newevent.NewEvent() |
---|
[34a0c17] | 19 | (FitStopEvent, EVT_FIT_STOP) = wx.lib.newevent.NewEvent() |
---|
[eda428b] | 20 | _BOX_WIDTH = 76 |
---|
[c77d859] | 21 | |
---|
| 22 | import basepage |
---|
| 23 | from basepage import BasicPage |
---|
[b787e68c] | 24 | from basepage import PageInfoEvent |
---|
[997131a] | 25 | from DataLoader.qsmearing import smear_selection |
---|
[c77d859] | 26 | |
---|
| 27 | class FitPage(BasicPage): |
---|
| 28 | """ |
---|
| 29 | FitPanel class contains fields allowing to display results when |
---|
| 30 | fitting a model and one data |
---|
| 31 | @note: For Fit to be performed the user should check at least one parameter |
---|
| 32 | on fit Panel window. |
---|
| 33 | |
---|
| 34 | """ |
---|
[cfc0913] | 35 | def __init__(self,parent, page_info): |
---|
| 36 | BasicPage.__init__(self, parent, page_info) |
---|
[c77d859] | 37 | """ |
---|
| 38 | Initialization of the Panel |
---|
| 39 | """ |
---|
| 40 | ## fit page does not content npts txtcrtl |
---|
| 41 | self.npts=None |
---|
[2b63df0] | 42 | ## thread for compute Chisqr |
---|
| 43 | self.calc_Chisqr=None |
---|
[dcf29d7] | 44 | ## default fitengine type |
---|
[707436d] | 45 | self.engine_type = None |
---|
[b787e68c] | 46 | ## draw sizer |
---|
[c77d859] | 47 | self._fill_datainfo_sizer() |
---|
[da26c1a] | 48 | |
---|
[c77d859] | 49 | self._fill_model_sizer( self.sizer1) |
---|
[cfc0913] | 50 | self._fill_range_sizer() |
---|
[fbf4bf8] | 51 | #self._on_select_model(event=None) |
---|
[997131a] | 52 | if self.data !=None: |
---|
| 53 | self.smearer = smear_selection( self.data ) |
---|
[847091f] | 54 | if self.smearer ==None: |
---|
| 55 | self.enable_smearer.Disable() |
---|
| 56 | self.disable_smearer.Disable() |
---|
[813334e] | 57 | |
---|
[cfc0913] | 58 | ## to update the panel according to the fit engine type selected |
---|
[77e23a2] | 59 | self.Bind(EVT_FITTER_TYPE,self._on_engine_change) |
---|
[34a0c17] | 60 | self.Bind(EVT_FIT_STOP,self._on_fit_complete) |
---|
[77e23a2] | 61 | |
---|
[34a0c17] | 62 | def _on_fit_complete(self, event): |
---|
| 63 | """ |
---|
| 64 | When fit is complete ,reset the fit button label. |
---|
| 65 | """ |
---|
| 66 | #self.btFit.SetLabel("Fit") |
---|
| 67 | #self.btFit.Unbind(event=wx.EVT_BUTTON, id=self.btFit.GetId()) |
---|
| 68 | #self.btFit.Bind(event=wx.EVT_BUTTON, handler=self._onFit,id=self.btFit.GetId()) |
---|
| 69 | pass |
---|
| 70 | |
---|
| 71 | |
---|
[77e23a2] | 72 | def _on_engine_change(self, event): |
---|
| 73 | """ |
---|
| 74 | get an event containing the current name of the fit engine type |
---|
| 75 | @param event: FitterTypeEvent containing the name of the current engine |
---|
| 76 | """ |
---|
[dcf29d7] | 77 | self.engine_type = event.type |
---|
| 78 | |
---|
[77e23a2] | 79 | if len(self.parameters)==0: |
---|
| 80 | return |
---|
[ad6dd4c] | 81 | if event.type =="park": |
---|
| 82 | self.btFit.SetLabel("Fit") |
---|
[77e23a2] | 83 | for item in self.parameters: |
---|
| 84 | if event.type =="scipy": |
---|
[60132ef] | 85 | item[5].SetValue("") |
---|
[77e23a2] | 86 | item[5].Hide() |
---|
[60132ef] | 87 | item[6].SetValue("") |
---|
[77e23a2] | 88 | item[6].Hide() |
---|
| 89 | self.text2_min.Hide() |
---|
| 90 | self.text2_max.Hide() |
---|
| 91 | else: |
---|
| 92 | item[5].Show(True) |
---|
| 93 | item[6].Show(True) |
---|
| 94 | self.text2_min.Show(True) |
---|
| 95 | self.text2_max.Show(True) |
---|
[3fef0a8] | 96 | for item in self.orientation_params: |
---|
| 97 | if event.type =="scipy": |
---|
| 98 | item[5].SetValue("") |
---|
| 99 | item[5].Hide() |
---|
| 100 | item[6].SetValue("") |
---|
| 101 | item[6].Hide() |
---|
| 102 | self.text2_min.Hide() |
---|
| 103 | self.text2_max.Hide() |
---|
| 104 | else: |
---|
| 105 | item[5].Show(True) |
---|
| 106 | item[6].Show(True) |
---|
| 107 | self.text2_min.Show(True) |
---|
| 108 | self.text2_max.Show(True) |
---|
| 109 | |
---|
| 110 | for item in self.orientation_params_disp: |
---|
| 111 | if event.type =="scipy": |
---|
| 112 | item[5].SetValue("") |
---|
| 113 | item[5].Hide() |
---|
| 114 | item[6].SetValue("") |
---|
| 115 | item[6].Hide() |
---|
| 116 | self.text2_min.Hide() |
---|
| 117 | self.text2_max.Hide() |
---|
| 118 | else: |
---|
| 119 | item[5].Show(True) |
---|
| 120 | item[6].Show(True) |
---|
| 121 | self.text2_min.Show(True) |
---|
| 122 | self.text2_max.Show(True) |
---|
[77e23a2] | 123 | |
---|
| 124 | self.sizer3.Layout() |
---|
| 125 | self.SetScrollbars(20,20,200,100) |
---|
[c77d859] | 126 | |
---|
| 127 | |
---|
| 128 | def _fill_range_sizer(self): |
---|
| 129 | """ |
---|
| 130 | Fill the sizer containing the plotting range |
---|
| 131 | add access to npts |
---|
| 132 | """ |
---|
[1ae3fe1] | 133 | sizer_fit = wx.GridSizer(1, 1,0, 0) |
---|
[c77d859] | 134 | |
---|
| 135 | self.btFit = wx.Button(self,wx.NewId(),'Fit') |
---|
| 136 | self.btFit.Bind(wx.EVT_BUTTON, self._onFit,id= self.btFit.GetId()) |
---|
| 137 | self.btFit.SetToolTipString("Perform fit.") |
---|
[2d5f7a1] | 138 | |
---|
[c77d859] | 139 | |
---|
| 140 | sizer_fit.Add((5,5),1, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
[1ae3fe1] | 141 | sizer_fit.Add(self.btFit,0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
[c77d859] | 142 | |
---|
| 143 | sizer_smearer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 144 | #Filling the sizer containing instruments smearing info. |
---|
| 145 | self.disable_smearer = wx.RadioButton(self, -1, 'No', style=wx.RB_GROUP) |
---|
| 146 | self.enable_smearer = wx.RadioButton(self, -1, 'Yes') |
---|
| 147 | self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.disable_smearer.GetId()) |
---|
| 148 | self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.enable_smearer.GetId()) |
---|
| 149 | |
---|
| 150 | sizer_smearer.Add(wx.StaticText(self,-1,'Instrument Smearing? ')) |
---|
| 151 | sizer_smearer.Add((10, 10)) |
---|
| 152 | sizer_smearer.Add( self.enable_smearer ) |
---|
| 153 | sizer_smearer.Add((10,10)) |
---|
| 154 | sizer_smearer.Add( self.disable_smearer ) |
---|
| 155 | |
---|
[7b0fd65] | 156 | #Display Chi^2/dof |
---|
[d1e0473] | 157 | sizer_smearer.Add((68,10)) |
---|
[7b0fd65] | 158 | box_description= wx.StaticBox(self, -1,'Chi2/dof') |
---|
| 159 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
[2a5bba7] | 160 | boxsizer1.SetMinSize((60,-1)) |
---|
[2b63df0] | 161 | temp_smearer = None |
---|
| 162 | if self.enable_smearer.GetValue(): |
---|
| 163 | temp_smearer= self.smearer |
---|
| 164 | |
---|
| 165 | self.tcChi = wx.StaticText(self, -1, "-", style=wx.ALIGN_LEFT) |
---|
| 166 | |
---|
[7b0fd65] | 167 | boxsizer1.Add( self.tcChi ) |
---|
| 168 | sizer_smearer.Add( boxsizer1 ) |
---|
| 169 | |
---|
| 170 | #Set sizer for Fitting section |
---|
[330573d] | 171 | self._set_range_sizer( title="Fitting",object1=sizer_smearer, object= sizer_fit) |
---|
[7b0fd65] | 172 | |
---|
[c77d859] | 173 | |
---|
| 174 | def _fill_datainfo_sizer(self): |
---|
| 175 | """ |
---|
| 176 | fill sizer 0 with data info |
---|
| 177 | """ |
---|
| 178 | self.sizer0.Clear(True) |
---|
| 179 | ## no loaded data , don't fill the sizer |
---|
| 180 | if self.data== None: |
---|
| 181 | self.sizer0.Layout() |
---|
| 182 | return |
---|
| 183 | |
---|
[fa58441] | 184 | box_description= wx.StaticBox(self, -1, 'Data') |
---|
[c77d859] | 185 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 186 | #---------------------------------------------------------- |
---|
| 187 | sizer_data = wx.GridSizer(3, 3,5, 5) |
---|
| 188 | #Filling the sizer containing data related fields |
---|
| 189 | DataSource =wx.StaticText(self, -1,str(self.data.name)) |
---|
| 190 | |
---|
[fa58441] | 191 | sizer_data.Add(wx.StaticText(self, -1, 'Source Name : ')) |
---|
[c77d859] | 192 | sizer_data.Add(DataSource ) |
---|
[2a5bba7] | 193 | sizer_data.Add( (0,5) ) |
---|
[c77d859] | 194 | |
---|
| 195 | #---------sizer 2 draw-------------------------------- |
---|
| 196 | #set maximum range for x in linear scale |
---|
| 197 | if not hasattr(self.data,"data"): #Display only for 1D data fit |
---|
| 198 | # Minimum value of data |
---|
[813334e] | 199 | data_min = min(self.data.x) |
---|
[c77d859] | 200 | # Maximum value of data |
---|
[813334e] | 201 | data_max = max(self.data.x) |
---|
[7b0fd65] | 202 | text4_3 = wx.StaticText(self, -1, 'Total Q Range (1/A)', |
---|
[c77d859] | 203 | style=wx.ALIGN_LEFT) |
---|
| 204 | sizer_data.Add( text4_3 ) |
---|
[813334e] | 205 | sizer_data.Add(wx.StaticText(self, -1, "Min : %s"%str(data_min))) |
---|
| 206 | sizer_data.Add(wx.StaticText(self, -1, "Max : %s"%str(data_max))) |
---|
[c77d859] | 207 | |
---|
| 208 | else: |
---|
[813334e] | 209 | ## Minimum value of data |
---|
| 210 | data_min= 0 |
---|
| 211 | x= max(math.fabs(self.data.xmin), math.fabs(self.data.xmax)) |
---|
| 212 | y= max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) |
---|
| 213 | ## Maximum value of data |
---|
| 214 | data_max = math.sqrt(x*x + y*y) |
---|
| 215 | |
---|
[d2d0cfdf] | 216 | #For qmin and qmax, do not use format_number |
---|
| 217 | #.(If do, qmin and max could be different from what is in the data.) |
---|
[d1e0473] | 218 | text4_3 = wx.StaticText(self, -1, "Total Q Range (1/A)", |
---|
[c77d859] | 219 | style=wx.ALIGN_LEFT) |
---|
| 220 | sizer_data.Add( text4_3 ) |
---|
[813334e] | 221 | sizer_data.Add(wx.StaticText(self, -1, "Min : %s"%str(data_min))) |
---|
| 222 | sizer_data.Add(wx.StaticText(self, -1, "Max : %s"%str(data_max))) |
---|
| 223 | ## set q range to plot |
---|
| 224 | self.qmin_x= data_min |
---|
| 225 | self.qmax_x= data_max |
---|
| 226 | |
---|
[c77d859] | 227 | boxsizer1.Add(sizer_data) |
---|
| 228 | #------------------------------------------------------------ |
---|
| 229 | self.sizer0.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 230 | self.sizer0.Layout() |
---|
[813334e] | 231 | |
---|
[c77d859] | 232 | |
---|
[7b0fd65] | 233 | |
---|
[c77d859] | 234 | def _fill_model_sizer(self, sizer): |
---|
| 235 | """ |
---|
| 236 | fill sizer containing model info |
---|
| 237 | """ |
---|
[87fbc60] | 238 | |
---|
[c77d859] | 239 | ## class base method to add view 2d button |
---|
[7b0fd65] | 240 | self._set_model_sizer(sizer=sizer, title="Model",object=None ) |
---|
| 241 | |
---|
[c77d859] | 242 | |
---|
[30d103a] | 243 | #def _set_sizer_gaussian(self): |
---|
| 244 | def _set_sizer_dispersion(self, dispersity): |
---|
[c77d859] | 245 | """ |
---|
| 246 | draw sizer with gaussian dispersity parameters |
---|
| 247 | """ |
---|
| 248 | self.fittable_param=[] |
---|
| 249 | self.fixed_param=[] |
---|
[60132ef] | 250 | self.orientation_params_disp=[] |
---|
| 251 | |
---|
[c77d859] | 252 | self.sizer4_4.Clear(True) |
---|
| 253 | |
---|
| 254 | if self.model==None: |
---|
| 255 | ##no model is selected |
---|
| 256 | return |
---|
| 257 | if not self.enable_disp.GetValue(): |
---|
| 258 | ## the user didn't select dispersity display |
---|
| 259 | return |
---|
[376916c] | 260 | |
---|
| 261 | self._reset_dispersity() |
---|
| 262 | # Create the dispersion objects |
---|
| 263 | for item in self.model.dispersion.keys(): |
---|
[30d103a] | 264 | #disp_model = GaussianDispersion() |
---|
| 265 | disp_model = dispersity() |
---|
[376916c] | 266 | self._disp_obj_dict[item] = disp_model |
---|
| 267 | self.model.set_dispersion(item, disp_model) |
---|
[c477b31] | 268 | self.state._disp_obj_dict[item]= disp_model |
---|
[376916c] | 269 | |
---|
[c77d859] | 270 | ix=0 |
---|
| 271 | iy=1 |
---|
| 272 | disp = wx.StaticText(self, -1, 'Names') |
---|
| 273 | self.sizer4_4.Add(disp,( iy, ix),(1,1), |
---|
| 274 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 275 | ix += 1 |
---|
| 276 | values = wx.StaticText(self, -1, 'Values') |
---|
| 277 | self.sizer4_4.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 278 | ix +=2 |
---|
| 279 | self.text_disp_1 = wx.StaticText(self, -1, 'Errors') |
---|
| 280 | self.sizer4_4.Add( self.text_disp_1,(iy, ix),(1,1),\ |
---|
| 281 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 282 | self.text_disp_1.Hide() |
---|
| 283 | ix += 1 |
---|
| 284 | npts = wx.StaticText(self, -1, 'Npts') |
---|
| 285 | self.sizer4_4.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 286 | ix += 1 |
---|
| 287 | nsigmas = wx.StaticText(self, -1, 'Nsigmas') |
---|
| 288 | self.sizer4_4.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[6dc9ad8] | 289 | |
---|
[c77d859] | 290 | for item in self.model.dispersion.keys(): |
---|
[780d095] | 291 | if not item in self.model.orientation_params: |
---|
| 292 | self.disp_cb_dict[item]= None |
---|
| 293 | name1=item+".width" |
---|
| 294 | name2=item+".npts" |
---|
| 295 | name3=item+".nsigmas" |
---|
| 296 | iy += 1 |
---|
| 297 | for p in self.model.dispersion[item].keys(): |
---|
| 298 | |
---|
| 299 | if p=="width": |
---|
| 300 | ix = 0 |
---|
| 301 | cb = wx.CheckBox(self, -1, name1, (10, 10)) |
---|
| 302 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 303 | self.sizer4_4.Add( cb,( iy, ix),(1,1), |
---|
| 304 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 305 | ix = 1 |
---|
| 306 | value= self.model.getParam(name1) |
---|
[6f2c919] | 307 | ctl1 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
[c77d859] | 308 | style=wx.TE_PROCESS_ENTER) |
---|
[780d095] | 309 | ctl1.SetValue(str (format_number(value))) |
---|
| 310 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1),wx.EXPAND) |
---|
| 311 | ## text to show error sign |
---|
| 312 | ix = 2 |
---|
| 313 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 314 | self.sizer4_4.Add(text2,(iy, ix),(1,1), |
---|
| 315 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 316 | text2.Hide() |
---|
| 317 | ## txtcrtl to add error from fit |
---|
| 318 | ix = 3 |
---|
| 319 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 320 | self.sizer4_4.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 321 | ctl2.Hide() |
---|
| 322 | self.fittable_param.append([cb,name1,ctl1,text2, |
---|
| 323 | ctl2, None, None,None]) |
---|
| 324 | elif p=="npts": |
---|
| 325 | ix = 4 |
---|
| 326 | value= self.model.getParam(name2) |
---|
[6f2c919] | 327 | Tctl = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
[780d095] | 328 | style=wx.TE_PROCESS_ENTER) |
---|
| 329 | |
---|
| 330 | Tctl.SetValue(str (format_number(value))) |
---|
| 331 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
| 332 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 333 | self.fixed_param.append([None,name2, Tctl,None,None, |
---|
| 334 | None, None,None]) |
---|
| 335 | elif p=="nsigmas": |
---|
| 336 | ix = 5 |
---|
| 337 | value= self.model.getParam(name3) |
---|
[6f2c919] | 338 | Tctl = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
[780d095] | 339 | style=wx.TE_PROCESS_ENTER) |
---|
| 340 | Tctl.SetValue(str (format_number(value))) |
---|
| 341 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
| 342 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 343 | ix +=1 |
---|
| 344 | self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
| 345 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 346 | |
---|
| 347 | self.fixed_param.append([None,name3, Tctl |
---|
| 348 | ,None,None, None, None,None]) |
---|
| 349 | ix =0 |
---|
| 350 | iy +=1 |
---|
| 351 | self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 352 | for item in self.model.dispersion.keys(): |
---|
| 353 | if item in self.model.orientation_params: |
---|
| 354 | self.disp_cb_dict[item]= None |
---|
| 355 | name1=item+".width" |
---|
| 356 | name2=item+".npts" |
---|
| 357 | name3=item+".nsigmas" |
---|
| 358 | iy += 1 |
---|
| 359 | for p in self.model.dispersion[item].keys(): |
---|
| 360 | |
---|
| 361 | if p=="width": |
---|
| 362 | ix = 0 |
---|
| 363 | cb = wx.CheckBox(self, -1, name1, (10, 10)) |
---|
| 364 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 365 | self.sizer4_4.Add( cb,( iy, ix),(1,1), |
---|
| 366 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 367 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 368 | cb.Show(True) |
---|
[780d095] | 369 | cb.Enable() |
---|
| 370 | else: |
---|
[6dc9ad8] | 371 | cb.Hide() |
---|
[780d095] | 372 | cb.Disable() |
---|
| 373 | ix = 1 |
---|
| 374 | value= self.model.getParam(name1) |
---|
[6f2c919] | 375 | ctl1 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
[c77d859] | 376 | style=wx.TE_PROCESS_ENTER) |
---|
[780d095] | 377 | ctl1.SetValue(str (format_number(value))) |
---|
| 378 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 379 | ctl1.Show(True) |
---|
[780d095] | 380 | ctl1.Enable() |
---|
| 381 | else: |
---|
[6dc9ad8] | 382 | ctl1.Hide() |
---|
[780d095] | 383 | ctl1.Disable() |
---|
| 384 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1),wx.EXPAND) |
---|
| 385 | ## text to show error sign |
---|
| 386 | ix = 2 |
---|
| 387 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 388 | self.sizer4_4.Add(text2,(iy, ix),(1,1), |
---|
| 389 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 390 | text2.Hide() |
---|
| 391 | ## txtcrtl to add error from fit |
---|
| 392 | ix = 3 |
---|
| 393 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 394 | self.sizer4_4.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 395 | ctl2.Hide() |
---|
| 396 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 397 | #ctl2.Show(True) |
---|
[780d095] | 398 | ctl2.Enable() |
---|
| 399 | else: |
---|
[6dc9ad8] | 400 | #ctl2.Hide() |
---|
[780d095] | 401 | ctl2.Disable() |
---|
| 402 | self.fittable_param.append([cb,name1,ctl1,text2, |
---|
| 403 | ctl2, None, None,None]) |
---|
[60132ef] | 404 | self.orientation_params_disp.append([cb,name1,ctl1,text2, |
---|
[780d095] | 405 | ctl2, None, None,None]) |
---|
| 406 | elif p=="npts": |
---|
| 407 | ix = 4 |
---|
| 408 | value= self.model.getParam(name2) |
---|
[6f2c919] | 409 | Tctl = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
[780d095] | 410 | style=wx.TE_PROCESS_ENTER) |
---|
| 411 | |
---|
| 412 | Tctl.SetValue(str (format_number(value))) |
---|
| 413 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 414 | Tctl.Show(True) |
---|
[780d095] | 415 | Tctl.Enable() |
---|
| 416 | else: |
---|
[6dc9ad8] | 417 | Tctl.Hide() |
---|
[780d095] | 418 | Tctl.Disable() |
---|
| 419 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
| 420 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 421 | self.fixed_param.append([None,name2, Tctl,None,None, |
---|
| 422 | None, None,None]) |
---|
[60132ef] | 423 | self.orientation_params_disp.append([None,name2, Tctl,None,None, |
---|
[780d095] | 424 | None, None,None]) |
---|
| 425 | elif p=="nsigmas": |
---|
| 426 | ix = 5 |
---|
| 427 | value= self.model.getParam(name3) |
---|
[6f2c919] | 428 | Tctl = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
[780d095] | 429 | style=wx.TE_PROCESS_ENTER) |
---|
| 430 | Tctl.SetValue(str (format_number(value))) |
---|
| 431 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 432 | Tctl.Show(True) |
---|
[780d095] | 433 | Tctl.Enable() |
---|
| 434 | else: |
---|
[6dc9ad8] | 435 | Tctl.Hide() |
---|
[780d095] | 436 | Tctl.Disable() |
---|
| 437 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
| 438 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 439 | ix +=1 |
---|
[58c6ba6] | 440 | #self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
| 441 | #wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[780d095] | 442 | self.fixed_param.append([None,name3, Tctl |
---|
| 443 | ,None,None, None, None,None]) |
---|
[60132ef] | 444 | self.orientation_params_disp.append([None,name3, Tctl |
---|
[1c1436d] | 445 | ,None,None, None, None,None]) |
---|
[d2d0cfdf] | 446 | |
---|
[71f0373] | 447 | self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) |
---|
| 448 | self.state.model = self.model.clone() |
---|
[240b9966] | 449 | ## save state into |
---|
| 450 | self._copy_parameters_state(self.orientation_params_disp, |
---|
| 451 | self.state.orientation_params_disp) |
---|
| 452 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
| 453 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
[71f0373] | 454 | |
---|
[c77d859] | 455 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
| 456 | " Selected Distribution: Gaussian")) |
---|
| 457 | ix =0 |
---|
| 458 | iy +=1 |
---|
[58c6ba6] | 459 | #self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[c77d859] | 460 | self.sizer4_4.Layout() |
---|
| 461 | self.sizer4.Layout() |
---|
[71f0373] | 462 | self.Layout() |
---|
[c77d859] | 463 | self.SetScrollbars(20,20,200,100) |
---|
[71f0373] | 464 | self.Refresh() |
---|
[0a518e4c] | 465 | |
---|
[c77d859] | 466 | |
---|
| 467 | def _onFit(self, event): |
---|
| 468 | """ |
---|
| 469 | Allow to fit |
---|
| 470 | """ |
---|
| 471 | from sans.guiframe.utils import check_value |
---|
| 472 | flag = check_value( self.qmin, self.qmax) |
---|
| 473 | |
---|
| 474 | if not flag: |
---|
| 475 | msg= "Fitting range invalid" |
---|
| 476 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
| 477 | return |
---|
| 478 | |
---|
| 479 | if len(self.param_toFit) <= 0: |
---|
| 480 | msg= "Select at least one parameter to fit" |
---|
| 481 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
| 482 | return |
---|
[d0ce2c30] | 483 | |
---|
| 484 | # Remove or do not allow fitting on the Q=0 point, especially when y(q=0)=None at x[0]. |
---|
[ad6dd4c] | 485 | #ToDo: Fix this. |
---|
[1c1436d] | 486 | self.qmin_x = float(self.qmin.GetValue()) |
---|
[c77d859] | 487 | self.qmax_x =float( self.qmax.GetValue()) |
---|
[6f023e8] | 488 | self.manager._reset_schedule_problem( value=0) |
---|
[ca7a626] | 489 | self.manager.schedule_for_fit( value=1,page=self,fitproblem =None) |
---|
| 490 | self.manager.set_fit_range(page= self,qmin= self.qmin_x, qmax= self.qmax_x) |
---|
[ad6dd4c] | 491 | |
---|
[c77d859] | 492 | #single fit |
---|
[ca7a626] | 493 | self.manager.onFit() |
---|
[ad6dd4c] | 494 | ## allow stopping the fit |
---|
[34a0c17] | 495 | #if self.engine_type=="scipy": |
---|
| 496 | # self.btFit.SetLabel("Stop") |
---|
| 497 | # self.btFit.Unbind(event=wx.EVT_BUTTON, id= self.btFit.GetId()) |
---|
| 498 | # self.btFit.Bind(event= wx.EVT_BUTTON, handler=self._StopFit, id=self.btFit.GetId()) |
---|
| 499 | #else: |
---|
| 500 | # self.btFit.SetLabel("Fit") |
---|
| 501 | # self.btFit.Bind(event= wx.EVT_BUTTON, handler=self._onFit, id=self.btFit.GetId()) |
---|
[1c1436d] | 502 | self.btFit.SetFocus() |
---|
[c77d859] | 503 | self.sizer5.Layout() |
---|
| 504 | self.SetScrollbars(20,20,55,40) |
---|
| 505 | |
---|
[ad6dd4c] | 506 | def _StopFit(self, event): |
---|
| 507 | """ |
---|
| 508 | Stop fit |
---|
| 509 | """ |
---|
| 510 | self.btFit.SetLabel("Fit") |
---|
| 511 | if self.engine_type=="scipy": |
---|
| 512 | self.manager.stop_fit() |
---|
[34a0c17] | 513 | self.btFit.Unbind(event=wx.EVT_BUTTON, id=self.btFit.GetId()) |
---|
| 514 | self.btFit.Bind(event=wx.EVT_BUTTON, handler=self._onFit,id=self.btFit.GetId()) |
---|
| 515 | |
---|
| 516 | |
---|
[ad6dd4c] | 517 | self.btFit.SetFocus() |
---|
| 518 | self.sizer5.Layout() |
---|
| 519 | self.SetScrollbars(20,20,55,40) |
---|
| 520 | |
---|
[c77d859] | 521 | def _on_select_model(self, event): |
---|
| 522 | """ |
---|
| 523 | call back for model selection |
---|
| 524 | """ |
---|
[59a7f2d] | 525 | self._on_select_model_helper() |
---|
[70c57ebf] | 526 | self.set_model_param_sizer(self.model) |
---|
| 527 | |
---|
[3b605bb] | 528 | self.enable_disp.SetValue(False) |
---|
| 529 | self.disable_disp.SetValue(True) |
---|
[1c1436d] | 530 | self.set_dispers_sizer() |
---|
[70c57ebf] | 531 | if self.model !=None: |
---|
| 532 | try: |
---|
| 533 | temp_smear= None |
---|
| 534 | if self.enable_smearer.GetValue(): |
---|
| 535 | temp_smear= self.smearer |
---|
| 536 | self.compute_chisqr(temp_smear) |
---|
| 537 | except: |
---|
| 538 | ## error occured on chisqr computation |
---|
| 539 | pass |
---|
| 540 | evt = ModelEventbox(model=self.model) |
---|
| 541 | wx.PostEvent(self.event_owner, evt) |
---|
[848a2ef] | 542 | self.btFit.SetFocus() |
---|
[240b9966] | 543 | self.state.enable_disp = self.enable_disp.GetValue() |
---|
| 544 | self.state.disable_disp = self.disable_disp.GetValue() |
---|
[3b9e023] | 545 | |
---|
| 546 | self.state.structurecombobox = self.structurebox.GetCurrentSelection() |
---|
| 547 | self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection() |
---|
[077809c] | 548 | |
---|
[3b9e023] | 549 | |
---|
[3595309d] | 550 | if event !=None: |
---|
| 551 | self._undo.Enable(True) |
---|
| 552 | ## post state to fit panel |
---|
| 553 | event = PageInfoEvent(page = self) |
---|
| 554 | wx.PostEvent(self.parent, event) |
---|
[330573d] | 555 | |
---|
[298b762] | 556 | |
---|
| 557 | def _onparamRangeEnter(self, event): |
---|
| 558 | """ |
---|
| 559 | Check validity of value enter in the parameters range field |
---|
| 560 | """ |
---|
| 561 | tcrtl= event.GetEventObject() |
---|
| 562 | if tcrtl.GetValue().lstrip().rstrip()!="": |
---|
| 563 | try: |
---|
| 564 | value = float(tcrtl.GetValue()) |
---|
| 565 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
| 566 | tcrtl.Refresh() |
---|
| 567 | except: |
---|
| 568 | tcrtl.SetBackgroundColour("pink") |
---|
| 569 | tcrtl.Refresh() |
---|
[0aeabc6] | 570 | return |
---|
[298b762] | 571 | else: |
---|
| 572 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
| 573 | tcrtl.Refresh() |
---|
[0aeabc6] | 574 | self._onparamEnter_helper() |
---|
| 575 | |
---|
| 576 | ##compute chisqr for range change |
---|
| 577 | temp_smearer = None |
---|
| 578 | if self.enable_smearer.GetValue(): |
---|
| 579 | msg="" |
---|
| 580 | temp_smearer= self.smearer |
---|
| 581 | ##Calculate chi2 |
---|
[077809c] | 582 | |
---|
[0aeabc6] | 583 | self.compute_chisqr(smearer= temp_smearer) |
---|
[240b9966] | 584 | ## new state posted |
---|
| 585 | if self.state_change: |
---|
[3595309d] | 586 | self._undo.Enable(True) |
---|
[240b9966] | 587 | event = PageInfoEvent(page = self) |
---|
| 588 | wx.PostEvent(self.parent, event) |
---|
| 589 | self.state_change= False |
---|
[0aeabc6] | 590 | |
---|
[298b762] | 591 | |
---|
[dd5949d] | 592 | def _onparamEnter(self,event): |
---|
| 593 | """ |
---|
| 594 | when enter value on panel redraw model according to changed |
---|
| 595 | """ |
---|
[69bee6d] | 596 | tcrtl= event.GetEventObject() |
---|
[240b9966] | 597 | |
---|
[69bee6d] | 598 | if check_float(tcrtl): |
---|
| 599 | self._onparamEnter_helper() |
---|
[da26c1a] | 600 | temp_smearer = None |
---|
| 601 | if self.enable_smearer.GetValue(): |
---|
| 602 | temp_smearer= self.smearer |
---|
[077809c] | 603 | |
---|
[da26c1a] | 604 | self.compute_chisqr(smearer= temp_smearer) |
---|
[240b9966] | 605 | ## new state posted |
---|
| 606 | if self.state_change: |
---|
[3595309d] | 607 | self._undo.Enable(True) |
---|
| 608 | event = PageInfoEvent(page = self) |
---|
| 609 | wx.PostEvent(self.parent, event) |
---|
| 610 | self.state_change= False |
---|
[69bee6d] | 611 | else: |
---|
| 612 | msg= "Cannot Plot :Must enter a number!!! " |
---|
| 613 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 614 | return |
---|
[cfc0913] | 615 | |
---|
[882a912] | 616 | |
---|
| 617 | def set_data(self, data ): |
---|
| 618 | """ |
---|
| 619 | reset the current data |
---|
| 620 | """ |
---|
| 621 | if data ==None: |
---|
| 622 | return |
---|
| 623 | self.data =data |
---|
| 624 | self.state.data= data |
---|
| 625 | self._fill_datainfo_sizer() |
---|
| 626 | self.SetScrollbars(20,20,200,100) |
---|
| 627 | self.Layout() |
---|
| 628 | |
---|
[240b9966] | 629 | def reset_page(self, state,first=False): |
---|
[a074145] | 630 | """ |
---|
| 631 | reset the state |
---|
| 632 | """ |
---|
[240b9966] | 633 | if first: |
---|
| 634 | self._undo.Enable(False) |
---|
| 635 | |
---|
[a074145] | 636 | self.reset_page_helper(state) |
---|
[f20767b] | 637 | evt = ModelEventbox(model=state.model) |
---|
[a074145] | 638 | wx.PostEvent(self.event_owner, evt) |
---|
| 639 | |
---|
| 640 | |
---|
[2140e68] | 641 | def get_range(self): |
---|
| 642 | """ |
---|
| 643 | return the fitting range |
---|
| 644 | """ |
---|
[c9a4377] | 645 | return float(self.qmin_x) , float(self.qmax_x) |
---|
[c77d859] | 646 | |
---|
| 647 | def get_param_list(self): |
---|
| 648 | """ |
---|
| 649 | @return self.param_toFit: list containing references to TextCtrl |
---|
| 650 | checked.Theses TextCtrl will allow reference to parameters to fit. |
---|
| 651 | @raise: if return an empty list of parameter fit will nnote work |
---|
| 652 | properly so raise ValueError,"missing parameter to fit" |
---|
| 653 | """ |
---|
| 654 | if self.param_toFit !=[]: |
---|
| 655 | return self.param_toFit |
---|
| 656 | else: |
---|
| 657 | raise ValueError,"missing parameter to fit" |
---|
| 658 | |
---|
| 659 | def onsetValues(self,chisqr, out,cov): |
---|
| 660 | """ |
---|
| 661 | Build the panel from the fit result |
---|
| 662 | @param chisqr:Value of the goodness of fit metric |
---|
| 663 | @param out:list of parameter with the best value found during fitting |
---|
| 664 | @param cov:Covariance matrix |
---|
| 665 | |
---|
| 666 | """ |
---|
| 667 | self.tcChi.SetLabel(format_number(chisqr)) |
---|
| 668 | params = {} |
---|
| 669 | is_modified = False |
---|
| 670 | has_error = False |
---|
[0a518e4c] | 671 | self.text2_3.Hide() |
---|
[e473e4f5] | 672 | try: |
---|
| 673 | n = self.disp_box.GetCurrentSelection() |
---|
| 674 | dispersity= self.disp_box.GetClientData(n) |
---|
| 675 | name= dispersity.__name__ |
---|
| 676 | if name == "GaussianDispersion": |
---|
| 677 | if hasattr(self,"text_disp_1" ): |
---|
| 678 | if self.text_disp_1 !=None: |
---|
| 679 | self.text_disp_1.Hide() |
---|
| 680 | except: |
---|
| 681 | pass |
---|
[c77d859] | 682 | #set the panel when fit result are float not list |
---|
| 683 | if out.__class__==numpy.float64: |
---|
| 684 | self.param_toFit[0][2].SetValue(format_number(out)) |
---|
| 685 | self.param_toFit[0][2].Refresh() |
---|
[0a518e4c] | 686 | |
---|
| 687 | self.param_toFit[0][4].Clear() |
---|
| 688 | self.param_toFit[0][4].Hide() |
---|
[c77d859] | 689 | if cov !=None : |
---|
| 690 | self.text2_3.Show(True) |
---|
[e473e4f5] | 691 | try: |
---|
| 692 | name= dispersity.__name__ |
---|
| 693 | if name == "GaussianDispersion": |
---|
| 694 | if hasattr(self,"text_disp_1" ): |
---|
| 695 | if self.text_disp_1 !=None: |
---|
| 696 | self.text_disp_1.Show(True) |
---|
| 697 | except: |
---|
| 698 | pass |
---|
[ad6dd4c] | 699 | if cov[0]==None or not numpy.isfinite(cov[0]): |
---|
[69bee6d] | 700 | self.param_toFit[0][3].Hide() |
---|
| 701 | self.param_toFit[0][4].Clear() |
---|
| 702 | self.param_toFit[0][4].Hide() |
---|
| 703 | self.param_toFit[0][4].Refresh() |
---|
| 704 | else: |
---|
| 705 | self.param_toFit[0][3].Show(True) |
---|
| 706 | self.param_toFit[0][4].Clear() |
---|
| 707 | self.param_toFit[0][4].SetValue(format_number(cov[0])) |
---|
| 708 | self.param_toFit[0][4].Show(True) |
---|
| 709 | self.param_toFit[0][4].Refresh() |
---|
[c77d859] | 710 | else: |
---|
| 711 | i=0 |
---|
| 712 | j=0 |
---|
| 713 | #Set the panel when fit result are list |
---|
| 714 | for item in self.param_toFit: |
---|
[0a518e4c] | 715 | ## reset error value to initial state |
---|
| 716 | item[4].Clear() |
---|
| 717 | item[4].Hide() |
---|
| 718 | item[4].Refresh() |
---|
[c77d859] | 719 | if( out != None ) and len(out)<=len(self.param_toFit)and i < len(out): |
---|
| 720 | item[2].SetValue(format_number(self.model.getParam(item[1]))) |
---|
| 721 | item[2].Refresh() |
---|
| 722 | if(cov !=None)and len(cov)<=len(self.param_toFit)and i < len(cov): |
---|
| 723 | self.text2_3.Show(True) |
---|
[e473e4f5] | 724 | try: |
---|
| 725 | name= dispersity.__name__ |
---|
| 726 | if name == "GaussianDispersion": |
---|
| 727 | if hasattr(self,"text_disp_1" ): |
---|
| 728 | if self.text_disp_1!=None: |
---|
| 729 | self.text_disp_1.Show(True) |
---|
| 730 | except: |
---|
| 731 | pass |
---|
[c77d859] | 732 | item[3].Show(True) |
---|
| 733 | item[4].Clear() |
---|
| 734 | for j in range(len(out)): |
---|
| 735 | if out[j]==self.model.getParam(item[1]): |
---|
| 736 | break |
---|
[69bee6d] | 737 | ## unable to compare cov[j]==numpy.nan so switch to None |
---|
[ad6dd4c] | 738 | if cov[j]==None or not numpy.isfinite(cov[j]): |
---|
[69bee6d] | 739 | item[3].Hide() |
---|
| 740 | item[4].Refresh() |
---|
| 741 | item[4].Clear() |
---|
| 742 | item[4].Hide() |
---|
| 743 | else: |
---|
| 744 | item[4].SetValue(format_number(cov[j])) |
---|
| 745 | item[4].Refresh() |
---|
| 746 | item[4].Show(True) |
---|
[c77d859] | 747 | i+=1 |
---|
| 748 | |
---|
| 749 | self.sizer3.Layout() |
---|
| 750 | self.sizer4.Layout() |
---|
[2cded48] | 751 | self.Layout() |
---|
[7437880] | 752 | self.Refresh() |
---|
[c77d859] | 753 | self.SetScrollbars(20,20,200,100) |
---|
| 754 | |
---|
| 755 | |
---|
| 756 | def onSmear(self, event): |
---|
| 757 | """ |
---|
| 758 | Create a smear object that will change the way residuals |
---|
| 759 | are compute when fitting |
---|
| 760 | """ |
---|
[3370922] | 761 | temp_smearer = None |
---|
[c77d859] | 762 | if self.enable_smearer.GetValue(): |
---|
[997131a] | 763 | msg="" |
---|
| 764 | temp_smearer= self.smearer |
---|
[c77d859] | 765 | if hasattr(self.data,"dxl"): |
---|
| 766 | msg= ": Resolution smearing parameters" |
---|
| 767 | if hasattr(self.data,"dxw"): |
---|
| 768 | msg= ": Slit smearing parameters" |
---|
[997131a] | 769 | if self.smearer ==None: |
---|
[c77d859] | 770 | wx.PostEvent(self.manager.parent, StatusEvent(status=\ |
---|
| 771 | "Data contains no smearing information")) |
---|
| 772 | else: |
---|
| 773 | wx.PostEvent(self.manager.parent, StatusEvent(status=\ |
---|
| 774 | "Data contains smearing information %s"%msg)) |
---|
[3370922] | 775 | |
---|
[fb8daaaf] | 776 | ## set smearing value whether or not the data contain the smearing info |
---|
[3370922] | 777 | self.manager.set_smearer(smearer=temp_smearer, qmin= float(self.qmin_x), |
---|
[2b63df0] | 778 | qmax= float(self.qmax_x)) |
---|
[875f1a2] | 779 | ##Calculate chi2 |
---|
[997131a] | 780 | self.compute_chisqr(smearer= temp_smearer) |
---|
[cfc0913] | 781 | ## save the state enable smearing |
---|
[330573d] | 782 | self.state.smearer= temp_smearer |
---|
| 783 | #self.save_current_state() |
---|
| 784 | |
---|
[847091f] | 785 | |
---|
[2b63df0] | 786 | def complete_chisqr(self, output, elapsed=None): |
---|
| 787 | """ |
---|
| 788 | print result chisqr |
---|
| 789 | """ |
---|
| 790 | try: |
---|
[077809c] | 791 | if output ==None: |
---|
| 792 | output= "-" |
---|
[ba95543] | 793 | self.tcChi.SetLabel(str(format_number(output))) |
---|
[0aeabc6] | 794 | |
---|
| 795 | self.sizer5.Layout() |
---|
| 796 | self.Layout() |
---|
| 797 | self.Refresh |
---|
| 798 | ## post state to fit panel |
---|
| 799 | self.state.tcChi =output |
---|
[330573d] | 800 | #event = PageInfoEvent(page = self) |
---|
| 801 | #wx.PostEvent(self.parent, event) |
---|
[2b63df0] | 802 | except: |
---|
[0aeabc6] | 803 | pass |
---|
[2b63df0] | 804 | |
---|
| 805 | |
---|
| 806 | def compute_chisqr1D(self, smearer=None): |
---|
| 807 | """ |
---|
| 808 | Compute chisqr for 1D |
---|
| 809 | """ |
---|
| 810 | from sans.guiframe.utils import check_value |
---|
| 811 | flag = check_value( self.qmin, self.qmax) |
---|
| 812 | |
---|
| 813 | if not flag: |
---|
| 814 | return |
---|
| 815 | |
---|
| 816 | try: |
---|
| 817 | self.qmin_x = float(self.qmin.GetValue()) |
---|
| 818 | self.qmax_x = float(self.qmax.GetValue()) |
---|
| 819 | ##return residuals within self.qmin_x and self.qmax_x |
---|
| 820 | from gui_thread import CalcChisqr1D |
---|
| 821 | ## If a thread is already started, stop it |
---|
| 822 | if self.calc_Chisqr!= None and self.calc_Chisqr.isrunning(): |
---|
| 823 | self.calc_Chisqr.stop() |
---|
| 824 | |
---|
[077809c] | 825 | self.calc_Chisqr= CalcChisqr1D( data1d= self.data, |
---|
[2b63df0] | 826 | model= self.model, |
---|
| 827 | smearer=smearer, |
---|
| 828 | qmin=self.qmin_x, |
---|
| 829 | qmax=self.qmax_x, |
---|
| 830 | completefn = self.complete_chisqr, |
---|
| 831 | updatefn = None) |
---|
| 832 | |
---|
| 833 | self.calc_Chisqr.queue() |
---|
| 834 | |
---|
| 835 | except: |
---|
| 836 | raise ValueError," Could not compute Chisqr for %s Model 2D: "%self.model.name |
---|
| 837 | |
---|
| 838 | |
---|
| 839 | |
---|
| 840 | |
---|
[b787e68c] | 841 | |
---|
[c77d859] | 842 | def compute_chisqr2D(self): |
---|
| 843 | """ |
---|
| 844 | compute chi square given a model and data 2D and set the value |
---|
| 845 | to the tcChi txtcrl |
---|
| 846 | """ |
---|
| 847 | from sans.guiframe.utils import check_value |
---|
| 848 | flag = check_value( self.qmin, self.qmax) |
---|
[2b63df0] | 849 | if not flag: |
---|
| 850 | return |
---|
| 851 | |
---|
| 852 | try: |
---|
| 853 | self.qmin_x = float(self.qmin.GetValue()) |
---|
| 854 | self.qmax_x = float(self.qmax.GetValue()) |
---|
| 855 | |
---|
| 856 | ##return residuals within self.qmin_x and self.qmax_x |
---|
| 857 | from gui_thread import CalcChisqr2D |
---|
| 858 | ## If a thread is already started, stop it |
---|
| 859 | if self.calc_Chisqr!= None and self.calc_Chisqr.isrunning(): |
---|
| 860 | self.calc_Chisqr.stop() |
---|
[0aeabc6] | 861 | |
---|
[077809c] | 862 | self.calc_Chisqr= CalcChisqr2D( data2d= self.data, |
---|
[2b63df0] | 863 | model= self.model, |
---|
| 864 | qmin= self.qmin_x, |
---|
| 865 | qmax = self.qmax_x, |
---|
| 866 | completefn = self.complete_chisqr, |
---|
| 867 | updatefn = None) |
---|
[c77d859] | 868 | |
---|
[2b63df0] | 869 | self.calc_Chisqr.queue() |
---|
| 870 | |
---|
| 871 | except: |
---|
[077809c] | 872 | raise |
---|
[2b63df0] | 873 | |
---|
[c77d859] | 874 | |
---|
[997131a] | 875 | def compute_chisqr(self , smearer=None): |
---|
[c77d859] | 876 | """ |
---|
| 877 | compute chi square given a model and data 1D and set the value |
---|
| 878 | to the tcChi txtcrl |
---|
| 879 | """ |
---|
| 880 | from sans.guiframe.utils import check_value |
---|
| 881 | flag = check_value( self.qmin, self.qmax) |
---|
| 882 | if flag== True: |
---|
| 883 | try: |
---|
| 884 | if hasattr(self.data,"data"): |
---|
| 885 | self.compute_chisqr2D() |
---|
| 886 | return |
---|
| 887 | else: |
---|
[2b63df0] | 888 | self.compute_chisqr1D(smearer=smearer) |
---|
| 889 | return |
---|
[c77d859] | 890 | except: |
---|
[077809c] | 891 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
[2b63df0] | 892 | "Chisqr Error: %s"% sys.exc_value)) |
---|
[a8088d7] | 893 | return |
---|
[c77d859] | 894 | |
---|
| 895 | |
---|
| 896 | def select_all_param(self,event): |
---|
| 897 | """ |
---|
| 898 | set to true or false all checkBox given the main checkbox value cb1 |
---|
[d1e0473] | 899 | """ |
---|
| 900 | |
---|
[c77d859] | 901 | self.param_toFit=[] |
---|
| 902 | if self.parameters !=[]: |
---|
[998b6b8] | 903 | if self.cb1.GetValue(): |
---|
[c77d859] | 904 | for item in self.parameters: |
---|
[3fef0a8] | 905 | ## for data2D select all to fit |
---|
| 906 | if self.data.__class__.__name__=="Data2D": |
---|
[c77d859] | 907 | item[0].SetValue(True) |
---|
| 908 | self.param_toFit.append(item ) |
---|
[3fef0a8] | 909 | else: |
---|
| 910 | ## for 1D all parameters except orientation |
---|
| 911 | if not item in self.orientation_params: |
---|
| 912 | item[0].SetValue(True) |
---|
| 913 | self.param_toFit.append(item ) |
---|
| 914 | if len(self.fittable_param)>0: |
---|
| 915 | for item in self.fittable_param: |
---|
| 916 | if self.data.__class__.__name__=="Data2D": |
---|
| 917 | item[0].SetValue(True) |
---|
| 918 | self.param_toFit.append(item ) |
---|
| 919 | else: |
---|
| 920 | ## for 1D all parameters except orientation |
---|
[513115c] | 921 | if not item in self.orientation_params_disp: |
---|
[3fef0a8] | 922 | item[0].SetValue(True) |
---|
| 923 | self.param_toFit.append(item ) |
---|
[c77d859] | 924 | else: |
---|
| 925 | for item in self.parameters: |
---|
| 926 | item[0].SetValue(False) |
---|
| 927 | for item in self.fittable_param: |
---|
| 928 | item[0].SetValue(False) |
---|
| 929 | self.param_toFit=[] |
---|
[330573d] | 930 | self._copy_parameters_state(self.orientation_params, |
---|
| 931 | self.state.orientation_params) |
---|
| 932 | self._copy_parameters_state(self.orientation_params_disp, |
---|
| 933 | self.state.orientation_params_disp) |
---|
| 934 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
| 935 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
| 936 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
| 937 | |
---|
| 938 | #self.save_current_state() |
---|
[3595309d] | 939 | if event !=None: |
---|
| 940 | self._undo.Enable(True) |
---|
| 941 | ## post state to fit panel |
---|
| 942 | event = PageInfoEvent(page = self) |
---|
| 943 | wx.PostEvent(self.parent, event) |
---|
| 944 | |
---|
[c77d859] | 945 | |
---|
| 946 | |
---|
| 947 | def select_param(self,event): |
---|
| 948 | """ |
---|
| 949 | Select TextCtrl checked for fitting purpose and stores them |
---|
| 950 | in self.param_toFit=[] list |
---|
| 951 | """ |
---|
| 952 | self.param_toFit=[] |
---|
| 953 | for item in self.parameters: |
---|
| 954 | #Select parameters to fit for list of primary parameters |
---|
[998b6b8] | 955 | if item[0].GetValue(): |
---|
[c77d859] | 956 | if not (item in self.param_toFit): |
---|
| 957 | self.param_toFit.append(item ) |
---|
| 958 | else: |
---|
| 959 | #remove parameters from the fitting list |
---|
| 960 | if item in self.param_toFit: |
---|
| 961 | self.param_toFit.remove(item) |
---|
| 962 | #Select parameters to fit for list of fittable parameters with dispersion |
---|
| 963 | for item in self.fittable_param: |
---|
[998b6b8] | 964 | if item[0].GetValue(): |
---|
[c77d859] | 965 | if not (item in self.param_toFit): |
---|
| 966 | self.param_toFit.append(item) |
---|
| 967 | else: |
---|
| 968 | #remove parameters from the fitting list |
---|
| 969 | if item in self.param_toFit: |
---|
| 970 | self.param_toFit.remove(item) |
---|
| 971 | #Set the value of checkbox that selected every checkbox or not |
---|
| 972 | if len(self.parameters)+len(self.fittable_param) ==len(self.param_toFit): |
---|
| 973 | self.cb1.SetValue(True) |
---|
| 974 | else: |
---|
| 975 | self.cb1.SetValue(False) |
---|
[cfc0913] | 976 | ## save current state of the page |
---|
[330573d] | 977 | self._copy_parameters_state(self.orientation_params, |
---|
| 978 | self.state.orientation_params) |
---|
| 979 | self._copy_parameters_state(self.orientation_params_disp, |
---|
| 980 | self.state.orientation_params_disp) |
---|
| 981 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
| 982 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
| 983 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
| 984 | |
---|
| 985 | #self.save_current_state() |
---|
[3595309d] | 986 | if event !=None: |
---|
| 987 | self._undo.Enable(True) |
---|
| 988 | ## post state to fit panel |
---|
| 989 | event = PageInfoEvent(page = self) |
---|
| 990 | wx.PostEvent(self.parent, event) |
---|
| 991 | |
---|
[c77d859] | 992 | |
---|
| 993 | |
---|
[77e23a2] | 994 | def set_model_param_sizer(self, model): |
---|
[c77d859] | 995 | """ |
---|
| 996 | Build the panel from the model content |
---|
| 997 | @param model: the model selected in combo box for fitting purpose |
---|
| 998 | """ |
---|
| 999 | self.sizer3.Clear(True) |
---|
| 1000 | self.parameters = [] |
---|
| 1001 | self.param_toFit=[] |
---|
| 1002 | self.fittable_param=[] |
---|
| 1003 | self.fixed_param=[] |
---|
[780d095] | 1004 | self.orientation_params=[] |
---|
[60132ef] | 1005 | self.orientation_params_disp=[] |
---|
[c77d859] | 1006 | |
---|
| 1007 | if model ==None: |
---|
| 1008 | self.sizer3.Layout() |
---|
| 1009 | self.SetScrollbars(20,20,200,100) |
---|
| 1010 | return |
---|
[707436d] | 1011 | ## the panel is drawn using the current value of the fit engine |
---|
| 1012 | if self.engine_type==None and self.manager !=None: |
---|
| 1013 | self.engine_type= self.manager._return_engine_type() |
---|
| 1014 | |
---|
[c77d859] | 1015 | box_description= wx.StaticBox(self, -1,str("Model Parameters")) |
---|
| 1016 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 1017 | sizer = wx.GridBagSizer(5,5) |
---|
| 1018 | ## save the current model |
---|
| 1019 | self.model = model |
---|
| 1020 | |
---|
| 1021 | keys = self.model.getParamList() |
---|
| 1022 | #list of dispersion paramaters |
---|
| 1023 | self.disp_list=self.model.getDispParamList() |
---|
| 1024 | |
---|
| 1025 | keys.sort() |
---|
| 1026 | |
---|
[6dc9ad8] | 1027 | iy = 0 |
---|
[c77d859] | 1028 | ix = 0 |
---|
| 1029 | self.cb1 = wx.CheckBox(self, -1,"Select all", (10, 10)) |
---|
| 1030 | wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param) |
---|
| 1031 | self.cb1.SetValue(False) |
---|
| 1032 | |
---|
| 1033 | sizer.Add(self.cb1,(iy, ix),(1,1),\ |
---|
[eda428b] | 1034 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
[c77d859] | 1035 | ix +=1 |
---|
| 1036 | self.text2_2 = wx.StaticText(self, -1, 'Values') |
---|
| 1037 | sizer.Add(self.text2_2,(iy, ix),(1,1),\ |
---|
| 1038 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1039 | ix +=2 |
---|
| 1040 | self.text2_3 = wx.StaticText(self, -1, 'Errors') |
---|
| 1041 | sizer.Add(self.text2_3,(iy, ix),(1,1),\ |
---|
| 1042 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1043 | self.text2_3.Hide() |
---|
| 1044 | ix +=1 |
---|
| 1045 | self.text2_min = wx.StaticText(self, -1, 'Min') |
---|
| 1046 | sizer.Add(self.text2_min,(iy, ix),(1,1),\ |
---|
| 1047 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1048 | self.text2_min.Hide() |
---|
| 1049 | ix +=1 |
---|
| 1050 | self.text2_max = wx.StaticText(self, -1, 'Max') |
---|
| 1051 | sizer.Add(self.text2_max,(iy, ix),(1,1),\ |
---|
| 1052 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1053 | self.text2_max.Hide() |
---|
[6fdfc8f] | 1054 | ix += 1 |
---|
| 1055 | self.text2_4 = wx.StaticText(self, -1, '[Units]') |
---|
| 1056 | sizer.Add(self.text2_4,(iy, ix),(1,1),\ |
---|
| 1057 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1058 | self.text2_4.Hide() |
---|
[dcf29d7] | 1059 | if self.engine_type=="park": |
---|
| 1060 | self.text2_max.Show(True) |
---|
| 1061 | self.text2_min.Show(True) |
---|
[c77d859] | 1062 | |
---|
| 1063 | for item in keys: |
---|
[780d095] | 1064 | if not item in self.disp_list and not item in self.model.orientation_params: |
---|
[330573d] | 1065 | |
---|
[c77d859] | 1066 | iy += 1 |
---|
| 1067 | ix = 0 |
---|
| 1068 | ## add parameters name with checkbox for selecting to fit |
---|
| 1069 | cb = wx.CheckBox(self, -1, item ) |
---|
| 1070 | cb.SetValue(False) |
---|
| 1071 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 1072 | sizer.Add( cb,( iy, ix),(1,1), |
---|
[eda428b] | 1073 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
[d1e0473] | 1074 | |
---|
[c77d859] | 1075 | ## add parameter value |
---|
| 1076 | ix += 1 |
---|
| 1077 | value= self.model.getParam(item) |
---|
[6f2c919] | 1078 | ctl1 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
[c77d859] | 1079 | style=wx.TE_PROCESS_ENTER) |
---|
| 1080 | |
---|
[77e23a2] | 1081 | ctl1.SetValue(format_number(value)) |
---|
[c77d859] | 1082 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 1083 | ## text to show error sign |
---|
| 1084 | ix += 1 |
---|
| 1085 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 1086 | sizer.Add(text2,(iy, ix),(1,1),\ |
---|
| 1087 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1088 | text2.Hide() |
---|
| 1089 | ## txtcrtl to add error from fit |
---|
| 1090 | ix += 1 |
---|
| 1091 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 1092 | sizer.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1093 | ctl2.Hide() |
---|
| 1094 | |
---|
[77e23a2] | 1095 | param_min, param_max= self.model.details[item][1:] |
---|
[c77d859] | 1096 | ix += 1 |
---|
[6f2c919] | 1097 | ctl3 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
| 1098 | kill_focus_callback = self._onparamRangeEnter, |
---|
| 1099 | set_focus_callback = self._onparamRangeEnter) |
---|
[298b762] | 1100 | if param_min ==None: |
---|
| 1101 | ctl3.SetValue("") |
---|
| 1102 | else: |
---|
| 1103 | ctl3.SetValue(str(param_min)) |
---|
[c77d859] | 1104 | sizer.Add(ctl3, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1105 | ctl3.Hide() |
---|
[77e23a2] | 1106 | |
---|
[c77d859] | 1107 | ix += 1 |
---|
[6f2c919] | 1108 | ctl4 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
| 1109 | kill_focus_callback = self._onparamRangeEnter, |
---|
| 1110 | set_focus_callback = self._onparamRangeEnter) |
---|
[c77d859] | 1111 | sizer.Add(ctl4, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[298b762] | 1112 | if param_max==None: |
---|
| 1113 | ctl4.SetValue("") |
---|
| 1114 | else: |
---|
| 1115 | ctl4.SetValue(str(param_max)) |
---|
[c77d859] | 1116 | ctl4.Hide() |
---|
[dcf29d7] | 1117 | |
---|
| 1118 | if self.engine_type=="park": |
---|
| 1119 | ctl3.Show(True) |
---|
| 1120 | ctl4.Show(True) |
---|
[6fdfc8f] | 1121 | ix +=1 |
---|
| 1122 | # Units |
---|
| 1123 | try: |
---|
| 1124 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
| 1125 | except: |
---|
| 1126 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
| 1127 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[dcf29d7] | 1128 | |
---|
[c77d859] | 1129 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 1130 | self.parameters.append([cb,item, ctl1, |
---|
[240b9966] | 1131 | text2,ctl2, ctl3, ctl4,units]) |
---|
[2d5f7a1] | 1132 | |
---|
[c77d859] | 1133 | iy+=1 |
---|
[2a5bba7] | 1134 | sizer.Add((10,10),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[5af5183] | 1135 | |
---|
[f20767b] | 1136 | # type can be either Guassian or Array |
---|
[5b53a5c] | 1137 | if len(self.model.dispersion.values())>0: |
---|
| 1138 | type= self.model.dispersion.values()[0]["type"] |
---|
| 1139 | else: |
---|
| 1140 | type = "Gaussian" |
---|
[6dc9ad8] | 1141 | |
---|
| 1142 | iy += 1 |
---|
| 1143 | ix = 0 |
---|
| 1144 | #Add tile for orientational angle |
---|
| 1145 | for item in keys: |
---|
| 1146 | if item in self.model.orientation_params: |
---|
| 1147 | orient_angle = wx.StaticText(self, -1, '[For 2D only]:') |
---|
| 1148 | sizer.Add(orient_angle,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 1149 | if not self.data.__class__.__name__ =="Data2D": |
---|
| 1150 | orient_angle.Hide() |
---|
| 1151 | else: |
---|
| 1152 | orient_angle.Show(True) |
---|
| 1153 | break |
---|
[5b53a5c] | 1154 | |
---|
[f20767b] | 1155 | #For Gaussian only |
---|
| 1156 | if type.lower() != "array": |
---|
| 1157 | for item in self.model.orientation_params: |
---|
| 1158 | if not item in self.disp_list: |
---|
| 1159 | iy += 1 |
---|
| 1160 | ix = 0 |
---|
| 1161 | ## add parameters name with checkbox for selecting to fit |
---|
| 1162 | cb = wx.CheckBox(self, -1, item ) |
---|
| 1163 | cb.SetValue(False) |
---|
| 1164 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 1165 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 1166 | cb.Show(True) |
---|
[f20767b] | 1167 | cb.Enable() |
---|
| 1168 | else: |
---|
[6dc9ad8] | 1169 | cb.Hide() |
---|
[f20767b] | 1170 | cb.Disable() |
---|
| 1171 | sizer.Add( cb,( iy, ix),(1,1), |
---|
| 1172 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
| 1173 | |
---|
| 1174 | ## add parameter value |
---|
| 1175 | ix += 1 |
---|
| 1176 | value= self.model.getParam(item) |
---|
| 1177 | ctl1 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 1178 | style=wx.TE_PROCESS_ENTER) |
---|
[780d095] | 1179 | |
---|
[f20767b] | 1180 | ctl1.SetValue(format_number(value)) |
---|
| 1181 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 1182 | #ctl1.Show(True) |
---|
[f20767b] | 1183 | ctl1.Enable() |
---|
| 1184 | else: |
---|
[6dc9ad8] | 1185 | #ctl1.Hide() |
---|
[f20767b] | 1186 | ctl1.Disable() |
---|
| 1187 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 1188 | ## text to show error sign |
---|
| 1189 | ix += 1 |
---|
| 1190 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 1191 | sizer.Add(text2,(iy, ix),(1,1),\ |
---|
| 1192 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1193 | text2.Hide() |
---|
| 1194 | ## txtcrtl to add error from fit |
---|
| 1195 | ix += 1 |
---|
| 1196 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
| 1197 | sizer.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1198 | ctl2.Hide() |
---|
| 1199 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 1200 | ctl1.Show(True) |
---|
[f20767b] | 1201 | ctl1.Enable() |
---|
| 1202 | else: |
---|
[6dc9ad8] | 1203 | ctl1.Hide() |
---|
[f20767b] | 1204 | ctl1.Disable() |
---|
| 1205 | param_min, param_max= self.model.details[item][1:] |
---|
| 1206 | ix += 1 |
---|
| 1207 | ctl3 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
| 1208 | kill_focus_callback = self._onparamRangeEnter, |
---|
| 1209 | set_focus_callback = self._onparamRangeEnter) |
---|
| 1210 | if param_min ==None: |
---|
| 1211 | ctl3.SetValue("") |
---|
| 1212 | else: |
---|
| 1213 | ctl3.SetValue(str(param_min)) |
---|
| 1214 | sizer.Add(ctl3, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1215 | ctl3.Hide() |
---|
| 1216 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 1217 | #ctl3.Show(True) |
---|
[f20767b] | 1218 | ctl3.Enable() |
---|
| 1219 | else: |
---|
[6dc9ad8] | 1220 | #ctl3.Hide() |
---|
[f20767b] | 1221 | ctl3.Disable() |
---|
| 1222 | ix += 1 |
---|
| 1223 | ctl4 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
| 1224 | kill_focus_callback = self._onparamRangeEnter, |
---|
| 1225 | set_focus_callback = self._onparamRangeEnter) |
---|
| 1226 | sizer.Add(ctl4, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1227 | if param_max ==None: |
---|
| 1228 | ctl4.SetValue("") |
---|
| 1229 | else: |
---|
| 1230 | ctl4.SetValue(str(param_max)) |
---|
| 1231 | ctl4.Hide() |
---|
| 1232 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 1233 | #ctl4.Show(True) |
---|
[f20767b] | 1234 | ctl4.Enable() |
---|
| 1235 | else: |
---|
[6dc9ad8] | 1236 | #ctl4.Hide() |
---|
[f20767b] | 1237 | ctl4.Disable() |
---|
| 1238 | if self.engine_type=="park": |
---|
| 1239 | ctl3.Show(True) |
---|
| 1240 | ctl4.Show(True) |
---|
| 1241 | ix +=1 |
---|
| 1242 | # Units |
---|
| 1243 | try: |
---|
| 1244 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
| 1245 | except: |
---|
| 1246 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
| 1247 | if self.data.__class__.__name__ =="Data2D": |
---|
[6dc9ad8] | 1248 | units.Show(True) |
---|
[f20767b] | 1249 | units.Enable() |
---|
| 1250 | else: |
---|
[6dc9ad8] | 1251 | units.Hide() |
---|
[f20767b] | 1252 | units.Disable() |
---|
| 1253 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 1254 | |
---|
| 1255 | |
---|
| 1256 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 1257 | self.parameters.append([cb,item, ctl1, |
---|
| 1258 | text2,ctl2, ctl3, ctl4,units]) |
---|
| 1259 | self.orientation_params.append([cb,item, ctl1, |
---|
| 1260 | text2,ctl2, ctl3, ctl4,units]) |
---|
[780d095] | 1261 | |
---|
| 1262 | iy+=1 |
---|
[58c6ba6] | 1263 | #sizer.Add((10,10),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[c77d859] | 1264 | |
---|
| 1265 | #Display units text on panel |
---|
| 1266 | for item in keys: |
---|
| 1267 | if self.model.details[item][0]!='': |
---|
| 1268 | self.text2_4.Show() |
---|
| 1269 | break |
---|
| 1270 | else: |
---|
| 1271 | self.text2_4.Hide() |
---|
[240b9966] | 1272 | |
---|
| 1273 | self._copy_parameters_state(self.orientation_params, |
---|
| 1274 | self.state.orientation_params) |
---|
| 1275 | self._copy_parameters_state(self.orientation_params_disp, |
---|
| 1276 | self.state.orientation_params_disp) |
---|
| 1277 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
| 1278 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
| 1279 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
[c77d859] | 1280 | |
---|
[240b9966] | 1281 | boxsizer1.Add(sizer) |
---|
[c77d859] | 1282 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 1283 | self.sizer3.Layout() |
---|
[330573d] | 1284 | self.Layout() |
---|
| 1285 | self.Refresh() |
---|
[c77d859] | 1286 | self.SetScrollbars(20,20,200,100) |
---|
[330573d] | 1287 | |
---|
[c77d859] | 1288 | |
---|
| 1289 | |
---|
| 1290 | class HelpWindow(wx.Frame): |
---|
| 1291 | def __init__(self, parent, id, title): |
---|
| 1292 | wx.Frame.__init__(self, parent, id, title, size=(570, 400)) |
---|
| 1293 | |
---|
| 1294 | from sans.models.CylinderModel import CylinderModel |
---|
| 1295 | model = CylinderModel() |
---|
[2d5f7a1] | 1296 | |
---|
[c77d859] | 1297 | from danse.common.plottools.plottables import Data1D |
---|
| 1298 | data= Data1D(x=[1,2], y=[3,4], dy=[0.1, 0,1]) |
---|
| 1299 | |
---|
[cfc0913] | 1300 | from fitpanel import PageInfo |
---|
[c77d859] | 1301 | myinfo = PageInfo(self, model, data=data ) |
---|
| 1302 | |
---|
| 1303 | ## add data |
---|
| 1304 | |
---|
| 1305 | from models import ModelList |
---|
| 1306 | mylist= ModelList() |
---|
| 1307 | |
---|
| 1308 | from sans.models.SphereModel import SphereModel |
---|
| 1309 | from sans.models.SquareWellStructure import SquareWellStructure |
---|
| 1310 | from sans.models.DebyeModel import DebyeModel |
---|
| 1311 | from sans.models.LineModel import LineModel |
---|
| 1312 | name= "shapes" |
---|
| 1313 | list1= [SphereModel] |
---|
| 1314 | mylist.set_list( name, list1) |
---|
| 1315 | |
---|
| 1316 | name= "Shape-independent" |
---|
| 1317 | list1= [DebyeModel] |
---|
| 1318 | mylist.set_list( name, list1) |
---|
| 1319 | |
---|
| 1320 | name= "Structure Factors" |
---|
| 1321 | list1= [SquareWellStructure] |
---|
| 1322 | mylist.set_list( name, list1) |
---|
| 1323 | |
---|
| 1324 | name= "Added models" |
---|
| 1325 | list1= [LineModel] |
---|
| 1326 | mylist.set_list( name, list1) |
---|
| 1327 | |
---|
| 1328 | myinfo.model_list_box = mylist.get_list() |
---|
| 1329 | |
---|
| 1330 | self.page = FitPage(self, myinfo) |
---|
| 1331 | |
---|
| 1332 | |
---|
| 1333 | |
---|
| 1334 | self.Centre() |
---|
| 1335 | self.Show(True) |
---|
| 1336 | |
---|
| 1337 | |
---|
| 1338 | |
---|
| 1339 | if __name__=="__main__": |
---|
| 1340 | app = wx.App() |
---|
| 1341 | HelpWindow(None, -1, 'HelpWindow') |
---|
| 1342 | app.MainLoop() |
---|
| 1343 | |
---|