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