[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 |
---|
[7609f1a] | 11 | from DataLoader.data_info import Data1D |
---|
[c4397785] | 12 | from sans.guiframe.events import StatusEvent |
---|
[85b3971] | 13 | from sans.guiframe.utils import format_number,check_float |
---|
[7609f1a] | 14 | |
---|
[f72333f] | 15 | (Chi2UpdateEvent, EVT_CHI2_UPDATE) = wx.lib.newevent.NewEvent() |
---|
[eda428b] | 16 | _BOX_WIDTH = 76 |
---|
[a5701e6] | 17 | _DATA_BOX_WIDTH = 300 |
---|
[ba1f0b2] | 18 | SMEAR_SIZE_L = 0.00 |
---|
| 19 | SMEAR_SIZE_H = 0.00 |
---|
[7609f1a] | 20 | |
---|
[c77d859] | 21 | import basepage |
---|
| 22 | from basepage import BasicPage |
---|
[b787e68c] | 23 | from basepage import PageInfoEvent |
---|
[e4957fb] | 24 | from sans.models.qsmearing import smear_selection |
---|
[c77d859] | 25 | |
---|
[e030625] | 26 | |
---|
[c77d859] | 27 | class FitPage(BasicPage): |
---|
| 28 | """ |
---|
[5062bbf] | 29 | FitPanel class contains fields allowing to display results when |
---|
| 30 | fitting a model and one data |
---|
| 31 | |
---|
| 32 | :note: For Fit to be performed the user should check at least one parameter |
---|
[c77d859] | 33 | on fit Panel window. |
---|
| 34 | """ |
---|
[7975f2b] | 35 | |
---|
[6bbeacd4] | 36 | def __init__(self,parent, color='rand'): |
---|
[c77d859] | 37 | """ |
---|
[5062bbf] | 38 | Initialization of the Panel |
---|
[c77d859] | 39 | """ |
---|
[6bbeacd4] | 40 | BasicPage.__init__(self, parent, color=color) |
---|
[88f286d] | 41 | |
---|
[b787e68c] | 42 | ## draw sizer |
---|
[c77d859] | 43 | self._fill_datainfo_sizer() |
---|
[2296316] | 44 | self.is_2D = None |
---|
[f22e626] | 45 | self.fit_started = False |
---|
[7609f1a] | 46 | # get smear info from data |
---|
| 47 | self._get_smear_info() |
---|
[c77d859] | 48 | self._fill_model_sizer( self.sizer1) |
---|
[7609f1a] | 49 | self._get_defult_custom_smear() |
---|
[cfc0913] | 50 | self._fill_range_sizer() |
---|
[6bbeacd4] | 51 | self._set_smear(self.data) |
---|
[f72333f] | 52 | self.Bind(EVT_CHI2_UPDATE, self.on_complete_chisqr) |
---|
[2296316] | 53 | # bind key event |
---|
| 54 | self.Bind(wx.EVT_RIGHT_DOWN, self.on_right_down) |
---|
[982e953] | 55 | self._set_bookmark_flag(False) |
---|
| 56 | self._set_save_flag(False) |
---|
[aad74b3] | 57 | self._set_preview_flag(False) |
---|
[716da5e] | 58 | self.btFit.SetFocus() |
---|
[9466f2d6] | 59 | |
---|
| 60 | |
---|
[66ff250] | 61 | def _on_fit_complete(self): |
---|
[34a0c17] | 62 | """ |
---|
[5062bbf] | 63 | When fit is complete ,reset the fit button label. |
---|
[34a0c17] | 64 | """ |
---|
[66ff250] | 65 | self.btFit.SetLabel("Fit") |
---|
| 66 | self.bind_fit_button() |
---|
[34a0c17] | 67 | |
---|
[f72333f] | 68 | def _is_2D(self): |
---|
| 69 | """ |
---|
[5062bbf] | 70 | Check if data_name is Data2D |
---|
| 71 | |
---|
| 72 | :return: True or False |
---|
| 73 | |
---|
[f72333f] | 74 | """ |
---|
[ba1f0b2] | 75 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 76 | self.enable2D: |
---|
[f72333f] | 77 | return True |
---|
| 78 | return False |
---|
| 79 | |
---|
[66ff250] | 80 | def _on_engine_change(self, name): |
---|
[77e23a2] | 81 | """ |
---|
[66ff250] | 82 | get the current name of the fit engine type |
---|
| 83 | and update the panel accordingly |
---|
[77e23a2] | 84 | """ |
---|
[66ff250] | 85 | |
---|
| 86 | self.engine_type = str(name) |
---|
[0b12abb5] | 87 | self.state.engine_type = self.engine_type |
---|
[9e87b76] | 88 | if not self.is_mac: |
---|
| 89 | if len(self.parameters) == 0: |
---|
| 90 | self.Layout() |
---|
| 91 | return |
---|
[edd166b] | 92 | self.Layout() |
---|
[9e87b76] | 93 | self.Refresh() |
---|
[66ff250] | 94 | |
---|
[6bbeacd4] | 95 | |
---|
| 96 | |
---|
[c77d859] | 97 | def _fill_range_sizer(self): |
---|
| 98 | """ |
---|
[5062bbf] | 99 | Fill the sizer containing the plotting range |
---|
| 100 | add access to npts |
---|
[c77d859] | 101 | """ |
---|
[51a71a3] | 102 | is_2Ddata = False |
---|
| 103 | |
---|
| 104 | # Check if data is 2D |
---|
[ba1f0b2] | 105 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 106 | self.enable2D: |
---|
[51a71a3] | 107 | is_2Ddata = True |
---|
| 108 | |
---|
[ff8f99b] | 109 | title = "Fitting" |
---|
[7609f1a] | 110 | #smear messages & titles |
---|
| 111 | smear_message_none = "No smearing is selected..." |
---|
| 112 | smear_message_dqdata = "The dQ data is being used for smearing..." |
---|
[f72333f] | 113 | smear_message_2d = "Higher accuracy is very time-expensive. Use it with care..." |
---|
[7609f1a] | 114 | smear_message_new_ssmear = "Please enter only the value of interest to customize smearing..." |
---|
| 115 | smear_message_new_psmear = "Please enter both; the dQ will be generated by interpolation..." |
---|
[2296316] | 116 | smear_message_2d_x_title = "<dQp>[1/A]:" |
---|
| 117 | smear_message_2d_y_title = "<dQs>[1/A]:" |
---|
[f72333f] | 118 | smear_message_pinhole_min_title = "dQ_low[1/A]:" |
---|
| 119 | smear_message_pinhole_max_title = "dQ_high[1/A]:" |
---|
[7609f1a] | 120 | smear_message_slit_height_title = "Slit height[1/A]:" |
---|
| 121 | smear_message_slit_width_title = "Slit width[1/A]:" |
---|
| 122 | |
---|
| 123 | self._get_smear_info() |
---|
[c77d859] | 124 | |
---|
[51a71a3] | 125 | #Sizers |
---|
| 126 | box_description_range = wx.StaticBox(self, -1,str(title)) |
---|
| 127 | boxsizer_range = wx.StaticBoxSizer(box_description_range, wx.VERTICAL) |
---|
[7609f1a] | 128 | self.sizer_set_smearer = wx.BoxSizer(wx.VERTICAL) |
---|
[c77d859] | 129 | sizer_smearer = wx.BoxSizer(wx.HORIZONTAL) |
---|
[7609f1a] | 130 | self.sizer_new_smear= wx.BoxSizer(wx.HORIZONTAL) |
---|
| 131 | self.sizer_set_masking = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 132 | sizer_chi2 = wx.BoxSizer(wx.VERTICAL) |
---|
| 133 | smear_set_box= wx.StaticBox(self, -1,'Set Instrumental Smearing') |
---|
| 134 | sizer_smearer_box = wx.StaticBoxSizer(smear_set_box, wx.HORIZONTAL) |
---|
| 135 | sizer_smearer_box.SetMinSize((_DATA_BOX_WIDTH,85)) |
---|
[0cf97c5] | 136 | sizer_fit = wx.GridSizer(2, 4, 2, 6) |
---|
[2012eae] | 137 | |
---|
[f72333f] | 138 | # combobox for smear2d accuracy selection |
---|
| 139 | self.smear_accuracy = wx.ComboBox(self, -1,size=(50,-1),style=wx.CB_READONLY) |
---|
| 140 | self._set_accuracy_list() |
---|
| 141 | self.smear_accuracy.SetValue(self.smear2d_accuracy) |
---|
| 142 | self.smear_accuracy.SetSelection(0) |
---|
| 143 | self.smear_accuracy.SetToolTipString("'Higher' uses more Gaussian points for smearing computation.") |
---|
| 144 | |
---|
| 145 | wx.EVT_COMBOBOX(self.smear_accuracy,-1, self._on_select_accuracy) |
---|
| 146 | |
---|
[2012eae] | 147 | #Fit button |
---|
| 148 | self.btFit = wx.Button(self,wx.NewId(),'Fit', size=(88,25)) |
---|
[e030625] | 149 | self.default_bt_colour = self.btFit.GetDefaultAttributes() |
---|
[29bf83b] | 150 | self.btFit.Bind(wx.EVT_BUTTON, self._onFit,id= self.btFit.GetId()) |
---|
[2012eae] | 151 | self.btFit.SetToolTipString("Start fitting.") |
---|
[7609f1a] | 152 | |
---|
[f72333f] | 153 | #textcntrl for custom resolution |
---|
| 154 | self.smear_pinhole_max = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH-25,20),style=wx.TE_PROCESS_ENTER, |
---|
[7609f1a] | 155 | text_enter_callback = self.onPinholeSmear) |
---|
[f72333f] | 156 | self.smear_pinhole_min = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH-25,20),style=wx.TE_PROCESS_ENTER, |
---|
[7609f1a] | 157 | text_enter_callback = self.onPinholeSmear) |
---|
[f72333f] | 158 | self.smear_slit_height= self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH-25,20),style=wx.TE_PROCESS_ENTER, |
---|
[7609f1a] | 159 | text_enter_callback = self.onSlitSmear) |
---|
[f72333f] | 160 | self.smear_slit_width = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH-25,20),style=wx.TE_PROCESS_ENTER, |
---|
[7609f1a] | 161 | text_enter_callback = self.onSlitSmear) |
---|
[f72333f] | 162 | |
---|
| 163 | ## smear |
---|
| 164 | self.smear_data_left= BGTextCtrl(self, -1, size=(_BOX_WIDTH-25,20), style=0) |
---|
[7609f1a] | 165 | self.smear_data_left.SetValue(str(self.dq_l)) |
---|
[f72333f] | 166 | self.smear_data_right = BGTextCtrl(self, -1, size=(_BOX_WIDTH-25,20), style=0) |
---|
[7609f1a] | 167 | self.smear_data_right.SetValue(str(self.dq_r)) |
---|
| 168 | |
---|
[f72333f] | 169 | #set default values for smear |
---|
[7609f1a] | 170 | self.smear_pinhole_max.SetValue(str(self.dx_max)) |
---|
| 171 | self.smear_pinhole_min.SetValue(str(self.dx_min)) |
---|
| 172 | self.smear_slit_height.SetValue(str(self.dxl)) |
---|
| 173 | self.smear_slit_width.SetValue(str(self.dxw)) |
---|
| 174 | |
---|
[c77d859] | 175 | #Filling the sizer containing instruments smearing info. |
---|
[7609f1a] | 176 | self.disable_smearer = wx.RadioButton(self, -1, 'None', style=wx.RB_GROUP) |
---|
| 177 | self.enable_smearer = wx.RadioButton(self, -1, 'Use dQ Data') |
---|
| 178 | #self.enable_smearer.SetToolTipString("Click to use the loaded dQ data for smearing.") |
---|
| 179 | self.pinhole_smearer = wx.RadioButton(self, -1, 'Custom Pinhole Smear') |
---|
| 180 | #self.pinhole_smearer.SetToolTipString("Click to input custom resolution for pinhole smearing.") |
---|
| 181 | self.slit_smearer = wx.RadioButton(self, -1, 'Custom Slit Smear') |
---|
| 182 | #self.slit_smearer.SetToolTipString("Click to input custom resolution for slit smearing.") |
---|
[c77d859] | 183 | self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.disable_smearer.GetId()) |
---|
| 184 | self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.enable_smearer.GetId()) |
---|
[7609f1a] | 185 | self.Bind(wx.EVT_RADIOBUTTON, self.onPinholeSmear, id=self.pinhole_smearer.GetId()) |
---|
| 186 | self.Bind(wx.EVT_RADIOBUTTON, self.onSlitSmear, id=self.slit_smearer.GetId()) |
---|
[ff8f99b] | 187 | self.disable_smearer.SetValue(True) |
---|
[c77d859] | 188 | |
---|
[7609f1a] | 189 | # add 4 types of smearing to the sizer |
---|
| 190 | sizer_smearer.Add( self.disable_smearer,0, wx.LEFT, 10) |
---|
[c77d859] | 191 | sizer_smearer.Add((10,10)) |
---|
[7609f1a] | 192 | sizer_smearer.Add( self.enable_smearer) |
---|
| 193 | sizer_smearer.Add((10,10)) |
---|
| 194 | sizer_smearer.Add( self.pinhole_smearer ) |
---|
| 195 | sizer_smearer.Add((10,10)) |
---|
| 196 | sizer_smearer.Add( self.slit_smearer ) |
---|
| 197 | sizer_smearer.Add((10,10)) |
---|
| 198 | |
---|
[51a71a3] | 199 | # StaticText for chi2, N(for fitting), Npts |
---|
| 200 | self.tcChi = BGTextCtrl(self, -1, "-", size=(75,20), style=0) |
---|
[e9875db] | 201 | self.tcChi.SetToolTipString("Chi2/Npts(Fit)") |
---|
[51a71a3] | 202 | self.Npts_fit = BGTextCtrl(self, -1, "-", size=(75,20), style=0) |
---|
[0cf97c5] | 203 | self.Npts_fit.SetToolTipString(\ |
---|
| 204 | " Npts : number of points selected for fitting") |
---|
| 205 | self.Npts_total = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
| 206 | style=wx.TE_PROCESS_ENTER, |
---|
| 207 | text_enter_callback=self._onQrangeEnter) |
---|
| 208 | self.Npts_total.SetValue(format_number(self.npts_x)) |
---|
| 209 | self.Npts_total.SetToolTipString(\ |
---|
| 210 | " Total Npts : total number of data points") |
---|
| 211 | |
---|
[2296316] | 212 | # Update and Draw button |
---|
| 213 | self.draw_button = wx.Button(self,wx.NewId(),'Compute', size=(88,24)) |
---|
[0cf97c5] | 214 | self.draw_button.Bind(wx.EVT_BUTTON, \ |
---|
| 215 | self._onDraw,id= self.draw_button.GetId()) |
---|
[2296316] | 216 | self.draw_button.SetToolTipString("Compute and Draw.") |
---|
| 217 | |
---|
[51a71a3] | 218 | box_description_1= wx.StaticText(self, -1,' Chi2/Npts') |
---|
[0cf97c5] | 219 | box_description_2= wx.StaticText(self, -1,'Npts(Fit)') |
---|
| 220 | box_description_3= wx.StaticText(self, -1,'Total Npts') |
---|
| 221 | box_description_3.SetToolTipString( \ |
---|
| 222 | " Total Npts : total number of data points") |
---|
[2296316] | 223 | #box_description_4= wx.StaticText(self, -1,' ') |
---|
[7609f1a] | 224 | |
---|
[2012eae] | 225 | |
---|
[51a71a3] | 226 | sizer_fit.Add(box_description_1,0,0) |
---|
| 227 | sizer_fit.Add(box_description_2,0,0) |
---|
| 228 | sizer_fit.Add(box_description_3,0,0) |
---|
[2296316] | 229 | sizer_fit.Add(self.draw_button,0,0) |
---|
[51a71a3] | 230 | sizer_fit.Add(self.tcChi,0,0) |
---|
| 231 | sizer_fit.Add(self.Npts_fit ,0,0) |
---|
| 232 | sizer_fit.Add(self.Npts_total,0,0) |
---|
| 233 | sizer_fit.Add(self.btFit,0,0) |
---|
| 234 | |
---|
| 235 | # StaticText for smear |
---|
| 236 | #self.tcChi = wx.StaticText(self, -1, "-", style=wx.ALIGN_LEFT) |
---|
[7609f1a] | 237 | self.smear_description_none = wx.StaticText(self, -1, smear_message_none , style=wx.ALIGN_LEFT) |
---|
| 238 | self.smear_description_dqdata = wx.StaticText(self, -1, smear_message_dqdata , style=wx.ALIGN_LEFT) |
---|
| 239 | self.smear_description_type = wx.StaticText(self, -1, "Type:" , style=wx.ALIGN_LEFT) |
---|
[f72333f] | 240 | self.smear_description_accuracy_type = wx.StaticText(self, -1, "Accuracy:" , style=wx.ALIGN_LEFT) |
---|
| 241 | self.smear_description_smear_type = BGTextCtrl(self, -1, size=(57,20), style=0) |
---|
[7609f1a] | 242 | self.smear_description_smear_type.SetValue(str(self.dq_l)) |
---|
| 243 | self.SetBackgroundColour(self.GetParent().GetBackgroundColour()) |
---|
| 244 | self.smear_description_2d = wx.StaticText(self, -1, smear_message_2d , style=wx.ALIGN_LEFT) |
---|
| 245 | self.smear_message_new_s = wx.StaticText(self, -1, smear_message_new_ssmear , style=wx.ALIGN_LEFT) |
---|
| 246 | self.smear_message_new_p = wx.StaticText(self, -1, smear_message_new_psmear , style=wx.ALIGN_LEFT) |
---|
[f72333f] | 247 | self.smear_description_2d_x = wx.StaticText(self, -1, smear_message_2d_x_title , style=wx.ALIGN_LEFT) |
---|
[2296316] | 248 | self.smear_description_2d_x.SetToolTipString(" dQp(parallel) in q_r direction.") |
---|
[f72333f] | 249 | self.smear_description_2d_y = wx.StaticText(self, -1, smear_message_2d_y_title , style=wx.ALIGN_LEFT) |
---|
[2296316] | 250 | self.smear_description_2d_y.SetToolTipString(" dQs(perpendicular) in q_phi direction.") |
---|
[7609f1a] | 251 | self.smear_description_pin_min = wx.StaticText(self, -1, smear_message_pinhole_min_title , style=wx.ALIGN_LEFT) |
---|
| 252 | self.smear_description_pin_max = wx.StaticText(self, -1, smear_message_pinhole_max_title , style=wx.ALIGN_LEFT) |
---|
| 253 | self.smear_description_slit_height = wx.StaticText(self, -1, smear_message_slit_height_title , style=wx.ALIGN_LEFT) |
---|
| 254 | self.smear_description_slit_width = wx.StaticText(self, -1, smear_message_slit_width_title , style=wx.ALIGN_LEFT) |
---|
| 255 | |
---|
| 256 | #arrange sizers |
---|
[51a71a3] | 257 | #boxsizer1.Add( self.tcChi ) |
---|
[7609f1a] | 258 | self.sizer_set_smearer.Add(sizer_smearer ) |
---|
| 259 | self.sizer_set_smearer.Add((10,10)) |
---|
| 260 | self.sizer_set_smearer.Add( self.smear_description_none,0, wx.CENTER, 10 ) |
---|
| 261 | self.sizer_set_smearer.Add( self.smear_description_dqdata,0, wx.CENTER, 10 ) |
---|
| 262 | self.sizer_set_smearer.Add( self.smear_description_2d,0, wx.CENTER, 10 ) |
---|
| 263 | self.sizer_new_smear.Add( self.smear_description_type,0, wx.CENTER, 10 ) |
---|
[f72333f] | 264 | self.sizer_new_smear.Add( self.smear_description_accuracy_type,0, wx.CENTER, 10 ) |
---|
| 265 | self.sizer_new_smear.Add( self.smear_accuracy ) |
---|
[7609f1a] | 266 | self.sizer_new_smear.Add( self.smear_description_smear_type,0, wx.CENTER, 10 ) |
---|
| 267 | self.sizer_new_smear.Add((15,-1)) |
---|
[f72333f] | 268 | self.sizer_new_smear.Add( self.smear_description_2d_x,0, wx.CENTER, 10 ) |
---|
[7609f1a] | 269 | self.sizer_new_smear.Add( self.smear_description_pin_min,0, wx.CENTER, 10 ) |
---|
| 270 | self.sizer_new_smear.Add( self.smear_description_slit_height,0, wx.CENTER, 10 ) |
---|
[f72333f] | 271 | |
---|
[7609f1a] | 272 | self.sizer_new_smear.Add( self.smear_pinhole_min,0, wx.CENTER, 10 ) |
---|
| 273 | self.sizer_new_smear.Add( self.smear_slit_height,0, wx.CENTER, 10 ) |
---|
| 274 | self.sizer_new_smear.Add( self.smear_data_left,0, wx.CENTER, 10 ) |
---|
| 275 | self.sizer_new_smear.Add((20,-1)) |
---|
[f72333f] | 276 | self.sizer_new_smear.Add( self.smear_description_2d_y,0, wx.CENTER, 10 ) |
---|
[7609f1a] | 277 | self.sizer_new_smear.Add( self.smear_description_pin_max,0, wx.CENTER, 10 ) |
---|
| 278 | self.sizer_new_smear.Add( self.smear_description_slit_width,0, wx.CENTER, 10 ) |
---|
[f72333f] | 279 | |
---|
[7609f1a] | 280 | self.sizer_new_smear.Add( self.smear_pinhole_max,0, wx.CENTER, 10 ) |
---|
| 281 | self.sizer_new_smear.Add( self.smear_slit_width,0, wx.CENTER, 10 ) |
---|
| 282 | self.sizer_new_smear.Add( self.smear_data_right,0, wx.CENTER, 10 ) |
---|
| 283 | |
---|
| 284 | self.sizer_set_smearer.Add( self.smear_message_new_s,0, wx.CENTER, 10) |
---|
| 285 | self.sizer_set_smearer.Add( self.smear_message_new_p,0, wx.CENTER, 10) |
---|
| 286 | self.sizer_set_smearer.Add((5,2)) |
---|
| 287 | self.sizer_set_smearer.Add( self.sizer_new_smear,0, wx.CENTER, 10 ) |
---|
| 288 | |
---|
[51a71a3] | 289 | # add all to chi2 sizer |
---|
| 290 | sizer_smearer_box.Add(self.sizer_set_smearer) |
---|
[7609f1a] | 291 | sizer_chi2.Add(sizer_smearer_box) |
---|
| 292 | sizer_chi2.Add((-1,5)) |
---|
[51a71a3] | 293 | |
---|
[7609f1a] | 294 | # hide all smear messages and textctrl |
---|
| 295 | self._hide_all_smear_info() |
---|
| 296 | |
---|
| 297 | # get smear_selection |
---|
[f867cd9] | 298 | self.current_smearer= smear_selection( self.data, self.model ) |
---|
[83ad478] | 299 | |
---|
[7609f1a] | 300 | # Show only the relevant smear messages, etc |
---|
| 301 | if self.current_smearer == None: |
---|
[51a71a3] | 302 | if not is_2Ddata: |
---|
[7609f1a] | 303 | self.smear_description_none.Show(True) |
---|
| 304 | self.enable_smearer.Disable() |
---|
| 305 | else: |
---|
[f72333f] | 306 | self.smear_description_none.Show(True) |
---|
| 307 | #self.smear_description_2d.Show(True) |
---|
| 308 | #self.pinhole_smearer.Disable() |
---|
[7609f1a] | 309 | self.slit_smearer.Disable() |
---|
[f72333f] | 310 | #self.enable_smearer.Disable() |
---|
[0f8f831] | 311 | if self.data == None: |
---|
| 312 | self.slit_smearer.Disable() |
---|
| 313 | self.pinhole_smearer.Disable() |
---|
| 314 | self.enable_smearer.Disable() |
---|
[7609f1a] | 315 | else: self._show_smear_sizer() |
---|
[51a71a3] | 316 | boxsizer_range.Add(self.sizer_set_masking) |
---|
[6bbeacd4] | 317 | #2D data? default |
---|
| 318 | is_2Ddata = False |
---|
[7609f1a] | 319 | |
---|
[6bbeacd4] | 320 | #check if it is 2D data |
---|
[ba1f0b2] | 321 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 322 | self.enable2D: |
---|
[6bbeacd4] | 323 | is_2Ddata = True |
---|
| 324 | |
---|
| 325 | self.sizer5.Clear(True) |
---|
| 326 | |
---|
[f95301b] | 327 | self.qmin = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20), |
---|
[6bbeacd4] | 328 | style=wx.TE_PROCESS_ENTER, |
---|
| 329 | text_enter_callback = self._onQrangeEnter) |
---|
[f95301b] | 330 | self.qmin.SetValue(str(self.qmin_x)) |
---|
| 331 | self.qmin.SetToolTipString("Minimun value of Q in linear scale.") |
---|
[6bbeacd4] | 332 | |
---|
| 333 | self.qmax = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20), |
---|
| 334 | style=wx.TE_PROCESS_ENTER, |
---|
| 335 | text_enter_callback=self._onQrangeEnter) |
---|
| 336 | self.qmax.SetValue(str(self.qmax_x)) |
---|
| 337 | self.qmax.SetToolTipString("Maximum value of Q in linear scale.") |
---|
[0cf97c5] | 338 | """ |
---|
[6bbeacd4] | 339 | self.theory_npts_tcrtl = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
| 340 | style=wx.TE_PROCESS_ENTER, |
---|
| 341 | text_enter_callback=self._onQrangeEnter) |
---|
| 342 | self.theory_npts_tcrtl.SetValue(format_number(self.npts_x)) |
---|
| 343 | self.theory_npts_tcrtl.SetToolTipString("Number of point to plot.") |
---|
[0cf97c5] | 344 | """ |
---|
[6bbeacd4] | 345 | id = wx.NewId() |
---|
| 346 | self.reset_qrange =wx.Button(self,id,'Reset',size=(77,20)) |
---|
| 347 | |
---|
| 348 | self.reset_qrange.Bind(wx.EVT_BUTTON, self.on_reset_clicked,id=id) |
---|
| 349 | self.reset_qrange.SetToolTipString("Reset Q range to the default values") |
---|
| 350 | |
---|
| 351 | sizer_horizontal=wx.BoxSizer(wx.HORIZONTAL) |
---|
[0cf97c5] | 352 | sizer= wx.GridSizer(2, 4, 2, 6) |
---|
[6bbeacd4] | 353 | |
---|
| 354 | self.btEditMask = wx.Button(self,wx.NewId(),'Editor', size=(88,23)) |
---|
| 355 | self.btEditMask.Bind(wx.EVT_BUTTON, self._onMask,id= self.btEditMask.GetId()) |
---|
| 356 | self.btEditMask.SetToolTipString("Edit Mask.") |
---|
| 357 | self.EditMask_title = wx.StaticText(self, -1, ' Masking(2D)') |
---|
| 358 | |
---|
| 359 | sizer.Add(wx.StaticText(self, -1, 'Q range')) |
---|
| 360 | sizer.Add(wx.StaticText(self, -1, ' Min[1/A]')) |
---|
| 361 | sizer.Add(wx.StaticText(self, -1, ' Max[1/A]')) |
---|
| 362 | sizer.Add(self.EditMask_title) |
---|
[0cf97c5] | 363 | #sizer.Add(wx.StaticText(self, -1, '')) |
---|
[6bbeacd4] | 364 | sizer.Add(self.reset_qrange) |
---|
[f95301b] | 365 | sizer.Add(self.qmin) |
---|
[6bbeacd4] | 366 | sizer.Add(self.qmax) |
---|
[0cf97c5] | 367 | #sizer.Add(self.theory_npts_tcrtl) |
---|
[6bbeacd4] | 368 | sizer.Add(self.btEditMask) |
---|
| 369 | boxsizer_range.Add(sizer_chi2) |
---|
| 370 | boxsizer_range.Add((10,10)) |
---|
| 371 | boxsizer_range.Add(sizer) |
---|
| 372 | |
---|
| 373 | boxsizer_range.Add((10,15)) |
---|
| 374 | boxsizer_range.Add(sizer_fit) |
---|
| 375 | if is_2Ddata: |
---|
| 376 | self.btEditMask.Enable() |
---|
| 377 | self.EditMask_title.Enable() |
---|
| 378 | else: |
---|
| 379 | self.btEditMask.Disable() |
---|
| 380 | self.EditMask_title.Disable() |
---|
| 381 | ## save state |
---|
| 382 | self.save_current_state() |
---|
| 383 | self.sizer5.Add(boxsizer_range,0, wx.EXPAND | wx.ALL, 10) |
---|
| 384 | self.sizer5.Layout() |
---|
| 385 | |
---|
[c77d859] | 386 | def _fill_datainfo_sizer(self): |
---|
| 387 | """ |
---|
[5062bbf] | 388 | fill sizer 0 with data info |
---|
[c77d859] | 389 | """ |
---|
| 390 | ## no loaded data , don't fill the sizer |
---|
[9237df4] | 391 | if self.data is None: |
---|
| 392 | data_min = "" |
---|
| 393 | data_max = "" |
---|
[4efefc6] | 394 | data_name = " None" |
---|
[9237df4] | 395 | else: |
---|
| 396 | data_name = self.data.name |
---|
| 397 | #set maximum range for x in linear scale |
---|
| 398 | if not hasattr(self.data,"data"): #Display only for 1D data fit |
---|
| 399 | # Minimum value of data |
---|
| 400 | data_min = min(self.data.x) |
---|
| 401 | # Maximum value of data |
---|
| 402 | data_max = max(self.data.x) |
---|
| 403 | else: |
---|
| 404 | ## Minimum value of data |
---|
| 405 | data_min = 0 |
---|
| 406 | x = max(math.fabs(self.data.xmin), math.fabs(self.data.xmax)) |
---|
| 407 | y = max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) |
---|
| 408 | ## Maximum value of data |
---|
| 409 | data_max = math.sqrt(x*x + y*y) |
---|
[6bbeacd4] | 410 | ## set q range to plot |
---|
| 411 | self.qmin_x = data_min |
---|
| 412 | self.qmax_x = data_max |
---|
[4efefc6] | 413 | box_description= wx.StaticBox(self, -1, 'I(q) Data Source') |
---|
[c77d859] | 414 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 415 | #---------------------------------------------------------- |
---|
[9237df4] | 416 | sizer_data = wx.BoxSizer(wx.HORIZONTAL) |
---|
[c77d859] | 417 | #Filling the sizer containing data related fields |
---|
[9237df4] | 418 | #self.dataSource = wx.StaticText(self, -1,str(self.data.name)) |
---|
[7609f1a] | 419 | self.dataSource = BGTextCtrl(self, -1) |
---|
[9237df4] | 420 | self.dataSource.SetValue(str(data_name)) |
---|
[7609f1a] | 421 | #self.dataSource.SetEditable(False) |
---|
[9237df4] | 422 | self.dataSource.SetMinSize((_DATA_BOX_WIDTH, -1)) |
---|
[c1e6400] | 423 | sizer_data.Add(wx.StaticText(self, -1, 'Name : ')) |
---|
[9237df4] | 424 | sizer_data.Add(self.dataSource ) |
---|
[88f286d] | 425 | sizer_data.Add( (0,5) ) |
---|
[4efefc6] | 426 | """ |
---|
[c77d859] | 427 | #---------sizer 2 draw-------------------------------- |
---|
[9237df4] | 428 | text4_3 = wx.StaticText(self, -1, 'Total Q Range (1/A)', |
---|
| 429 | style=wx.ALIGN_LEFT) |
---|
| 430 | sizer_range = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 431 | sizer_range.Add( text4_3 ,0, wx.RIGHT, 10) |
---|
[7609f1a] | 432 | self.minimum_q = BGTextCtrl(self, -1, size=(_BOX_WIDTH,20)) |
---|
[9237df4] | 433 | self.minimum_q.SetValue(str(data_min)) |
---|
[7609f1a] | 434 | self.maximum_q = BGTextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
[9237df4] | 435 | self.maximum_q.SetValue(str(data_max)) |
---|
| 436 | sizer_range.Add(wx.StaticText(self, -1, "Min: "),0, wx.LEFT, 10) |
---|
| 437 | sizer_range.Add(self.minimum_q,0, wx.LEFT, 10) |
---|
| 438 | sizer_range.Add(wx.StaticText(self, -1, "Max: "),0, wx.LEFT, 10) |
---|
| 439 | sizer_range.Add(self.maximum_q,0, wx.LEFT, 10) |
---|
[4efefc6] | 440 | """ |
---|
[9237df4] | 441 | boxsizer1.Add(sizer_data,0, wx.ALL, 10) |
---|
[4efefc6] | 442 | #boxsizer1.Add(sizer_range, 0 , wx.LEFT, 10) |
---|
[c77d859] | 443 | #------------------------------------------------------------ |
---|
[4efefc6] | 444 | |
---|
[c77d859] | 445 | self.sizer0.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 446 | self.sizer0.Layout() |
---|
[813334e] | 447 | |
---|
[c77d859] | 448 | def _fill_model_sizer(self, sizer): |
---|
| 449 | """ |
---|
[5062bbf] | 450 | fill sizer containing model info |
---|
[c77d859] | 451 | """ |
---|
[7ad6ff5] | 452 | ##Add model function Details button in fitpanel. |
---|
[ff8f99b] | 453 | ##The following 3 lines are for Mac. Let JHC know before modifying... |
---|
| 454 | title = "Model" |
---|
[e4c9030] | 455 | self.formfactorbox = None |
---|
| 456 | self.multifactorbox = None |
---|
[88f286d] | 457 | self.mbox_description= wx.StaticBox(self, -1,str(title)) |
---|
| 458 | boxsizer1 = wx.StaticBoxSizer(self.mbox_description, wx.VERTICAL) |
---|
| 459 | |
---|
[7ad6ff5] | 460 | id = wx.NewId() |
---|
[e3a76c8] | 461 | self.model_help =wx.Button(self,id,'Details', size=(80,23)) |
---|
[7ad6ff5] | 462 | self.model_help.Bind(wx.EVT_BUTTON, self.on_model_help_clicked,id=id) |
---|
| 463 | self.model_help.SetToolTipString("Model Function Help") |
---|
[a5701e6] | 464 | id = wx.NewId() |
---|
[6371c9c] | 465 | self.model_view = wx.Button(self, id,"1D Mode", size=(80, 23)) |
---|
[a5701e6] | 466 | self.model_view.Bind(wx.EVT_BUTTON, self._onModel2D, id=id) |
---|
[8e33400] | 467 | hint = "toggle view of model from 1D to 2D or 2D to 1D" |
---|
[a5701e6] | 468 | self.model_view.SetToolTipString(hint) |
---|
| 469 | |
---|
| 470 | self.shape_rbutton = wx.RadioButton(self, -1, 'Shapes', style=wx.RB_GROUP) |
---|
| 471 | self.shape_indep_rbutton = wx.RadioButton(self, -1, "Shape-Independent") |
---|
| 472 | self.struct_rbutton = wx.RadioButton(self, -1, "Structure Factor ") |
---|
| 473 | self.plugin_rbutton = wx.RadioButton(self, -1, "Customized Models") |
---|
| 474 | |
---|
| 475 | self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 476 | id= self.shape_rbutton.GetId()) |
---|
| 477 | self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 478 | id= self.shape_indep_rbutton.GetId()) |
---|
| 479 | self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 480 | id= self.struct_rbutton.GetId()) |
---|
| 481 | self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, |
---|
| 482 | id= self.plugin_rbutton.GetId()) |
---|
| 483 | #MAC needs SetValue |
---|
| 484 | self.shape_rbutton.SetValue(True) |
---|
| 485 | |
---|
| 486 | sizer_radiobutton = wx.GridSizer(2, 3, 5, 5) |
---|
| 487 | sizer_radiobutton.Add(self.shape_rbutton) |
---|
| 488 | sizer_radiobutton.Add(self.shape_indep_rbutton) |
---|
| 489 | #sizer_radiobutton.Add((5, 5)) |
---|
| 490 | sizer_radiobutton.Add(self.model_view,1, wx.LEFT, 20) |
---|
| 491 | sizer_radiobutton.Add(self.plugin_rbutton) |
---|
| 492 | sizer_radiobutton.Add(self.struct_rbutton) |
---|
| 493 | #sizer_radiobutton.Add((5, 5)) |
---|
| 494 | sizer_radiobutton.Add(self.model_help,1, wx.LEFT, 20) |
---|
| 495 | |
---|
| 496 | sizer_selection = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 497 | mutifactor_selection = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 498 | |
---|
| 499 | self.text1 = wx.StaticText(self,-1,"" ) |
---|
| 500 | self.text2 = wx.StaticText(self,-1,"P(Q)*S(Q)" ) |
---|
| 501 | self.mutifactor_text = wx.StaticText( self,-1,"No. of Shells: ") |
---|
| 502 | self.mutifactor_text1 = wx.StaticText( self,-1,"" ) |
---|
| 503 | self.show_sld_button = wx.Button( self,-1,"Show SLD Profile" ) |
---|
| 504 | self.show_sld_button.Bind(wx.EVT_BUTTON,self._on_show_sld) |
---|
| 505 | |
---|
| 506 | self.formfactorbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
| 507 | if self.model!= None: |
---|
| 508 | self.formfactorbox.SetValue(self.model.name) |
---|
| 509 | self.structurebox = wx.ComboBox(self, -1, style=wx.CB_READONLY) |
---|
| 510 | self.multifactorbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) |
---|
| 511 | self.initialize_combox() |
---|
| 512 | wx.EVT_COMBOBOX(self.formfactorbox, -1, self._on_select_model) |
---|
[9466f2d6] | 513 | |
---|
[a5701e6] | 514 | wx.EVT_COMBOBOX(self.structurebox, -1, self._on_select_model) |
---|
| 515 | wx.EVT_COMBOBOX(self.multifactorbox, -1, self._on_select_model) |
---|
| 516 | ## check model type to show sizer |
---|
| 517 | if self.model !=None: |
---|
| 518 | self._set_model_sizer_selection(self.model) |
---|
| 519 | |
---|
| 520 | sizer_selection.Add(self.text1) |
---|
| 521 | sizer_selection.Add((5, 5)) |
---|
| 522 | sizer_selection.Add(self.formfactorbox) |
---|
| 523 | sizer_selection.Add((5, 5)) |
---|
| 524 | sizer_selection.Add(self.text2) |
---|
| 525 | sizer_selection.Add((5, 5)) |
---|
| 526 | sizer_selection.Add(self.structurebox) |
---|
| 527 | |
---|
| 528 | mutifactor_selection.Add((10,5)) |
---|
| 529 | mutifactor_selection.Add(self.mutifactor_text) |
---|
| 530 | mutifactor_selection.Add(self.multifactorbox) |
---|
| 531 | mutifactor_selection.Add((5, 5)) |
---|
| 532 | mutifactor_selection.Add(self.mutifactor_text1) |
---|
| 533 | mutifactor_selection.Add((10, 5)) |
---|
| 534 | mutifactor_selection.Add(self.show_sld_button) |
---|
| 535 | |
---|
| 536 | |
---|
| 537 | boxsizer1.Add(sizer_radiobutton) |
---|
| 538 | boxsizer1.Add((10, 10)) |
---|
| 539 | boxsizer1.Add(sizer_selection) |
---|
| 540 | boxsizer1.Add((10, 10)) |
---|
| 541 | boxsizer1.Add(mutifactor_selection) |
---|
| 542 | |
---|
| 543 | self._set_multfactor_combobox() |
---|
| 544 | self.multifactorbox.SetSelection(1) |
---|
| 545 | self.show_sld_button.Hide() |
---|
| 546 | sizer.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 547 | sizer.Layout() |
---|
[5062bbf] | 548 | |
---|
[2296316] | 549 | def _set_sizer_dispersion(self): |
---|
[c77d859] | 550 | """ |
---|
[5062bbf] | 551 | draw sizer with gaussian dispersity parameters |
---|
[c77d859] | 552 | """ |
---|
| 553 | self.fittable_param=[] |
---|
| 554 | self.fixed_param=[] |
---|
[60132ef] | 555 | self.orientation_params_disp=[] |
---|
[920a6e5] | 556 | |
---|
[c77d859] | 557 | self.sizer4_4.Clear(True) |
---|
| 558 | if self.model==None: |
---|
| 559 | ##no model is selected |
---|
| 560 | return |
---|
| 561 | if not self.enable_disp.GetValue(): |
---|
| 562 | ## the user didn't select dispersity display |
---|
| 563 | return |
---|
[b421b1a] | 564 | |
---|
[376916c] | 565 | self._reset_dispersity() |
---|
[b421b1a] | 566 | |
---|
[2296316] | 567 | ## fill a sizer with the combobox to select dispersion type |
---|
| 568 | #sizer_select_dispers = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 569 | model_disp = wx.StaticText(self, -1, 'Function') |
---|
| 570 | |
---|
| 571 | import sans.models.dispersion_models |
---|
| 572 | self.polydisp= sans.models.dispersion_models.models |
---|
[b421b1a] | 573 | |
---|
[2296316] | 574 | ix = 0 |
---|
| 575 | iy = 0 |
---|
[52efcc5] | 576 | disp = wx.StaticText(self, -1, ' ') |
---|
[c77d859] | 577 | self.sizer4_4.Add(disp,( iy, ix),(1,1), |
---|
| 578 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 579 | ix += 1 |
---|
[2296316] | 580 | values = wx.StaticText(self, -1, 'PD[ratio]') |
---|
[01b6bd0] | 581 | polytext = "Polydispersity (= STD/mean); " |
---|
| 582 | polytext += "the standard deviation over the mean value." |
---|
| 583 | values.SetToolTipString(polytext) |
---|
[d7b7156] | 584 | |
---|
| 585 | self.sizer4_4.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, |
---|
| 586 | 0) |
---|
[c77d859] | 587 | ix +=2 |
---|
[e5a1c31] | 588 | if self.is_mac: |
---|
| 589 | err_text = 'Error' |
---|
| 590 | else: |
---|
| 591 | err_text = '' |
---|
| 592 | self.text_disp_1 = wx.StaticText(self, -1, err_text) |
---|
[c77d859] | 593 | self.sizer4_4.Add( self.text_disp_1,(iy, ix),(1,1),\ |
---|
| 594 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[920a6e5] | 595 | |
---|
| 596 | |
---|
| 597 | ix +=1 |
---|
| 598 | self.text_disp_min = wx.StaticText(self, -1, 'Min') |
---|
| 599 | self.sizer4_4.Add(self.text_disp_min,(iy, ix),(1,1),\ |
---|
| 600 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[2296316] | 601 | |
---|
[920a6e5] | 602 | ix +=1 |
---|
| 603 | self.text_disp_max = wx.StaticText(self, -1, 'Max') |
---|
| 604 | self.sizer4_4.Add(self.text_disp_max,(iy, ix),(1,1),\ |
---|
| 605 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[339b563] | 606 | |
---|
[c77d859] | 607 | ix += 1 |
---|
| 608 | npts = wx.StaticText(self, -1, 'Npts') |
---|
[d7b7156] | 609 | npts.SetToolTipString("Number of sampling points for the numerical\n\ |
---|
| 610 | integration over the distribution function.") |
---|
[c77d859] | 611 | self.sizer4_4.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 612 | ix += 1 |
---|
[2296316] | 613 | nsigmas = wx.StaticText(self, -1, 'Nsigs') |
---|
[d7b7156] | 614 | nsigmas.SetToolTipString(" Number of sigmas between which the range\n\ |
---|
| 615 | of the distribution function will be used for weighting. \n\ |
---|
| 616 | The value '3' covers 99.5% for Gaussian distribution \n\ |
---|
[01b6bd0] | 617 | function. Note: Not recommended to change this value.") |
---|
[d7b7156] | 618 | self.sizer4_4.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, |
---|
| 619 | 0) |
---|
[2296316] | 620 | ix +=1 |
---|
| 621 | self.sizer4_4.Add(model_disp,(iy, ix),(1,1),\ |
---|
| 622 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[920a6e5] | 623 | |
---|
| 624 | if self.engine_type=="park": |
---|
| 625 | self.text_disp_max.Show(True) |
---|
| 626 | self.text_disp_min.Show(True) |
---|
[6dc9ad8] | 627 | |
---|
[c77d859] | 628 | for item in self.model.dispersion.keys(): |
---|
[780d095] | 629 | if not item in self.model.orientation_params: |
---|
[edd166b] | 630 | if not self.disp_cb_dict.has_key(item): |
---|
| 631 | self.disp_cb_dict[item]= None |
---|
[d7b7156] | 632 | name0="Distribution of " + item |
---|
[780d095] | 633 | name1=item+".width" |
---|
| 634 | name2=item+".npts" |
---|
| 635 | name3=item+".nsigmas" |
---|
[c99a6c5] | 636 | if not self.model.details.has_key(name1): |
---|
[b421b1a] | 637 | self.model.details [name1] = ["",None,None] |
---|
[c99a6c5] | 638 | |
---|
[780d095] | 639 | iy += 1 |
---|
| 640 | for p in self.model.dispersion[item].keys(): |
---|
| 641 | |
---|
| 642 | if p=="width": |
---|
| 643 | ix = 0 |
---|
[d7b7156] | 644 | cb = wx.CheckBox(self, -1, name0, (10, 10)) |
---|
[2296316] | 645 | cb.SetToolTipString("Check mark to fit") |
---|
[780d095] | 646 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 647 | self.sizer4_4.Add( cb,( iy, ix),(1,1), |
---|
[d7b7156] | 648 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, |
---|
[2296316] | 649 | 5) |
---|
[780d095] | 650 | ix = 1 |
---|
| 651 | value= self.model.getParam(name1) |
---|
[2296316] | 652 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.3,20) |
---|
[d7b7156] | 653 | ,style=wx.TE_PROCESS_ENTER) |
---|
[01b6bd0] | 654 | ctl1.SetLabel('PD[ratio]') |
---|
| 655 | poly_text = "Polydispersity (STD/mean) of %s\n" % item |
---|
| 656 | poly_text += "STD: the standard deviation" |
---|
| 657 | poly_text += " from the mean value." |
---|
| 658 | ctl1.SetToolTipString(poly_text) |
---|
[2296316] | 659 | ctl1.SetValue(str (format_number(value, True))) |
---|
[780d095] | 660 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1),wx.EXPAND) |
---|
| 661 | ## text to show error sign |
---|
| 662 | ix = 2 |
---|
| 663 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 664 | self.sizer4_4.Add(text2,(iy, ix),(1,1), |
---|
| 665 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[ce92ded] | 666 | if not self.is_mac: |
---|
| 667 | text2.Hide() |
---|
[b421b1a] | 668 | |
---|
[780d095] | 669 | ix = 3 |
---|
[2296316] | 670 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/1.3,20), |
---|
[d7b7156] | 671 | style=0) |
---|
[eacf1d66] | 672 | |
---|
[d7b7156] | 673 | self.sizer4_4.Add(ctl2, (iy,ix),(1,1), |
---|
| 674 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[ce92ded] | 675 | if not self.is_mac: |
---|
| 676 | ctl2.Hide() |
---|
[eacf1d66] | 677 | |
---|
[920a6e5] | 678 | ix = 4 |
---|
[d7b7156] | 679 | ctl3 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2, |
---|
| 680 | 20), style=wx.TE_PROCESS_ENTER, |
---|
| 681 | text_enter_callback = self._onparamRangeEnter) |
---|
[b9405cd] | 682 | |
---|
[d7b7156] | 683 | self.sizer4_4.Add(ctl3, (iy,ix),(1,1), |
---|
| 684 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[2296316] | 685 | |
---|
[920a6e5] | 686 | |
---|
| 687 | ix = 5 |
---|
[d7b7156] | 688 | ctl4 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2, |
---|
| 689 | 20), style=wx.TE_PROCESS_ENTER, |
---|
| 690 | text_enter_callback = self._onparamRangeEnter) |
---|
[b9405cd] | 691 | |
---|
[d7b7156] | 692 | self.sizer4_4.Add(ctl4, (iy,ix),(1,1), |
---|
| 693 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[eacf1d66] | 694 | |
---|
[920a6e5] | 695 | |
---|
| 696 | if self.engine_type=="park": |
---|
| 697 | ctl3.Show(True) |
---|
| 698 | ctl4.Show(True) |
---|
[2296316] | 699 | |
---|
[780d095] | 700 | elif p=="npts": |
---|
[920a6e5] | 701 | ix = 6 |
---|
[780d095] | 702 | value= self.model.getParam(name2) |
---|
[d7b7156] | 703 | Tctl = self.ModelTextCtrl(self, -1, |
---|
[2296316] | 704 | size=(_BOX_WIDTH/2.2,20), |
---|
[780d095] | 705 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 706 | |
---|
[780d095] | 707 | Tctl.SetValue(str (format_number(value))) |
---|
| 708 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
| 709 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 710 | self.fixed_param.append([None,name2, Tctl,None,None, |
---|
| 711 | None, None,None]) |
---|
| 712 | elif p=="nsigmas": |
---|
[920a6e5] | 713 | ix = 7 |
---|
[780d095] | 714 | value= self.model.getParam(name3) |
---|
[d7b7156] | 715 | Tct2 = self.ModelTextCtrl(self, -1, |
---|
[2296316] | 716 | size=(_BOX_WIDTH/2.2,20), |
---|
[780d095] | 717 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 718 | |
---|
[c985bef] | 719 | Tct2.SetValue(str (format_number(value))) |
---|
| 720 | self.sizer4_4.Add(Tct2, (iy,ix),(1,1), |
---|
[780d095] | 721 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[2296316] | 722 | #ix +=1 |
---|
| 723 | #self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
| 724 | # wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[920a6e5] | 725 | |
---|
[2296316] | 726 | self.fixed_param.append([None, name3, Tct2, |
---|
| 727 | None, None, None, |
---|
| 728 | None, None]) |
---|
| 729 | |
---|
| 730 | |
---|
| 731 | ix = 8 |
---|
| 732 | disp_box = wx.ComboBox(self, -1,size=(65,-1), |
---|
| 733 | style=wx.CB_READONLY, name = '%s'% name1) |
---|
| 734 | for key, value in self.polydisp.iteritems(): |
---|
| 735 | name_disp = str(key) |
---|
| 736 | disp_box.Append(name_disp,value) |
---|
| 737 | disp_box.SetStringSelection("gaussian") |
---|
| 738 | wx.EVT_COMBOBOX(disp_box,-1, self._on_disp_func) |
---|
| 739 | self.sizer4_4.Add(disp_box,(iy,ix),(1,1), wx.EXPAND) |
---|
| 740 | self.fittable_param.append([cb,name1,ctl1,text2, |
---|
| 741 | ctl2, ctl3, ctl4, disp_box]) |
---|
| 742 | |
---|
[780d095] | 743 | ix =0 |
---|
| 744 | iy +=1 |
---|
[d7b7156] | 745 | self.sizer4_4.Add((20,20),(iy,ix),(1,1), |
---|
| 746 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 747 | first_orient = True |
---|
[780d095] | 748 | for item in self.model.dispersion.keys(): |
---|
| 749 | if item in self.model.orientation_params: |
---|
[edd166b] | 750 | if not self.disp_cb_dict.has_key(item): |
---|
| 751 | self.disp_cb_dict[item]= None |
---|
[d7b7156] | 752 | name0="Distribution of " + item |
---|
[780d095] | 753 | name1=item+".width" |
---|
| 754 | name2=item+".npts" |
---|
| 755 | name3=item+".nsigmas" |
---|
[d7b7156] | 756 | |
---|
[c99a6c5] | 757 | if not self.model.details.has_key(name1): |
---|
[b421b1a] | 758 | self.model.details [name1] = ["",None,None] |
---|
| 759 | |
---|
| 760 | |
---|
[780d095] | 761 | iy += 1 |
---|
| 762 | for p in self.model.dispersion[item].keys(): |
---|
| 763 | |
---|
| 764 | if p=="width": |
---|
| 765 | ix = 0 |
---|
[d7b7156] | 766 | cb = wx.CheckBox(self, -1, name0, (10, 10)) |
---|
[2296316] | 767 | cb.SetToolTipString("Check mark to fit") |
---|
[780d095] | 768 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
| 769 | self.sizer4_4.Add( cb,( iy, ix),(1,1), |
---|
[d7b7156] | 770 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, |
---|
[2296316] | 771 | 5) |
---|
[ba1f0b2] | 772 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 773 | self.enable2D: |
---|
[6dc9ad8] | 774 | cb.Show(True) |
---|
[c99a6c5] | 775 | elif cb.IsShown(): |
---|
[6dc9ad8] | 776 | cb.Hide() |
---|
[780d095] | 777 | ix = 1 |
---|
| 778 | value= self.model.getParam(name1) |
---|
[2296316] | 779 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.3, |
---|
[d7b7156] | 780 | 20),style=wx.TE_PROCESS_ENTER) |
---|
[01b6bd0] | 781 | poly_tip = "Absolute Sigma for %s." % item |
---|
| 782 | ctl1.SetToolTipString(poly_tip) |
---|
[2296316] | 783 | ctl1.SetValue(str (format_number(value, True))) |
---|
[ba1f0b2] | 784 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 785 | self.enable2D: |
---|
[d7b7156] | 786 | if first_orient: |
---|
[01b6bd0] | 787 | values.SetLabel('PD[ratio], Sig[deg]') |
---|
| 788 | poly_text = "PD(polydispersity for lengths):\n" |
---|
| 789 | poly_text += "It should be a value between" |
---|
| 790 | poly_text += "0 and 1\n" |
---|
| 791 | poly_text += "Sigma for angles: \n" |
---|
| 792 | poly_text += "It is the STD (ratio*mean)" |
---|
[2b0f822] | 793 | poly_text += " of the distribution.\n " |
---|
[01b6bd0] | 794 | |
---|
| 795 | values.SetToolTipString(poly_text) |
---|
[d7b7156] | 796 | first_orient = False |
---|
[6dc9ad8] | 797 | ctl1.Show(True) |
---|
[c99a6c5] | 798 | elif ctl1.IsShown(): |
---|
[6dc9ad8] | 799 | ctl1.Hide() |
---|
[d7b7156] | 800 | |
---|
[780d095] | 801 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1),wx.EXPAND) |
---|
| 802 | ## text to show error sign |
---|
| 803 | ix = 2 |
---|
| 804 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 805 | self.sizer4_4.Add(text2,(iy, ix),(1,1), |
---|
| 806 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[e792aee] | 807 | |
---|
| 808 | text2.Hide() |
---|
[b421b1a] | 809 | |
---|
[780d095] | 810 | ix = 3 |
---|
[2296316] | 811 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/1.3,20), |
---|
[d7b7156] | 812 | style=0) |
---|
[b421b1a] | 813 | |
---|
[d7b7156] | 814 | self.sizer4_4.Add(ctl2, (iy,ix),(1,1), |
---|
| 815 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[e792aee] | 816 | |
---|
| 817 | ctl2.Hide() |
---|
[1180528] | 818 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 819 | self.enable2D: |
---|
| 820 | if self.is_mac: |
---|
| 821 | text2.Show(True) |
---|
| 822 | ctl2.Show(True) |
---|
[920a6e5] | 823 | |
---|
| 824 | ix = 4 |
---|
[d7b7156] | 825 | ctl3 = self.ModelTextCtrl(self, -1, |
---|
| 826 | size=(_BOX_WIDTH/2,20), |
---|
| 827 | style=wx.TE_PROCESS_ENTER, |
---|
| 828 | text_enter_callback = self._onparamRangeEnter) |
---|
[eacf1d66] | 829 | |
---|
[d7b7156] | 830 | self.sizer4_4.Add(ctl3, (iy,ix),(1,1), |
---|
| 831 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[c99a6c5] | 832 | |
---|
[920a6e5] | 833 | ctl3.Hide() |
---|
| 834 | |
---|
| 835 | ix = 5 |
---|
[d7b7156] | 836 | ctl4 = self.ModelTextCtrl(self, -1, |
---|
| 837 | size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
| 838 | text_enter_callback = self._onparamRangeEnter) |
---|
| 839 | self.sizer4_4.Add(ctl4, (iy,ix),(1,1), |
---|
| 840 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[920a6e5] | 841 | ctl4.Hide() |
---|
| 842 | |
---|
[ba1f0b2] | 843 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 844 | self.enable2D: |
---|
[920a6e5] | 845 | ctl3.Show(True) |
---|
[c99a6c5] | 846 | ctl4.Show(True) |
---|
[2296316] | 847 | |
---|
[780d095] | 848 | elif p=="npts": |
---|
[920a6e5] | 849 | ix = 6 |
---|
[780d095] | 850 | value= self.model.getParam(name2) |
---|
[d7b7156] | 851 | Tctl = self.ModelTextCtrl(self, -1, |
---|
[2296316] | 852 | size=(_BOX_WIDTH/2.2, 20), |
---|
[780d095] | 853 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 854 | |
---|
[780d095] | 855 | Tctl.SetValue(str (format_number(value))) |
---|
[ba1f0b2] | 856 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 857 | self.enable2D: |
---|
[6dc9ad8] | 858 | Tctl.Show(True) |
---|
[780d095] | 859 | else: |
---|
[6dc9ad8] | 860 | Tctl.Hide() |
---|
[780d095] | 861 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
| 862 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 863 | self.fixed_param.append([None,name2, Tctl,None,None, |
---|
| 864 | None, None,None]) |
---|
[d7b7156] | 865 | self.orientation_params_disp.append([None,name2, |
---|
| 866 | Tctl,None,None, |
---|
[780d095] | 867 | None, None,None]) |
---|
| 868 | elif p=="nsigmas": |
---|
[920a6e5] | 869 | ix = 7 |
---|
[780d095] | 870 | value= self.model.getParam(name3) |
---|
[d7b7156] | 871 | Tct2 = self.ModelTextCtrl(self, -1, |
---|
[2296316] | 872 | size=(_BOX_WIDTH/2.2,20), |
---|
[780d095] | 873 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 874 | |
---|
[c985bef] | 875 | Tct2.SetValue(str (format_number(value))) |
---|
[ba1f0b2] | 876 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 877 | self.enable2D: |
---|
[c985bef] | 878 | Tct2.Show(True) |
---|
[780d095] | 879 | else: |
---|
[c985bef] | 880 | Tct2.Hide() |
---|
| 881 | self.sizer4_4.Add(Tct2, (iy,ix),(1,1), |
---|
[780d095] | 882 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[2296316] | 883 | |
---|
[7975f2b] | 884 | |
---|
[c985bef] | 885 | self.fixed_param.append([None,name3, Tct2 |
---|
[d7b7156] | 886 | ,None,None, None, None,None]) |
---|
[920a6e5] | 887 | |
---|
[d7b7156] | 888 | self.orientation_params_disp.append([None,name3, |
---|
| 889 | Tct2 ,None,None, None, None,None]) |
---|
| 890 | |
---|
[2296316] | 891 | |
---|
| 892 | ix = 8 |
---|
| 893 | disp_box = wx.ComboBox(self, -1,size=(65,-1), |
---|
| 894 | style=wx.CB_READONLY, name = '%s'% name1) |
---|
| 895 | for key, value in self.polydisp.iteritems(): |
---|
| 896 | name_disp = str(key) |
---|
| 897 | disp_box.Append(name_disp,value) |
---|
| 898 | disp_box.SetStringSelection("gaussian") |
---|
| 899 | wx.EVT_COMBOBOX(disp_box,-1, self._on_disp_func) |
---|
| 900 | self.sizer4_4.Add(disp_box,(iy,ix),(1,1), wx.EXPAND) |
---|
| 901 | self.fittable_param.append([cb,name1,ctl1,text2, |
---|
| 902 | ctl2, ctl3, ctl4, disp_box]) |
---|
| 903 | self.orientation_params_disp.append([cb,name1,ctl1, |
---|
| 904 | text2, ctl2, ctl3, ctl4, disp_box]) |
---|
| 905 | |
---|
[ba1f0b2] | 906 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 907 | self.enable2D: |
---|
[2296316] | 908 | disp_box.Show(True) |
---|
| 909 | else: |
---|
| 910 | disp_box.Hide() |
---|
| 911 | |
---|
| 912 | |
---|
[b421b1a] | 913 | self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) |
---|
| 914 | |
---|
[71f0373] | 915 | self.state.model = self.model.clone() |
---|
[240b9966] | 916 | ## save state into |
---|
[4043c96] | 917 | self.state.cb1 = self.cb1.GetValue() |
---|
[920a6e5] | 918 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
[240b9966] | 919 | self._copy_parameters_state(self.orientation_params_disp, |
---|
| 920 | self.state.orientation_params_disp) |
---|
[d7b7156] | 921 | self._copy_parameters_state(self.fittable_param, |
---|
| 922 | self.state.fittable_param) |
---|
[240b9966] | 923 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
[d40a9cd] | 924 | |
---|
| 925 | |
---|
[c77d859] | 926 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
| 927 | " Selected Distribution: Gaussian")) |
---|
[b324aa9] | 928 | #Fill the list of fittable parameters |
---|
| 929 | self.select_all_param(event=None) |
---|
| 930 | |
---|
[71f0373] | 931 | self.Layout() |
---|
[7975f2b] | 932 | |
---|
[2296316] | 933 | |
---|
| 934 | def _onDraw(self, event): |
---|
| 935 | """ |
---|
| 936 | Update and Draw the model |
---|
| 937 | """ |
---|
| 938 | if self.model ==None: |
---|
| 939 | msg="Please select a Model first..." |
---|
| 940 | wx.MessageBox(msg, 'Info') |
---|
[06aa2eeb] | 941 | |
---|
[2296316] | 942 | return |
---|
| 943 | flag = self._update_paramv_on_fit() |
---|
| 944 | self._onparamEnter_helper() |
---|
| 945 | if not flag: |
---|
| 946 | msg= "The parameters are invalid" |
---|
| 947 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
| 948 | return |
---|
| 949 | |
---|
| 950 | |
---|
[c77d859] | 951 | def _onFit(self, event): |
---|
| 952 | """ |
---|
[5062bbf] | 953 | Allow to fit |
---|
[c77d859] | 954 | """ |
---|
[054c10a] | 955 | if event != None: |
---|
| 956 | event.Skip() |
---|
[dc613d6] | 957 | if len(self.parent._manager.fit_thread_list)>0 and\ |
---|
| 958 | self.parent._manager._fit_engine != "park": |
---|
| 959 | msg = "The FitEnging will be set to 'ParkMC'\n" |
---|
| 960 | msg += " to fit with more than one data set..." |
---|
| 961 | wx.MessageBox(msg, 'Info') |
---|
| 962 | #wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
| 963 | # "Fitting: %s"%msg)) |
---|
| 964 | |
---|
[504dd9f5] | 965 | if self.data is None: |
---|
[ecfcef6] | 966 | msg = "Please get Data first..." |
---|
[504dd9f5] | 967 | wx.MessageBox(msg, 'Info') |
---|
| 968 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
| 969 | "Fit: %s" % msg)) |
---|
| 970 | return |
---|
| 971 | if self.model is None: |
---|
| 972 | msg = "Please select a Model first..." |
---|
[4470b10] | 973 | wx.MessageBox(msg, 'Info') |
---|
[90a7bbd] | 974 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
[2296316] | 975 | "Fit: %s"%msg, type="stop")) |
---|
[4470b10] | 976 | return |
---|
[ecfcef6] | 977 | |
---|
| 978 | if len(self.param_toFit) <= 0: |
---|
| 979 | msg= "Select at least one parameter to fit" |
---|
| 980 | wx.MessageBox(msg, 'Info') |
---|
| 981 | wx.PostEvent(self._manager.parent, StatusEvent(status= msg, |
---|
| 982 | type="stop" )) |
---|
| 983 | return |
---|
| 984 | |
---|
[85b3971] | 985 | flag = self._update_paramv_on_fit() |
---|
[acd0bda3] | 986 | |
---|
[c77d859] | 987 | if not flag: |
---|
[7609f1a] | 988 | msg= "Fitting range or parameters are invalid" |
---|
[2296316] | 989 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg, |
---|
| 990 | type="stop")) |
---|
[c77d859] | 991 | return |
---|
[ecfcef6] | 992 | |
---|
[7975f2b] | 993 | self.select_param(event =None) |
---|
[acd0bda3] | 994 | |
---|
[c99a6c5] | 995 | #Clear errors if exist from previous fitting |
---|
[edd166b] | 996 | #self._clear_Err_on_Fit() |
---|
[d0ce2c30] | 997 | |
---|
[d7b7156] | 998 | # Remove or do not allow fitting on the Q=0 point, especially |
---|
| 999 | # when y(q=0)=None at x[0]. |
---|
[f95301b] | 1000 | self.qmin_x = float(self.qmin.GetValue()) |
---|
[c13b8cc] | 1001 | self.qmax_x = float( self.qmax.GetValue()) |
---|
[dc613d6] | 1002 | self._manager._reset_schedule_problem(value=0, uid=self.uid) |
---|
[66ff250] | 1003 | self._manager.schedule_for_fit(uid=self.uid,value=1, fitproblem =None) |
---|
| 1004 | self._manager.set_fit_range(uid=self.uid,qmin= self.qmin_x, |
---|
[d7b7156] | 1005 | qmax= self.qmax_x) |
---|
[ad6dd4c] | 1006 | |
---|
[c77d859] | 1007 | #single fit |
---|
[dc613d6] | 1008 | self._manager.onFit(uid=self.uid) |
---|
[66ff250] | 1009 | self.btFit.SetLabel("Stop") |
---|
| 1010 | self.bind_fit_button() |
---|
[cfbd06a] | 1011 | |
---|
[f22e626] | 1012 | |
---|
[66ff250] | 1013 | def bind_fit_button(self): |
---|
| 1014 | """ |
---|
| 1015 | bind the fit button to either fit handler or stop fit handler |
---|
| 1016 | """ |
---|
[29bf83b] | 1017 | self.btFit.Unbind(event=wx.EVT_BUTTON, id= self.btFit.GetId()) |
---|
[66ff250] | 1018 | if self.btFit.GetLabel().lower() == "stop": |
---|
[f22e626] | 1019 | self.fit_started = True |
---|
[29bf83b] | 1020 | self.btFit.SetForegroundColour('red') |
---|
| 1021 | self.btFit.Bind(event=wx.EVT_BUTTON, handler=self._StopFit, |
---|
[66ff250] | 1022 | id=self.btFit.GetId()) |
---|
| 1023 | elif self.btFit.GetLabel().lower() == "fit": |
---|
[f22e626] | 1024 | self.fit_started = False |
---|
[e030625] | 1025 | self.btFit.SetDefault() |
---|
[29bf83b] | 1026 | self.btFit.SetForegroundColour('black') |
---|
[e030625] | 1027 | #self.btFit.SetBackgroundColour(self.default_bt_colour) |
---|
[29bf83b] | 1028 | self.btFit.Bind(event=wx.EVT_BUTTON, handler=self._onFit, |
---|
[66ff250] | 1029 | id=self.btFit.GetId()) |
---|
| 1030 | else: |
---|
| 1031 | msg = "FitPage: fit button has unknown label" |
---|
| 1032 | raise ValuerError, msg |
---|
| 1033 | self._manager._reset_schedule_problem(value=0) |
---|
| 1034 | |
---|
[f22e626] | 1035 | def is_fitting(self): |
---|
| 1036 | if self.fit_started: |
---|
| 1037 | self._StopFit(event=None) |
---|
| 1038 | |
---|
| 1039 | def _StopFit(self, event=None): |
---|
[ad6dd4c] | 1040 | """ |
---|
[5062bbf] | 1041 | Stop fit |
---|
[ad6dd4c] | 1042 | """ |
---|
[3ddc2c4] | 1043 | #time.sleep(0.1) |
---|
[5f2de0aa] | 1044 | if event != None: |
---|
| 1045 | event.Skip() |
---|
[66ff250] | 1046 | #if self.engine_type=="scipy": |
---|
| 1047 | self._manager.stop_fit(self.uid) |
---|
| 1048 | self._manager._reset_schedule_problem(value=0) |
---|
[db47703] | 1049 | self._on_fit_complete() |
---|
[66ff250] | 1050 | |
---|
[0b12abb5] | 1051 | def _on_select_model(self, event=None): |
---|
[c77d859] | 1052 | """ |
---|
[5062bbf] | 1053 | call back for model selection |
---|
[6747217] | 1054 | """ |
---|
[9466f2d6] | 1055 | |
---|
[9a22655] | 1056 | |
---|
[59a7f2d] | 1057 | self._on_select_model_helper() |
---|
[70c57ebf] | 1058 | self.set_model_param_sizer(self.model) |
---|
[982e953] | 1059 | if self.model is None: |
---|
| 1060 | self._set_bookmark_flag(False) |
---|
[2657df9] | 1061 | self._keep.Enable(False) |
---|
[982e953] | 1062 | self._set_save_flag(False) |
---|
[3b605bb] | 1063 | self.enable_disp.SetValue(False) |
---|
| 1064 | self.disable_disp.SetValue(True) |
---|
[4043c96] | 1065 | try: |
---|
| 1066 | self.set_dispers_sizer() |
---|
| 1067 | except: |
---|
| 1068 | pass |
---|
[53ae26d] | 1069 | #self.btFit.SetFocus() |
---|
[6747217] | 1070 | self.state.enable_disp = self.enable_disp.GetValue() |
---|
| 1071 | self.state.disable_disp = self.disable_disp.GetValue() |
---|
| 1072 | self.state.pinhole_smearer = self.pinhole_smearer.GetValue() |
---|
| 1073 | self.state.slit_smearer = self.slit_smearer.GetValue() |
---|
| 1074 | |
---|
| 1075 | self.state.structurecombobox = self.structurebox.GetCurrentSelection() |
---|
| 1076 | self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection() |
---|
| 1077 | |
---|
[9237df4] | 1078 | if self.model != None: |
---|
[1258aa3] | 1079 | if self.data != None: |
---|
| 1080 | self._set_bookmark_flag(True) |
---|
[2657df9] | 1081 | self._keep.Enable(True) |
---|
[f932c02] | 1082 | #self._set_save_flag(True) |
---|
[64bda1e] | 1083 | # Reset smearer, model and data |
---|
[6bbeacd4] | 1084 | self._set_smear(self.data) |
---|
[70c57ebf] | 1085 | try: |
---|
[6bbeacd4] | 1086 | # update smearer sizer |
---|
| 1087 | self.onSmear(None) |
---|
[64bda1e] | 1088 | temp_smear = None |
---|
[70c57ebf] | 1089 | if self.enable_smearer.GetValue(): |
---|
[64bda1e] | 1090 | # Set the smearer environments |
---|
[6bbeacd4] | 1091 | temp_smear = self.smearer |
---|
[70c57ebf] | 1092 | except: |
---|
[66ff250] | 1093 | raise |
---|
[70c57ebf] | 1094 | ## error occured on chisqr computation |
---|
[66ff250] | 1095 | #pass |
---|
[0b12abb5] | 1096 | ## event to post model to fit to fitting plugins |
---|
| 1097 | (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() |
---|
[d9638fd] | 1098 | |
---|
[6bbeacd4] | 1099 | ## set smearing value whether or not |
---|
| 1100 | # the data contain the smearing info |
---|
| 1101 | evt = ModelEventbox(model=self.model, |
---|
| 1102 | smearer=temp_smear, |
---|
| 1103 | qmin=float(self.qmin_x), |
---|
[66ff250] | 1104 | uid=self.uid, |
---|
[6bbeacd4] | 1105 | qmax=float(self.qmax_x)) |
---|
| 1106 | |
---|
| 1107 | self._manager._on_model_panel(evt=evt) |
---|
[88f286d] | 1108 | self.mbox_description.SetLabel("Model [%s]" % str(self.model.name)) |
---|
[0b12abb5] | 1109 | self.state.model = self.model.clone() |
---|
| 1110 | self.state.model.name = self.model.name |
---|
[88f286d] | 1111 | |
---|
[31f9c172] | 1112 | self._draw_model() |
---|
[6bbeacd4] | 1113 | if event != None: |
---|
[3595309d] | 1114 | ## post state to fit panel |
---|
[e030625] | 1115 | new_event = PageInfoEvent(page = self) |
---|
| 1116 | wx.PostEvent(self.parent, new_event) |
---|
[9466f2d6] | 1117 | #update list of plugins if new plugin is available |
---|
| 1118 | if self.plugin_rbutton.GetValue(): |
---|
| 1119 | temp = self.parent.update_model_list() |
---|
| 1120 | if temp: |
---|
| 1121 | self.model_list_box = temp |
---|
| 1122 | current_val = self.formfactorbox.GetValue() |
---|
| 1123 | pos = self.formfactorbox.GetSelection() |
---|
| 1124 | self._show_combox_helper() |
---|
| 1125 | self.formfactorbox.SetSelection(pos) |
---|
| 1126 | self.formfactorbox.SetValue(current_val) |
---|
[31f9c172] | 1127 | self._onDraw(event=None) |
---|
[ce92ded] | 1128 | self.SetupScrolling() |
---|
[9466f2d6] | 1129 | |
---|
[0b12abb5] | 1130 | |
---|
[dd5949d] | 1131 | def _onparamEnter(self,event): |
---|
| 1132 | """ |
---|
[5062bbf] | 1133 | when enter value on panel redraw model according to changed |
---|
[dd5949d] | 1134 | """ |
---|
[4470b10] | 1135 | if self.model ==None: |
---|
| 1136 | msg="Please select a Model first..." |
---|
| 1137 | wx.MessageBox(msg, 'Info') |
---|
[90a7bbd] | 1138 | #wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
[4470b10] | 1139 | # "Parameters: %s"%msg)) |
---|
| 1140 | return |
---|
| 1141 | |
---|
[51a71a3] | 1142 | #default flag |
---|
[7975f2b] | 1143 | flag = False |
---|
[51a71a3] | 1144 | self.fitrange = True |
---|
| 1145 | #get event object |
---|
[dce84c0] | 1146 | tcrtl = event.GetEventObject() |
---|
| 1147 | |
---|
[66ff250] | 1148 | #wx.PostEvent(self._manager.parent, StatusEvent(status=" \ |
---|
| 1149 | # updating ... ",type="update")) |
---|
[edd166b] | 1150 | #Clear msg if previously shown. |
---|
| 1151 | msg= "" |
---|
| 1152 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
[c99a6c5] | 1153 | |
---|
[7975f2b] | 1154 | if check_float(tcrtl): |
---|
[2012eae] | 1155 | flag = self._onparamEnter_helper() |
---|
| 1156 | self.set_npts2fit() |
---|
[51a71a3] | 1157 | if self.fitrange: |
---|
| 1158 | temp_smearer = None |
---|
| 1159 | if not self.disable_smearer.GetValue(): |
---|
| 1160 | temp_smearer= self.current_smearer |
---|
[d7b7156] | 1161 | ## set smearing value whether or not |
---|
| 1162 | # the data contain the smearing info |
---|
[51a71a3] | 1163 | if self.slit_smearer.GetValue(): |
---|
| 1164 | flag1 = self.update_slit_smear() |
---|
| 1165 | flag = flag or flag1 |
---|
| 1166 | elif self.pinhole_smearer.GetValue(): |
---|
| 1167 | flag1 = self.update_pinhole_smear() |
---|
| 1168 | flag = flag or flag1 |
---|
[ba1f0b2] | 1169 | elif self.data.__class__.__name__ != "Data2D" and \ |
---|
| 1170 | not self.enable2D: |
---|
[90a7bbd] | 1171 | self._manager.set_smearer(smearer=temp_smearer, |
---|
[ba1f0b2] | 1172 | enable2D=self.enable2D, |
---|
[66ff250] | 1173 | uid=self.uid, |
---|
[d7b7156] | 1174 | qmin= float(self.qmin_x), |
---|
[6bbeacd4] | 1175 | qmax= float(self.qmax_x), |
---|
| 1176 | draw=True) |
---|
[51a71a3] | 1177 | if flag: |
---|
[f72333f] | 1178 | #self.compute_chisqr(smearer= temp_smearer) |
---|
[51a71a3] | 1179 | |
---|
| 1180 | ## new state posted |
---|
| 1181 | if self.state_change: |
---|
| 1182 | #self._undo.Enable(True) |
---|
| 1183 | event = PageInfoEvent(page = self) |
---|
| 1184 | wx.PostEvent(self.parent, event) |
---|
| 1185 | self.state_change= False |
---|
| 1186 | else: |
---|
[d7b7156] | 1187 | # invalid fit range: do nothing here: |
---|
| 1188 | # msg already displayed in validate |
---|
| 1189 | return |
---|
[69bee6d] | 1190 | else: |
---|
[7975f2b] | 1191 | self.save_current_state() |
---|
[69bee6d] | 1192 | msg= "Cannot Plot :Must enter a number!!! " |
---|
| 1193 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
[7609f1a] | 1194 | |
---|
| 1195 | self.save_current_state() |
---|
| 1196 | return |
---|
| 1197 | |
---|
[e2f7b92] | 1198 | def _onparamRangeEnter(self, event): |
---|
[920a6e5] | 1199 | """ |
---|
[5062bbf] | 1200 | Check validity of value enter in the parameters range field |
---|
[920a6e5] | 1201 | """ |
---|
[6bbeacd4] | 1202 | #if self.check_invalid_panel(): |
---|
| 1203 | # return |
---|
[920a6e5] | 1204 | tcrtl= event.GetEventObject() |
---|
[edd166b] | 1205 | #Clear msg if previously shown. |
---|
| 1206 | msg= "" |
---|
| 1207 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1208 | # Flag to register when a parameter has changed. |
---|
| 1209 | is_modified = False |
---|
[920a6e5] | 1210 | if tcrtl.GetValue().lstrip().rstrip()!="": |
---|
| 1211 | try: |
---|
| 1212 | value = float(tcrtl.GetValue()) |
---|
| 1213 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
[edd166b] | 1214 | self._check_value_enter(self.fittable_param ,is_modified) |
---|
| 1215 | self._check_value_enter(self.parameters ,is_modified) |
---|
[920a6e5] | 1216 | except: |
---|
| 1217 | tcrtl.SetBackgroundColour("pink") |
---|
[edd166b] | 1218 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
| 1219 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1220 | return |
---|
[920a6e5] | 1221 | else: |
---|
| 1222 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
[e2f7b92] | 1223 | |
---|
[edd166b] | 1224 | #self._undo.Enable(True) |
---|
| 1225 | self.save_current_state() |
---|
| 1226 | event = PageInfoEvent(page = self) |
---|
| 1227 | wx.PostEvent(self.parent, event) |
---|
| 1228 | self.state_change= False |
---|
[c69b6d5] | 1229 | |
---|
[12eac73] | 1230 | |
---|
| 1231 | def _onQrangeEnter(self, event): |
---|
| 1232 | """ |
---|
[5062bbf] | 1233 | Check validity of value enter in the Q range field |
---|
[12eac73] | 1234 | """ |
---|
[6bbeacd4] | 1235 | #if self.check_invalid_panel(): |
---|
| 1236 | # return |
---|
[12eac73] | 1237 | tcrtl= event.GetEventObject() |
---|
| 1238 | #Clear msg if previously shown. |
---|
| 1239 | msg= "" |
---|
| 1240 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1241 | # Flag to register when a parameter has changed. |
---|
| 1242 | is_modified = False |
---|
| 1243 | if tcrtl.GetValue().lstrip().rstrip()!="": |
---|
| 1244 | try: |
---|
| 1245 | value = float(tcrtl.GetValue()) |
---|
| 1246 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
| 1247 | |
---|
| 1248 | # If qmin and qmax have been modified, update qmin and qmax |
---|
[f95301b] | 1249 | if self._validate_qrange( self.qmin, self.qmax): |
---|
| 1250 | tempmin = float(self.qmin.GetValue()) |
---|
[12eac73] | 1251 | if tempmin != self.qmin_x: |
---|
| 1252 | self.qmin_x = tempmin |
---|
| 1253 | tempmax = float(self.qmax.GetValue()) |
---|
| 1254 | if tempmax != self.qmax_x: |
---|
| 1255 | self.qmax_x = tempmax |
---|
| 1256 | else: |
---|
| 1257 | tcrtl.SetBackgroundColour("pink") |
---|
| 1258 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
| 1259 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1260 | return |
---|
| 1261 | |
---|
| 1262 | except: |
---|
| 1263 | tcrtl.SetBackgroundColour("pink") |
---|
| 1264 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
| 1265 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1266 | return |
---|
| 1267 | #Check if # of points for theory model are valid(>0). |
---|
[51a71a3] | 1268 | # check for 2d |
---|
[ba64348] | 1269 | if self.data is not None: |
---|
[ba1f0b2] | 1270 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 1271 | self.enable2D: |
---|
[ba64348] | 1272 | # set mask |
---|
| 1273 | radius= numpy.sqrt( self.data.qx_data*self.data.qx_data + |
---|
| 1274 | self.data.qy_data*self.data.qy_data ) |
---|
| 1275 | index_data = ((self.qmin_x <= radius)& \ |
---|
| 1276 | (radius<= self.qmax_x)) |
---|
| 1277 | index_data = (index_data)&(self.data.mask) |
---|
| 1278 | index_data = (index_data)&(numpy.isfinite(self.data.data)) |
---|
| 1279 | if len(index_data[index_data]) < 10: |
---|
| 1280 | msg = "Cannot Plot :No or too little npts in" |
---|
| 1281 | msg += " that data range!!! " |
---|
| 1282 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1283 | return |
---|
| 1284 | else: |
---|
| 1285 | self.data.mask = index_data |
---|
| 1286 | #self.Npts_fit.SetValue(str(len(self.data.mask))) |
---|
| 1287 | self.set_npts2fit() |
---|
[51a71a3] | 1288 | else: |
---|
[ba64348] | 1289 | index_data = ((self.qmin_x <= self.data.x)& \ |
---|
| 1290 | (self.data.x <= self.qmax_x)) |
---|
| 1291 | self.Npts_fit.SetValue(str(len(self.data.x[index_data]))) |
---|
[0cf97c5] | 1292 | else: |
---|
| 1293 | self.npts_x = self.Npts_total.GetValue() |
---|
| 1294 | self._save_plotting_range() |
---|
| 1295 | |
---|
[12eac73] | 1296 | else: |
---|
| 1297 | tcrtl.SetBackgroundColour("pink") |
---|
| 1298 | msg= "Model Error:wrong value entered!!!" |
---|
| 1299 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
| 1300 | |
---|
[f72333f] | 1301 | self._draw_model() |
---|
| 1302 | ##update chi2 |
---|
| 1303 | #self.compute_chisqr(smearer= temp_smearer) |
---|
[12eac73] | 1304 | #self._undo.Enable(True) |
---|
| 1305 | self.save_current_state() |
---|
| 1306 | event = PageInfoEvent(page = self) |
---|
| 1307 | wx.PostEvent(self.parent, event) |
---|
| 1308 | self.state_change= False |
---|
[51a71a3] | 1309 | return |
---|
[5062bbf] | 1310 | |
---|
[edd166b] | 1311 | def _clear_Err_on_Fit(self): |
---|
| 1312 | """ |
---|
[5062bbf] | 1313 | hide the error text control shown |
---|
| 1314 | after fitting |
---|
[edd166b] | 1315 | """ |
---|
[ce92ded] | 1316 | if self.is_mac: |
---|
| 1317 | return |
---|
[edd166b] | 1318 | if hasattr(self,"text2_3"): |
---|
| 1319 | self.text2_3.Hide() |
---|
| 1320 | |
---|
| 1321 | if len(self.parameters)>0: |
---|
| 1322 | for item in self.parameters: |
---|
| 1323 | #Skip t ifhe angle parameters if 1D data |
---|
[ba1f0b2] | 1324 | if self.data.__class__.__name__ != "Data2D" and \ |
---|
| 1325 | not self.enable2D: |
---|
[edd166b] | 1326 | if item in self.orientation_params: |
---|
| 1327 | continue |
---|
| 1328 | if item in self.param_toFit: |
---|
| 1329 | continue |
---|
| 1330 | ## hide statictext +/- |
---|
[1dd00f4] | 1331 | if len(item) < 4 : |
---|
| 1332 | continue |
---|
[edd166b] | 1333 | if item[3]!=None and item[3].IsShown(): |
---|
| 1334 | item[3].Hide() |
---|
| 1335 | ## hide textcrtl for error after fit |
---|
| 1336 | if item[4]!=None and item[4].IsShown(): |
---|
| 1337 | item[4].Hide() |
---|
[7975f2b] | 1338 | |
---|
[edd166b] | 1339 | if len(self.fittable_param)>0: |
---|
| 1340 | for item in self.fittable_param: |
---|
| 1341 | #Skip t ifhe angle parameters if 1D data |
---|
[ba1f0b2] | 1342 | if self.data.__class__.__name__ != "Data2D" and \ |
---|
| 1343 | not self.enable2D: |
---|
[edd166b] | 1344 | if item in self.orientation_params: |
---|
| 1345 | continue |
---|
| 1346 | if item in self.param_toFit: |
---|
| 1347 | continue |
---|
[1dd00f4] | 1348 | if len(item) < 4 : |
---|
| 1349 | continue |
---|
[edd166b] | 1350 | ## hide statictext +/- |
---|
| 1351 | if item[3]!=None and item[3].IsShown(): |
---|
| 1352 | item[3].Hide() |
---|
| 1353 | ## hide textcrtl for error after fit |
---|
| 1354 | if item[4]!=None and item[4].IsShown(): |
---|
| 1355 | item[4].Hide() |
---|
| 1356 | return |
---|
[920a6e5] | 1357 | |
---|
[7609f1a] | 1358 | def _get_defult_custom_smear(self): |
---|
| 1359 | """ |
---|
[5062bbf] | 1360 | Get the defult values for custum smearing. |
---|
[7609f1a] | 1361 | """ |
---|
| 1362 | # get the default values |
---|
| 1363 | if self.dxl == None: self.dxl = 0.0 |
---|
| 1364 | if self.dxw == None: self.dxw = "" |
---|
| 1365 | if self.dx_min == None: self.dx_min = SMEAR_SIZE_L |
---|
| 1366 | if self.dx_max == None: self.dx_max = SMEAR_SIZE_H |
---|
| 1367 | |
---|
| 1368 | def _get_smear_info(self): |
---|
| 1369 | """ |
---|
[5062bbf] | 1370 | Get the smear info from data. |
---|
| 1371 | |
---|
| 1372 | :return: self.smear_type, self.dq_l and self.dq_r, |
---|
[d7b7156] | 1373 | respectively the type of the smear, dq_min and |
---|
| 1374 | dq_max for pinhole smear data |
---|
[7609f1a] | 1375 | while dxl and dxw for slit smear |
---|
[5062bbf] | 1376 | |
---|
[7609f1a] | 1377 | """ |
---|
| 1378 | |
---|
| 1379 | # default |
---|
| 1380 | self.smear_type = None |
---|
| 1381 | self.dq_l = None |
---|
| 1382 | self.dq_r = None |
---|
[f72333f] | 1383 | data = self.data |
---|
| 1384 | if self.data is None: |
---|
[7609f1a] | 1385 | return |
---|
[ba1f0b2] | 1386 | elif self.data.__class__.__name__ == "Data2D" or \ |
---|
| 1387 | self.enable2D: |
---|
[f72333f] | 1388 | if data.dqx_data == None or data.dqy_data ==None: |
---|
| 1389 | return |
---|
[d7b7156] | 1390 | elif self.smearer != None and (data.dqx_data.any()!=0) and \ |
---|
| 1391 | (data.dqx_data.any()!=0): |
---|
[f72333f] | 1392 | self.smear_type = "Pinhole2d" |
---|
| 1393 | self.dq_l = format_number(numpy.average(data.dqx_data)) |
---|
| 1394 | self.dq_r = format_number(numpy.average(data.dqy_data)) |
---|
| 1395 | return |
---|
| 1396 | else: |
---|
| 1397 | return |
---|
[7609f1a] | 1398 | # check if it is pinhole smear and get min max if it is. |
---|
| 1399 | if data.dx != None and all(data.dx !=0): |
---|
| 1400 | self.smear_type = "Pinhole" |
---|
[f72333f] | 1401 | self.dq_l = data.dx[0] |
---|
| 1402 | self.dq_r = data.dx[-1] |
---|
[7609f1a] | 1403 | |
---|
| 1404 | # check if it is slit smear and get min max if it is. |
---|
| 1405 | elif data.dxl != None or data.dxw != None: |
---|
| 1406 | self.smear_type = "Slit" |
---|
| 1407 | if data.dxl != None and all(data.dxl !=0): |
---|
| 1408 | self.dq_l = data.dxl[0] |
---|
| 1409 | if data.dxw != None and all(data.dxw !=0): |
---|
[5062bbf] | 1410 | self.dq_r = data.dxw[0] |
---|
[7609f1a] | 1411 | #return self.smear_type,self.dq_l,self.dq_r |
---|
| 1412 | |
---|
| 1413 | def _show_smear_sizer(self): |
---|
| 1414 | """ |
---|
[5062bbf] | 1415 | Show only the sizers depending on smear selection |
---|
[7609f1a] | 1416 | """ |
---|
[f72333f] | 1417 | # smear disabled |
---|
[7609f1a] | 1418 | if self.disable_smearer.GetValue(): |
---|
| 1419 | self.smear_description_none.Show(True) |
---|
[f72333f] | 1420 | # 2Dsmear |
---|
| 1421 | elif self._is_2D(): |
---|
| 1422 | self.smear_description_accuracy_type.Show(True) |
---|
| 1423 | self.smear_accuracy.Show(True) |
---|
| 1424 | self.smear_description_accuracy_type.Show(True) |
---|
| 1425 | self.smear_description_2d.Show(True) |
---|
| 1426 | self.smear_description_2d_x.Show(True) |
---|
| 1427 | self.smear_description_2d_y.Show(True) |
---|
| 1428 | if self.pinhole_smearer.GetValue(): |
---|
| 1429 | self.smear_pinhole_min.Show(True) |
---|
| 1430 | self.smear_pinhole_max.Show(True) |
---|
| 1431 | # smear from data |
---|
[7609f1a] | 1432 | elif self.enable_smearer.GetValue(): |
---|
[f72333f] | 1433 | |
---|
[7609f1a] | 1434 | self.smear_description_dqdata.Show(True) |
---|
| 1435 | if self.smear_type != None: |
---|
| 1436 | self.smear_description_smear_type.Show(True) |
---|
| 1437 | if self.smear_type == 'Slit': |
---|
| 1438 | self.smear_description_slit_height.Show(True) |
---|
[f72333f] | 1439 | self.smear_description_slit_width.Show(True) |
---|
[7609f1a] | 1440 | elif self.smear_type == 'Pinhole': |
---|
| 1441 | self.smear_description_pin_min.Show(True) |
---|
| 1442 | self.smear_description_pin_max.Show(True) |
---|
[f72333f] | 1443 | self.smear_description_smear_type.Show(True) |
---|
| 1444 | self.smear_description_type.Show(True) |
---|
[7609f1a] | 1445 | self.smear_data_left.Show(True) |
---|
| 1446 | self.smear_data_right.Show(True) |
---|
[f72333f] | 1447 | # custom pinhole smear |
---|
[7609f1a] | 1448 | elif self.pinhole_smearer.GetValue(): |
---|
[f72333f] | 1449 | if self.smear_type == 'Pinhole': |
---|
| 1450 | self.smear_message_new_p.Show(True) |
---|
| 1451 | self.smear_description_pin_min.Show(True) |
---|
| 1452 | self.smear_description_pin_max.Show(True) |
---|
| 1453 | |
---|
[7609f1a] | 1454 | self.smear_pinhole_min.Show(True) |
---|
| 1455 | self.smear_pinhole_max.Show(True) |
---|
[f72333f] | 1456 | # custom slit smear |
---|
[7609f1a] | 1457 | elif self.slit_smearer.GetValue(): |
---|
| 1458 | self.smear_message_new_s.Show(True) |
---|
| 1459 | self.smear_description_slit_height.Show(True) |
---|
| 1460 | self.smear_slit_height.Show(True) |
---|
| 1461 | self.smear_description_slit_width.Show(True) |
---|
| 1462 | self.smear_slit_width.Show(True) |
---|
| 1463 | |
---|
| 1464 | def _hide_all_smear_info(self): |
---|
| 1465 | """ |
---|
[5062bbf] | 1466 | Hide all smearing messages in the set_smearer sizer |
---|
[7609f1a] | 1467 | """ |
---|
| 1468 | self.smear_description_none.Hide() |
---|
| 1469 | self.smear_description_dqdata.Hide() |
---|
| 1470 | self.smear_description_type.Hide() |
---|
| 1471 | self.smear_description_smear_type.Hide() |
---|
[f72333f] | 1472 | self.smear_description_accuracy_type.Hide() |
---|
| 1473 | self.smear_description_2d_x.Hide() |
---|
| 1474 | self.smear_description_2d_y.Hide() |
---|
[7609f1a] | 1475 | self.smear_description_2d.Hide() |
---|
[f72333f] | 1476 | |
---|
| 1477 | self.smear_accuracy.Hide() |
---|
[7609f1a] | 1478 | self.smear_data_left.Hide() |
---|
| 1479 | self.smear_data_right.Hide() |
---|
| 1480 | self.smear_description_pin_min.Hide() |
---|
| 1481 | self.smear_pinhole_min.Hide() |
---|
| 1482 | self.smear_description_pin_max.Hide() |
---|
| 1483 | self.smear_pinhole_max.Hide() |
---|
| 1484 | self.smear_description_slit_height.Hide() |
---|
| 1485 | self.smear_slit_height.Hide() |
---|
| 1486 | self.smear_description_slit_width.Hide() |
---|
| 1487 | self.smear_slit_width.Hide() |
---|
| 1488 | self.smear_message_new_p.Hide() |
---|
| 1489 | self.smear_message_new_s.Hide() |
---|
| 1490 | |
---|
[f72333f] | 1491 | def _set_accuracy_list(self): |
---|
| 1492 | """ |
---|
[5062bbf] | 1493 | Set the list of an accuracy in 2D custum smear: Xhigh, High, Med, or Low |
---|
[f72333f] | 1494 | """ |
---|
| 1495 | # list of accuracy choices |
---|
| 1496 | list = ['Low','Med','High','Xhigh'] |
---|
| 1497 | for idx in range(len(list)): |
---|
| 1498 | self.smear_accuracy.Append(list[idx],idx) |
---|
| 1499 | |
---|
[fb59ed9] | 1500 | def _set_fun_box_list(self,fun_box): |
---|
| 1501 | """ |
---|
| 1502 | Set the list of func for multifunctional models |
---|
| 1503 | """ |
---|
| 1504 | # Check if it is multi_functional model |
---|
[8960479] | 1505 | if self.model.__class__ not in self.model_list_box["Multi-Functions"] \ |
---|
| 1506 | and not self.temp_multi_functional: |
---|
[fb59ed9] | 1507 | return None |
---|
| 1508 | # Get the func name list |
---|
| 1509 | list = self.model.fun_list |
---|
| 1510 | if len(list) == 0: |
---|
| 1511 | return None |
---|
| 1512 | # build function (combo)box |
---|
| 1513 | ind = 0 |
---|
| 1514 | while(ind < len(list)): |
---|
| 1515 | for key, val in list.iteritems(): |
---|
| 1516 | if (val == ind): |
---|
| 1517 | fun_box.Append(key,val) |
---|
| 1518 | break |
---|
| 1519 | ind += 1 |
---|
| 1520 | |
---|
[f72333f] | 1521 | def _on_select_accuracy(self,event): |
---|
| 1522 | """ |
---|
[5062bbf] | 1523 | Select an accuracy in 2D custom smear: Xhigh, High, Med, or Low |
---|
[f72333f] | 1524 | """ |
---|
| 1525 | #event.Skip() |
---|
[4fbc93e] | 1526 | # Check if the accuracy is same as before |
---|
| 1527 | #self.smear2d_accuracy = event.GetEventObject().GetValue() |
---|
| 1528 | self.smear2d_accuracy = self.smear_accuracy.GetValue() |
---|
[f72333f] | 1529 | if self.pinhole_smearer.GetValue(): |
---|
| 1530 | self.onPinholeSmear(event=None) |
---|
[4fbc93e] | 1531 | else: |
---|
| 1532 | self.onSmear(event=None) |
---|
| 1533 | if self.current_smearer != None: |
---|
[d7b7156] | 1534 | self.current_smearer.set_accuracy(accuracy = |
---|
| 1535 | self.smear2d_accuracy) |
---|
[f72333f] | 1536 | event.Skip() |
---|
[fb59ed9] | 1537 | |
---|
| 1538 | def _on_fun_box(self,event): |
---|
| 1539 | """ |
---|
| 1540 | Select an func: Erf,Rparabola,LParabola |
---|
| 1541 | """ |
---|
| 1542 | fun_val = None |
---|
| 1543 | fun_box = event.GetEventObject() |
---|
| 1544 | name = fun_box.Name |
---|
| 1545 | value = fun_box.GetValue() |
---|
| 1546 | if self.model.fun_list.has_key(value): |
---|
| 1547 | fun_val = self.model.fun_list[value] |
---|
| 1548 | |
---|
| 1549 | self.model.setParam(name,fun_val) |
---|
| 1550 | # save state |
---|
[d7b7156] | 1551 | self._copy_parameters_state(self.str_parameters, |
---|
| 1552 | self.state.str_parameters) |
---|
[fb59ed9] | 1553 | # update params |
---|
| 1554 | self._update_paramv_on_fit() |
---|
| 1555 | # draw |
---|
| 1556 | self._draw_model() |
---|
| 1557 | self.Refresh() |
---|
| 1558 | # get ready for new event |
---|
| 1559 | event.Skip() |
---|
[4fbc93e] | 1560 | |
---|
[51a71a3] | 1561 | def _onMask(self, event): |
---|
| 1562 | """ |
---|
[5062bbf] | 1563 | Build a panel to allow to edit Mask |
---|
[51a71a3] | 1564 | """ |
---|
| 1565 | |
---|
[d7b7156] | 1566 | from sans.guiframe.local_perspectives.plotting.masking \ |
---|
| 1567 | import MaskPanel as MaskDialog |
---|
[51a71a3] | 1568 | |
---|
[8c21d53] | 1569 | self.panel = MaskDialog(base=self, data=self.data,id =-1 ) |
---|
[b9d68ff] | 1570 | #self.panel.Bind(wx.EVT_CLOSE, self._draw_masked_model) |
---|
[51a71a3] | 1571 | self.panel.ShowModal() |
---|
| 1572 | #wx.PostEvent(self.parent, event) |
---|
| 1573 | |
---|
[6d03e00] | 1574 | def _draw_masked_model(self): |
---|
[f72333f] | 1575 | """ |
---|
| 1576 | Draw model image w/mask |
---|
| 1577 | """ |
---|
[8ce1ad1] | 1578 | self.parent.Enable(True) |
---|
[48bab15] | 1579 | #event.Skip() |
---|
[51a71a3] | 1580 | is_valid_qrange = self._update_paramv_on_fit() |
---|
[247cb58] | 1581 | |
---|
[6d03e00] | 1582 | if is_valid_qrange and self.model != None: |
---|
[247cb58] | 1583 | # try re draw the model plot if it exists |
---|
[51a71a3] | 1584 | self._draw_model() |
---|
[8c21d53] | 1585 | #self.panel.OnClose(event)#Destroy() # frame |
---|
[51a71a3] | 1586 | self.set_npts2fit() |
---|
[247cb58] | 1587 | elif self.model == None: |
---|
[8c21d53] | 1588 | #self.panel.OnClose(event)#Destroy() |
---|
[247cb58] | 1589 | self.set_npts2fit() |
---|
| 1590 | msg= "No model is found on updating MASK in the model plot... " |
---|
| 1591 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
[51a71a3] | 1592 | else: |
---|
[247cb58] | 1593 | msg = ' Please consider your Q range, too.' |
---|
[51a71a3] | 1594 | self.panel.ShowMessage(msg) |
---|
[48bab15] | 1595 | |
---|
[882a912] | 1596 | |
---|
[6bbeacd4] | 1597 | def _set_smear(self, data): |
---|
| 1598 | """ |
---|
| 1599 | """ |
---|
| 1600 | if data is None: |
---|
| 1601 | return |
---|
[ba1f0b2] | 1602 | self.smearer = smear_selection(data, self.model) |
---|
[6bbeacd4] | 1603 | self.disable_smearer.SetValue(True) |
---|
| 1604 | if self.smearer == None: |
---|
| 1605 | self.enable_smearer.Disable() |
---|
| 1606 | else: |
---|
| 1607 | self.enable_smearer.Enable() |
---|
[f6aee42] | 1608 | |
---|
| 1609 | def _mac_sleep(self, sec=0.2): |
---|
| 1610 | """ |
---|
| 1611 | Give sleep to MAC |
---|
| 1612 | """ |
---|
| 1613 | if self.is_mac: |
---|
| 1614 | time.sleep(sec) |
---|
| 1615 | |
---|
[a5701e6] | 1616 | def get_view_mode(self): |
---|
| 1617 | """ |
---|
| 1618 | return True if the panel allow 2D or False if 1D |
---|
| 1619 | """ |
---|
| 1620 | return self.enable2D |
---|
| 1621 | |
---|
[9237df4] | 1622 | def set_data(self, data): |
---|
[882a912] | 1623 | """ |
---|
[5062bbf] | 1624 | reset the current data |
---|
[882a912] | 1625 | """ |
---|
[6bbeacd4] | 1626 | flag = False |
---|
| 1627 | if self.data is None and data is not None: |
---|
| 1628 | self.window_name = str(data.name) |
---|
| 1629 | ## Title to appear on top of the window |
---|
| 1630 | self.window_caption = str(data.name) |
---|
| 1631 | flag = True |
---|
[9237df4] | 1632 | self.data = data |
---|
| 1633 | if self.data is None: |
---|
| 1634 | data_min = "" |
---|
| 1635 | data_max = "" |
---|
| 1636 | data_name = "" |
---|
[982e953] | 1637 | self._set_bookmark_flag(False) |
---|
[2657df9] | 1638 | self._keep.Enable(False) |
---|
[982e953] | 1639 | self._set_save_flag(False) |
---|
[9237df4] | 1640 | else: |
---|
[1258aa3] | 1641 | if self.model != None: |
---|
| 1642 | self._set_bookmark_flag(True) |
---|
[2657df9] | 1643 | self._keep.Enable(True) |
---|
[982e953] | 1644 | self._set_save_flag(True) |
---|
[aad74b3] | 1645 | self._set_preview_flag(True) |
---|
[ba1f0b2] | 1646 | |
---|
[6bbeacd4] | 1647 | self._set_smear(data) |
---|
[7609f1a] | 1648 | # more disables for 2D |
---|
[ba1f0b2] | 1649 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 1650 | self.enable2D: |
---|
[7609f1a] | 1651 | self.slit_smearer.Disable() |
---|
[ba1f0b2] | 1652 | self.pinhole_smearer.Enable(True) |
---|
[51a71a3] | 1653 | self.default_mask = copy.deepcopy(self.data.mask) |
---|
[0f8f831] | 1654 | else: |
---|
| 1655 | self.slit_smearer.Enable(True) |
---|
| 1656 | self.pinhole_smearer.Enable(True) |
---|
[e2f0554] | 1657 | |
---|
[ffa69b6] | 1658 | self.formfactorbox.Enable() |
---|
| 1659 | self.structurebox.Enable() |
---|
[9237df4] | 1660 | data_name = self.data.name |
---|
| 1661 | #set maximum range for x in linear scale |
---|
| 1662 | if not hasattr(self.data,"data"): #Display only for 1D data fit |
---|
| 1663 | # Minimum value of data |
---|
| 1664 | data_min = min(self.data.x) |
---|
| 1665 | # Maximum value of data |
---|
| 1666 | data_max = max(self.data.x) |
---|
[51a71a3] | 1667 | #number of total data points |
---|
| 1668 | self.Npts_total.SetValue(str(len(self.data.x))) |
---|
| 1669 | #default:number of data points selected to fit |
---|
| 1670 | self.Npts_fit.SetValue(str(len(self.data.x))) |
---|
[19403da] | 1671 | self.btEditMask.Disable() |
---|
| 1672 | self.EditMask_title.Disable() |
---|
[9237df4] | 1673 | else: |
---|
[e2f0554] | 1674 | |
---|
[9237df4] | 1675 | ## Minimum value of data |
---|
| 1676 | data_min = 0 |
---|
| 1677 | x = max(math.fabs(self.data.xmin), math.fabs(self.data.xmax)) |
---|
| 1678 | y = max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) |
---|
| 1679 | ## Maximum value of data |
---|
| 1680 | data_max = math.sqrt(x*x + y*y) |
---|
[51a71a3] | 1681 | #number of total data points |
---|
| 1682 | self.Npts_total.SetValue(str(len(self.data.data))) |
---|
| 1683 | #default:number of data points selected to fit |
---|
| 1684 | self.Npts_fit.SetValue(str(len(self.data.data))) |
---|
[19403da] | 1685 | self.btEditMask.Enable() |
---|
| 1686 | self.EditMask_title.Enable() |
---|
[e9875db] | 1687 | self.Npts_total.SetEditable(False) |
---|
| 1688 | self.Npts_total.SetBackgroundColour(\ |
---|
| 1689 | self.GetParent().GetBackgroundColour()) |
---|
| 1690 | |
---|
| 1691 | self.Npts_total.Bind(wx.EVT_MOUSE_EVENTS, self._npts_click) |
---|
| 1692 | #self.Npts_total.Disable() |
---|
[9237df4] | 1693 | self.dataSource.SetValue(data_name) |
---|
| 1694 | self.qmin_x = data_min |
---|
| 1695 | self.qmax_x = data_max |
---|
[4efefc6] | 1696 | #self.minimum_q.SetValue(str(data_min)) |
---|
| 1697 | #self.maximum_q.SetValue(str(data_max)) |
---|
[f95301b] | 1698 | self.qmin.SetValue(str(data_min)) |
---|
[ffa69b6] | 1699 | self.qmax.SetValue(str(data_max)) |
---|
[f95301b] | 1700 | self.qmin.SetBackgroundColour("white") |
---|
[ffa69b6] | 1701 | self.qmax.SetBackgroundColour("white") |
---|
| 1702 | self.state.data = data |
---|
| 1703 | self.state.qmin = self.qmin_x |
---|
| 1704 | self.state.qmax = self.qmax_x |
---|
[e2f0554] | 1705 | |
---|
[6bbeacd4] | 1706 | #update model plot with new data information |
---|
| 1707 | if flag: |
---|
[e2f0554] | 1708 | #set model view button |
---|
| 1709 | if self.data.__class__.__name__ == "Data2D": |
---|
| 1710 | self.enable2D = True |
---|
| 1711 | self.model_view.SetLabel("2D Mode") |
---|
| 1712 | else: |
---|
| 1713 | self.enable2D = False |
---|
| 1714 | self.model_view.SetLabel("1D Mode") |
---|
[fa65e99] | 1715 | |
---|
[e2f0554] | 1716 | self.model_view.Disable() |
---|
[6bbeacd4] | 1717 | self._draw_model() |
---|
[e9875db] | 1718 | |
---|
| 1719 | def _npts_click(self, event): |
---|
| 1720 | """ |
---|
| 1721 | Prevent further handling of the mouse event on Npts_total |
---|
| 1722 | by not calling Skip(). |
---|
| 1723 | """ |
---|
| 1724 | pass |
---|
| 1725 | |
---|
[240b9966] | 1726 | def reset_page(self, state,first=False): |
---|
[a074145] | 1727 | """ |
---|
[5062bbf] | 1728 | reset the state |
---|
[a074145] | 1729 | """ |
---|
| 1730 | self.reset_page_helper(state) |
---|
[0b12abb5] | 1731 | #import sans.guiframe.gui_manager |
---|
| 1732 | #evt = ModelEventbox(model=state.model) |
---|
| 1733 | #wx.PostEvent(self.event_owner, evt) |
---|
[edd166b] | 1734 | |
---|
| 1735 | if self.engine_type != None: |
---|
[90a7bbd] | 1736 | self._manager._on_change_engine(engine=self.engine_type) |
---|
[7975f2b] | 1737 | |
---|
[edd166b] | 1738 | self.select_param(event = None) |
---|
| 1739 | #Save state_fit |
---|
[c985bef] | 1740 | self.save_current_state_fit() |
---|
[7975f2b] | 1741 | self._lay_out() |
---|
[c985bef] | 1742 | self.Refresh() |
---|
[edd166b] | 1743 | |
---|
[2140e68] | 1744 | def get_range(self): |
---|
| 1745 | """ |
---|
[5062bbf] | 1746 | return the fitting range |
---|
[2140e68] | 1747 | """ |
---|
[c9a4377] | 1748 | return float(self.qmin_x) , float(self.qmax_x) |
---|
[7975f2b] | 1749 | |
---|
| 1750 | def get_npts2fit(self): |
---|
| 1751 | """ |
---|
[5062bbf] | 1752 | return numbers of data points within qrange |
---|
| 1753 | |
---|
| 1754 | :Note: This is for Park where chi2 is not normalized by Npts of fit |
---|
| 1755 | |
---|
[7975f2b] | 1756 | """ |
---|
[6bbeacd4] | 1757 | if self.data is None: |
---|
| 1758 | return |
---|
[7975f2b] | 1759 | npts2fit = 0 |
---|
| 1760 | qmin,qmax = self.get_range() |
---|
[ba1f0b2] | 1761 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 1762 | self.enable2D: |
---|
[d7b7156] | 1763 | radius= numpy.sqrt( self.data.qx_data*self.data.qx_data + |
---|
| 1764 | self.data.qy_data*self.data.qy_data ) |
---|
[51a71a3] | 1765 | index_data = (self.qmin_x <= radius)&(radius<= self.qmax_x) |
---|
| 1766 | index_data= (index_data)&(self.data.mask) |
---|
| 1767 | index_data = (index_data)&(numpy.isfinite(self.data.data)) |
---|
| 1768 | npts2fit = len(self.data.data[index_data]) |
---|
[7975f2b] | 1769 | else: |
---|
| 1770 | for qx in self.data.x: |
---|
| 1771 | if qx >= qmin and qx <= qmax: |
---|
| 1772 | npts2fit += 1 |
---|
| 1773 | return npts2fit |
---|
| 1774 | |
---|
[51a71a3] | 1775 | def set_npts2fit(self): |
---|
| 1776 | """ |
---|
[5062bbf] | 1777 | setValue Npts for fitting |
---|
[51a71a3] | 1778 | """ |
---|
| 1779 | self.Npts_fit.SetValue(str(self.get_npts2fit())) |
---|
| 1780 | |
---|
[c69b6d5] | 1781 | def get_chi2(self): |
---|
| 1782 | """ |
---|
[5062bbf] | 1783 | return the current chi2 |
---|
[c69b6d5] | 1784 | """ |
---|
[2012eae] | 1785 | return self.tcChi.GetValue() |
---|
[c77d859] | 1786 | |
---|
| 1787 | def get_param_list(self): |
---|
| 1788 | """ |
---|
[5062bbf] | 1789 | :return self.param_toFit: list containing references to TextCtrl |
---|
[c77d859] | 1790 | checked.Theses TextCtrl will allow reference to parameters to fit. |
---|
[5062bbf] | 1791 | |
---|
| 1792 | :raise: if return an empty list of parameter fit will nnote work |
---|
[c77d859] | 1793 | properly so raise ValueError,"missing parameter to fit" |
---|
| 1794 | """ |
---|
| 1795 | if self.param_toFit !=[]: |
---|
| 1796 | return self.param_toFit |
---|
| 1797 | else: |
---|
[ba1f0b2] | 1798 | msg = "missing parameters to fit" |
---|
| 1799 | wx.MessageBox(msg, 'warning') |
---|
| 1800 | return False |
---|
| 1801 | #raise ValueError,"missing parameters to fit" |
---|
[c77d859] | 1802 | |
---|
[2296316] | 1803 | def onsetValues(self, chisqr, p_name, out, cov): |
---|
[c77d859] | 1804 | """ |
---|
[5062bbf] | 1805 | Build the panel from the fit result |
---|
| 1806 | |
---|
| 1807 | :param chisqr: Value of the goodness of fit metric |
---|
| 1808 | :param p_name: the name of parameters |
---|
| 1809 | :param out: list of parameter with the best value found during fitting |
---|
| 1810 | :param cov: Covariance matrix |
---|
| 1811 | |
---|
[c77d859] | 1812 | """ |
---|
[edd166b] | 1813 | if out == None or not numpy.isfinite(chisqr): |
---|
| 1814 | raise ValueError,"Fit error occured..." |
---|
| 1815 | |
---|
| 1816 | is_modified = False |
---|
[bd0a098e] | 1817 | has_error = False |
---|
| 1818 | dispersity = '' |
---|
[7975f2b] | 1819 | |
---|
| 1820 | #Hide textctrl boxes of errors. |
---|
[edd166b] | 1821 | self._clear_Err_on_Fit() |
---|
[7975f2b] | 1822 | |
---|
| 1823 | #Check if chi2 is finite |
---|
[2296316] | 1824 | if chisqr != None and numpy.isfinite(chisqr): |
---|
[e575db9] | 1825 | #format chi2 |
---|
[7609f1a] | 1826 | if self.engine_type == "park": |
---|
[e575db9] | 1827 | npt_fit = float(self.get_npts2fit()) |
---|
[7609f1a] | 1828 | if npt_fit > 0: |
---|
| 1829 | chisqr =chisqr/npt_fit |
---|
[2296316] | 1830 | chi2 = format_number(chisqr, True) |
---|
[2012eae] | 1831 | self.tcChi.SetValue(chi2) |
---|
[7975f2b] | 1832 | self.tcChi.Refresh() |
---|
| 1833 | else: |
---|
[2012eae] | 1834 | self.tcChi.SetValue("-") |
---|
[c13b8cc] | 1835 | |
---|
[edd166b] | 1836 | #Hide error title |
---|
[ce92ded] | 1837 | if self.text2_3.IsShown() and not self.is_mac: |
---|
| 1838 | self.text2_3.Hide() |
---|
[edd166b] | 1839 | |
---|
[e473e4f5] | 1840 | try: |
---|
[2296316] | 1841 | if self.enable_disp.GetValue(): |
---|
| 1842 | if hasattr(self,"text_disp_1" ): |
---|
[ce92ded] | 1843 | if self.text_disp_1 != None and not self.is_mac: |
---|
[2296316] | 1844 | self.text_disp_1.Hide() |
---|
[e473e4f5] | 1845 | except: |
---|
[bd0a098e] | 1846 | dispersity = None |
---|
[e473e4f5] | 1847 | pass |
---|
[c77d859] | 1848 | #set the panel when fit result are float not list |
---|
[c99a6c5] | 1849 | if out.__class__== numpy.float64: |
---|
[2296316] | 1850 | self.param_toFit[0][2].SetValue(format_number(out, True)) |
---|
[0a518e4c] | 1851 | |
---|
[ce92ded] | 1852 | if self.param_toFit[0][4].IsShown and not self.is_mac: |
---|
[c69b6d5] | 1853 | self.param_toFit[0][4].Hide() |
---|
[c77d859] | 1854 | if cov !=None : |
---|
| 1855 | self.text2_3.Show(True) |
---|
[e473e4f5] | 1856 | try: |
---|
[2296316] | 1857 | if self.enable_disp.GetValue(): |
---|
| 1858 | if hasattr(self,"text_disp_1" ): |
---|
| 1859 | if self.text_disp_1 !=None: |
---|
| 1860 | self.text_disp_1.Show(True) |
---|
[e473e4f5] | 1861 | except: |
---|
| 1862 | pass |
---|
[c99a6c5] | 1863 | |
---|
[ad6dd4c] | 1864 | if cov[0]==None or not numpy.isfinite(cov[0]): |
---|
[ce92ded] | 1865 | if self.param_toFit[0][3].IsShown and not self.is_mac: |
---|
[c69b6d5] | 1866 | self.param_toFit[0][3].Hide() |
---|
[7975f2b] | 1867 | else: |
---|
| 1868 | self.param_toFit[0][3].Show(True) |
---|
[69bee6d] | 1869 | self.param_toFit[0][4].Show(True) |
---|
[2296316] | 1870 | self.param_toFit[0][4].SetValue(format_number(cov[0], True)) |
---|
[ffb838f] | 1871 | has_error = True |
---|
[c77d859] | 1872 | else: |
---|
[edd166b] | 1873 | |
---|
[c69b6d5] | 1874 | i = 0 |
---|
[c77d859] | 1875 | #Set the panel when fit result are list |
---|
[ce92ded] | 1876 | for item in self.param_toFit: |
---|
[f56bf29] | 1877 | if len(item)>5 and item != None: |
---|
[edd166b] | 1878 | ## reset error value to initial state |
---|
[f56bf29] | 1879 | if not self.is_mac: |
---|
| 1880 | item[3].Hide() |
---|
| 1881 | item[4].Hide() |
---|
[d3fe885] | 1882 | |
---|
[edd166b] | 1883 | for ind in range(len(out)): |
---|
| 1884 | |
---|
[ce92ded] | 1885 | if item[1] == p_name[ind]: |
---|
[edd166b] | 1886 | break |
---|
[7975f2b] | 1887 | if len(out)<=len(self.param_toFit) and out[ind] !=None: |
---|
[ce92ded] | 1888 | val_out = format_number(out[ind], True) |
---|
| 1889 | item[2].SetValue(val_out) |
---|
[c4d723b] | 1890 | |
---|
[c99a6c5] | 1891 | |
---|
[7975f2b] | 1892 | if(cov !=None): |
---|
[edd166b] | 1893 | |
---|
| 1894 | try: |
---|
[7975f2b] | 1895 | if dispersity !=None: |
---|
[2296316] | 1896 | if self.enable_disp.GetValue(): |
---|
[7975f2b] | 1897 | if hasattr(self,"text_disp_1" ): |
---|
| 1898 | if self.text_disp_1!=None: |
---|
[ce92ded] | 1899 | if not self.text_disp_1.IsShown()\ |
---|
| 1900 | and not self.is_mac: |
---|
[7975f2b] | 1901 | self.text_disp_1.Show(True) |
---|
[edd166b] | 1902 | except: |
---|
| 1903 | pass |
---|
| 1904 | |
---|
[7975f2b] | 1905 | if cov[ind]!=None : |
---|
| 1906 | if numpy.isfinite(float(cov[ind])): |
---|
[2296316] | 1907 | val_err = format_number(cov[ind], True) |
---|
[ce92ded] | 1908 | if not self.is_mac: |
---|
| 1909 | item[3].Show(True) |
---|
| 1910 | item[4].Show(True) |
---|
| 1911 | item[4].SetValue(val_err) |
---|
[c4d723b] | 1912 | |
---|
[7975f2b] | 1913 | has_error = True |
---|
[e575db9] | 1914 | i += 1 |
---|
[c99a6c5] | 1915 | #Show error title when any errors displayed |
---|
[b421b1a] | 1916 | if has_error: |
---|
[c99a6c5] | 1917 | if not self.text2_3.IsShown(): |
---|
[86ab3f2] | 1918 | self.text2_3.Show(True) |
---|
[7975f2b] | 1919 | ## save current state |
---|
| 1920 | self.save_current_state() |
---|
[c4d723b] | 1921 | |
---|
[cdb042d] | 1922 | #self._lay_out() |
---|
[3821f64] | 1923 | if not self.is_mac: |
---|
| 1924 | self.Layout() |
---|
| 1925 | self.Refresh() |
---|
[f6aee42] | 1926 | self._mac_sleep(0.1) |
---|
[37290c4] | 1927 | #plot model ( when drawing, do not update chisqr value again) |
---|
[bd02c72] | 1928 | self._draw_model(update_chisqr=False) |
---|
[7975f2b] | 1929 | #PostStatusEvent |
---|
[12cd4ec] | 1930 | #msg = "Fit completed!dddd " |
---|
| 1931 | #wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
[c69b6d5] | 1932 | |
---|
[7609f1a] | 1933 | def onPinholeSmear(self, event): |
---|
| 1934 | """ |
---|
[5062bbf] | 1935 | Create a custom pinhole smear object that will change the way residuals |
---|
| 1936 | are compute when fitting |
---|
| 1937 | |
---|
| 1938 | :Note: accuracy is given by strings'High','Med', 'Low' FOR 2d, |
---|
| 1939 | None for 1D |
---|
| 1940 | |
---|
[7609f1a] | 1941 | """ |
---|
| 1942 | |
---|
[6bbeacd4] | 1943 | #if self.check_invalid_panel(): |
---|
| 1944 | # return |
---|
[7609f1a] | 1945 | if self.model ==None: |
---|
[4470b10] | 1946 | self.disable_smearer.SetValue(True) |
---|
| 1947 | msg="Please select a Model first..." |
---|
| 1948 | wx.MessageBox(msg, 'Info') |
---|
[90a7bbd] | 1949 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
[7609f1a] | 1950 | "Smear: %s"%msg)) |
---|
| 1951 | return |
---|
[4470b10] | 1952 | |
---|
[2d409fa] | 1953 | # Need update param values |
---|
[f72333f] | 1954 | self._update_paramv_on_fit() |
---|
| 1955 | |
---|
[7609f1a] | 1956 | # msg default |
---|
| 1957 | msg = None |
---|
| 1958 | if event != None: |
---|
| 1959 | tcrtl= event.GetEventObject() |
---|
| 1960 | # event case of radio button |
---|
| 1961 | if tcrtl.GetValue()== True: |
---|
| 1962 | self.dx_min = 0.0 |
---|
| 1963 | self.dx_max = 0.0 |
---|
| 1964 | is_new_pinhole = True |
---|
| 1965 | else: |
---|
| 1966 | is_new_pinhole = self._is_changed_pinhole() |
---|
[d493f66] | 1967 | else: |
---|
[1da28b8] | 1968 | is_new_pinhole = True |
---|
[7609f1a] | 1969 | # if any value is changed |
---|
| 1970 | if is_new_pinhole: |
---|
| 1971 | msg = self._set_pinhole_smear() |
---|
| 1972 | # hide all silt sizer |
---|
| 1973 | self._hide_all_smear_info() |
---|
[f72333f] | 1974 | |
---|
[7609f1a] | 1975 | ##Calculate chi2 |
---|
[f72333f] | 1976 | temp_smearer = self.current_smearer |
---|
| 1977 | #self.compute_chisqr(smearer= temp_smearer) |
---|
| 1978 | |
---|
[7609f1a] | 1979 | # show relevant slit sizers |
---|
| 1980 | self._show_smear_sizer() |
---|
[f72333f] | 1981 | |
---|
[7609f1a] | 1982 | self.sizer_set_smearer.Layout() |
---|
| 1983 | self.Layout() |
---|
| 1984 | |
---|
| 1985 | if event != None: |
---|
| 1986 | event.Skip() |
---|
| 1987 | #self._undo.Enable(True) |
---|
| 1988 | self.save_current_state() |
---|
| 1989 | event = PageInfoEvent(page = self) |
---|
| 1990 | wx.PostEvent(self.parent, event) |
---|
| 1991 | |
---|
| 1992 | def _is_changed_pinhole(self): |
---|
| 1993 | """ |
---|
[5062bbf] | 1994 | check if any of pinhole smear is changed |
---|
| 1995 | |
---|
| 1996 | :return: True or False |
---|
| 1997 | |
---|
[7609f1a] | 1998 | """ |
---|
| 1999 | # get the values |
---|
| 2000 | pin_min = self.smear_pinhole_min.GetValue() |
---|
| 2001 | pin_max = self.smear_pinhole_max.GetValue() |
---|
| 2002 | |
---|
| 2003 | # Check changes in slit width |
---|
| 2004 | try: |
---|
| 2005 | dx_min = float(pin_min) |
---|
| 2006 | except: |
---|
| 2007 | return True |
---|
| 2008 | if self.dx_min != dx_min: |
---|
| 2009 | return True |
---|
| 2010 | |
---|
| 2011 | # Check changes in slit heigth |
---|
| 2012 | try: |
---|
| 2013 | dx_max = float(pin_max) |
---|
| 2014 | except: |
---|
| 2015 | return True |
---|
| 2016 | if self.dx_max != dx_max: |
---|
| 2017 | return True |
---|
| 2018 | return False |
---|
| 2019 | |
---|
| 2020 | def _set_pinhole_smear(self): |
---|
| 2021 | """ |
---|
[5062bbf] | 2022 | Set custom pinhole smear |
---|
| 2023 | |
---|
| 2024 | :return: msg |
---|
| 2025 | |
---|
[7609f1a] | 2026 | """ |
---|
| 2027 | # copy data |
---|
| 2028 | data = copy.deepcopy(self.data) |
---|
[f72333f] | 2029 | if self._is_2D(): |
---|
| 2030 | self.smear_type = 'Pinhole2d' |
---|
| 2031 | len_data = len(data.data) |
---|
| 2032 | data.dqx_data = numpy.zeros(len_data) |
---|
| 2033 | data.dqy_data = numpy.zeros(len_data) |
---|
| 2034 | else: |
---|
| 2035 | self.smear_type = 'Pinhole' |
---|
| 2036 | len_data = len(data.x) |
---|
| 2037 | data.dx = numpy.zeros(len_data) |
---|
| 2038 | data.dxl = None |
---|
| 2039 | data.dxw = None |
---|
[7609f1a] | 2040 | msg = None |
---|
| 2041 | |
---|
| 2042 | get_pin_min = self.smear_pinhole_min |
---|
| 2043 | get_pin_max = self.smear_pinhole_max |
---|
| 2044 | |
---|
[f72333f] | 2045 | if not check_float(get_pin_min): |
---|
| 2046 | get_pin_min.SetBackgroundColour("pink") |
---|
| 2047 | msg= "Model Error:wrong value entered!!!" |
---|
| 2048 | elif not check_float(get_pin_max ): |
---|
| 2049 | get_pin_max.SetBackgroundColour("pink") |
---|
| 2050 | msg= "Model Error:wrong value entered!!!" |
---|
| 2051 | else: |
---|
[7609f1a] | 2052 | if len_data < 2: len_data = 2 |
---|
| 2053 | self.dx_min = float(get_pin_min.GetValue()) |
---|
| 2054 | self.dx_max = float(get_pin_max.GetValue()) |
---|
[f72333f] | 2055 | if self.dx_min < 0: |
---|
| 2056 | get_pin_min.SetBackgroundColour("pink") |
---|
| 2057 | msg= "Model Error:This value can not be negative!!!" |
---|
| 2058 | elif self.dx_max <0: |
---|
| 2059 | get_pin_max.SetBackgroundColour("pink") |
---|
| 2060 | msg= "Model Error:This value can not be negative!!!" |
---|
| 2061 | elif self.dx_min != None and self.dx_max != None: |
---|
| 2062 | if self._is_2D(): |
---|
| 2063 | data.dqx_data[data.dqx_data==0] = self.dx_min |
---|
| 2064 | data.dqy_data[data.dqy_data==0] = self.dx_max |
---|
| 2065 | elif self.dx_min == self.dx_max: |
---|
[7609f1a] | 2066 | data.dx[data.dx==0] = self.dx_min |
---|
| 2067 | else: |
---|
[f72333f] | 2068 | step = (self.dx_max - self.dx_min)/(len_data-1) |
---|
[d7b7156] | 2069 | data.dx = numpy.arange(self.dx_min,self.dx_max+step/1.1, |
---|
| 2070 | step) |
---|
[7609f1a] | 2071 | elif self.dx_min != None: |
---|
[f72333f] | 2072 | if self._is_2D(): data.dqx_data[data.dqx_data==0] = self.dx_min |
---|
| 2073 | else: data.dx[data.dx==0] = self.dx_min |
---|
[7609f1a] | 2074 | elif self.dx_max != None: |
---|
[f72333f] | 2075 | if self._is_2D(): data.dqy_data[data.dqy_data==0] = self.dx_max |
---|
| 2076 | else: data.dx[data.dx==0] = self.dx_max |
---|
[f867cd9] | 2077 | self.current_smearer = smear_selection(data, self.model) |
---|
[4fbc93e] | 2078 | # 2D need to set accuracy |
---|
| 2079 | if self._is_2D(): |
---|
[d7b7156] | 2080 | self.current_smearer.set_accuracy(accuracy = \ |
---|
| 2081 | self.smear2d_accuracy) |
---|
[7609f1a] | 2082 | |
---|
[f72333f] | 2083 | if msg != None: |
---|
[90a7bbd] | 2084 | wx.PostEvent(self._manager.parent, StatusEvent(status = msg )) |
---|
[f72333f] | 2085 | else: |
---|
| 2086 | get_pin_min.SetBackgroundColour("white") |
---|
| 2087 | get_pin_max.SetBackgroundColour("white") |
---|
[7609f1a] | 2088 | ## set smearing value whether or not the data contain the smearing info |
---|
[6bbeacd4] | 2089 | self._manager.set_smearer(smearer=self.current_smearer, |
---|
[ba1f0b2] | 2090 | enable2D=self.enable2D, |
---|
[6bbeacd4] | 2091 | qmin=float(self.qmin_x), |
---|
| 2092 | qmax= float(self.qmax_x), |
---|
[b29e47e] | 2093 | uid=self.uid) |
---|
[7609f1a] | 2094 | return msg |
---|
| 2095 | |
---|
| 2096 | def update_pinhole_smear(self): |
---|
| 2097 | """ |
---|
[5062bbf] | 2098 | called by kill_focus on pinhole TextCntrl |
---|
| 2099 | to update the changes |
---|
| 2100 | |
---|
| 2101 | :return: False when wrong value was entered |
---|
| 2102 | |
---|
[7609f1a] | 2103 | """ |
---|
| 2104 | # msg default |
---|
| 2105 | msg = None |
---|
| 2106 | # check if any value is changed |
---|
| 2107 | if self._is_changed_pinhole(): |
---|
| 2108 | msg = self._set_pinhole_smear() |
---|
| 2109 | #self._undo.Enable(True) |
---|
| 2110 | self.save_current_state() |
---|
| 2111 | |
---|
| 2112 | if msg != None: |
---|
| 2113 | return False |
---|
| 2114 | else: |
---|
| 2115 | return True |
---|
| 2116 | |
---|
| 2117 | def onSlitSmear(self, event): |
---|
| 2118 | """ |
---|
[5062bbf] | 2119 | Create a custom slit smear object that will change the way residuals |
---|
| 2120 | are compute when fitting |
---|
[7609f1a] | 2121 | """ |
---|
[4470b10] | 2122 | |
---|
[6bbeacd4] | 2123 | #if self.check_invalid_panel(): |
---|
| 2124 | # return |
---|
[4470b10] | 2125 | |
---|
[7609f1a] | 2126 | if self.model ==None: |
---|
[4470b10] | 2127 | self.disable_smearer.SetValue(True) |
---|
| 2128 | |
---|
| 2129 | msg="Please select a Model first..." |
---|
| 2130 | wx.MessageBox(msg, 'Info') |
---|
[90a7bbd] | 2131 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
[7609f1a] | 2132 | "Smear: %s"%msg)) |
---|
| 2133 | return |
---|
[4470b10] | 2134 | |
---|
[2d409fa] | 2135 | # Need update param values |
---|
| 2136 | self._update_paramv_on_fit() |
---|
[f72333f] | 2137 | |
---|
[7609f1a] | 2138 | # msg default |
---|
| 2139 | msg = None |
---|
| 2140 | # for event given |
---|
| 2141 | if event != None: |
---|
| 2142 | tcrtl= event.GetEventObject() |
---|
| 2143 | # event case of radio button |
---|
| 2144 | if tcrtl.GetValue(): |
---|
| 2145 | self.dxl = 0.0 |
---|
| 2146 | self.dxw = 0.0 |
---|
| 2147 | is_new_slit = True |
---|
| 2148 | else: |
---|
| 2149 | is_new_slit = self._is_changed_slit() |
---|
[d493f66] | 2150 | else: |
---|
[1da28b8] | 2151 | is_new_slit = True |
---|
[4470b10] | 2152 | |
---|
[7609f1a] | 2153 | # if any value is changed |
---|
| 2154 | if is_new_slit: |
---|
| 2155 | msg = self._set_slit_smear() |
---|
[4470b10] | 2156 | |
---|
[7609f1a] | 2157 | # hide all silt sizer |
---|
| 2158 | self._hide_all_smear_info() |
---|
| 2159 | ##Calculate chi2 |
---|
[f72333f] | 2160 | #self.compute_chisqr(smearer= self.current_smearer) |
---|
[7609f1a] | 2161 | # show relevant slit sizers |
---|
| 2162 | self._show_smear_sizer() |
---|
| 2163 | self.sizer_set_smearer.Layout() |
---|
| 2164 | self.Layout() |
---|
[4470b10] | 2165 | |
---|
[7609f1a] | 2166 | if event != None: |
---|
| 2167 | event.Skip() |
---|
| 2168 | #self._undo.Enable(True) |
---|
| 2169 | self.save_current_state() |
---|
| 2170 | event = PageInfoEvent(page = self) |
---|
| 2171 | wx.PostEvent(self.parent, event) |
---|
| 2172 | if msg != None: |
---|
[90a7bbd] | 2173 | wx.PostEvent(self._manager.parent, StatusEvent(status = msg)) |
---|
[7609f1a] | 2174 | |
---|
| 2175 | def _is_changed_slit(self): |
---|
| 2176 | """ |
---|
[5062bbf] | 2177 | check if any of slit lengths is changed |
---|
| 2178 | |
---|
| 2179 | :return: True or False |
---|
[4470b10] | 2180 | |
---|
[5062bbf] | 2181 | """ |
---|
[7609f1a] | 2182 | # get the values |
---|
| 2183 | width = self.smear_slit_width.GetValue() |
---|
| 2184 | height = self.smear_slit_height.GetValue() |
---|
| 2185 | |
---|
[d7b7156] | 2186 | # check and change the box bg color if it was pink |
---|
| 2187 | # but it should be white now |
---|
[7609f1a] | 2188 | # because this is the case that _set_slit_smear() will not handle |
---|
| 2189 | if height.lstrip().rstrip()=="": |
---|
| 2190 | self.smear_slit_height.SetBackgroundColour(wx.WHITE) |
---|
| 2191 | if width.lstrip().rstrip()=="": |
---|
| 2192 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
---|
| 2193 | |
---|
| 2194 | # Check changes in slit width |
---|
| 2195 | if width == "": |
---|
| 2196 | dxw = 0.0 |
---|
| 2197 | else: |
---|
| 2198 | try: |
---|
| 2199 | dxw = float(width) |
---|
| 2200 | except: |
---|
| 2201 | return True |
---|
| 2202 | if self.dxw != dxw: |
---|
| 2203 | return True |
---|
| 2204 | |
---|
| 2205 | # Check changes in slit heigth |
---|
| 2206 | if height == "": |
---|
| 2207 | dxl = 0.0 |
---|
| 2208 | else: |
---|
| 2209 | try: |
---|
| 2210 | dxl = float(height) |
---|
| 2211 | except: |
---|
| 2212 | return True |
---|
| 2213 | if self.dxl != dxl: |
---|
| 2214 | return True |
---|
[4470b10] | 2215 | |
---|
[7609f1a] | 2216 | return False |
---|
| 2217 | |
---|
| 2218 | def _set_slit_smear(self): |
---|
| 2219 | """ |
---|
[5062bbf] | 2220 | Set custom slit smear |
---|
| 2221 | |
---|
| 2222 | :return: message to inform the user about the validity |
---|
| 2223 | of the values entered for slit smear |
---|
[7609f1a] | 2224 | """ |
---|
[ba1f0b2] | 2225 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 2226 | self.enable2D: |
---|
[0b12abb5] | 2227 | return |
---|
[7609f1a] | 2228 | temp_smearer = None |
---|
| 2229 | # make sure once more if it is smearer |
---|
| 2230 | data = copy.deepcopy(self.data) |
---|
| 2231 | data_len = len(data.x) |
---|
| 2232 | data.dx = None |
---|
| 2233 | data.dxl = None |
---|
| 2234 | data.dxw = None |
---|
| 2235 | msg = None |
---|
| 2236 | |
---|
| 2237 | try: |
---|
| 2238 | self.dxl = float(self.smear_slit_height.GetValue()) |
---|
| 2239 | data.dxl = self.dxl* numpy.ones(data_len) |
---|
| 2240 | self.smear_slit_height.SetBackgroundColour(wx.WHITE) |
---|
| 2241 | except: |
---|
| 2242 | data.dxl = numpy.zeros(data_len) |
---|
| 2243 | if self.smear_slit_height.GetValue().lstrip().rstrip()!="": |
---|
| 2244 | self.smear_slit_height.SetBackgroundColour("pink") |
---|
| 2245 | msg = "Wrong value entered... " |
---|
| 2246 | else: |
---|
| 2247 | self.smear_slit_height.SetBackgroundColour(wx.WHITE) |
---|
| 2248 | try: |
---|
| 2249 | self.dxw = float(self.smear_slit_width.GetValue()) |
---|
| 2250 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
---|
| 2251 | data.dxw = self.dxw* numpy.ones(data_len) |
---|
| 2252 | except: |
---|
| 2253 | data.dxw = numpy.zeros(data_len) |
---|
| 2254 | if self.smear_slit_width.GetValue().lstrip().rstrip()!="": |
---|
| 2255 | self.smear_slit_width.SetBackgroundColour("pink") |
---|
| 2256 | msg = "Wrong Fit value entered... " |
---|
| 2257 | else: |
---|
| 2258 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
---|
[4470b10] | 2259 | |
---|
[f867cd9] | 2260 | self.current_smearer = smear_selection(data, self.model) |
---|
[7609f1a] | 2261 | #temp_smearer = self.current_smearer |
---|
| 2262 | ## set smearing value whether or not the data contain the smearing info |
---|
[6bbeacd4] | 2263 | self._manager.set_smearer(smearer=self.current_smearer, |
---|
[ba1f0b2] | 2264 | enable2D=self.enable2D, |
---|
[6bbeacd4] | 2265 | qmin=float(self.qmin_x), |
---|
| 2266 | qmax= float(self.qmax_x), |
---|
[512bbd0] | 2267 | uid=self.uid) |
---|
[7609f1a] | 2268 | return msg |
---|
| 2269 | |
---|
| 2270 | def update_slit_smear(self): |
---|
| 2271 | """ |
---|
[5062bbf] | 2272 | called by kill_focus on pinhole TextCntrl |
---|
| 2273 | to update the changes |
---|
| 2274 | |
---|
| 2275 | :return: False when wrong value was entered |
---|
| 2276 | |
---|
[7609f1a] | 2277 | """ |
---|
| 2278 | # msg default |
---|
| 2279 | msg = None |
---|
| 2280 | # check if any value is changed |
---|
| 2281 | if self._is_changed_slit(): |
---|
| 2282 | msg = self._set_slit_smear() |
---|
| 2283 | #self._undo.Enable(True) |
---|
| 2284 | self.save_current_state() |
---|
| 2285 | |
---|
| 2286 | if msg != None: |
---|
| 2287 | return False |
---|
| 2288 | else: |
---|
| 2289 | return True |
---|
| 2290 | |
---|
[c77d859] | 2291 | def onSmear(self, event): |
---|
| 2292 | """ |
---|
[5062bbf] | 2293 | Create a smear object that will change the way residuals |
---|
| 2294 | are compute when fitting |
---|
[c77d859] | 2295 | """ |
---|
[f72333f] | 2296 | if event != None: |
---|
| 2297 | event.Skip() |
---|
[6bbeacd4] | 2298 | if self.data is None: |
---|
[ffa69b6] | 2299 | return |
---|
[6bbeacd4] | 2300 | |
---|
[64bda1e] | 2301 | if self.model == None: |
---|
[4470b10] | 2302 | self.disable_smearer.SetValue(True) |
---|
| 2303 | msg="Please select a Model first..." |
---|
| 2304 | wx.MessageBox(msg, 'Info') |
---|
[90a7bbd] | 2305 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
[2a2af47] | 2306 | "Smear: %s"%msg)) |
---|
| 2307 | return |
---|
[f72333f] | 2308 | |
---|
[2d409fa] | 2309 | # Need update param values |
---|
| 2310 | self._update_paramv_on_fit() |
---|
[6bbeacd4] | 2311 | |
---|
[3370922] | 2312 | temp_smearer = None |
---|
[7609f1a] | 2313 | self._get_smear_info() |
---|
| 2314 | |
---|
| 2315 | #renew smear sizer |
---|
| 2316 | if self.smear_type != None: |
---|
| 2317 | self.smear_description_smear_type.SetValue(str(self.smear_type)) |
---|
| 2318 | self.smear_data_left.SetValue(str(self.dq_l)) |
---|
| 2319 | self.smear_data_right.SetValue(str(self.dq_r)) |
---|
[f72333f] | 2320 | |
---|
[7609f1a] | 2321 | self._hide_all_smear_info() |
---|
| 2322 | |
---|
| 2323 | data = copy.deepcopy(self.data) |
---|
| 2324 | # make sure once more if it is smearer |
---|
[f867cd9] | 2325 | self.current_smearer = smear_selection(data, self.model) |
---|
[f72333f] | 2326 | |
---|
[c77d859] | 2327 | if self.enable_smearer.GetValue(): |
---|
| 2328 | if hasattr(self.data,"dxl"): |
---|
[7609f1a] | 2329 | |
---|
[c77d859] | 2330 | msg= ": Resolution smearing parameters" |
---|
| 2331 | if hasattr(self.data,"dxw"): |
---|
| 2332 | msg= ": Slit smearing parameters" |
---|
[997131a] | 2333 | if self.smearer ==None: |
---|
[90a7bbd] | 2334 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
[c77d859] | 2335 | "Data contains no smearing information")) |
---|
| 2336 | else: |
---|
[90a7bbd] | 2337 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
[f72333f] | 2338 | "Data contains smearing information")) |
---|
| 2339 | |
---|
| 2340 | #self.smear_description_dqdata.Show(True) |
---|
[7609f1a] | 2341 | self.smear_data_left.Show(True) |
---|
| 2342 | self.smear_data_right.Show(True) |
---|
[f72333f] | 2343 | temp_smearer= self.current_smearer |
---|
[7609f1a] | 2344 | elif self.disable_smearer.GetValue(): |
---|
| 2345 | self.smear_description_none.Show(True) |
---|
| 2346 | |
---|
| 2347 | self._show_smear_sizer() |
---|
[f72333f] | 2348 | |
---|
[7609f1a] | 2349 | self.sizer_set_smearer.Layout() |
---|
| 2350 | self.Layout() |
---|
[fb8daaaf] | 2351 | ## set smearing value whether or not the data contain the smearing info |
---|
[ba1f0b2] | 2352 | self._manager.set_smearer(uid=self.uid, smearer=temp_smearer, |
---|
| 2353 | enable2D=self.enable2D, |
---|
| 2354 | qmin= float(self.qmin_x), |
---|
[6bbeacd4] | 2355 | qmax= float(self.qmax_x), draw=True) |
---|
| 2356 | |
---|
[5582a9f1] | 2357 | self.state.enable_smearer= self.enable_smearer.GetValue() |
---|
| 2358 | self.state.disable_smearer=self.disable_smearer.GetValue() |
---|
[7609f1a] | 2359 | self.state.pinhole_smearer = self.pinhole_smearer.GetValue() |
---|
| 2360 | self.state.slit_smearer = self.slit_smearer.GetValue() |
---|
[f72333f] | 2361 | |
---|
| 2362 | def on_complete_chisqr(self, event): |
---|
| 2363 | """ |
---|
[5062bbf] | 2364 | print result chisqr |
---|
| 2365 | |
---|
| 2366 | :event: activated by fitting/ complete after draw |
---|
| 2367 | |
---|
[f72333f] | 2368 | """ |
---|
| 2369 | try: |
---|
[06aa2eeb] | 2370 | if event == None: |
---|
| 2371 | output= "-" |
---|
| 2372 | elif not numpy.isfinite(event.output): |
---|
[f72333f] | 2373 | output= "-" |
---|
| 2374 | else: |
---|
| 2375 | output = event.output |
---|
[2296316] | 2376 | self.tcChi.SetValue(str(format_number(output, True))) |
---|
[f72333f] | 2377 | |
---|
[3c44c66] | 2378 | self.state.tcChi = self.tcChi.GetValue() |
---|
[f72333f] | 2379 | except: |
---|
| 2380 | pass |
---|
[c77d859] | 2381 | |
---|
[5062bbf] | 2382 | |
---|
[c77d859] | 2383 | def select_all_param(self,event): |
---|
| 2384 | """ |
---|
[5062bbf] | 2385 | set to true or false all checkBox given the main checkbox value cb1 |
---|
[d1e0473] | 2386 | """ |
---|
[c77d859] | 2387 | self.param_toFit=[] |
---|
| 2388 | if self.parameters !=[]: |
---|
[998b6b8] | 2389 | if self.cb1.GetValue(): |
---|
[c77d859] | 2390 | for item in self.parameters: |
---|
[3fef0a8] | 2391 | ## for data2D select all to fit |
---|
[ba1f0b2] | 2392 | if self.data.__class__.__name__== "Data2D" or \ |
---|
| 2393 | self.enable2D: |
---|
[c77d859] | 2394 | item[0].SetValue(True) |
---|
| 2395 | self.param_toFit.append(item ) |
---|
[3fef0a8] | 2396 | else: |
---|
| 2397 | ## for 1D all parameters except orientation |
---|
| 2398 | if not item in self.orientation_params: |
---|
| 2399 | item[0].SetValue(True) |
---|
| 2400 | self.param_toFit.append(item ) |
---|
[b324aa9] | 2401 | #if len(self.fittable_param)>0: |
---|
| 2402 | for item in self.fittable_param: |
---|
[ba1f0b2] | 2403 | if self.data.__class__.__name__== "Data2D" or \ |
---|
| 2404 | self.enable2D: |
---|
[b324aa9] | 2405 | item[0].SetValue(True) |
---|
| 2406 | self.param_toFit.append(item ) |
---|
[2296316] | 2407 | try: |
---|
| 2408 | if len(self.values[item[1]]) > 0: |
---|
| 2409 | item[0].SetValue(False) |
---|
| 2410 | except: |
---|
| 2411 | pass |
---|
| 2412 | |
---|
[b324aa9] | 2413 | else: |
---|
| 2414 | ## for 1D all parameters except orientation |
---|
| 2415 | if not item in self.orientation_params_disp: |
---|
[3fef0a8] | 2416 | item[0].SetValue(True) |
---|
| 2417 | self.param_toFit.append(item ) |
---|
[2296316] | 2418 | try: |
---|
| 2419 | if len(self.values[item[1]]) > 0: |
---|
| 2420 | item[0].SetValue(False) |
---|
| 2421 | except: |
---|
| 2422 | pass |
---|
| 2423 | |
---|
[c77d859] | 2424 | else: |
---|
| 2425 | for item in self.parameters: |
---|
| 2426 | item[0].SetValue(False) |
---|
| 2427 | for item in self.fittable_param: |
---|
| 2428 | item[0].SetValue(False) |
---|
| 2429 | self.param_toFit=[] |
---|
[330573d] | 2430 | |
---|
[52cac46] | 2431 | self.save_current_state_fit() |
---|
[b324aa9] | 2432 | |
---|
[3595309d] | 2433 | if event !=None: |
---|
[3a37fe0] | 2434 | #self._undo.Enable(True) |
---|
[3595309d] | 2435 | ## post state to fit panel |
---|
| 2436 | event = PageInfoEvent(page = self) |
---|
| 2437 | wx.PostEvent(self.parent, event) |
---|
| 2438 | |
---|
[c77d859] | 2439 | def select_param(self,event): |
---|
| 2440 | """ |
---|
[5062bbf] | 2441 | Select TextCtrl checked for fitting purpose and stores them |
---|
| 2442 | in self.param_toFit=[] list |
---|
[c77d859] | 2443 | """ |
---|
| 2444 | self.param_toFit=[] |
---|
| 2445 | for item in self.parameters: |
---|
[edd166b] | 2446 | #Skip t ifhe angle parameters if 1D data |
---|
[ba1f0b2] | 2447 | if self.data.__class__.__name__ != "Data2D" and\ |
---|
| 2448 | not self.enable2D: |
---|
[edd166b] | 2449 | if item in self.orientation_params: |
---|
| 2450 | continue |
---|
[c77d859] | 2451 | #Select parameters to fit for list of primary parameters |
---|
[998b6b8] | 2452 | if item[0].GetValue(): |
---|
[c77d859] | 2453 | if not (item in self.param_toFit): |
---|
| 2454 | self.param_toFit.append(item ) |
---|
| 2455 | else: |
---|
| 2456 | #remove parameters from the fitting list |
---|
| 2457 | if item in self.param_toFit: |
---|
| 2458 | self.param_toFit.remove(item) |
---|
[edd166b] | 2459 | |
---|
[d7b7156] | 2460 | #Select parameters to fit for list of fittable parameters |
---|
| 2461 | # with dispersion |
---|
[c77d859] | 2462 | for item in self.fittable_param: |
---|
[edd166b] | 2463 | #Skip t ifhe angle parameters if 1D data |
---|
[ba1f0b2] | 2464 | if self.data.__class__.__name__ != "Data2D" and\ |
---|
| 2465 | not self.enable2D: |
---|
[edd166b] | 2466 | if item in self.orientation_params: |
---|
| 2467 | continue |
---|
[998b6b8] | 2468 | if item[0].GetValue(): |
---|
[c77d859] | 2469 | if not (item in self.param_toFit): |
---|
| 2470 | self.param_toFit.append(item) |
---|
| 2471 | else: |
---|
| 2472 | #remove parameters from the fitting list |
---|
| 2473 | if item in self.param_toFit: |
---|
[edd166b] | 2474 | self.param_toFit.remove(item) |
---|
| 2475 | |
---|
| 2476 | #Calculate num. of angle parameters |
---|
[ba1f0b2] | 2477 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 2478 | self.enable2D: |
---|
[edd166b] | 2479 | len_orient_para = 0 |
---|
| 2480 | else: |
---|
| 2481 | len_orient_para = len(self.orientation_params) #assume even len |
---|
| 2482 | #Total num. of angle parameters |
---|
| 2483 | if len(self.fittable_param) > 0: |
---|
| 2484 | len_orient_para *= 2 |
---|
[c77d859] | 2485 | #Set the value of checkbox that selected every checkbox or not |
---|
[d7b7156] | 2486 | if len(self.parameters)+len(self.fittable_param)-len_orient_para ==\ |
---|
| 2487 | len(self.param_toFit): |
---|
[c77d859] | 2488 | self.cb1.SetValue(True) |
---|
| 2489 | else: |
---|
| 2490 | self.cb1.SetValue(False) |
---|
[52cac46] | 2491 | self.save_current_state_fit() |
---|
[3595309d] | 2492 | if event !=None: |
---|
[3a37fe0] | 2493 | #self._undo.Enable(True) |
---|
[3595309d] | 2494 | ## post state to fit panel |
---|
| 2495 | event = PageInfoEvent(page = self) |
---|
| 2496 | wx.PostEvent(self.parent, event) |
---|
[c77d859] | 2497 | |
---|
[77e23a2] | 2498 | def set_model_param_sizer(self, model): |
---|
[c77d859] | 2499 | """ |
---|
[5062bbf] | 2500 | Build the panel from the model content |
---|
| 2501 | |
---|
| 2502 | :param model: the model selected in combo box for fitting purpose |
---|
| 2503 | |
---|
[c77d859] | 2504 | """ |
---|
| 2505 | self.sizer3.Clear(True) |
---|
| 2506 | self.parameters = [] |
---|
[fb59ed9] | 2507 | self.str_parameters = [] |
---|
[c77d859] | 2508 | self.param_toFit=[] |
---|
| 2509 | self.fittable_param=[] |
---|
| 2510 | self.fixed_param=[] |
---|
[780d095] | 2511 | self.orientation_params=[] |
---|
[60132ef] | 2512 | self.orientation_params_disp=[] |
---|
[c77d859] | 2513 | |
---|
| 2514 | if model ==None: |
---|
| 2515 | self.sizer3.Layout() |
---|
[ce92ded] | 2516 | self.SetupScrolling() |
---|
[c77d859] | 2517 | return |
---|
[707436d] | 2518 | ## the panel is drawn using the current value of the fit engine |
---|
[90a7bbd] | 2519 | if self.engine_type==None and self._manager !=None: |
---|
| 2520 | self.engine_type= self._manager._return_engine_type() |
---|
[c99a6c5] | 2521 | |
---|
[c77d859] | 2522 | box_description= wx.StaticBox(self, -1,str("Model Parameters")) |
---|
| 2523 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 2524 | sizer = wx.GridBagSizer(5,5) |
---|
| 2525 | ## save the current model |
---|
| 2526 | self.model = model |
---|
| 2527 | |
---|
| 2528 | keys = self.model.getParamList() |
---|
| 2529 | #list of dispersion paramaters |
---|
| 2530 | self.disp_list=self.model.getDispParamList() |
---|
[b421b1a] | 2531 | |
---|
[db08737] | 2532 | def custom_compare(a,b): |
---|
| 2533 | """ |
---|
| 2534 | Custom compare to order, first by alphabets then second by number. |
---|
| 2535 | """ |
---|
[fb59ed9] | 2536 | # number at the last digit |
---|
[db08737] | 2537 | a_last = a[len(a)-1] |
---|
| 2538 | b_last = b[len(b)-1] |
---|
[fb59ed9] | 2539 | # default |
---|
[db08737] | 2540 | num_a = None |
---|
| 2541 | num_b = None |
---|
[fb59ed9] | 2542 | # split the names |
---|
| 2543 | a2 = a.lower().split('_') |
---|
| 2544 | b2 = b.lower().split('_') |
---|
| 2545 | # check length of a2, b2 |
---|
| 2546 | len_a2 = len(a2) |
---|
| 2547 | len_b2 = len(b2) |
---|
[db08737] | 2548 | # check if it contains a int number(<10) |
---|
| 2549 | try: |
---|
| 2550 | num_a = int(a_last) |
---|
| 2551 | except: pass |
---|
| 2552 | try: |
---|
| 2553 | num_b = int(b_last) |
---|
| 2554 | except: pass |
---|
[fb59ed9] | 2555 | # Put 'scale' near the top; happens |
---|
| 2556 | # when numbered param name exists |
---|
| 2557 | if a == 'scale': |
---|
| 2558 | return -1 |
---|
[db08737] | 2559 | # both have a number |
---|
| 2560 | if num_a != None and num_b != None: |
---|
[fb59ed9] | 2561 | if num_a > num_b: return -1 |
---|
| 2562 | # same number |
---|
[db08737] | 2563 | elif num_a == num_b: |
---|
[fb59ed9] | 2564 | # different last names |
---|
| 2565 | if a2[len_a2-1] != b2[len_b2-1] and num_a != 0: |
---|
| 2566 | return -cmp(a2[len_a2-1], b2[len_b2-1]) |
---|
| 2567 | else: |
---|
| 2568 | return cmp(a, b) |
---|
| 2569 | else: return 1 |
---|
[db08737] | 2570 | # one of them has a number |
---|
[20905a0] | 2571 | elif num_a != None: return 1 |
---|
| 2572 | elif num_b != None: return -1 |
---|
[fb59ed9] | 2573 | # no numbers |
---|
[20905a0] | 2574 | else: return cmp(a.lower(), b.lower()) |
---|
[fb59ed9] | 2575 | |
---|
[20905a0] | 2576 | |
---|
[db08737] | 2577 | keys.sort(custom_compare) |
---|
[c77d859] | 2578 | |
---|
[6dc9ad8] | 2579 | iy = 0 |
---|
[c77d859] | 2580 | ix = 0 |
---|
[2f6c260] | 2581 | select_text = "Select All" |
---|
[b324aa9] | 2582 | self.cb1 = wx.CheckBox(self, -1,str(select_text), (10, 10)) |
---|
[c77d859] | 2583 | wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param) |
---|
[2f6c260] | 2584 | self.cb1.SetToolTipString("To check/uncheck all the boxes below.") |
---|
[ecfcef6] | 2585 | self.cb1.SetValue(True) |
---|
[c77d859] | 2586 | |
---|
| 2587 | sizer.Add(self.cb1,(iy, ix),(1,1),\ |
---|
[eda428b] | 2588 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
[c77d859] | 2589 | ix +=1 |
---|
[f56bf29] | 2590 | self.text2_2 = wx.StaticText(self, -1, 'Value') |
---|
[c77d859] | 2591 | sizer.Add(self.text2_2,(iy, ix),(1,1),\ |
---|
| 2592 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 2593 | ix +=2 |
---|
[f56bf29] | 2594 | self.text2_3 = wx.StaticText(self, -1, 'Error') |
---|
[c77d859] | 2595 | sizer.Add(self.text2_3,(iy, ix),(1,1),\ |
---|
| 2596 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[3821f64] | 2597 | if not self.is_mac: |
---|
| 2598 | self.text2_3.Hide() |
---|
[c77d859] | 2599 | ix +=1 |
---|
| 2600 | self.text2_min = wx.StaticText(self, -1, 'Min') |
---|
| 2601 | sizer.Add(self.text2_min,(iy, ix),(1,1),\ |
---|
| 2602 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[2296316] | 2603 | #self.text2_min.Hide() |
---|
[c77d859] | 2604 | ix +=1 |
---|
| 2605 | self.text2_max = wx.StaticText(self, -1, 'Max') |
---|
| 2606 | sizer.Add(self.text2_max,(iy, ix),(1,1),\ |
---|
| 2607 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[2296316] | 2608 | #self.text2_max.Hide() |
---|
[6fdfc8f] | 2609 | ix += 1 |
---|
| 2610 | self.text2_4 = wx.StaticText(self, -1, '[Units]') |
---|
| 2611 | sizer.Add(self.text2_4,(iy, ix),(1,1),\ |
---|
| 2612 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 2613 | self.text2_4.Hide() |
---|
[b421b1a] | 2614 | |
---|
[c77d859] | 2615 | for item in keys: |
---|
[d7b7156] | 2616 | if not item in self.disp_list and not item in \ |
---|
| 2617 | self.model.orientation_params: |
---|
[b421b1a] | 2618 | |
---|
| 2619 | ##prepare a spot to store errors |
---|
| 2620 | if not self.model.details.has_key(item): |
---|
| 2621 | self.model.details [item] = ["",None,None] |
---|
| 2622 | |
---|
[c77d859] | 2623 | iy += 1 |
---|
| 2624 | ix = 0 |
---|
[8960479] | 2625 | if (self.model.__class__ in \ |
---|
| 2626 | self.model_list_box["Multi-Functions"] or \ |
---|
| 2627 | self.temp_multi_functional)\ |
---|
| 2628 | and (item in self.model.non_fittable): |
---|
[fb59ed9] | 2629 | non_fittable_name = wx.StaticText(self, -1, item ) |
---|
| 2630 | sizer.Add(non_fittable_name,(iy, ix),(1,1),\ |
---|
| 2631 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 21) |
---|
| 2632 | ## add parameter value |
---|
| 2633 | ix += 1 |
---|
| 2634 | value= self.model.getParam(item) |
---|
| 2635 | if len(self.model.fun_list) > 0: |
---|
| 2636 | num = item.split('_')[1][5:7] |
---|
[d7b7156] | 2637 | fun_box = wx.ComboBox(self, -1,size=(100,-1), |
---|
| 2638 | style=wx.CB_READONLY, name = '%s'% item) |
---|
[fb59ed9] | 2639 | self._set_fun_box_list(fun_box) |
---|
| 2640 | fun_box.SetSelection(0) |
---|
[d7b7156] | 2641 | #self.fun_box.SetToolTipString("A function |
---|
| 2642 | # describing the interface") |
---|
[fb59ed9] | 2643 | wx.EVT_COMBOBOX(fun_box,-1, self._on_fun_box) |
---|
| 2644 | else: |
---|
[d7b7156] | 2645 | fun_box = self.ModelTextCtrl(self, -1, |
---|
| 2646 | size=(_BOX_WIDTH,20), |
---|
| 2647 | style=wx.TE_PROCESS_ENTER, name ='%s'% item) |
---|
[fb59ed9] | 2648 | fun_box.SetToolTipString("Hit 'Enter' after typing.") |
---|
[2296316] | 2649 | fun_box.SetValue(format_number(value, True)) |
---|
[fb59ed9] | 2650 | sizer.Add(fun_box, (iy,ix),(1,1), wx.EXPAND) |
---|
[d7b7156] | 2651 | self.str_parameters.append([None,item, fun_box, |
---|
[2296316] | 2652 | None, None, None, |
---|
| 2653 | None, None]) |
---|
[fb59ed9] | 2654 | |
---|
| 2655 | |
---|
[7975f2b] | 2656 | else: |
---|
[fb59ed9] | 2657 | ## add parameters name with checkbox for selecting to fit |
---|
| 2658 | cb = wx.CheckBox(self, -1, item ) |
---|
[2296316] | 2659 | cb.SetToolTipString(" Check mark to fit.") |
---|
[fb59ed9] | 2660 | #cb.SetValue(True) |
---|
| 2661 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
[dcf29d7] | 2662 | |
---|
[fb59ed9] | 2663 | sizer.Add( cb,( iy, ix),(1,1), |
---|
| 2664 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
| 2665 | |
---|
| 2666 | ## add parameter value |
---|
| 2667 | ix += 1 |
---|
| 2668 | value= self.model.getParam(item) |
---|
| 2669 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 2670 | style=wx.TE_PROCESS_ENTER) |
---|
| 2671 | ctl1.SetToolTipString("Hit 'Enter' after typing.") |
---|
[2296316] | 2672 | ctl1.SetValue(format_number(value, True)) |
---|
[fb59ed9] | 2673 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 2674 | ## text to show error sign |
---|
| 2675 | ix += 1 |
---|
| 2676 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 2677 | sizer.Add(text2,(iy, ix),(1,1),\ |
---|
| 2678 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[ce92ded] | 2679 | if not self.is_mac: |
---|
| 2680 | text2.Hide() |
---|
[fb59ed9] | 2681 | ix += 1 |
---|
[2296316] | 2682 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/1.2,20), style=0) |
---|
[d7b7156] | 2683 | sizer.Add(ctl2, (iy,ix),(1,1), |
---|
| 2684 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[ce92ded] | 2685 | if not self.is_mac: |
---|
| 2686 | ctl2.Hide() |
---|
[fb59ed9] | 2687 | |
---|
| 2688 | ix += 1 |
---|
[2296316] | 2689 | ctl3 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.9,20), |
---|
[d7b7156] | 2690 | style=wx.TE_PROCESS_ENTER, |
---|
| 2691 | text_enter_callback = self._onparamRangeEnter) |
---|
[fb59ed9] | 2692 | |
---|
[d7b7156] | 2693 | sizer.Add(ctl3, (iy,ix),(1,1), |
---|
| 2694 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[fb59ed9] | 2695 | |
---|
| 2696 | ix += 1 |
---|
[2296316] | 2697 | ctl4 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.9,20), |
---|
[d7b7156] | 2698 | style=wx.TE_PROCESS_ENTER, |
---|
| 2699 | text_enter_callback = self._onparamRangeEnter) |
---|
| 2700 | sizer.Add(ctl4, (iy,ix),(1,1), |
---|
[2296316] | 2701 | wx.EXPAND|wx.FIXED_MINSIZE, 0) |
---|
[fb59ed9] | 2702 | |
---|
| 2703 | ix +=1 |
---|
| 2704 | # Units |
---|
| 2705 | if self.model.details.has_key(item): |
---|
[d7b7156] | 2706 | units = wx.StaticText(self, -1, |
---|
| 2707 | self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
[fb59ed9] | 2708 | else: |
---|
| 2709 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
[d7b7156] | 2710 | sizer.Add(units, (iy,ix),(1,1), |
---|
| 2711 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[fb59ed9] | 2712 | |
---|
| 2713 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 2714 | self.parameters.append([cb,item, ctl1, |
---|
| 2715 | text2,ctl2, ctl3, ctl4,units]) |
---|
| 2716 | |
---|
[c77d859] | 2717 | iy+=1 |
---|
[d7b7156] | 2718 | sizer.Add((10,10),(iy,ix),(1,1), |
---|
| 2719 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[5af5183] | 2720 | |
---|
[f20767b] | 2721 | # type can be either Guassian or Array |
---|
[5b53a5c] | 2722 | if len(self.model.dispersion.values())>0: |
---|
| 2723 | type= self.model.dispersion.values()[0]["type"] |
---|
| 2724 | else: |
---|
| 2725 | type = "Gaussian" |
---|
[6dc9ad8] | 2726 | |
---|
| 2727 | iy += 1 |
---|
| 2728 | ix = 0 |
---|
| 2729 | #Add tile for orientational angle |
---|
| 2730 | for item in keys: |
---|
| 2731 | if item in self.model.orientation_params: |
---|
| 2732 | orient_angle = wx.StaticText(self, -1, '[For 2D only]:') |
---|
[d7b7156] | 2733 | sizer.Add(orient_angle,(iy, ix),(1,1), |
---|
| 2734 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[ba1f0b2] | 2735 | if not self.data.__class__.__name__ == "Data2D" and \ |
---|
| 2736 | not self.enable2D: |
---|
[6dc9ad8] | 2737 | orient_angle.Hide() |
---|
| 2738 | else: |
---|
| 2739 | orient_angle.Show(True) |
---|
| 2740 | break |
---|
[5b53a5c] | 2741 | |
---|
[f20767b] | 2742 | #For Gaussian only |
---|
| 2743 | if type.lower() != "array": |
---|
| 2744 | for item in self.model.orientation_params: |
---|
| 2745 | if not item in self.disp_list: |
---|
[c13b8cc] | 2746 | ##prepare a spot to store min max |
---|
| 2747 | if not self.model.details.has_key(item): |
---|
| 2748 | self.model.details [item] = ["",None,None] |
---|
| 2749 | |
---|
[f20767b] | 2750 | iy += 1 |
---|
| 2751 | ix = 0 |
---|
| 2752 | ## add parameters name with checkbox for selecting to fit |
---|
| 2753 | cb = wx.CheckBox(self, -1, item ) |
---|
| 2754 | cb.SetValue(False) |
---|
[2296316] | 2755 | cb.SetToolTipString("Check mark to fit") |
---|
[f20767b] | 2756 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
[ba1f0b2] | 2757 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 2758 | self.enable2D: |
---|
[6dc9ad8] | 2759 | cb.Show(True) |
---|
[f20767b] | 2760 | else: |
---|
[6dc9ad8] | 2761 | cb.Hide() |
---|
[f20767b] | 2762 | sizer.Add( cb,( iy, ix),(1,1), |
---|
| 2763 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
| 2764 | |
---|
| 2765 | ## add parameter value |
---|
| 2766 | ix += 1 |
---|
| 2767 | value= self.model.getParam(item) |
---|
[7975f2b] | 2768 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
[f20767b] | 2769 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 2770 | ctl1.SetToolTipString("Hit 'Enter' after typing.") |
---|
[2296316] | 2771 | ctl1.SetValue(format_number(value, True)) |
---|
[ba1f0b2] | 2772 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 2773 | self.enable2D: |
---|
[c5cd3b9] | 2774 | ctl1.Show(True) |
---|
[f20767b] | 2775 | else: |
---|
[c5cd3b9] | 2776 | ctl1.Hide() |
---|
[f20767b] | 2777 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 2778 | ## text to show error sign |
---|
| 2779 | ix += 1 |
---|
| 2780 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 2781 | sizer.Add(text2,(iy, ix),(1,1),\ |
---|
| 2782 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[e792aee] | 2783 | |
---|
| 2784 | text2.Hide() |
---|
[f20767b] | 2785 | ix += 1 |
---|
[2296316] | 2786 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/1.2,20), style=0) |
---|
[d7b7156] | 2787 | sizer.Add(ctl2, (iy,ix),(1,1), |
---|
| 2788 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[e792aee] | 2789 | |
---|
| 2790 | ctl2.Hide() |
---|
[e2f7b92] | 2791 | |
---|
[c99a6c5] | 2792 | |
---|
[f20767b] | 2793 | ix += 1 |
---|
[2296316] | 2794 | ctl3 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.8,20), |
---|
[d7b7156] | 2795 | style=wx.TE_PROCESS_ENTER, |
---|
| 2796 | text_enter_callback = self._onparamRangeEnter) |
---|
[b9405cd] | 2797 | |
---|
[d7b7156] | 2798 | sizer.Add(ctl3, (iy,ix),(1,1), |
---|
| 2799 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[f20767b] | 2800 | ctl3.Hide() |
---|
[b324aa9] | 2801 | |
---|
[f20767b] | 2802 | ix += 1 |
---|
[2296316] | 2803 | ctl4 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.8,20), |
---|
[d7b7156] | 2804 | style=wx.TE_PROCESS_ENTER, |
---|
| 2805 | text_enter_callback = self._onparamRangeEnter) |
---|
| 2806 | sizer.Add(ctl4, (iy,ix),(1,1), |
---|
| 2807 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[eacf1d66] | 2808 | |
---|
[f20767b] | 2809 | ctl4.Hide() |
---|
[edd166b] | 2810 | |
---|
[ba1f0b2] | 2811 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
[1180528] | 2812 | self.enable2D: |
---|
| 2813 | if self.is_mac: |
---|
| 2814 | text2.Show(True) |
---|
| 2815 | ctl2.Show(True) |
---|
[f20767b] | 2816 | ctl3.Show(True) |
---|
| 2817 | ctl4.Show(True) |
---|
[c5cd3b9] | 2818 | |
---|
[f20767b] | 2819 | ix +=1 |
---|
| 2820 | # Units |
---|
[7975f2b] | 2821 | if self.model.details.has_key(item): |
---|
[d7b7156] | 2822 | units = wx.StaticText(self, -1, |
---|
| 2823 | self.model.details[item][0], |
---|
| 2824 | style=wx.ALIGN_LEFT) |
---|
[7975f2b] | 2825 | else: |
---|
[f20767b] | 2826 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
[ba1f0b2] | 2827 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 2828 | self.enable2D: |
---|
[6dc9ad8] | 2829 | units.Show(True) |
---|
[c99a6c5] | 2830 | |
---|
[f20767b] | 2831 | else: |
---|
[6dc9ad8] | 2832 | units.Hide() |
---|
[c99a6c5] | 2833 | |
---|
[d7b7156] | 2834 | sizer.Add(units, (iy,ix),(1,1), |
---|
| 2835 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[7975f2b] | 2836 | |
---|
[d7b7156] | 2837 | ##[cb state, name, value, "+/-", error of fit,min,max,units] |
---|
[f20767b] | 2838 | self.parameters.append([cb,item, ctl1, |
---|
| 2839 | text2,ctl2, ctl3, ctl4,units]) |
---|
| 2840 | self.orientation_params.append([cb,item, ctl1, |
---|
| 2841 | text2,ctl2, ctl3, ctl4,units]) |
---|
[780d095] | 2842 | |
---|
| 2843 | iy+=1 |
---|
[c77d859] | 2844 | |
---|
| 2845 | #Display units text on panel |
---|
| 2846 | for item in keys: |
---|
[7975f2b] | 2847 | if self.model.details.has_key(item): |
---|
[c77d859] | 2848 | self.text2_4.Show() |
---|
[b324aa9] | 2849 | #Fill the list of fittable parameters |
---|
| 2850 | self.select_all_param(event=None) |
---|
[7975f2b] | 2851 | |
---|
[52cac46] | 2852 | self.save_current_state_fit() |
---|
[240b9966] | 2853 | boxsizer1.Add(sizer) |
---|
[c77d859] | 2854 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 2855 | self.sizer3.Layout() |
---|
[330573d] | 2856 | self.Layout() |
---|
| 2857 | self.Refresh() |
---|
[2296316] | 2858 | |
---|
| 2859 | def on_right_down(self, event): |
---|
| 2860 | """ |
---|
| 2861 | Get key stroke event |
---|
| 2862 | """ |
---|
| 2863 | if self.data == None: |
---|
| 2864 | return |
---|
| 2865 | # Figuring out key combo: Cmd for copy, Alt for paste |
---|
| 2866 | if event.AltDown() and event.ShiftDown(): |
---|
| 2867 | self._show_ftol_dialog() |
---|
| 2868 | flag = True |
---|
[1b1bbf9] | 2869 | elif event.AltDown() or event.ShiftDown(): |
---|
[2296316] | 2870 | flag = False |
---|
[1b1bbf9] | 2871 | else: |
---|
| 2872 | return |
---|
[2296316] | 2873 | # make event free |
---|
| 2874 | event.Skip() |
---|
| 2875 | # messages depending on the flag |
---|
| 2876 | if not flag: |
---|
| 2877 | msg = " Could not open ftol dialog;" |
---|
| 2878 | msg += " Check if the Scipy fit engine is selected in the menubar." |
---|
| 2879 | infor = 'warning' |
---|
| 2880 | # inform msg to wx |
---|
| 2881 | wx.PostEvent( self.parent.parent, |
---|
| 2882 | StatusEvent(status= msg, info=infor)) |
---|
| 2883 | |
---|
| 2884 | |
---|
| 2885 | def _show_ftol_dialog(self): |
---|
| 2886 | """ |
---|
| 2887 | Dialog to select ftol for Scipy |
---|
| 2888 | """ |
---|
| 2889 | from ftol_dialog import ChangeFtol |
---|
| 2890 | panel = ChangeFtol(self) |
---|
| 2891 | panel.ShowModal() |
---|
| 2892 | |
---|
[8b6f489] | 2893 | def _onModel2D(self, event): |
---|
| 2894 | """ |
---|
| 2895 | toggle view of model from 1D to 2D or 2D from 1D |
---|
| 2896 | """ |
---|
[6371c9c] | 2897 | if self.model_view.GetLabelText() == "1D Mode": |
---|
| 2898 | self.model_view.SetLabel("2D Mode") |
---|
[8b6f489] | 2899 | self.enable2D = True |
---|
[ba1f0b2] | 2900 | |
---|
[8b6f489] | 2901 | else: |
---|
[6371c9c] | 2902 | self.model_view.SetLabel("1D Mode") |
---|
[8b6f489] | 2903 | self.enable2D = False |
---|
[52cac46] | 2904 | |
---|
[ba1f0b2] | 2905 | self.set_model_param_sizer(self.model) |
---|
| 2906 | self._set_sizer_dispersion() |
---|
| 2907 | self._draw_model() |
---|
| 2908 | |
---|
| 2909 | |
---|
| 2910 | self.state.enable2D = copy.deepcopy(self.enable2D) |
---|
| 2911 | |
---|
[7609f1a] | 2912 | class BGTextCtrl(wx.TextCtrl): |
---|
| 2913 | """ |
---|
[5062bbf] | 2914 | Text control used to display outputs. |
---|
| 2915 | No editing allowed. The background is |
---|
| 2916 | grayed out. User can't select text. |
---|
[7609f1a] | 2917 | """ |
---|
| 2918 | def __init__(self, *args, **kwds): |
---|
| 2919 | wx.TextCtrl.__init__(self, *args, **kwds) |
---|
| 2920 | self.SetEditable(False) |
---|
[59b8c74] | 2921 | self.SetBackgroundColour(self.GetParent().parent.GetBackgroundColour()) |
---|
[7609f1a] | 2922 | |
---|
| 2923 | # Bind to mouse event to avoid text highlighting |
---|
| 2924 | # The event will be skipped once the call-back |
---|
| 2925 | # is called. |
---|
| 2926 | self.Bind(wx.EVT_MOUSE_EVENTS, self._click) |
---|
| 2927 | |
---|
| 2928 | def _click(self, event): |
---|
| 2929 | """ |
---|
[5062bbf] | 2930 | Prevent further handling of the mouse event |
---|
| 2931 | by not calling Skip(). |
---|
[7609f1a] | 2932 | """ |
---|
| 2933 | pass |
---|
[5062bbf] | 2934 | |
---|