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