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