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