[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() |
---|
[2012eae] | 150 | self.btFit.Bind(wx.EVT_BUTTON, self._onFit,id= self.btFit.GetId()) |
---|
| 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 | """ |
---|
| 1017 | self.btFit.Unbind(event=wx.EVT_BUTTON, id= self.btFit.GetId()) |
---|
| 1018 | if self.btFit.GetLabel().lower() == "stop": |
---|
[f22e626] | 1019 | self.fit_started = True |
---|
[270e240] | 1020 | self.btFit.SetForegroundColour('red') |
---|
[66ff250] | 1021 | self.btFit.Bind(event=wx.EVT_BUTTON, handler=self._StopFit, |
---|
| 1022 | id=self.btFit.GetId()) |
---|
| 1023 | elif self.btFit.GetLabel().lower() == "fit": |
---|
[f22e626] | 1024 | self.fit_started = False |
---|
[e030625] | 1025 | self.btFit.SetDefault() |
---|
[270e240] | 1026 | self.btFit.SetForegroundColour('black') |
---|
[e030625] | 1027 | #self.btFit.SetBackgroundColour(self.default_bt_colour) |
---|
[66ff250] | 1028 | self.btFit.Bind(event=wx.EVT_BUTTON, handler=self._onFit, |
---|
| 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 | """ |
---|
[1ab9dc1] | 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) |
---|
| 1049 | self._on_fit_complete() |
---|
| 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 |
---|
[6747217] | 1069 | self.btFit.SetFocus() |
---|
| 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 | |
---|
| 1569 | self.panel = MaskDialog(self, data=self.data,id =-1 ) |
---|
| 1570 | self.panel.Bind(wx.EVT_CLOSE, self._draw_masked_model) |
---|
| 1571 | self.panel.ShowModal() |
---|
| 1572 | #wx.PostEvent(self.parent, event) |
---|
| 1573 | |
---|
| 1574 | def _draw_masked_model(self,event): |
---|
[f72333f] | 1575 | """ |
---|
| 1576 | Draw model image w/mask |
---|
| 1577 | """ |
---|
[51a71a3] | 1578 | event.Skip() |
---|
| 1579 | |
---|
| 1580 | is_valid_qrange = self._update_paramv_on_fit() |
---|
[247cb58] | 1581 | |
---|
[51a71a3] | 1582 | if is_valid_qrange: |
---|
[247cb58] | 1583 | # try re draw the model plot if it exists |
---|
[51a71a3] | 1584 | self._draw_model() |
---|
| 1585 | self.panel.Destroy() # frame |
---|
| 1586 | self.set_npts2fit() |
---|
[247cb58] | 1587 | elif self.model == None: |
---|
| 1588 | self.panel.Destroy() |
---|
| 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) |
---|
[882a912] | 1595 | |
---|
[6bbeacd4] | 1596 | def _set_smear(self, data): |
---|
| 1597 | """ |
---|
| 1598 | """ |
---|
| 1599 | if data is None: |
---|
| 1600 | return |
---|
[ba1f0b2] | 1601 | self.smearer = smear_selection(data, self.model) |
---|
[6bbeacd4] | 1602 | self.disable_smearer.SetValue(True) |
---|
| 1603 | if self.smearer == None: |
---|
| 1604 | self.enable_smearer.Disable() |
---|
| 1605 | else: |
---|
| 1606 | self.enable_smearer.Enable() |
---|
[f6aee42] | 1607 | |
---|
| 1608 | def _mac_sleep(self, sec=0.2): |
---|
| 1609 | """ |
---|
| 1610 | Give sleep to MAC |
---|
| 1611 | """ |
---|
| 1612 | if self.is_mac: |
---|
| 1613 | time.sleep(sec) |
---|
| 1614 | |
---|
[a5701e6] | 1615 | def get_view_mode(self): |
---|
| 1616 | """ |
---|
| 1617 | return True if the panel allow 2D or False if 1D |
---|
| 1618 | """ |
---|
| 1619 | return self.enable2D |
---|
| 1620 | |
---|
[9237df4] | 1621 | def set_data(self, data): |
---|
[882a912] | 1622 | """ |
---|
[5062bbf] | 1623 | reset the current data |
---|
[882a912] | 1624 | """ |
---|
[6bbeacd4] | 1625 | flag = False |
---|
| 1626 | if self.data is None and data is not None: |
---|
| 1627 | self.window_name = str(data.name) |
---|
| 1628 | ## Title to appear on top of the window |
---|
| 1629 | self.window_caption = str(data.name) |
---|
| 1630 | flag = True |
---|
[9237df4] | 1631 | self.data = data |
---|
| 1632 | if self.data is None: |
---|
| 1633 | data_min = "" |
---|
| 1634 | data_max = "" |
---|
| 1635 | data_name = "" |
---|
[982e953] | 1636 | self._set_bookmark_flag(False) |
---|
[2657df9] | 1637 | self._keep.Enable(False) |
---|
[982e953] | 1638 | self._set_save_flag(False) |
---|
[9237df4] | 1639 | else: |
---|
[1258aa3] | 1640 | if self.model != None: |
---|
| 1641 | self._set_bookmark_flag(True) |
---|
[2657df9] | 1642 | self._keep.Enable(True) |
---|
[982e953] | 1643 | self._set_save_flag(True) |
---|
[aad74b3] | 1644 | self._set_preview_flag(True) |
---|
[ba1f0b2] | 1645 | |
---|
[6bbeacd4] | 1646 | self._set_smear(data) |
---|
[7609f1a] | 1647 | # more disables for 2D |
---|
[ba1f0b2] | 1648 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 1649 | self.enable2D: |
---|
[7609f1a] | 1650 | self.slit_smearer.Disable() |
---|
[ba1f0b2] | 1651 | self.pinhole_smearer.Enable(True) |
---|
[51a71a3] | 1652 | self.default_mask = copy.deepcopy(self.data.mask) |
---|
[0f8f831] | 1653 | else: |
---|
| 1654 | self.slit_smearer.Enable(True) |
---|
| 1655 | self.pinhole_smearer.Enable(True) |
---|
[e2f0554] | 1656 | |
---|
[ffa69b6] | 1657 | self.formfactorbox.Enable() |
---|
| 1658 | self.structurebox.Enable() |
---|
[9237df4] | 1659 | data_name = self.data.name |
---|
| 1660 | #set maximum range for x in linear scale |
---|
| 1661 | if not hasattr(self.data,"data"): #Display only for 1D data fit |
---|
| 1662 | # Minimum value of data |
---|
| 1663 | data_min = min(self.data.x) |
---|
| 1664 | # Maximum value of data |
---|
| 1665 | data_max = max(self.data.x) |
---|
[51a71a3] | 1666 | #number of total data points |
---|
| 1667 | self.Npts_total.SetValue(str(len(self.data.x))) |
---|
| 1668 | #default:number of data points selected to fit |
---|
| 1669 | self.Npts_fit.SetValue(str(len(self.data.x))) |
---|
[19403da] | 1670 | self.btEditMask.Disable() |
---|
| 1671 | self.EditMask_title.Disable() |
---|
[9237df4] | 1672 | else: |
---|
[e2f0554] | 1673 | |
---|
[9237df4] | 1674 | ## Minimum value of data |
---|
| 1675 | data_min = 0 |
---|
| 1676 | x = max(math.fabs(self.data.xmin), math.fabs(self.data.xmax)) |
---|
| 1677 | y = max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) |
---|
| 1678 | ## Maximum value of data |
---|
| 1679 | data_max = math.sqrt(x*x + y*y) |
---|
[51a71a3] | 1680 | #number of total data points |
---|
| 1681 | self.Npts_total.SetValue(str(len(self.data.data))) |
---|
| 1682 | #default:number of data points selected to fit |
---|
| 1683 | self.Npts_fit.SetValue(str(len(self.data.data))) |
---|
[19403da] | 1684 | self.btEditMask.Enable() |
---|
| 1685 | self.EditMask_title.Enable() |
---|
[e9875db] | 1686 | self.Npts_total.SetEditable(False) |
---|
| 1687 | self.Npts_total.SetBackgroundColour(\ |
---|
| 1688 | self.GetParent().GetBackgroundColour()) |
---|
| 1689 | |
---|
| 1690 | self.Npts_total.Bind(wx.EVT_MOUSE_EVENTS, self._npts_click) |
---|
| 1691 | #self.Npts_total.Disable() |
---|
[9237df4] | 1692 | self.dataSource.SetValue(data_name) |
---|
| 1693 | self.qmin_x = data_min |
---|
| 1694 | self.qmax_x = data_max |
---|
[4efefc6] | 1695 | #self.minimum_q.SetValue(str(data_min)) |
---|
| 1696 | #self.maximum_q.SetValue(str(data_max)) |
---|
[f95301b] | 1697 | self.qmin.SetValue(str(data_min)) |
---|
[ffa69b6] | 1698 | self.qmax.SetValue(str(data_max)) |
---|
[f95301b] | 1699 | self.qmin.SetBackgroundColour("white") |
---|
[ffa69b6] | 1700 | self.qmax.SetBackgroundColour("white") |
---|
| 1701 | self.state.data = data |
---|
| 1702 | self.state.qmin = self.qmin_x |
---|
| 1703 | self.state.qmax = self.qmax_x |
---|
[e2f0554] | 1704 | |
---|
[6bbeacd4] | 1705 | #update model plot with new data information |
---|
| 1706 | if flag: |
---|
[e2f0554] | 1707 | #set model view button |
---|
| 1708 | if self.data.__class__.__name__ == "Data2D": |
---|
| 1709 | self.enable2D = True |
---|
| 1710 | self.model_view.SetLabel("2D Mode") |
---|
| 1711 | else: |
---|
| 1712 | self.enable2D = False |
---|
| 1713 | self.model_view.SetLabel("1D Mode") |
---|
[fa65e99] | 1714 | |
---|
[e2f0554] | 1715 | self.model_view.Disable() |
---|
[6bbeacd4] | 1716 | self._draw_model() |
---|
[e9875db] | 1717 | |
---|
| 1718 | def _npts_click(self, event): |
---|
| 1719 | """ |
---|
| 1720 | Prevent further handling of the mouse event on Npts_total |
---|
| 1721 | by not calling Skip(). |
---|
| 1722 | """ |
---|
| 1723 | pass |
---|
| 1724 | |
---|
[240b9966] | 1725 | def reset_page(self, state,first=False): |
---|
[a074145] | 1726 | """ |
---|
[5062bbf] | 1727 | reset the state |
---|
[a074145] | 1728 | """ |
---|
| 1729 | self.reset_page_helper(state) |
---|
[0b12abb5] | 1730 | #import sans.guiframe.gui_manager |
---|
| 1731 | #evt = ModelEventbox(model=state.model) |
---|
| 1732 | #wx.PostEvent(self.event_owner, evt) |
---|
[edd166b] | 1733 | |
---|
| 1734 | if self.engine_type != None: |
---|
[90a7bbd] | 1735 | self._manager._on_change_engine(engine=self.engine_type) |
---|
[7975f2b] | 1736 | |
---|
[edd166b] | 1737 | self.select_param(event = None) |
---|
| 1738 | #Save state_fit |
---|
[c985bef] | 1739 | self.save_current_state_fit() |
---|
[7975f2b] | 1740 | self._lay_out() |
---|
[c985bef] | 1741 | self.Refresh() |
---|
[edd166b] | 1742 | |
---|
[2140e68] | 1743 | def get_range(self): |
---|
| 1744 | """ |
---|
[5062bbf] | 1745 | return the fitting range |
---|
[2140e68] | 1746 | """ |
---|
[c9a4377] | 1747 | return float(self.qmin_x) , float(self.qmax_x) |
---|
[7975f2b] | 1748 | |
---|
| 1749 | def get_npts2fit(self): |
---|
| 1750 | """ |
---|
[5062bbf] | 1751 | return numbers of data points within qrange |
---|
| 1752 | |
---|
| 1753 | :Note: This is for Park where chi2 is not normalized by Npts of fit |
---|
| 1754 | |
---|
[7975f2b] | 1755 | """ |
---|
[6bbeacd4] | 1756 | if self.data is None: |
---|
| 1757 | return |
---|
[7975f2b] | 1758 | npts2fit = 0 |
---|
| 1759 | qmin,qmax = self.get_range() |
---|
[ba1f0b2] | 1760 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 1761 | self.enable2D: |
---|
[d7b7156] | 1762 | radius= numpy.sqrt( self.data.qx_data*self.data.qx_data + |
---|
| 1763 | self.data.qy_data*self.data.qy_data ) |
---|
[51a71a3] | 1764 | index_data = (self.qmin_x <= radius)&(radius<= self.qmax_x) |
---|
| 1765 | index_data= (index_data)&(self.data.mask) |
---|
| 1766 | index_data = (index_data)&(numpy.isfinite(self.data.data)) |
---|
| 1767 | npts2fit = len(self.data.data[index_data]) |
---|
[7975f2b] | 1768 | else: |
---|
| 1769 | for qx in self.data.x: |
---|
| 1770 | if qx >= qmin and qx <= qmax: |
---|
| 1771 | npts2fit += 1 |
---|
| 1772 | return npts2fit |
---|
| 1773 | |
---|
[51a71a3] | 1774 | def set_npts2fit(self): |
---|
| 1775 | """ |
---|
[5062bbf] | 1776 | setValue Npts for fitting |
---|
[51a71a3] | 1777 | """ |
---|
| 1778 | self.Npts_fit.SetValue(str(self.get_npts2fit())) |
---|
| 1779 | |
---|
[c69b6d5] | 1780 | def get_chi2(self): |
---|
| 1781 | """ |
---|
[5062bbf] | 1782 | return the current chi2 |
---|
[c69b6d5] | 1783 | """ |
---|
[2012eae] | 1784 | return self.tcChi.GetValue() |
---|
[c77d859] | 1785 | |
---|
| 1786 | def get_param_list(self): |
---|
| 1787 | """ |
---|
[5062bbf] | 1788 | :return self.param_toFit: list containing references to TextCtrl |
---|
[c77d859] | 1789 | checked.Theses TextCtrl will allow reference to parameters to fit. |
---|
[5062bbf] | 1790 | |
---|
| 1791 | :raise: if return an empty list of parameter fit will nnote work |
---|
[c77d859] | 1792 | properly so raise ValueError,"missing parameter to fit" |
---|
| 1793 | """ |
---|
| 1794 | if self.param_toFit !=[]: |
---|
| 1795 | return self.param_toFit |
---|
| 1796 | else: |
---|
[ba1f0b2] | 1797 | msg = "missing parameters to fit" |
---|
| 1798 | wx.MessageBox(msg, 'warning') |
---|
| 1799 | return False |
---|
| 1800 | #raise ValueError,"missing parameters to fit" |
---|
[c77d859] | 1801 | |
---|
[2296316] | 1802 | def onsetValues(self, chisqr, p_name, out, cov): |
---|
[c77d859] | 1803 | """ |
---|
[5062bbf] | 1804 | Build the panel from the fit result |
---|
| 1805 | |
---|
| 1806 | :param chisqr: Value of the goodness of fit metric |
---|
| 1807 | :param p_name: the name of parameters |
---|
| 1808 | :param out: list of parameter with the best value found during fitting |
---|
| 1809 | :param cov: Covariance matrix |
---|
| 1810 | |
---|
[c77d859] | 1811 | """ |
---|
[edd166b] | 1812 | if out == None or not numpy.isfinite(chisqr): |
---|
| 1813 | raise ValueError,"Fit error occured..." |
---|
| 1814 | |
---|
| 1815 | is_modified = False |
---|
[bd0a098e] | 1816 | has_error = False |
---|
| 1817 | dispersity = '' |
---|
[7975f2b] | 1818 | |
---|
| 1819 | #Hide textctrl boxes of errors. |
---|
[edd166b] | 1820 | self._clear_Err_on_Fit() |
---|
[7975f2b] | 1821 | |
---|
| 1822 | #Check if chi2 is finite |
---|
[2296316] | 1823 | if chisqr != None and numpy.isfinite(chisqr): |
---|
[e575db9] | 1824 | #format chi2 |
---|
[7609f1a] | 1825 | if self.engine_type == "park": |
---|
[e575db9] | 1826 | npt_fit = float(self.get_npts2fit()) |
---|
[7609f1a] | 1827 | if npt_fit > 0: |
---|
| 1828 | chisqr =chisqr/npt_fit |
---|
[2296316] | 1829 | chi2 = format_number(chisqr, True) |
---|
[2012eae] | 1830 | self.tcChi.SetValue(chi2) |
---|
[7975f2b] | 1831 | self.tcChi.Refresh() |
---|
| 1832 | else: |
---|
[2012eae] | 1833 | self.tcChi.SetValue("-") |
---|
[c13b8cc] | 1834 | |
---|
[edd166b] | 1835 | #Hide error title |
---|
[ce92ded] | 1836 | if self.text2_3.IsShown() and not self.is_mac: |
---|
| 1837 | self.text2_3.Hide() |
---|
[edd166b] | 1838 | |
---|
[e473e4f5] | 1839 | try: |
---|
[2296316] | 1840 | if self.enable_disp.GetValue(): |
---|
| 1841 | if hasattr(self,"text_disp_1" ): |
---|
[ce92ded] | 1842 | if self.text_disp_1 != None and not self.is_mac: |
---|
[2296316] | 1843 | self.text_disp_1.Hide() |
---|
[e473e4f5] | 1844 | except: |
---|
[bd0a098e] | 1845 | dispersity = None |
---|
[e473e4f5] | 1846 | pass |
---|
[c77d859] | 1847 | #set the panel when fit result are float not list |
---|
[c99a6c5] | 1848 | if out.__class__== numpy.float64: |
---|
[2296316] | 1849 | self.param_toFit[0][2].SetValue(format_number(out, True)) |
---|
[0a518e4c] | 1850 | |
---|
[ce92ded] | 1851 | if self.param_toFit[0][4].IsShown and not self.is_mac: |
---|
[c69b6d5] | 1852 | self.param_toFit[0][4].Hide() |
---|
[c77d859] | 1853 | if cov !=None : |
---|
| 1854 | self.text2_3.Show(True) |
---|
[e473e4f5] | 1855 | try: |
---|
[2296316] | 1856 | if self.enable_disp.GetValue(): |
---|
| 1857 | if hasattr(self,"text_disp_1" ): |
---|
| 1858 | if self.text_disp_1 !=None: |
---|
| 1859 | self.text_disp_1.Show(True) |
---|
[e473e4f5] | 1860 | except: |
---|
| 1861 | pass |
---|
[c99a6c5] | 1862 | |
---|
[ad6dd4c] | 1863 | if cov[0]==None or not numpy.isfinite(cov[0]): |
---|
[ce92ded] | 1864 | if self.param_toFit[0][3].IsShown and not self.is_mac: |
---|
[c69b6d5] | 1865 | self.param_toFit[0][3].Hide() |
---|
[7975f2b] | 1866 | else: |
---|
| 1867 | self.param_toFit[0][3].Show(True) |
---|
[69bee6d] | 1868 | self.param_toFit[0][4].Show(True) |
---|
[2296316] | 1869 | self.param_toFit[0][4].SetValue(format_number(cov[0], True)) |
---|
[ffb838f] | 1870 | has_error = True |
---|
[c77d859] | 1871 | else: |
---|
[edd166b] | 1872 | |
---|
[c69b6d5] | 1873 | i = 0 |
---|
[c77d859] | 1874 | #Set the panel when fit result are list |
---|
[ce92ded] | 1875 | for item in self.param_toFit: |
---|
[f56bf29] | 1876 | if len(item)>5 and item != None: |
---|
[edd166b] | 1877 | ## reset error value to initial state |
---|
[f56bf29] | 1878 | if not self.is_mac: |
---|
| 1879 | item[3].Hide() |
---|
| 1880 | item[4].Hide() |
---|
[7975f2b] | 1881 | |
---|
[edd166b] | 1882 | for ind in range(len(out)): |
---|
| 1883 | |
---|
[ce92ded] | 1884 | if item[1] == p_name[ind]: |
---|
[edd166b] | 1885 | break |
---|
[7975f2b] | 1886 | if len(out)<=len(self.param_toFit) and out[ind] !=None: |
---|
[ce92ded] | 1887 | val_out = format_number(out[ind], True) |
---|
| 1888 | item[2].SetValue(val_out) |
---|
[1dd00f4] | 1889 | |
---|
[c99a6c5] | 1890 | |
---|
[7975f2b] | 1891 | if(cov !=None): |
---|
[edd166b] | 1892 | |
---|
| 1893 | try: |
---|
[7975f2b] | 1894 | if dispersity !=None: |
---|
[2296316] | 1895 | if self.enable_disp.GetValue(): |
---|
[7975f2b] | 1896 | if hasattr(self,"text_disp_1" ): |
---|
| 1897 | if self.text_disp_1!=None: |
---|
[ce92ded] | 1898 | if not self.text_disp_1.IsShown()\ |
---|
| 1899 | and not self.is_mac: |
---|
[7975f2b] | 1900 | self.text_disp_1.Show(True) |
---|
[edd166b] | 1901 | except: |
---|
| 1902 | pass |
---|
| 1903 | |
---|
[7975f2b] | 1904 | if cov[ind]!=None : |
---|
| 1905 | if numpy.isfinite(float(cov[ind])): |
---|
[2296316] | 1906 | val_err = format_number(cov[ind], True) |
---|
[ce92ded] | 1907 | if not self.is_mac: |
---|
| 1908 | item[3].Show(True) |
---|
| 1909 | item[4].Show(True) |
---|
| 1910 | item[4].SetValue(val_err) |
---|
[9112910e] | 1911 | |
---|
[7975f2b] | 1912 | has_error = True |
---|
[e575db9] | 1913 | i += 1 |
---|
[c99a6c5] | 1914 | #Show error title when any errors displayed |
---|
[b421b1a] | 1915 | if has_error: |
---|
[c99a6c5] | 1916 | if not self.text2_3.IsShown(): |
---|
[86ab3f2] | 1917 | self.text2_3.Show(True) |
---|
[7975f2b] | 1918 | ## save current state |
---|
| 1919 | self.save_current_state() |
---|
[37290c4] | 1920 | |
---|
[cdb042d] | 1921 | #self._lay_out() |
---|
[3821f64] | 1922 | if not self.is_mac: |
---|
| 1923 | self.Layout() |
---|
| 1924 | self.Refresh() |
---|
[f6aee42] | 1925 | self._mac_sleep(0.1) |
---|
[37290c4] | 1926 | #plot model ( when drawing, do not update chisqr value again) |
---|
| 1927 | self._draw_model(update_chisqr=False) |
---|
[7975f2b] | 1928 | #PostStatusEvent |
---|
[12cd4ec] | 1929 | #msg = "Fit completed!dddd " |
---|
| 1930 | #wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
[c69b6d5] | 1931 | |
---|
[7609f1a] | 1932 | def onPinholeSmear(self, event): |
---|
| 1933 | """ |
---|
[5062bbf] | 1934 | Create a custom pinhole smear object that will change the way residuals |
---|
| 1935 | are compute when fitting |
---|
| 1936 | |
---|
| 1937 | :Note: accuracy is given by strings'High','Med', 'Low' FOR 2d, |
---|
| 1938 | None for 1D |
---|
| 1939 | |
---|
[7609f1a] | 1940 | """ |
---|
| 1941 | |
---|
[6bbeacd4] | 1942 | #if self.check_invalid_panel(): |
---|
| 1943 | # return |
---|
[7609f1a] | 1944 | if self.model ==None: |
---|
[4470b10] | 1945 | self.disable_smearer.SetValue(True) |
---|
| 1946 | msg="Please select a Model first..." |
---|
| 1947 | wx.MessageBox(msg, 'Info') |
---|
[90a7bbd] | 1948 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
[7609f1a] | 1949 | "Smear: %s"%msg)) |
---|
| 1950 | return |
---|
[4470b10] | 1951 | |
---|
[2d409fa] | 1952 | # Need update param values |
---|
[f72333f] | 1953 | self._update_paramv_on_fit() |
---|
| 1954 | |
---|
[7609f1a] | 1955 | # msg default |
---|
| 1956 | msg = None |
---|
| 1957 | if event != None: |
---|
| 1958 | tcrtl= event.GetEventObject() |
---|
| 1959 | # event case of radio button |
---|
| 1960 | if tcrtl.GetValue()== True: |
---|
| 1961 | self.dx_min = 0.0 |
---|
| 1962 | self.dx_max = 0.0 |
---|
| 1963 | is_new_pinhole = True |
---|
| 1964 | else: |
---|
| 1965 | is_new_pinhole = self._is_changed_pinhole() |
---|
[d493f66] | 1966 | else: |
---|
[1da28b8] | 1967 | is_new_pinhole = True |
---|
[7609f1a] | 1968 | # if any value is changed |
---|
| 1969 | if is_new_pinhole: |
---|
| 1970 | msg = self._set_pinhole_smear() |
---|
| 1971 | # hide all silt sizer |
---|
| 1972 | self._hide_all_smear_info() |
---|
[f72333f] | 1973 | |
---|
[7609f1a] | 1974 | ##Calculate chi2 |
---|
[f72333f] | 1975 | temp_smearer = self.current_smearer |
---|
| 1976 | #self.compute_chisqr(smearer= temp_smearer) |
---|
| 1977 | |
---|
[7609f1a] | 1978 | # show relevant slit sizers |
---|
| 1979 | self._show_smear_sizer() |
---|
[f72333f] | 1980 | |
---|
[7609f1a] | 1981 | self.sizer_set_smearer.Layout() |
---|
| 1982 | self.Layout() |
---|
| 1983 | |
---|
| 1984 | if event != None: |
---|
| 1985 | event.Skip() |
---|
| 1986 | #self._undo.Enable(True) |
---|
| 1987 | self.save_current_state() |
---|
| 1988 | event = PageInfoEvent(page = self) |
---|
| 1989 | wx.PostEvent(self.parent, event) |
---|
| 1990 | |
---|
| 1991 | def _is_changed_pinhole(self): |
---|
| 1992 | """ |
---|
[5062bbf] | 1993 | check if any of pinhole smear is changed |
---|
| 1994 | |
---|
| 1995 | :return: True or False |
---|
| 1996 | |
---|
[7609f1a] | 1997 | """ |
---|
| 1998 | # get the values |
---|
| 1999 | pin_min = self.smear_pinhole_min.GetValue() |
---|
| 2000 | pin_max = self.smear_pinhole_max.GetValue() |
---|
| 2001 | |
---|
| 2002 | # Check changes in slit width |
---|
| 2003 | try: |
---|
| 2004 | dx_min = float(pin_min) |
---|
| 2005 | except: |
---|
| 2006 | return True |
---|
| 2007 | if self.dx_min != dx_min: |
---|
| 2008 | return True |
---|
| 2009 | |
---|
| 2010 | # Check changes in slit heigth |
---|
| 2011 | try: |
---|
| 2012 | dx_max = float(pin_max) |
---|
| 2013 | except: |
---|
| 2014 | return True |
---|
| 2015 | if self.dx_max != dx_max: |
---|
| 2016 | return True |
---|
| 2017 | return False |
---|
| 2018 | |
---|
| 2019 | def _set_pinhole_smear(self): |
---|
| 2020 | """ |
---|
[5062bbf] | 2021 | Set custom pinhole smear |
---|
| 2022 | |
---|
| 2023 | :return: msg |
---|
| 2024 | |
---|
[7609f1a] | 2025 | """ |
---|
| 2026 | # copy data |
---|
| 2027 | data = copy.deepcopy(self.data) |
---|
[f72333f] | 2028 | if self._is_2D(): |
---|
| 2029 | self.smear_type = 'Pinhole2d' |
---|
| 2030 | len_data = len(data.data) |
---|
| 2031 | data.dqx_data = numpy.zeros(len_data) |
---|
| 2032 | data.dqy_data = numpy.zeros(len_data) |
---|
| 2033 | else: |
---|
| 2034 | self.smear_type = 'Pinhole' |
---|
| 2035 | len_data = len(data.x) |
---|
| 2036 | data.dx = numpy.zeros(len_data) |
---|
| 2037 | data.dxl = None |
---|
| 2038 | data.dxw = None |
---|
[7609f1a] | 2039 | msg = None |
---|
| 2040 | |
---|
| 2041 | get_pin_min = self.smear_pinhole_min |
---|
| 2042 | get_pin_max = self.smear_pinhole_max |
---|
| 2043 | |
---|
[f72333f] | 2044 | if not check_float(get_pin_min): |
---|
| 2045 | get_pin_min.SetBackgroundColour("pink") |
---|
| 2046 | msg= "Model Error:wrong value entered!!!" |
---|
| 2047 | elif not check_float(get_pin_max ): |
---|
| 2048 | get_pin_max.SetBackgroundColour("pink") |
---|
| 2049 | msg= "Model Error:wrong value entered!!!" |
---|
| 2050 | else: |
---|
[7609f1a] | 2051 | if len_data < 2: len_data = 2 |
---|
| 2052 | self.dx_min = float(get_pin_min.GetValue()) |
---|
| 2053 | self.dx_max = float(get_pin_max.GetValue()) |
---|
[f72333f] | 2054 | if self.dx_min < 0: |
---|
| 2055 | get_pin_min.SetBackgroundColour("pink") |
---|
| 2056 | msg= "Model Error:This value can not be negative!!!" |
---|
| 2057 | elif self.dx_max <0: |
---|
| 2058 | get_pin_max.SetBackgroundColour("pink") |
---|
| 2059 | msg= "Model Error:This value can not be negative!!!" |
---|
| 2060 | elif self.dx_min != None and self.dx_max != None: |
---|
| 2061 | if self._is_2D(): |
---|
| 2062 | data.dqx_data[data.dqx_data==0] = self.dx_min |
---|
| 2063 | data.dqy_data[data.dqy_data==0] = self.dx_max |
---|
| 2064 | elif self.dx_min == self.dx_max: |
---|
[7609f1a] | 2065 | data.dx[data.dx==0] = self.dx_min |
---|
| 2066 | else: |
---|
[f72333f] | 2067 | step = (self.dx_max - self.dx_min)/(len_data-1) |
---|
[d7b7156] | 2068 | data.dx = numpy.arange(self.dx_min,self.dx_max+step/1.1, |
---|
| 2069 | step) |
---|
[7609f1a] | 2070 | elif self.dx_min != None: |
---|
[f72333f] | 2071 | if self._is_2D(): data.dqx_data[data.dqx_data==0] = self.dx_min |
---|
| 2072 | else: data.dx[data.dx==0] = self.dx_min |
---|
[7609f1a] | 2073 | elif self.dx_max != None: |
---|
[f72333f] | 2074 | if self._is_2D(): data.dqy_data[data.dqy_data==0] = self.dx_max |
---|
| 2075 | else: data.dx[data.dx==0] = self.dx_max |
---|
[f867cd9] | 2076 | self.current_smearer = smear_selection(data, self.model) |
---|
[4fbc93e] | 2077 | # 2D need to set accuracy |
---|
| 2078 | if self._is_2D(): |
---|
[d7b7156] | 2079 | self.current_smearer.set_accuracy(accuracy = \ |
---|
| 2080 | self.smear2d_accuracy) |
---|
[7609f1a] | 2081 | |
---|
[f72333f] | 2082 | if msg != None: |
---|
[90a7bbd] | 2083 | wx.PostEvent(self._manager.parent, StatusEvent(status = msg )) |
---|
[f72333f] | 2084 | else: |
---|
| 2085 | get_pin_min.SetBackgroundColour("white") |
---|
| 2086 | get_pin_max.SetBackgroundColour("white") |
---|
[7609f1a] | 2087 | ## set smearing value whether or not the data contain the smearing info |
---|
[6bbeacd4] | 2088 | self._manager.set_smearer(smearer=self.current_smearer, |
---|
[ba1f0b2] | 2089 | enable2D=self.enable2D, |
---|
[6bbeacd4] | 2090 | qmin=float(self.qmin_x), |
---|
| 2091 | qmax= float(self.qmax_x), |
---|
[b29e47e] | 2092 | uid=self.uid) |
---|
[7609f1a] | 2093 | return msg |
---|
| 2094 | |
---|
| 2095 | def update_pinhole_smear(self): |
---|
| 2096 | """ |
---|
[5062bbf] | 2097 | called by kill_focus on pinhole TextCntrl |
---|
| 2098 | to update the changes |
---|
| 2099 | |
---|
| 2100 | :return: False when wrong value was entered |
---|
| 2101 | |
---|
[7609f1a] | 2102 | """ |
---|
| 2103 | # msg default |
---|
| 2104 | msg = None |
---|
| 2105 | # check if any value is changed |
---|
| 2106 | if self._is_changed_pinhole(): |
---|
| 2107 | msg = self._set_pinhole_smear() |
---|
| 2108 | #self._undo.Enable(True) |
---|
| 2109 | self.save_current_state() |
---|
| 2110 | |
---|
| 2111 | if msg != None: |
---|
| 2112 | return False |
---|
| 2113 | else: |
---|
| 2114 | return True |
---|
| 2115 | |
---|
| 2116 | def onSlitSmear(self, event): |
---|
| 2117 | """ |
---|
[5062bbf] | 2118 | Create a custom slit smear object that will change the way residuals |
---|
| 2119 | are compute when fitting |
---|
[7609f1a] | 2120 | """ |
---|
[4470b10] | 2121 | |
---|
[6bbeacd4] | 2122 | #if self.check_invalid_panel(): |
---|
| 2123 | # return |
---|
[4470b10] | 2124 | |
---|
[7609f1a] | 2125 | if self.model ==None: |
---|
[4470b10] | 2126 | self.disable_smearer.SetValue(True) |
---|
| 2127 | |
---|
| 2128 | msg="Please select a Model first..." |
---|
| 2129 | wx.MessageBox(msg, 'Info') |
---|
[90a7bbd] | 2130 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
[7609f1a] | 2131 | "Smear: %s"%msg)) |
---|
| 2132 | return |
---|
[4470b10] | 2133 | |
---|
[2d409fa] | 2134 | # Need update param values |
---|
| 2135 | self._update_paramv_on_fit() |
---|
[f72333f] | 2136 | |
---|
[7609f1a] | 2137 | # msg default |
---|
| 2138 | msg = None |
---|
| 2139 | # for event given |
---|
| 2140 | if event != None: |
---|
| 2141 | tcrtl= event.GetEventObject() |
---|
| 2142 | # event case of radio button |
---|
| 2143 | if tcrtl.GetValue(): |
---|
| 2144 | self.dxl = 0.0 |
---|
| 2145 | self.dxw = 0.0 |
---|
| 2146 | is_new_slit = True |
---|
| 2147 | else: |
---|
| 2148 | is_new_slit = self._is_changed_slit() |
---|
[d493f66] | 2149 | else: |
---|
[1da28b8] | 2150 | is_new_slit = True |
---|
[4470b10] | 2151 | |
---|
[7609f1a] | 2152 | # if any value is changed |
---|
| 2153 | if is_new_slit: |
---|
| 2154 | msg = self._set_slit_smear() |
---|
[4470b10] | 2155 | |
---|
[7609f1a] | 2156 | # hide all silt sizer |
---|
| 2157 | self._hide_all_smear_info() |
---|
| 2158 | ##Calculate chi2 |
---|
[f72333f] | 2159 | #self.compute_chisqr(smearer= self.current_smearer) |
---|
[7609f1a] | 2160 | # show relevant slit sizers |
---|
| 2161 | self._show_smear_sizer() |
---|
| 2162 | self.sizer_set_smearer.Layout() |
---|
| 2163 | self.Layout() |
---|
[4470b10] | 2164 | |
---|
[7609f1a] | 2165 | if event != None: |
---|
| 2166 | event.Skip() |
---|
| 2167 | #self._undo.Enable(True) |
---|
| 2168 | self.save_current_state() |
---|
| 2169 | event = PageInfoEvent(page = self) |
---|
| 2170 | wx.PostEvent(self.parent, event) |
---|
| 2171 | if msg != None: |
---|
[90a7bbd] | 2172 | wx.PostEvent(self._manager.parent, StatusEvent(status = msg)) |
---|
[7609f1a] | 2173 | |
---|
| 2174 | def _is_changed_slit(self): |
---|
| 2175 | """ |
---|
[5062bbf] | 2176 | check if any of slit lengths is changed |
---|
| 2177 | |
---|
| 2178 | :return: True or False |
---|
[4470b10] | 2179 | |
---|
[5062bbf] | 2180 | """ |
---|
[7609f1a] | 2181 | # get the values |
---|
| 2182 | width = self.smear_slit_width.GetValue() |
---|
| 2183 | height = self.smear_slit_height.GetValue() |
---|
| 2184 | |
---|
[d7b7156] | 2185 | # check and change the box bg color if it was pink |
---|
| 2186 | # but it should be white now |
---|
[7609f1a] | 2187 | # because this is the case that _set_slit_smear() will not handle |
---|
| 2188 | if height.lstrip().rstrip()=="": |
---|
| 2189 | self.smear_slit_height.SetBackgroundColour(wx.WHITE) |
---|
| 2190 | if width.lstrip().rstrip()=="": |
---|
| 2191 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
---|
| 2192 | |
---|
| 2193 | # Check changes in slit width |
---|
| 2194 | if width == "": |
---|
| 2195 | dxw = 0.0 |
---|
| 2196 | else: |
---|
| 2197 | try: |
---|
| 2198 | dxw = float(width) |
---|
| 2199 | except: |
---|
| 2200 | return True |
---|
| 2201 | if self.dxw != dxw: |
---|
| 2202 | return True |
---|
| 2203 | |
---|
| 2204 | # Check changes in slit heigth |
---|
| 2205 | if height == "": |
---|
| 2206 | dxl = 0.0 |
---|
| 2207 | else: |
---|
| 2208 | try: |
---|
| 2209 | dxl = float(height) |
---|
| 2210 | except: |
---|
| 2211 | return True |
---|
| 2212 | if self.dxl != dxl: |
---|
| 2213 | return True |
---|
[4470b10] | 2214 | |
---|
[7609f1a] | 2215 | return False |
---|
| 2216 | |
---|
| 2217 | def _set_slit_smear(self): |
---|
| 2218 | """ |
---|
[5062bbf] | 2219 | Set custom slit smear |
---|
| 2220 | |
---|
| 2221 | :return: message to inform the user about the validity |
---|
| 2222 | of the values entered for slit smear |
---|
[7609f1a] | 2223 | """ |
---|
[ba1f0b2] | 2224 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 2225 | self.enable2D: |
---|
[0b12abb5] | 2226 | return |
---|
[7609f1a] | 2227 | temp_smearer = None |
---|
| 2228 | # make sure once more if it is smearer |
---|
| 2229 | data = copy.deepcopy(self.data) |
---|
| 2230 | data_len = len(data.x) |
---|
| 2231 | data.dx = None |
---|
| 2232 | data.dxl = None |
---|
| 2233 | data.dxw = None |
---|
| 2234 | msg = None |
---|
| 2235 | |
---|
| 2236 | try: |
---|
| 2237 | self.dxl = float(self.smear_slit_height.GetValue()) |
---|
| 2238 | data.dxl = self.dxl* numpy.ones(data_len) |
---|
| 2239 | self.smear_slit_height.SetBackgroundColour(wx.WHITE) |
---|
| 2240 | except: |
---|
| 2241 | data.dxl = numpy.zeros(data_len) |
---|
| 2242 | if self.smear_slit_height.GetValue().lstrip().rstrip()!="": |
---|
| 2243 | self.smear_slit_height.SetBackgroundColour("pink") |
---|
| 2244 | msg = "Wrong value entered... " |
---|
| 2245 | else: |
---|
| 2246 | self.smear_slit_height.SetBackgroundColour(wx.WHITE) |
---|
| 2247 | try: |
---|
| 2248 | self.dxw = float(self.smear_slit_width.GetValue()) |
---|
| 2249 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
---|
| 2250 | data.dxw = self.dxw* numpy.ones(data_len) |
---|
| 2251 | except: |
---|
| 2252 | data.dxw = numpy.zeros(data_len) |
---|
| 2253 | if self.smear_slit_width.GetValue().lstrip().rstrip()!="": |
---|
| 2254 | self.smear_slit_width.SetBackgroundColour("pink") |
---|
| 2255 | msg = "Wrong Fit value entered... " |
---|
| 2256 | else: |
---|
| 2257 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
---|
[4470b10] | 2258 | |
---|
[f867cd9] | 2259 | self.current_smearer = smear_selection(data, self.model) |
---|
[7609f1a] | 2260 | #temp_smearer = self.current_smearer |
---|
| 2261 | ## set smearing value whether or not the data contain the smearing info |
---|
[6bbeacd4] | 2262 | self._manager.set_smearer(smearer=self.current_smearer, |
---|
[ba1f0b2] | 2263 | enable2D=self.enable2D, |
---|
[6bbeacd4] | 2264 | qmin=float(self.qmin_x), |
---|
| 2265 | qmax= float(self.qmax_x), |
---|
[512bbd0] | 2266 | uid=self.uid) |
---|
[7609f1a] | 2267 | return msg |
---|
| 2268 | |
---|
| 2269 | def update_slit_smear(self): |
---|
| 2270 | """ |
---|
[5062bbf] | 2271 | called by kill_focus on pinhole TextCntrl |
---|
| 2272 | to update the changes |
---|
| 2273 | |
---|
| 2274 | :return: False when wrong value was entered |
---|
| 2275 | |
---|
[7609f1a] | 2276 | """ |
---|
| 2277 | # msg default |
---|
| 2278 | msg = None |
---|
| 2279 | # check if any value is changed |
---|
| 2280 | if self._is_changed_slit(): |
---|
| 2281 | msg = self._set_slit_smear() |
---|
| 2282 | #self._undo.Enable(True) |
---|
| 2283 | self.save_current_state() |
---|
| 2284 | |
---|
| 2285 | if msg != None: |
---|
| 2286 | return False |
---|
| 2287 | else: |
---|
| 2288 | return True |
---|
| 2289 | |
---|
[c77d859] | 2290 | def onSmear(self, event): |
---|
| 2291 | """ |
---|
[5062bbf] | 2292 | Create a smear object that will change the way residuals |
---|
| 2293 | are compute when fitting |
---|
[c77d859] | 2294 | """ |
---|
[f72333f] | 2295 | if event != None: |
---|
| 2296 | event.Skip() |
---|
[6bbeacd4] | 2297 | if self.data is None: |
---|
[ffa69b6] | 2298 | return |
---|
[6bbeacd4] | 2299 | |
---|
[64bda1e] | 2300 | if self.model == None: |
---|
[4470b10] | 2301 | self.disable_smearer.SetValue(True) |
---|
| 2302 | msg="Please select a Model first..." |
---|
| 2303 | wx.MessageBox(msg, 'Info') |
---|
[90a7bbd] | 2304 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
[2a2af47] | 2305 | "Smear: %s"%msg)) |
---|
| 2306 | return |
---|
[f72333f] | 2307 | |
---|
[2d409fa] | 2308 | # Need update param values |
---|
| 2309 | self._update_paramv_on_fit() |
---|
[6bbeacd4] | 2310 | |
---|
[3370922] | 2311 | temp_smearer = None |
---|
[7609f1a] | 2312 | self._get_smear_info() |
---|
| 2313 | |
---|
| 2314 | #renew smear sizer |
---|
| 2315 | if self.smear_type != None: |
---|
| 2316 | self.smear_description_smear_type.SetValue(str(self.smear_type)) |
---|
| 2317 | self.smear_data_left.SetValue(str(self.dq_l)) |
---|
| 2318 | self.smear_data_right.SetValue(str(self.dq_r)) |
---|
[f72333f] | 2319 | |
---|
[7609f1a] | 2320 | self._hide_all_smear_info() |
---|
| 2321 | |
---|
| 2322 | data = copy.deepcopy(self.data) |
---|
| 2323 | # make sure once more if it is smearer |
---|
[f867cd9] | 2324 | self.current_smearer = smear_selection(data, self.model) |
---|
[f72333f] | 2325 | |
---|
[c77d859] | 2326 | if self.enable_smearer.GetValue(): |
---|
| 2327 | if hasattr(self.data,"dxl"): |
---|
[7609f1a] | 2328 | |
---|
[c77d859] | 2329 | msg= ": Resolution smearing parameters" |
---|
| 2330 | if hasattr(self.data,"dxw"): |
---|
| 2331 | msg= ": Slit smearing parameters" |
---|
[997131a] | 2332 | if self.smearer ==None: |
---|
[90a7bbd] | 2333 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
[c77d859] | 2334 | "Data contains no smearing information")) |
---|
| 2335 | else: |
---|
[90a7bbd] | 2336 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
[f72333f] | 2337 | "Data contains smearing information")) |
---|
| 2338 | |
---|
| 2339 | #self.smear_description_dqdata.Show(True) |
---|
[7609f1a] | 2340 | self.smear_data_left.Show(True) |
---|
| 2341 | self.smear_data_right.Show(True) |
---|
[f72333f] | 2342 | temp_smearer= self.current_smearer |
---|
[7609f1a] | 2343 | elif self.disable_smearer.GetValue(): |
---|
| 2344 | self.smear_description_none.Show(True) |
---|
| 2345 | |
---|
| 2346 | self._show_smear_sizer() |
---|
[f72333f] | 2347 | |
---|
[7609f1a] | 2348 | self.sizer_set_smearer.Layout() |
---|
| 2349 | self.Layout() |
---|
[fb8daaaf] | 2350 | ## set smearing value whether or not the data contain the smearing info |
---|
[ba1f0b2] | 2351 | self._manager.set_smearer(uid=self.uid, smearer=temp_smearer, |
---|
| 2352 | enable2D=self.enable2D, |
---|
| 2353 | qmin= float(self.qmin_x), |
---|
[6bbeacd4] | 2354 | qmax= float(self.qmax_x), draw=True) |
---|
| 2355 | |
---|
[5582a9f1] | 2356 | self.state.enable_smearer= self.enable_smearer.GetValue() |
---|
| 2357 | self.state.disable_smearer=self.disable_smearer.GetValue() |
---|
[7609f1a] | 2358 | self.state.pinhole_smearer = self.pinhole_smearer.GetValue() |
---|
| 2359 | self.state.slit_smearer = self.slit_smearer.GetValue() |
---|
[f72333f] | 2360 | |
---|
| 2361 | def on_complete_chisqr(self, event): |
---|
| 2362 | """ |
---|
[5062bbf] | 2363 | print result chisqr |
---|
| 2364 | |
---|
| 2365 | :event: activated by fitting/ complete after draw |
---|
| 2366 | |
---|
[f72333f] | 2367 | """ |
---|
| 2368 | try: |
---|
[06aa2eeb] | 2369 | if event == None: |
---|
| 2370 | output= "-" |
---|
| 2371 | elif not numpy.isfinite(event.output): |
---|
[f72333f] | 2372 | output= "-" |
---|
| 2373 | else: |
---|
| 2374 | output = event.output |
---|
[2296316] | 2375 | self.tcChi.SetValue(str(format_number(output, True))) |
---|
[f72333f] | 2376 | |
---|
[3c44c66] | 2377 | self.state.tcChi = self.tcChi.GetValue() |
---|
[f72333f] | 2378 | except: |
---|
| 2379 | pass |
---|
[c77d859] | 2380 | |
---|
[5062bbf] | 2381 | |
---|
[c77d859] | 2382 | def select_all_param(self,event): |
---|
| 2383 | """ |
---|
[5062bbf] | 2384 | set to true or false all checkBox given the main checkbox value cb1 |
---|
[d1e0473] | 2385 | """ |
---|
[c77d859] | 2386 | self.param_toFit=[] |
---|
| 2387 | if self.parameters !=[]: |
---|
[998b6b8] | 2388 | if self.cb1.GetValue(): |
---|
[c77d859] | 2389 | for item in self.parameters: |
---|
[3fef0a8] | 2390 | ## for data2D select all to fit |
---|
[ba1f0b2] | 2391 | if self.data.__class__.__name__== "Data2D" or \ |
---|
| 2392 | self.enable2D: |
---|
[c77d859] | 2393 | item[0].SetValue(True) |
---|
| 2394 | self.param_toFit.append(item ) |
---|
[3fef0a8] | 2395 | else: |
---|
| 2396 | ## for 1D all parameters except orientation |
---|
| 2397 | if not item in self.orientation_params: |
---|
| 2398 | item[0].SetValue(True) |
---|
| 2399 | self.param_toFit.append(item ) |
---|
[b324aa9] | 2400 | #if len(self.fittable_param)>0: |
---|
| 2401 | for item in self.fittable_param: |
---|
[ba1f0b2] | 2402 | if self.data.__class__.__name__== "Data2D" or \ |
---|
| 2403 | self.enable2D: |
---|
[b324aa9] | 2404 | item[0].SetValue(True) |
---|
| 2405 | self.param_toFit.append(item ) |
---|
[2296316] | 2406 | try: |
---|
| 2407 | if len(self.values[item[1]]) > 0: |
---|
| 2408 | item[0].SetValue(False) |
---|
| 2409 | except: |
---|
| 2410 | pass |
---|
| 2411 | |
---|
[b324aa9] | 2412 | else: |
---|
| 2413 | ## for 1D all parameters except orientation |
---|
| 2414 | if not item in self.orientation_params_disp: |
---|
[3fef0a8] | 2415 | item[0].SetValue(True) |
---|
| 2416 | self.param_toFit.append(item ) |
---|
[2296316] | 2417 | try: |
---|
| 2418 | if len(self.values[item[1]]) > 0: |
---|
| 2419 | item[0].SetValue(False) |
---|
| 2420 | except: |
---|
| 2421 | pass |
---|
| 2422 | |
---|
[c77d859] | 2423 | else: |
---|
| 2424 | for item in self.parameters: |
---|
| 2425 | item[0].SetValue(False) |
---|
| 2426 | for item in self.fittable_param: |
---|
| 2427 | item[0].SetValue(False) |
---|
| 2428 | self.param_toFit=[] |
---|
[330573d] | 2429 | |
---|
[52cac46] | 2430 | self.save_current_state_fit() |
---|
[b324aa9] | 2431 | |
---|
[3595309d] | 2432 | if event !=None: |
---|
[3a37fe0] | 2433 | #self._undo.Enable(True) |
---|
[3595309d] | 2434 | ## post state to fit panel |
---|
| 2435 | event = PageInfoEvent(page = self) |
---|
| 2436 | wx.PostEvent(self.parent, event) |
---|
| 2437 | |
---|
[c77d859] | 2438 | def select_param(self,event): |
---|
| 2439 | """ |
---|
[5062bbf] | 2440 | Select TextCtrl checked for fitting purpose and stores them |
---|
| 2441 | in self.param_toFit=[] list |
---|
[c77d859] | 2442 | """ |
---|
| 2443 | self.param_toFit=[] |
---|
| 2444 | for item in self.parameters: |
---|
[edd166b] | 2445 | #Skip t ifhe angle parameters if 1D data |
---|
[ba1f0b2] | 2446 | if self.data.__class__.__name__ != "Data2D" and\ |
---|
| 2447 | not self.enable2D: |
---|
[edd166b] | 2448 | if item in self.orientation_params: |
---|
| 2449 | continue |
---|
[c77d859] | 2450 | #Select parameters to fit for list of primary parameters |
---|
[998b6b8] | 2451 | if item[0].GetValue(): |
---|
[c77d859] | 2452 | if not (item in self.param_toFit): |
---|
| 2453 | self.param_toFit.append(item ) |
---|
| 2454 | else: |
---|
| 2455 | #remove parameters from the fitting list |
---|
| 2456 | if item in self.param_toFit: |
---|
| 2457 | self.param_toFit.remove(item) |
---|
[edd166b] | 2458 | |
---|
[d7b7156] | 2459 | #Select parameters to fit for list of fittable parameters |
---|
| 2460 | # with dispersion |
---|
[c77d859] | 2461 | for item in self.fittable_param: |
---|
[edd166b] | 2462 | #Skip t ifhe angle parameters if 1D data |
---|
[ba1f0b2] | 2463 | if self.data.__class__.__name__ != "Data2D" and\ |
---|
| 2464 | not self.enable2D: |
---|
[edd166b] | 2465 | if item in self.orientation_params: |
---|
| 2466 | continue |
---|
[998b6b8] | 2467 | if item[0].GetValue(): |
---|
[c77d859] | 2468 | if not (item in self.param_toFit): |
---|
| 2469 | self.param_toFit.append(item) |
---|
| 2470 | else: |
---|
| 2471 | #remove parameters from the fitting list |
---|
| 2472 | if item in self.param_toFit: |
---|
[edd166b] | 2473 | self.param_toFit.remove(item) |
---|
| 2474 | |
---|
| 2475 | #Calculate num. of angle parameters |
---|
[ba1f0b2] | 2476 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 2477 | self.enable2D: |
---|
[edd166b] | 2478 | len_orient_para = 0 |
---|
| 2479 | else: |
---|
| 2480 | len_orient_para = len(self.orientation_params) #assume even len |
---|
| 2481 | #Total num. of angle parameters |
---|
| 2482 | if len(self.fittable_param) > 0: |
---|
| 2483 | len_orient_para *= 2 |
---|
[c77d859] | 2484 | #Set the value of checkbox that selected every checkbox or not |
---|
[d7b7156] | 2485 | if len(self.parameters)+len(self.fittable_param)-len_orient_para ==\ |
---|
| 2486 | len(self.param_toFit): |
---|
[c77d859] | 2487 | self.cb1.SetValue(True) |
---|
| 2488 | else: |
---|
| 2489 | self.cb1.SetValue(False) |
---|
[52cac46] | 2490 | self.save_current_state_fit() |
---|
[3595309d] | 2491 | if event !=None: |
---|
[3a37fe0] | 2492 | #self._undo.Enable(True) |
---|
[3595309d] | 2493 | ## post state to fit panel |
---|
| 2494 | event = PageInfoEvent(page = self) |
---|
| 2495 | wx.PostEvent(self.parent, event) |
---|
[c77d859] | 2496 | |
---|
[77e23a2] | 2497 | def set_model_param_sizer(self, model): |
---|
[c77d859] | 2498 | """ |
---|
[5062bbf] | 2499 | Build the panel from the model content |
---|
| 2500 | |
---|
| 2501 | :param model: the model selected in combo box for fitting purpose |
---|
| 2502 | |
---|
[c77d859] | 2503 | """ |
---|
| 2504 | self.sizer3.Clear(True) |
---|
| 2505 | self.parameters = [] |
---|
[fb59ed9] | 2506 | self.str_parameters = [] |
---|
[c77d859] | 2507 | self.param_toFit=[] |
---|
| 2508 | self.fittable_param=[] |
---|
| 2509 | self.fixed_param=[] |
---|
[780d095] | 2510 | self.orientation_params=[] |
---|
[60132ef] | 2511 | self.orientation_params_disp=[] |
---|
[c77d859] | 2512 | |
---|
| 2513 | if model ==None: |
---|
| 2514 | self.sizer3.Layout() |
---|
[ce92ded] | 2515 | self.SetupScrolling() |
---|
[c77d859] | 2516 | return |
---|
[707436d] | 2517 | ## the panel is drawn using the current value of the fit engine |
---|
[90a7bbd] | 2518 | if self.engine_type==None and self._manager !=None: |
---|
| 2519 | self.engine_type= self._manager._return_engine_type() |
---|
[c99a6c5] | 2520 | |
---|
[c77d859] | 2521 | box_description= wx.StaticBox(self, -1,str("Model Parameters")) |
---|
| 2522 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
| 2523 | sizer = wx.GridBagSizer(5,5) |
---|
| 2524 | ## save the current model |
---|
| 2525 | self.model = model |
---|
| 2526 | |
---|
| 2527 | keys = self.model.getParamList() |
---|
| 2528 | #list of dispersion paramaters |
---|
| 2529 | self.disp_list=self.model.getDispParamList() |
---|
[b421b1a] | 2530 | |
---|
[db08737] | 2531 | def custom_compare(a,b): |
---|
| 2532 | """ |
---|
| 2533 | Custom compare to order, first by alphabets then second by number. |
---|
| 2534 | """ |
---|
[fb59ed9] | 2535 | # number at the last digit |
---|
[db08737] | 2536 | a_last = a[len(a)-1] |
---|
| 2537 | b_last = b[len(b)-1] |
---|
[fb59ed9] | 2538 | # default |
---|
[db08737] | 2539 | num_a = None |
---|
| 2540 | num_b = None |
---|
[fb59ed9] | 2541 | # split the names |
---|
| 2542 | a2 = a.lower().split('_') |
---|
| 2543 | b2 = b.lower().split('_') |
---|
| 2544 | # check length of a2, b2 |
---|
| 2545 | len_a2 = len(a2) |
---|
| 2546 | len_b2 = len(b2) |
---|
[db08737] | 2547 | # check if it contains a int number(<10) |
---|
| 2548 | try: |
---|
| 2549 | num_a = int(a_last) |
---|
| 2550 | except: pass |
---|
| 2551 | try: |
---|
| 2552 | num_b = int(b_last) |
---|
| 2553 | except: pass |
---|
[fb59ed9] | 2554 | # Put 'scale' near the top; happens |
---|
| 2555 | # when numbered param name exists |
---|
| 2556 | if a == 'scale': |
---|
| 2557 | return -1 |
---|
[db08737] | 2558 | # both have a number |
---|
| 2559 | if num_a != None and num_b != None: |
---|
[fb59ed9] | 2560 | if num_a > num_b: return -1 |
---|
| 2561 | # same number |
---|
[db08737] | 2562 | elif num_a == num_b: |
---|
[fb59ed9] | 2563 | # different last names |
---|
| 2564 | if a2[len_a2-1] != b2[len_b2-1] and num_a != 0: |
---|
| 2565 | return -cmp(a2[len_a2-1], b2[len_b2-1]) |
---|
| 2566 | else: |
---|
| 2567 | return cmp(a, b) |
---|
| 2568 | else: return 1 |
---|
[db08737] | 2569 | # one of them has a number |
---|
[20905a0] | 2570 | elif num_a != None: return 1 |
---|
| 2571 | elif num_b != None: return -1 |
---|
[fb59ed9] | 2572 | # no numbers |
---|
[20905a0] | 2573 | else: return cmp(a.lower(), b.lower()) |
---|
[fb59ed9] | 2574 | |
---|
[20905a0] | 2575 | |
---|
[db08737] | 2576 | keys.sort(custom_compare) |
---|
[c77d859] | 2577 | |
---|
[6dc9ad8] | 2578 | iy = 0 |
---|
[c77d859] | 2579 | ix = 0 |
---|
[2f6c260] | 2580 | select_text = "Select All" |
---|
[b324aa9] | 2581 | self.cb1 = wx.CheckBox(self, -1,str(select_text), (10, 10)) |
---|
[c77d859] | 2582 | wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param) |
---|
[2f6c260] | 2583 | self.cb1.SetToolTipString("To check/uncheck all the boxes below.") |
---|
[ecfcef6] | 2584 | self.cb1.SetValue(True) |
---|
[c77d859] | 2585 | |
---|
| 2586 | sizer.Add(self.cb1,(iy, ix),(1,1),\ |
---|
[eda428b] | 2587 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
[c77d859] | 2588 | ix +=1 |
---|
[f56bf29] | 2589 | self.text2_2 = wx.StaticText(self, -1, 'Value') |
---|
[c77d859] | 2590 | sizer.Add(self.text2_2,(iy, ix),(1,1),\ |
---|
| 2591 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 2592 | ix +=2 |
---|
[f56bf29] | 2593 | self.text2_3 = wx.StaticText(self, -1, 'Error') |
---|
[c77d859] | 2594 | sizer.Add(self.text2_3,(iy, ix),(1,1),\ |
---|
| 2595 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[3821f64] | 2596 | if not self.is_mac: |
---|
| 2597 | self.text2_3.Hide() |
---|
[c77d859] | 2598 | ix +=1 |
---|
| 2599 | self.text2_min = wx.StaticText(self, -1, 'Min') |
---|
| 2600 | sizer.Add(self.text2_min,(iy, ix),(1,1),\ |
---|
| 2601 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[2296316] | 2602 | #self.text2_min.Hide() |
---|
[c77d859] | 2603 | ix +=1 |
---|
| 2604 | self.text2_max = wx.StaticText(self, -1, 'Max') |
---|
| 2605 | sizer.Add(self.text2_max,(iy, ix),(1,1),\ |
---|
| 2606 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[2296316] | 2607 | #self.text2_max.Hide() |
---|
[6fdfc8f] | 2608 | ix += 1 |
---|
| 2609 | self.text2_4 = wx.StaticText(self, -1, '[Units]') |
---|
| 2610 | sizer.Add(self.text2_4,(iy, ix),(1,1),\ |
---|
| 2611 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 2612 | self.text2_4.Hide() |
---|
[b421b1a] | 2613 | |
---|
[c77d859] | 2614 | for item in keys: |
---|
[d7b7156] | 2615 | if not item in self.disp_list and not item in \ |
---|
| 2616 | self.model.orientation_params: |
---|
[b421b1a] | 2617 | |
---|
| 2618 | ##prepare a spot to store errors |
---|
| 2619 | if not self.model.details.has_key(item): |
---|
| 2620 | self.model.details [item] = ["",None,None] |
---|
| 2621 | |
---|
[c77d859] | 2622 | iy += 1 |
---|
| 2623 | ix = 0 |
---|
[8960479] | 2624 | if (self.model.__class__ in \ |
---|
| 2625 | self.model_list_box["Multi-Functions"] or \ |
---|
| 2626 | self.temp_multi_functional)\ |
---|
| 2627 | and (item in self.model.non_fittable): |
---|
[fb59ed9] | 2628 | non_fittable_name = wx.StaticText(self, -1, item ) |
---|
| 2629 | sizer.Add(non_fittable_name,(iy, ix),(1,1),\ |
---|
| 2630 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 21) |
---|
| 2631 | ## add parameter value |
---|
| 2632 | ix += 1 |
---|
| 2633 | value= self.model.getParam(item) |
---|
| 2634 | if len(self.model.fun_list) > 0: |
---|
| 2635 | num = item.split('_')[1][5:7] |
---|
[d7b7156] | 2636 | fun_box = wx.ComboBox(self, -1,size=(100,-1), |
---|
| 2637 | style=wx.CB_READONLY, name = '%s'% item) |
---|
[fb59ed9] | 2638 | self._set_fun_box_list(fun_box) |
---|
| 2639 | fun_box.SetSelection(0) |
---|
[d7b7156] | 2640 | #self.fun_box.SetToolTipString("A function |
---|
| 2641 | # describing the interface") |
---|
[fb59ed9] | 2642 | wx.EVT_COMBOBOX(fun_box,-1, self._on_fun_box) |
---|
| 2643 | else: |
---|
[d7b7156] | 2644 | fun_box = self.ModelTextCtrl(self, -1, |
---|
| 2645 | size=(_BOX_WIDTH,20), |
---|
| 2646 | style=wx.TE_PROCESS_ENTER, name ='%s'% item) |
---|
[fb59ed9] | 2647 | fun_box.SetToolTipString("Hit 'Enter' after typing.") |
---|
[2296316] | 2648 | fun_box.SetValue(format_number(value, True)) |
---|
[fb59ed9] | 2649 | sizer.Add(fun_box, (iy,ix),(1,1), wx.EXPAND) |
---|
[d7b7156] | 2650 | self.str_parameters.append([None,item, fun_box, |
---|
[2296316] | 2651 | None, None, None, |
---|
| 2652 | None, None]) |
---|
[fb59ed9] | 2653 | |
---|
| 2654 | |
---|
[7975f2b] | 2655 | else: |
---|
[fb59ed9] | 2656 | ## add parameters name with checkbox for selecting to fit |
---|
| 2657 | cb = wx.CheckBox(self, -1, item ) |
---|
[2296316] | 2658 | cb.SetToolTipString(" Check mark to fit.") |
---|
[fb59ed9] | 2659 | #cb.SetValue(True) |
---|
| 2660 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
[dcf29d7] | 2661 | |
---|
[fb59ed9] | 2662 | sizer.Add( cb,( iy, ix),(1,1), |
---|
| 2663 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
| 2664 | |
---|
| 2665 | ## add parameter value |
---|
| 2666 | ix += 1 |
---|
| 2667 | value= self.model.getParam(item) |
---|
| 2668 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
| 2669 | style=wx.TE_PROCESS_ENTER) |
---|
| 2670 | ctl1.SetToolTipString("Hit 'Enter' after typing.") |
---|
[2296316] | 2671 | ctl1.SetValue(format_number(value, True)) |
---|
[fb59ed9] | 2672 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 2673 | ## text to show error sign |
---|
| 2674 | ix += 1 |
---|
| 2675 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 2676 | sizer.Add(text2,(iy, ix),(1,1),\ |
---|
| 2677 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[ce92ded] | 2678 | if not self.is_mac: |
---|
| 2679 | text2.Hide() |
---|
[fb59ed9] | 2680 | ix += 1 |
---|
[2296316] | 2681 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/1.2,20), style=0) |
---|
[d7b7156] | 2682 | sizer.Add(ctl2, (iy,ix),(1,1), |
---|
| 2683 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[ce92ded] | 2684 | if not self.is_mac: |
---|
| 2685 | ctl2.Hide() |
---|
[fb59ed9] | 2686 | |
---|
| 2687 | ix += 1 |
---|
[2296316] | 2688 | ctl3 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.9,20), |
---|
[d7b7156] | 2689 | style=wx.TE_PROCESS_ENTER, |
---|
| 2690 | text_enter_callback = self._onparamRangeEnter) |
---|
[fb59ed9] | 2691 | |
---|
[d7b7156] | 2692 | sizer.Add(ctl3, (iy,ix),(1,1), |
---|
| 2693 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[fb59ed9] | 2694 | |
---|
| 2695 | ix += 1 |
---|
[2296316] | 2696 | ctl4 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.9,20), |
---|
[d7b7156] | 2697 | style=wx.TE_PROCESS_ENTER, |
---|
| 2698 | text_enter_callback = self._onparamRangeEnter) |
---|
| 2699 | sizer.Add(ctl4, (iy,ix),(1,1), |
---|
[2296316] | 2700 | wx.EXPAND|wx.FIXED_MINSIZE, 0) |
---|
[fb59ed9] | 2701 | |
---|
| 2702 | ix +=1 |
---|
| 2703 | # Units |
---|
| 2704 | if self.model.details.has_key(item): |
---|
[d7b7156] | 2705 | units = wx.StaticText(self, -1, |
---|
| 2706 | self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
[fb59ed9] | 2707 | else: |
---|
| 2708 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
[d7b7156] | 2709 | sizer.Add(units, (iy,ix),(1,1), |
---|
| 2710 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[fb59ed9] | 2711 | |
---|
| 2712 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
| 2713 | self.parameters.append([cb,item, ctl1, |
---|
| 2714 | text2,ctl2, ctl3, ctl4,units]) |
---|
| 2715 | |
---|
[c77d859] | 2716 | iy+=1 |
---|
[d7b7156] | 2717 | sizer.Add((10,10),(iy,ix),(1,1), |
---|
| 2718 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[5af5183] | 2719 | |
---|
[f20767b] | 2720 | # type can be either Guassian or Array |
---|
[5b53a5c] | 2721 | if len(self.model.dispersion.values())>0: |
---|
| 2722 | type= self.model.dispersion.values()[0]["type"] |
---|
| 2723 | else: |
---|
| 2724 | type = "Gaussian" |
---|
[6dc9ad8] | 2725 | |
---|
| 2726 | iy += 1 |
---|
| 2727 | ix = 0 |
---|
| 2728 | #Add tile for orientational angle |
---|
| 2729 | for item in keys: |
---|
| 2730 | if item in self.model.orientation_params: |
---|
| 2731 | orient_angle = wx.StaticText(self, -1, '[For 2D only]:') |
---|
[d7b7156] | 2732 | sizer.Add(orient_angle,(iy, ix),(1,1), |
---|
| 2733 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[ba1f0b2] | 2734 | if not self.data.__class__.__name__ == "Data2D" and \ |
---|
| 2735 | not self.enable2D: |
---|
[6dc9ad8] | 2736 | orient_angle.Hide() |
---|
| 2737 | else: |
---|
| 2738 | orient_angle.Show(True) |
---|
| 2739 | break |
---|
[5b53a5c] | 2740 | |
---|
[f20767b] | 2741 | #For Gaussian only |
---|
| 2742 | if type.lower() != "array": |
---|
| 2743 | for item in self.model.orientation_params: |
---|
| 2744 | if not item in self.disp_list: |
---|
[c13b8cc] | 2745 | ##prepare a spot to store min max |
---|
| 2746 | if not self.model.details.has_key(item): |
---|
| 2747 | self.model.details [item] = ["",None,None] |
---|
| 2748 | |
---|
[f20767b] | 2749 | iy += 1 |
---|
| 2750 | ix = 0 |
---|
| 2751 | ## add parameters name with checkbox for selecting to fit |
---|
| 2752 | cb = wx.CheckBox(self, -1, item ) |
---|
| 2753 | cb.SetValue(False) |
---|
[2296316] | 2754 | cb.SetToolTipString("Check mark to fit") |
---|
[f20767b] | 2755 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
[ba1f0b2] | 2756 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 2757 | self.enable2D: |
---|
[6dc9ad8] | 2758 | cb.Show(True) |
---|
[f20767b] | 2759 | else: |
---|
[6dc9ad8] | 2760 | cb.Hide() |
---|
[f20767b] | 2761 | sizer.Add( cb,( iy, ix),(1,1), |
---|
| 2762 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
| 2763 | |
---|
| 2764 | ## add parameter value |
---|
| 2765 | ix += 1 |
---|
| 2766 | value= self.model.getParam(item) |
---|
[7975f2b] | 2767 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
[f20767b] | 2768 | style=wx.TE_PROCESS_ENTER) |
---|
[1a94c36] | 2769 | ctl1.SetToolTipString("Hit 'Enter' after typing.") |
---|
[2296316] | 2770 | ctl1.SetValue(format_number(value, True)) |
---|
[ba1f0b2] | 2771 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 2772 | self.enable2D: |
---|
[c5cd3b9] | 2773 | ctl1.Show(True) |
---|
[f20767b] | 2774 | else: |
---|
[c5cd3b9] | 2775 | ctl1.Hide() |
---|
[f20767b] | 2776 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
| 2777 | ## text to show error sign |
---|
| 2778 | ix += 1 |
---|
| 2779 | text2=wx.StaticText(self, -1, '+/-') |
---|
| 2780 | sizer.Add(text2,(iy, ix),(1,1),\ |
---|
| 2781 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[e792aee] | 2782 | |
---|
| 2783 | text2.Hide() |
---|
[f20767b] | 2784 | ix += 1 |
---|
[2296316] | 2785 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/1.2,20), style=0) |
---|
[d7b7156] | 2786 | sizer.Add(ctl2, (iy,ix),(1,1), |
---|
| 2787 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[e792aee] | 2788 | |
---|
| 2789 | ctl2.Hide() |
---|
[e2f7b92] | 2790 | |
---|
[c99a6c5] | 2791 | |
---|
[f20767b] | 2792 | ix += 1 |
---|
[2296316] | 2793 | ctl3 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.8,20), |
---|
[d7b7156] | 2794 | style=wx.TE_PROCESS_ENTER, |
---|
| 2795 | text_enter_callback = self._onparamRangeEnter) |
---|
[b9405cd] | 2796 | |
---|
[d7b7156] | 2797 | sizer.Add(ctl3, (iy,ix),(1,1), |
---|
| 2798 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[f20767b] | 2799 | ctl3.Hide() |
---|
[b324aa9] | 2800 | |
---|
[f20767b] | 2801 | ix += 1 |
---|
[2296316] | 2802 | ctl4 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.8,20), |
---|
[d7b7156] | 2803 | style=wx.TE_PROCESS_ENTER, |
---|
| 2804 | text_enter_callback = self._onparamRangeEnter) |
---|
| 2805 | sizer.Add(ctl4, (iy,ix),(1,1), |
---|
| 2806 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[eacf1d66] | 2807 | |
---|
[f20767b] | 2808 | ctl4.Hide() |
---|
[edd166b] | 2809 | |
---|
[ba1f0b2] | 2810 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
[1180528] | 2811 | self.enable2D: |
---|
| 2812 | if self.is_mac: |
---|
| 2813 | text2.Show(True) |
---|
| 2814 | ctl2.Show(True) |
---|
[f20767b] | 2815 | ctl3.Show(True) |
---|
| 2816 | ctl4.Show(True) |
---|
[c5cd3b9] | 2817 | |
---|
[f20767b] | 2818 | ix +=1 |
---|
| 2819 | # Units |
---|
[7975f2b] | 2820 | if self.model.details.has_key(item): |
---|
[d7b7156] | 2821 | units = wx.StaticText(self, -1, |
---|
| 2822 | self.model.details[item][0], |
---|
| 2823 | style=wx.ALIGN_LEFT) |
---|
[7975f2b] | 2824 | else: |
---|
[f20767b] | 2825 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
[ba1f0b2] | 2826 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
| 2827 | self.enable2D: |
---|
[6dc9ad8] | 2828 | units.Show(True) |
---|
[c99a6c5] | 2829 | |
---|
[f20767b] | 2830 | else: |
---|
[6dc9ad8] | 2831 | units.Hide() |
---|
[c99a6c5] | 2832 | |
---|
[d7b7156] | 2833 | sizer.Add(units, (iy,ix),(1,1), |
---|
| 2834 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[7975f2b] | 2835 | |
---|
[d7b7156] | 2836 | ##[cb state, name, value, "+/-", error of fit,min,max,units] |
---|
[f20767b] | 2837 | self.parameters.append([cb,item, ctl1, |
---|
| 2838 | text2,ctl2, ctl3, ctl4,units]) |
---|
| 2839 | self.orientation_params.append([cb,item, ctl1, |
---|
| 2840 | text2,ctl2, ctl3, ctl4,units]) |
---|
[780d095] | 2841 | |
---|
| 2842 | iy+=1 |
---|
[c77d859] | 2843 | |
---|
| 2844 | #Display units text on panel |
---|
| 2845 | for item in keys: |
---|
[7975f2b] | 2846 | if self.model.details.has_key(item): |
---|
[c77d859] | 2847 | self.text2_4.Show() |
---|
[b324aa9] | 2848 | #Fill the list of fittable parameters |
---|
| 2849 | self.select_all_param(event=None) |
---|
[7975f2b] | 2850 | |
---|
[52cac46] | 2851 | self.save_current_state_fit() |
---|
[240b9966] | 2852 | boxsizer1.Add(sizer) |
---|
[c77d859] | 2853 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 2854 | self.sizer3.Layout() |
---|
[330573d] | 2855 | self.Layout() |
---|
| 2856 | self.Refresh() |
---|
[2296316] | 2857 | |
---|
| 2858 | def on_right_down(self, event): |
---|
| 2859 | """ |
---|
| 2860 | Get key stroke event |
---|
| 2861 | """ |
---|
| 2862 | if self.data == None: |
---|
| 2863 | return |
---|
| 2864 | # Figuring out key combo: Cmd for copy, Alt for paste |
---|
| 2865 | if event.AltDown() and event.ShiftDown(): |
---|
| 2866 | self._show_ftol_dialog() |
---|
| 2867 | flag = True |
---|
[1b1bbf9] | 2868 | elif event.AltDown() or event.ShiftDown(): |
---|
[2296316] | 2869 | flag = False |
---|
[1b1bbf9] | 2870 | else: |
---|
| 2871 | return |
---|
[2296316] | 2872 | # make event free |
---|
| 2873 | event.Skip() |
---|
| 2874 | # messages depending on the flag |
---|
| 2875 | if not flag: |
---|
| 2876 | msg = " Could not open ftol dialog;" |
---|
| 2877 | msg += " Check if the Scipy fit engine is selected in the menubar." |
---|
| 2878 | infor = 'warning' |
---|
| 2879 | # inform msg to wx |
---|
| 2880 | wx.PostEvent( self.parent.parent, |
---|
| 2881 | StatusEvent(status= msg, info=infor)) |
---|
| 2882 | |
---|
| 2883 | |
---|
| 2884 | def _show_ftol_dialog(self): |
---|
| 2885 | """ |
---|
| 2886 | Dialog to select ftol for Scipy |
---|
| 2887 | """ |
---|
| 2888 | from ftol_dialog import ChangeFtol |
---|
| 2889 | panel = ChangeFtol(self) |
---|
| 2890 | panel.ShowModal() |
---|
| 2891 | |
---|
[8b6f489] | 2892 | def _onModel2D(self, event): |
---|
| 2893 | """ |
---|
| 2894 | toggle view of model from 1D to 2D or 2D from 1D |
---|
| 2895 | """ |
---|
[6371c9c] | 2896 | if self.model_view.GetLabelText() == "1D Mode": |
---|
| 2897 | self.model_view.SetLabel("2D Mode") |
---|
[8b6f489] | 2898 | self.enable2D = True |
---|
[ba1f0b2] | 2899 | |
---|
[8b6f489] | 2900 | else: |
---|
[6371c9c] | 2901 | self.model_view.SetLabel("1D Mode") |
---|
[8b6f489] | 2902 | self.enable2D = False |
---|
[52cac46] | 2903 | |
---|
[ba1f0b2] | 2904 | self.set_model_param_sizer(self.model) |
---|
| 2905 | self._set_sizer_dispersion() |
---|
| 2906 | self._draw_model() |
---|
| 2907 | |
---|
| 2908 | |
---|
| 2909 | self.state.enable2D = copy.deepcopy(self.enable2D) |
---|
| 2910 | |
---|
[7609f1a] | 2911 | class BGTextCtrl(wx.TextCtrl): |
---|
| 2912 | """ |
---|
[5062bbf] | 2913 | Text control used to display outputs. |
---|
| 2914 | No editing allowed. The background is |
---|
| 2915 | grayed out. User can't select text. |
---|
[7609f1a] | 2916 | """ |
---|
| 2917 | def __init__(self, *args, **kwds): |
---|
| 2918 | wx.TextCtrl.__init__(self, *args, **kwds) |
---|
| 2919 | self.SetEditable(False) |
---|
[59b8c74] | 2920 | self.SetBackgroundColour(self.GetParent().parent.GetBackgroundColour()) |
---|
[7609f1a] | 2921 | |
---|
| 2922 | # Bind to mouse event to avoid text highlighting |
---|
| 2923 | # The event will be skipped once the call-back |
---|
| 2924 | # is called. |
---|
| 2925 | self.Bind(wx.EVT_MOUSE_EVENTS, self._click) |
---|
| 2926 | |
---|
| 2927 | def _click(self, event): |
---|
| 2928 | """ |
---|
[5062bbf] | 2929 | Prevent further handling of the mouse event |
---|
| 2930 | by not calling Skip(). |
---|
[7609f1a] | 2931 | """ |
---|
| 2932 | pass |
---|
[5062bbf] | 2933 | |
---|