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