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