Changeset 3e41f43 in sasview for prview/perspectives/pr
- Timestamp:
- Jan 10, 2011 10:42:27 AM (14 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 3658abed
- Parents:
- d65a00a
- Location:
- prview/perspectives/pr
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
prview/perspectives/pr/explore_dialog.py
r7116b6e0 r3e41f43 68 68 69 69 # Plot area 70 self.plot = Model1D(self.x, y=y,dy=dy)70 self.plot = Model1D(self.x, y=y, dy=dy) 71 71 self.plot.name = DEFAULT_OUTPUT 72 72 … … 89 89 id = wx.NewId() 90 90 slicerpop = wx.Menu() 91 slicerpop.Append(id, '&Save image', 'Save image as PNG')91 slicerpop.Append(id, '&Save image', 'Save image as PNG') 92 92 wx.EVT_MENU(self, id, self.onSaveImage) 93 93 … … 126 126 self.outputs['Oscillation parameter'] = ["Osc", "a.u.", self.osc] 127 127 self.outputs['Positive fraction'] = ["P^+", "a.u.", self.pos] 128 self.outputs['1-sigma positive fraction'] = ["P^+_{1\ \sigma}", "a.u.", self.pos_err] 128 self.outputs['1-sigma positive fraction'] = ["P^+_{1\ \sigma}", 129 "a.u.", self.pos_err] 129 130 self.outputs['Rg'] = ["R_g", "A", self.rg] 130 131 self.outputs['I(q=0)'] = ["I(q=0)", "1/A", self.iq0] … … 157 158 158 159 # Control for number of points 159 self.npts_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 160 self.npts_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 161 size=(60,20)) 160 162 # Control for the minimum value of D_max 161 self.dmin_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 163 self.dmin_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 164 size=(60,20)) 162 165 # Control for the maximum value of D_max 163 self.dmax_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 166 self.dmax_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 167 size=(60,20)) 164 168 165 169 # Output selection box for the y axis … … 167 171 168 172 # Create the plot object 169 self.plotpanel = OutputPlot(self._default_min, self._default_max, self, -1, style=wx.RAISED_BORDER) 173 self.plotpanel = OutputPlot(self._default_min, self._default_max, 174 self, -1, style=wx.RAISED_BORDER) 170 175 171 176 # Create the layout of the dialog … … 258 263 self.plotpanel.plot.y = self.results.outputs[output_type][2] 259 264 self.plotpanel.plot.name = '_nolegend_' 260 self.plotpanel.graph.yaxis("\\rm{%s}" % self.results.outputs[output_type][0], self.results.outputs[output_type][1]) 265 y_label = "\\rm{%s}" % self.results.outputs[output_type][0] 266 self.plotpanel.graph.yaxis(y_label, 267 self.results.outputs[output_type][1]) 261 268 262 269 # Redraw … … 264 271 self.plotpanel.subplot.figure.canvas.draw_idle() 265 272 else: 266 msg = "ExploreDialog: the Results object's dictionary does not contain " 267 msg += "the [%s] output type. This must be indicative of a change in the " % str(output_type) 273 msg = "ExploreDialog: the Results object's dictionary " 274 msg += "does not contain " 275 msg += "the [%s] output type. This must be indicative of " 276 msg += "a change in the " % str(output_type) 268 277 msg += "ExploreDialog code." 269 278 logging.error(msg) … … 279 288 sizer_main = wx.BoxSizer(wx.VERTICAL) 280 289 sizer_button = wx.BoxSizer(wx.HORIZONTAL) 281 sizer_params = wx.GridBagSizer(5, 5)290 sizer_params = wx.GridBagSizer(5, 5) 282 291 283 292 iy = 0 284 293 ix = 0 285 294 label_npts = wx.StaticText(self, -1, "Npts") 286 sizer_params.Add(label_npts, (iy,ix), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 295 sizer_params.Add(label_npts, (iy, ix), (1, 1), 296 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 287 297 ix += 1 288 sizer_params.Add(self.npts_ctl, (iy,ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 298 sizer_params.Add(self.npts_ctl, (iy, ix), (1, 1), 299 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 289 300 self.npts_ctl.SetValue("%g" % DEFAULT_NPTS) 290 301 self.npts_ctl.Bind(wx.EVT_KILL_FOCUS, self._recalc) … … 292 303 ix += 1 293 304 label_dmin = wx.StaticText(self, -1, "Min Distance [A]") 294 sizer_params.Add(label_dmin, (iy,ix), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 305 sizer_params.Add(label_dmin, (iy, ix), (1, 1), 306 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 295 307 ix += 1 296 sizer_params.Add(self.dmin_ctl, (iy,ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 308 sizer_params.Add(self.dmin_ctl, (iy, ix), (1, 1), 309 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 297 310 self.dmin_ctl.SetValue(str(self._default_min)) 298 311 self.dmin_ctl.Bind(wx.EVT_KILL_FOCUS, self._recalc) … … 300 313 ix += 1 301 314 label_dmax = wx.StaticText(self, -1, "Max Distance [A]") 302 sizer_params.Add(label_dmax, (iy,ix), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 315 sizer_params.Add(label_dmax, (iy, ix), (1, 1), 316 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 303 317 ix += 1 304 sizer_params.Add(self.dmax_ctl, (iy,ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 318 sizer_params.Add(self.dmax_ctl, (iy, ix), (1, 1), 319 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 305 320 self.dmax_ctl.SetValue(str(self._default_max)) 306 321 self.dmax_ctl.Bind(wx.EVT_KILL_FOCUS, self._recalc) … … 314 329 self.output_box.SetStringSelection(DEFAULT_OUTPUT) 315 330 316 output_sizer = wx.GridBagSizer(5,5) 317 output_sizer.Add(selection_msg, (0,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) 318 output_sizer.Add(self.output_box, (0,1), (1,2), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) 319 320 wx.EVT_COMBOBOX(self.output_box,-1, self._plot_output) 331 output_sizer = wx.GridBagSizer(5, 5) 332 output_sizer.Add(selection_msg, (0, 0), (1, 1), 333 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) 334 output_sizer.Add(self.output_box, (0, 1), (1, 2), 335 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) 336 337 wx.EVT_COMBOBOX(self.output_box, -1, self._plot_output) 321 338 sizer_main.Add(output_sizer, 0, wx.EXPAND | wx.ALL, 10) 322 339 323 340 sizer_main.Add(self.plotpanel, 0, wx.EXPAND | wx.ALL, 10) 324 sizer_main.SetItemMinSize(self.plotpanel, 400, 400)341 sizer_main.SetItemMinSize(self.plotpanel, 400, 400) 325 342 326 343 sizer_main.Add(sizer_params, 0, wx.EXPAND|wx.ALL, 10) … … 357 374 358 375 # Loop over d_max values 359 for i in range(content.npts): 360 d = content.dmin + i * (content.dmax - content.dmin)/(content.npts-1.0) 376 for i in range(content.npts): 377 temp = (content.dmax - content.dmin)/(content.npts - 1.0) 378 d = content.dmin + i * temp 379 361 380 self.pr_state.d_max = d 362 381 try: … … 380 399 except: 381 400 # This inversion failed, skip this D_max value 382 logging.error("ExploreDialog: inversion failed for D_max=%s\n%s" % (str(d), sys.exc_value)) 401 msg = "ExploreDialog: inversion failed " 402 msg += "for D_max=%s\n%s" % (str(d), sys.exc_value) 403 logging.error(msg) 383 404 384 405 self.results = results -
prview/perspectives/pr/inversion_panel.py
rb35d3d1 r3e41f43 12 12 from sans.guicomm.events import StatusEvent 13 13 from inversion_state import InversionState 14 from pr_widgets import PrTextCtrl, DataFileTextCtrl, OutputTextCtrl 14 from pr_widgets import PrTextCtrl 15 from pr_widgets import DataFileTextCtrl 16 from pr_widgets import OutputTextCtrl 15 17 16 18 … … 28 30 oscillation_max = 1.5 29 31 30 def __init__(self, parent, id = -1, plots = None, standalone=False, **kwargs): 31 """ 32 """ 33 ScrolledPanel.__init__(self, parent, id = id, **kwargs) 32 def __init__(self, parent, id=-1, plots=None, 33 standalone=False, **kwargs): 34 """ 35 """ 36 ScrolledPanel.__init__(self, parent, id=id, **kwargs) 34 37 self.SetupScrolling() 35 38 … … 91 94 Allow direct hooks to text boxes 92 95 """ 93 if name =='nfunc':96 if name == 'nfunc': 94 97 self.nfunc_ctl.SetValue(str(int(value))) 95 elif name =='d_max':98 elif name == 'd_max': 96 99 self.dmax_ctl.SetValue(str(value)) 97 elif name =='alpha':100 elif name == 'alpha': 98 101 self.alpha_ctl.SetValue(str(value)) 99 elif name =='chi2':102 elif name == 'chi2': 100 103 self.chi2_ctl.SetValue("%-5.2g" % value) 101 elif name =='bck':104 elif name == 'bck': 102 105 self.bck_ctl.SetValue("%-5.2g" % value) 103 elif name =='q_min':106 elif name == 'q_min': 104 107 self.qmin_ctl.SetValue("%-5.2g" % value) 105 elif name =='q_max':108 elif name == 'q_max': 106 109 self.qmax_ctl.SetValue("%-5.2g" % value) 107 elif name =='elapsed':110 elif name == 'elapsed': 108 111 self.time_ctl.SetValue("%-5.2g" % value) 109 elif name =='rg':112 elif name ==' rg': 110 113 self.rg_ctl.SetValue("%-5.2g" % value) 111 elif name =='iq0':114 elif name == 'iq0': 112 115 self.iq0_ctl.SetValue("%-5.2g" % value) 113 elif name =='oscillation':116 elif name == 'oscillation': 114 117 self.osc_ctl.SetValue("%-5.2g" % value) 115 elif name =='slit_width':118 elif name == 'slit_width': 116 119 self.swidth_ctl.SetValue("%-5.2g" % value) 117 elif name =='slit_height':120 elif name == 'slit_height': 118 121 self.sheight_ctl.SetValue("%-5.2g" % value) 119 elif name =='positive':122 elif name == 'positive': 120 123 self.pos_ctl.SetValue("%-5.2g" % value) 121 elif name =='pos_err':124 elif name == 'pos_err': 122 125 self.pos_err_ctl.SetValue("%-5.2g" % value) 123 elif name =='alpha_estimate':126 elif name == 'alpha_estimate': 124 127 self.alpha_estimate_ctl.SetToolTipString("Click to accept value.") 125 128 self.alpha_estimate_ctl.Enable(True) … … 127 130 #self.alpha_estimate_ctl.Show() 128 131 #self.label_sugg.Show() 129 elif name =='nterms_estimate':132 elif name == 'nterms_estimate': 130 133 self.nterms_estimate_ctl.SetToolTipString("Click to accept value.") 131 134 self.nterms_estimate_ctl.Enable(True) 132 135 self.nterms_estimate_ctl.SetLabel("%-g" % value) 133 elif name =='plotname':136 elif name == 'plotname': 134 137 self.plot_data.SetValue(str(value)) 135 138 self._on_pars_changed(None) 136 elif name =='datafile':139 elif name == 'datafile': 137 140 self.plot_data.SetValue(str(value)) 138 141 self._on_pars_changed(None) … … 144 147 Allow direct hooks to text boxes 145 148 """ 146 if name =='nfunc':149 if name == 'nfunc': 147 150 try: 148 151 return int(self.nfunc_ctl.GetValue()) 149 152 except: 150 153 return -1 151 elif name =='d_max':154 elif name == 'd_max': 152 155 try: 153 156 return self.dmax_ctl.GetValue() 154 157 except: 155 158 return -1.0 156 elif name =='alpha':159 elif name == 'alpha': 157 160 try: 158 161 return self.alpha_ctl.GetValue() 159 162 except: 160 163 return -1.0 161 elif name =='chi2':164 elif name == 'chi2': 162 165 try: 163 166 return float(self.chi2_ctl.GetValue()) 164 167 except: 165 168 return None 166 elif name =='bck':169 elif name == 'bck': 167 170 try: 168 171 return float(self.bck_ctl.GetValue()) 169 172 except: 170 173 return None 171 elif name =='q_min':174 elif name == 'q_min': 172 175 try: 173 176 return float(self.qmin_ctl.GetValue()) … … 179 182 except: 180 183 return 0.0 181 elif name =='elapsed':184 elif name == 'elapsed': 182 185 try: 183 186 return float(self.time_ctl.GetValue()) 184 187 except: 185 188 return None 186 elif name =='rg':189 elif name == 'rg': 187 190 try: 188 191 return float(self.rg_ctl.GetValue()) … … 194 197 except: 195 198 return None 196 elif name =='oscillation':199 elif name == 'oscillation': 197 200 try: 198 201 return float(self.osc_ctl.GetValue()) 199 202 except: 200 203 return None 201 elif name =='slit_width':204 elif name == 'slit_width': 202 205 try: 203 206 return float(self.swidth_ctl.GetValue()) … … 209 212 except: 210 213 return None 211 elif name =='pos':214 elif name == 'pos': 212 215 try: 213 216 return float(self.pos_ctl.GetValue()) 214 217 except: 215 218 return None 216 elif name =='pos_err':219 elif name == 'pos_err': 217 220 try: 218 221 return float(self.pos_err_ctl.GetValue()) 219 222 except: 220 223 return None 221 elif name =='alpha_estimate':224 elif name == 'alpha_estimate': 222 225 try: 223 226 return float(self.alpha_estimate_ctl.GetLabel()) 224 227 except: 225 228 return None 226 elif name =='nterms_estimate':229 elif name == 'nterms_estimate': 227 230 try: 228 231 return int(self.nterms_estimate_ctl.GetLabel()) 229 232 except: 230 233 return None 231 elif name =='plotname':234 elif name == 'plotname': 232 235 return self.plot_data.GetValue() 233 elif name =='datafile':236 elif name == 'datafile': 234 237 return self.plot_data.GetValue() 235 238 else: … … 244 247 # Ask the user the location of the file to write to. 245 248 path = None 246 dlg = wx.FileDialog(self, "Choose a file", self._default_save_location, "", "*.prv", wx.SAVE) 249 dlg = wx.FileDialog(self, "Choose a file", 250 self._default_save_location, "", "*.prv", wx.SAVE) 247 251 if dlg.ShowModal() == wx.ID_OK: 248 252 path = dlg.GetPath() … … 372 376 373 377 boxsizer1 = wx.StaticBoxSizer(databox, wx.VERTICAL) 374 boxsizer1.SetMinSize((self._default_width, 50))375 pars_sizer = wx.GridBagSizer(5, 5)378 boxsizer1.SetMinSize((self._default_width, 50)) 379 pars_sizer = wx.GridBagSizer(5, 5) 376 380 377 381 iy = 0 378 382 self.file_radio = wx.StaticText(self, -1, "Data:") 379 pars_sizer.Add(self.file_radio, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 383 pars_sizer.Add(self.file_radio, (iy, 0), (1, 1), 384 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 380 385 381 386 self.plot_data = DataFileTextCtrl(self, -1, size=(260,20)) 382 387 383 pars_sizer.Add(self.plot_data, (iy,1), (1,1), wx.EXPAND|wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 15) 388 pars_sizer.Add(self.plot_data, (iy, 1), (1, 1), 389 wx.EXPAND|wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 15) 384 390 385 391 self.bck_chk = wx.CheckBox(self, -1, "Estimate background level") 386 self.bck_chk.SetToolTipString("Check box to let the fit estimate the constant background level.") 392 hint_msg = "Check box to let the fit estimate " 393 hint_msg += "the constant background level." 394 self.bck_chk.SetToolTipString(hint_msg) 387 395 self.bck_chk.Bind(wx.EVT_CHECKBOX, self._on_pars_changed) 388 396 iy += 1 389 pars_sizer.Add(self.bck_chk, (iy,0), (1,2), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 397 pars_sizer.Add(self.bck_chk, (iy, 0), (1, 2), 398 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 390 399 boxsizer1.Add(pars_sizer, 0, wx.EXPAND) 391 vbox.Add(boxsizer1, (iy_vb,0), (1,1), wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE|wx.TOP, 5) 400 vbox.Add(boxsizer1, (iy_vb, 0), (1, 1), 401 wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE|wx.TOP, 5) 392 402 393 403 # ----- Add slit parameters ----- … … 395 405 sbox = wx.StaticBox(self, -1, "Slit parameters") 396 406 sboxsizer = wx.StaticBoxSizer(sbox, wx.VERTICAL) 397 sboxsizer.SetMinSize((self._default_width, 20))407 sboxsizer.SetMinSize((self._default_width, 20)) 398 408 399 sizer_slit = wx.GridBagSizer(5, 5)400 401 label_sheight = wx.StaticText(self, -1, "Height", size=(40, 20))402 label_swidth = wx.StaticText(self, -1, "Width", size=(40, 20))409 sizer_slit = wx.GridBagSizer(5, 5) 410 411 label_sheight = wx.StaticText(self, -1, "Height", size=(40, 20)) 412 label_swidth = wx.StaticText(self, -1, "Width", size=(40, 20)) 403 413 #label_sunits1 = wx.StaticText(self, -1, "[A^(-1)]") 404 414 label_sunits2 = wx.StaticText(self, -1, "[A^(-1)]", size=(55,20)) 405 self.sheight_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 406 self.swidth_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 407 self.sheight_ctl.SetToolTipString("Enter slit height in units of Q or leave blank.") 408 self.swidth_ctl.SetToolTipString("Enter slit width in units of Q or leave blank.") 415 self.sheight_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 416 size=(60,20)) 417 self.swidth_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 418 size=(60,20)) 419 hint_msg = "Enter slit height in units of Q or leave blank." 420 self.sheight_ctl.SetToolTipString(hint_msg) 421 hint_msg = "Enter slit width in units of Q or leave blank." 422 self.swidth_ctl.SetToolTipString(hint_msg) 409 423 #self.sheight_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) 410 424 #self.swidth_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) 411 425 412 426 iy = 0 413 sizer_slit.Add(label_sheight, (iy,0), (1,1), wx.LEFT|wx.EXPAND, 5) 414 sizer_slit.Add(self.sheight_ctl, (iy,1), (1,1), wx.LEFT|wx.EXPAND, 5) 415 #sizer_slit.Add(label_sunits1, (iy,2), (1,1), wx.LEFT|wx.EXPAND, 10) 416 sizer_slit.Add(label_swidth, (iy,2), (1,1), wx.LEFT|wx.EXPAND, 5) 417 sizer_slit.Add(self.swidth_ctl, (iy,3), (1,1), wx.LEFT|wx.EXPAND, 5) 418 sizer_slit.Add(label_sunits2, (iy,4), (1,1), wx.LEFT|wx.EXPAND, 5) 427 sizer_slit.Add(label_sheight, (iy, 0), (1, 1), 428 wx.LEFT|wx.EXPAND, 5) 429 sizer_slit.Add(self.sheight_ctl, (iy, 1), (1, 1), 430 wx.LEFT|wx.EXPAND, 5) 431 432 sizer_slit.Add(label_swidth, (iy, 2), (1, 1), 433 wx.LEFT|wx.EXPAND, 5) 434 sizer_slit.Add(self.swidth_ctl, (iy, 3), (1, 1), 435 wx.LEFT|wx.EXPAND, 5) 436 sizer_slit.Add(label_sunits2, (iy, 4), (1, 1), 437 wx.LEFT|wx.EXPAND, 5) 419 438 420 439 sboxsizer.Add(sizer_slit, wx.TOP, 15) 421 440 iy_vb += 1 422 vbox.Add(sboxsizer, (iy_vb,0), (1,1), wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 441 vbox.Add(sboxsizer, (iy_vb, 0), (1, 1), 442 wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 423 443 424 444 … … 426 446 qbox = wx.StaticBox(self, -1, "Q range") 427 447 qboxsizer = wx.StaticBoxSizer(qbox, wx.VERTICAL) 428 qboxsizer.SetMinSize((self._default_width, 20))429 430 sizer_q = wx.GridBagSizer(5, 5)431 432 label_qmin = wx.StaticText(self, -1, "Q min", size=(40, 20))433 label_qmax = wx.StaticText(self, -1, "Q max", size=(40, 20))448 qboxsizer.SetMinSize((self._default_width, 20)) 449 450 sizer_q = wx.GridBagSizer(5, 5) 451 452 label_qmin = wx.StaticText(self, -1, "Q min", size=(40, 20)) 453 label_qmax = wx.StaticText(self, -1, "Q max", size=(40, 20)) 434 454 #label_qunits1 = wx.StaticText(self, -1, "[A^(-1)]") 435 label_qunits2 = wx.StaticText(self, -1, "[A^(-1)]", size=(55,20)) 436 self.qmin_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 437 self.qmax_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 438 self.qmin_ctl.SetToolTipString("Select a lower bound for Q or leave blank.") 439 self.qmax_ctl.SetToolTipString("Select an upper bound for Q or leave blank.") 455 label_qunits2 = wx.StaticText(self, -1, "[A^(-1)]", size=(55, 20)) 456 self.qmin_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 457 size=(60,20)) 458 self.qmax_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 459 size=(60,20)) 460 hint_msg = "Select a lower bound for Q or leave blank." 461 self.qmin_ctl.SetToolTipString(hint_msg) 462 hint_msg = "Select an upper bound for Q or leave blank." 463 self.qmax_ctl.SetToolTipString(hint_msg) 440 464 self.qmin_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) 441 465 self.qmax_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) 442 466 443 467 iy = 0 444 sizer_q.Add(label_qmin, (iy, 0), (1,1), wx.LEFT|wx.EXPAND, 5)445 sizer_q.Add(self.qmin_ctl, (iy, 1), (1,1), wx.LEFT|wx.EXPAND, 5)468 sizer_q.Add(label_qmin, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 5) 469 sizer_q.Add(self.qmin_ctl, (iy, 1), (1, 1), wx.LEFT|wx.EXPAND, 5) 446 470 #sizer_q.Add(label_qunits1, (iy,2), (1,1), wx.LEFT|wx.EXPAND, 15) 447 sizer_q.Add(label_qmax, (iy, 2), (1,1), wx.LEFT|wx.EXPAND, 5)448 sizer_q.Add(self.qmax_ctl, (iy, 3), (1,1), wx.LEFT|wx.EXPAND, 5)449 sizer_q.Add(label_qunits2, (iy, 4), (1,1), wx.LEFT|wx.EXPAND, 5)471 sizer_q.Add(label_qmax, (iy, 2), (1, 1), wx.LEFT|wx.EXPAND, 5) 472 sizer_q.Add(self.qmax_ctl, (iy, 3), (1, 1), wx.LEFT|wx.EXPAND, 5) 473 sizer_q.Add(label_qunits2, (iy, 4), (1, 1), wx.LEFT|wx.EXPAND, 5) 450 474 qboxsizer.Add(sizer_q, wx.TOP, 15) 451 475 452 476 iy_vb += 1 453 vbox.Add(qboxsizer, (iy_vb,0), (1,1), wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 454 455 456 457 477 vbox.Add(qboxsizer, (iy_vb,0), (1,1), 478 wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 479 458 480 # ----- Parameters ----- 459 481 parsbox = wx.StaticBox(self, -1, "Parameters") … … 461 483 boxsizer2.SetMinSize((self._default_width,50)) 462 484 463 explanation = "P(r) is found by fitting a set of base functions to I(Q). " 464 explanation += "The minimization involves a regularization term to ensure " 465 explanation += "a smooth P(r). The regularization constant gives the size of that " 466 explanation += "term. The suggested value is the value above which the " 467 explanation += "output P(r) will have only one peak." 485 explanation = "P(r) is found by fitting a set of base functions" 486 explanation += " to I(Q). The minimization involves" 487 explanation += " a regularization term to ensure a smooth P(r)." 488 explanation += " The regularization constant gives the size of that " 489 explanation += "term. The suggested value is the value above which the" 490 explanation += " output P(r) will have only one peak." 468 491 label_explain = wx.StaticText(self, -1, explanation, size=(280,120)) 469 492 boxsizer2.Add(label_explain, wx.LEFT|wx.BOTTOM, 5) … … 472 495 473 496 label_nfunc = wx.StaticText(self, -1, "Number of terms") 474 label_nfunc.SetMinSize((120, 20))497 label_nfunc.SetMinSize((120, 20)) 475 498 label_alpha = wx.StaticText(self, -1, "Regularization constant") 476 499 label_dmax = wx.StaticText(self, -1, "Max distance [A]") … … 478 501 #self.label_sugg.Hide() 479 502 480 self.nfunc_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 503 self.nfunc_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 504 size=(60,20)) 481 505 self.nfunc_ctl.SetToolTipString("Number of terms in the expansion.") 482 self.alpha_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 483 self.alpha_ctl.SetToolTipString("Control parameter for the size of the regularization term.") 484 self.dmax_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60,20)) 485 self.dmax_ctl.SetToolTipString("Maximum distance between any two points in the system.") 506 self.alpha_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 507 size=(60,20)) 508 hint_msg = "Control parameter for the size of the regularization term." 509 self.alpha_ctl.SetToolTipString(hint_msg) 510 self.dmax_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, 511 size=(60,20)) 512 hint_msg = "Maximum distance between any two points in the system." 513 self.dmax_ctl.SetToolTipString(hint_msg) 486 514 id = wx.NewId() 487 515 self.alpha_estimate_ctl = wx.Button(self, id, "") … … 498 526 self.Bind(wx.EVT_BUTTON, self._on_accept_nterms, id = id) 499 527 self.nterms_estimate_ctl.Enable(False) 500 #self.nterms_estimate_ctl.SetBackgroundColour('#ffdf85') 501 #self.nterms_estimate_ctl.SetBackgroundColour(self.GetBackgroundColour()) 528 502 529 self.nterms_estimate_ctl.SetToolTipString("Waiting for estimate...") 503 530 … … 515 542 516 543 iy = 0 517 sizer_params.Add(self.label_sugg, (iy,2), (1,1), wx.LEFT, 15)544 sizer_params.Add(self.label_sugg, (iy, 2), (1, 1), wx.LEFT, 15) 518 545 iy += 1 519 sizer_params.Add(label_nfunc, (iy, 0), (1,1), wx.LEFT, 15)520 sizer_params.Add(self.nfunc_ctl, (iy, 1), (1,1), wx.RIGHT, 0)521 sizer_params.Add(self.nterms_estimate_ctl, (iy, 2), (1,1), wx.LEFT, 15)546 sizer_params.Add(label_nfunc, (iy, 0), (1, 1), wx.LEFT, 15) 547 sizer_params.Add(self.nfunc_ctl, (iy, 1), (1, 1), wx.RIGHT, 0) 548 sizer_params.Add(self.nterms_estimate_ctl, (iy, 2), (1, 1), wx.LEFT, 15) 522 549 iy += 1 523 sizer_params.Add(label_alpha, (iy, 0), (1,1), wx.LEFT, 15)524 sizer_params.Add(self.alpha_ctl, (iy, 1), (1,1), wx.RIGHT, 0)525 sizer_params.Add(self.alpha_estimate_ctl, (iy, 2), (1,1), wx.LEFT, 15)550 sizer_params.Add(label_alpha, (iy, 0), (1, 1), wx.LEFT, 15) 551 sizer_params.Add(self.alpha_ctl, (iy, 1), (1, 1), wx.RIGHT, 0) 552 sizer_params.Add(self.alpha_estimate_ctl, (iy, 2), (1, 1), wx.LEFT, 15) 526 553 iy += 1 527 sizer_params.Add(label_dmax, (iy,0), (1,1), wx.LEFT, 15) 528 sizer_params.Add(self.dmax_ctl, (iy,1), (1,1), wx.RIGHT, 0) 529 sizer_params.Add(self.distance_explorator_ctl, (iy,2), (1,1), wx.LEFT, 15) 554 sizer_params.Add(label_dmax, (iy, 0), (1, 1), wx.LEFT, 15) 555 sizer_params.Add(self.dmax_ctl, (iy, 1), (1, 1), wx.RIGHT, 0) 556 sizer_params.Add(self.distance_explorator_ctl, (iy, 2), 557 (1, 1), wx.LEFT, 15) 530 558 531 559 boxsizer2.Add(sizer_params, 0) 532 560 533 561 iy_vb += 1 534 vbox.Add(boxsizer2, (iy_vb,0), (1,1), wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 562 vbox.Add(boxsizer2, (iy_vb, 0), (1, 1), 563 wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 535 564 536 565 … … 538 567 resbox = wx.StaticBox(self, -1, "Outputs") 539 568 ressizer = wx.StaticBoxSizer(resbox, wx.VERTICAL) 540 ressizer.SetMinSize((self._default_width, 50))569 ressizer.SetMinSize((self._default_width, 50)) 541 570 542 571 label_rg = wx.StaticText(self, -1, "Rg") … … 547 576 label_bck_unit = wx.StaticText(self, -1, "[A^(-1)]") 548 577 self.rg_ctl = OutputTextCtrl(self, -1, size=(60,20)) 549 self.rg_ctl.SetToolTipString("Radius of gyration for the computed P(r).") 578 hint_msg = "Radius of gyration for the computed P(r)." 579 self.rg_ctl.SetToolTipString(hint_msg) 550 580 self.iq0_ctl = OutputTextCtrl(self, -1, size=(60,20)) 551 self.iq0_ctl.SetToolTipString("Scattering intensity at Q=0 for the computed P(r).") 581 hint_msg = "Scattering intensity at Q=0 for the computed P(r)." 582 self.iq0_ctl.SetToolTipString(hint_msg) 552 583 self.bck_ctl = OutputTextCtrl(self, -1, size=(60,20)) 553 584 self.bck_ctl.SetToolTipString("Value of estimated constant background.") … … 562 593 563 594 self.time_ctl = OutputTextCtrl(self, -1, size=(60,20)) 564 self.time_ctl.SetToolTipString("Computation time for the last inversion, in seconds.") 595 hint_msg = "Computation time for the last inversion, in seconds." 596 self.time_ctl.SetToolTipString(hint_msg) 565 597 566 598 self.chi2_ctl = OutputTextCtrl(self, -1, size=(60,20)) … … 569 601 # Oscillation parameter 570 602 self.osc_ctl = OutputTextCtrl(self, -1, size=(60,20)) 571 self.osc_ctl.SetToolTipString("Oscillation parameter. P(r) for a sphere has an oscillation parameter of 1.1.") 603 hint_msg = "Oscillation parameter. P(r) for a sphere has an " 604 hint_msg += " oscillation parameter of 1.1." 605 self.osc_ctl.SetToolTipString(hint_msg) 572 606 573 607 # Positive fraction figure of merit 574 608 self.pos_ctl = OutputTextCtrl(self, -1, size=(60,20)) 575 self.pos_ctl.SetToolTipString("Fraction of P(r) that is positive. Theoretically, P(r) is defined positive.") 609 hint_msg = "Fraction of P(r) that is positive. " 610 hint_msg += "Theoretically, P(r) is defined positive." 611 self.pos_ctl.SetToolTipString(hint_msg) 576 612 577 613 # 1-simga positive fraction figure of merit 578 614 self.pos_err_ctl = OutputTextCtrl(self, -1, size=(60,20)) 579 message = "Fraction of P(r) that is at least 1 standard deviation greater than zero.\n" 580 message += "This figure of merit tells you about the size of the P(r) errors.\n" 581 message += "If it is close to 1 and the other figures of merit are bad, consider changing " 582 message += "the maximum distance." 615 message = "Fraction of P(r) that is at least 1 standard deviation" 616 message += " greater than zero.\n" 617 message += "This figure of merit tells you about the size of the " 618 message += "P(r) errors.\n" 619 message += "If it is close to 1 and the other figures of merit are bad," 620 message += " consider changing the maximum distance." 583 621 self.pos_err_ctl.SetToolTipString(message) 584 622 585 sizer_res = wx.GridBagSizer(5, 5)623 sizer_res = wx.GridBagSizer(5, 5) 586 624 587 625 iy = 0 588 sizer_res.Add(label_rg, (iy, 0), (1,1), wx.LEFT|wx.EXPAND, 15)589 sizer_res.Add(self.rg_ctl, (iy, 1), (1,1), wx.RIGHT|wx.EXPAND, 15)590 sizer_res.Add(label_rg_unit, (iy, 2), (1,1), wx.RIGHT|wx.EXPAND, 15)626 sizer_res.Add(label_rg, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) 627 sizer_res.Add(self.rg_ctl, (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) 628 sizer_res.Add(label_rg_unit, (iy, 2), (1, 1), wx.RIGHT|wx.EXPAND, 15) 591 629 iy += 1 592 sizer_res.Add(label_iq0, (iy, 0), (1,1), wx.LEFT|wx.EXPAND, 15)593 sizer_res.Add(self.iq0_ctl, (iy, 1), (1,1), wx.RIGHT|wx.EXPAND, 15)594 sizer_res.Add(label_iq0_unit, (iy,2), (1,1), wx.RIGHT|wx.EXPAND, 15)630 sizer_res.Add(label_iq0, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) 631 sizer_res.Add(self.iq0_ctl, (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) 632 sizer_res.Add(label_iq0_unit, (iy, 2), (1, 1), wx.RIGHT|wx.EXPAND, 15) 595 633 iy += 1 596 sizer_res.Add(label_bck, (iy, 0), (1,1), wx.LEFT|wx.EXPAND, 15)597 sizer_res.Add(self.bck_ctl, (iy,1), (1,1), wx.RIGHT|wx.EXPAND, 15)598 sizer_res.Add(label_bck_unit, (iy,2), (1,1), wx.RIGHT|wx.EXPAND, 15)634 sizer_res.Add(label_bck, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) 635 sizer_res.Add(self.bck_ctl, (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) 636 sizer_res.Add(label_bck_unit, (iy, 2), (1, 1), wx.RIGHT|wx.EXPAND, 15) 599 637 iy += 1 600 sizer_res.Add(label_time, (iy, 0), (1,1), wx.LEFT|wx.EXPAND, 15)601 sizer_res.Add(self.time_ctl, (iy, 1), (1,1), wx.RIGHT|wx.EXPAND, 15)602 sizer_res.Add(label_time_unit, (iy,2), (1,1), wx.RIGHT|wx.EXPAND, 15)638 sizer_res.Add(label_time, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) 639 sizer_res.Add(self.time_ctl, (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) 640 sizer_res.Add(label_time_unit, (iy, 2), (1, 1), wx.RIGHT|wx.EXPAND, 15) 603 641 iy += 1 604 sizer_res.Add(label_chi2, (iy, 0), (1,1), wx.LEFT|wx.EXPAND, 15)605 sizer_res.Add(self.chi2_ctl, (iy, 1), (1,1), wx.RIGHT|wx.EXPAND, 15)642 sizer_res.Add(label_chi2, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) 643 sizer_res.Add(self.chi2_ctl, (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) 606 644 iy += 1 607 sizer_res.Add(label_osc, (iy, 0), (1,1), wx.LEFT|wx.EXPAND, 15)608 sizer_res.Add(self.osc_ctl, (iy, 1), (1,1), wx.RIGHT|wx.EXPAND, 15)645 sizer_res.Add(label_osc, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) 646 sizer_res.Add(self.osc_ctl, (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) 609 647 610 648 iy += 1 611 sizer_res.Add(label_pos, (iy, 0), (1,1), wx.LEFT|wx.EXPAND, 15)612 sizer_res.Add(self.pos_ctl, (iy,1), (1,1), wx.RIGHT|wx.EXPAND, 15)649 sizer_res.Add(label_pos, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) 650 sizer_res.Add(self.pos_ctl, (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) 613 651 614 652 iy += 1 615 sizer_res.Add(label_pos_err, (iy, 0), (1,1), wx.LEFT|wx.EXPAND, 15)616 sizer_res.Add(self.pos_err_ctl, (iy,1), (1,1), wx.RIGHT|wx.EXPAND, 15)653 sizer_res.Add(label_pos_err, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) 654 sizer_res.Add(self.pos_err_ctl, (iy,1), (1, 1), wx.RIGHT|wx.EXPAND, 15) 617 655 618 656 ressizer.Add(sizer_res, 0) 619 657 iy_vb += 1 620 vbox.Add(ressizer, (iy_vb,0), (1,1), wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 658 vbox.Add(ressizer, (iy_vb, 0), (1, 1), 659 wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) 621 660 622 661 # ----- Buttons ----- … … 635 674 button_Save = wx.Button(self, id, "Save") 636 675 button_Save.SetToolTipString("Save the current P(r) work to file.") 637 self.Bind(wx.EVT_BUTTON, self._save_state, id =id)676 self.Bind(wx.EVT_BUTTON, self._save_state, id=id) 638 677 639 678 sizer_button = wx.BoxSizer(wx.HORIZONTAL) … … 642 681 sizer_button.Add(button_Reset, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) 643 682 sizer_button.Add(button_OK, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) 644 #sizer_button.Add(button_Cancel, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)683 645 684 iy_vb += 1 646 vbox.Add(sizer_button, (iy_vb,0), (1,1), wx.EXPAND|wx.BOTTOM|wx.TOP|wx.RIGHT, 10) 685 vbox.Add(sizer_button, (iy_vb, 0), (1, 1), 686 wx.EXPAND|wx.BOTTOM|wx.TOP|wx.RIGHT, 10) 647 687 648 688 self.Bind(wx.EVT_TEXT_ENTER, self._on_invert) … … 661 701 except: 662 702 # No estimate or bad estimate, either do nothing 663 import sys703 #import sys 664 704 print "InversionControl._on_accept_alpha: %s" % sys.exc_value 665 705 pass … … 742 782 try: 743 783 height_str = self.sheight_ctl.GetValue() 744 if len(height_str.lstrip().rstrip()) ==0:784 if len(height_str.lstrip().rstrip()) == 0: 745 785 height = 0 746 786 else: … … 791 831 nfunc = int(self.nfunc_ctl.GetValue()) 792 832 npts = self.manager.get_npts() 793 if npts>0 and nfunc>npts: 794 message = "Number of function terms should be smaller than the number of points" 833 if npts > 0 and nfunc > npts: 834 message = "Number of function terms should be smaller " 835 message += "than the number of points" 795 836 wx.PostEvent(self.manager.parent, StatusEvent(status=message)) 796 837 raise ValueError, message … … 805 846 try: 806 847 qmin_str = self.qmin_ctl.GetValue() 807 if len(qmin_str.lstrip().rstrip()) ==0:848 if len(qmin_str.lstrip().rstrip()) == 0: 808 849 qmin = None 809 850 else: … … 819 860 try: 820 861 qmax_str = self.qmax_ctl.GetValue() 821 if len(qmax_str.lstrip().rstrip()) ==0:862 if len(qmax_str.lstrip().rstrip()) == 0: 822 863 qmax = None 823 864 else: … … 861 902 dataset = self.plot_data.GetValue() 862 903 if dataset==None or len(dataset.strip())==0: 863 message = "No data to invert. Select a data set before proceeding with P(r) inversion." 904 message = "No data to invert. Select a data set before" 905 message += " proceeding with P(r) inversion." 864 906 wx.PostEvent(self.manager.parent, StatusEvent(status=message)) 865 907 else: … … 871 913 width=width) 872 914 else: 873 message = "The P(r) form contains invalid values: please submit it again." 915 message = "The P(r) form contains invalid values: " 916 message += "please submit it again." 874 917 wx.PostEvent(self.parent, StatusEvent(status=message)) 875 918 … … 893 936 except: 894 937 # Invalid data 895 logging.error("InversionControl._change_file: %s" % sys.exc_value) 938 msg = "InversionControl._change_file: %s" % sys.exc_value 939 logging.error(msg) 896 940 897 941 class HelpDialog(wx.Dialog): … … 924 968 sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 925 969 sizer_button.Add(button_OK, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 926 #sizer_button.Add(button_Cancel, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)970 927 971 vbox.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 928 972 … … 967 1011 sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 968 1012 sizer_button.Add(button_OK, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 969 sizer_button.Add(button_Cancel, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 1013 sizer_button.Add(button_Cancel, 0, 1014 wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 970 1015 vbox.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 971 1016 -
prview/perspectives/pr/inversion_state.py
rb35d3d1 r3e41f43 11 11 12 12 13 import time, os, sys 13 import time 14 import os 15 import sys 14 16 import logging 15 import DataLoader16 17 from xml.dom.minidom import parse 17 18 from lxml import etree 18 19 import DataLoader 19 20 from DataLoader.readers.cansas_reader import Reader as CansasReader 20 21 from DataLoader.readers.cansas_reader import get_content … … 136 137 Compatible with standalone writing, or appending to an 137 138 already existing XML document. In that case, the XML document 138 is required. An optional entry node in the XML document may also be given. 139 is required. An optional entry node in the XML document 140 may also be given. 139 141 140 142 :param file: file to write to … … 188 190 for item in in_list: 189 191 element = newdoc.createElement(item[0]) 190 exec "element.appendChild(newdoc.createTextNode(str(self.%s)))" % item[1] 192 cmd = "element.appendChild(newdoc.createTextNode(str(self.%s)))" 193 exec cmd % item[1] 191 194 inputs.appendChild(element) 192 195 … … 197 200 for item in out_list: 198 201 element = newdoc.createElement(item[0]) 199 exec "element.appendChild(newdoc.createTextNode(str(self.%s)))" % item[1] 202 cmd = "element.appendChild(newdoc.createTextNode(str(self.%s)))" 203 exec cmd % item[1] 200 204 outputs.appendChild(element) 201 205 … … 226 230 """ 227 231 if file is not None: 228 raise RuntimeError, "InversionState no longer supports non-CanSAS format for P(r) files" 229 230 if node.get('version')\ 231 and node.get('version') == '1.0': 232 msg = "InversionState no longer supports non-CanSAS" 233 msg += " format for P(r) files" 234 raise RuntimeError, msg 235 236 if node.get('version') and node.get('version') == '1.0': 232 237 233 238 # Get file name … … 242 247 self.timestamp = float(entry.get('epoch')) 243 248 except: 244 logging.error("InversionState.fromXML: Could not read timestamp\n %s" % sys.exc_value) 249 msg = "InversionState.fromXML: Could not read " 250 msg += "timestamp\n %s" % sys.exc_value 251 logging.error(msg) 245 252 246 253 # Parse inversion inputs … … 251 258 if input_field is not None: 252 259 try: 253 exec 'self.%s = float(input_field.text.strip())' % item[1] 260 cmd = 'self.%s = float(input_field.text.strip())' 261 exec cmd % item[1] 254 262 except: 255 263 exec 'self.%s = None' % item[1] … … 269 277 if input_field is not None: 270 278 try: 271 exec 'self.%s = float(input_field.text.strip())' % item[1] 279 cmd = 'self.%s = float(input_field.text.strip())' 280 exec cmd % item[1] 272 281 except: 273 282 exec 'self.%s = None' % item[1] … … 292 301 # Sanity check 293 302 if not len(self.coefficients) == self.nfunc: 294 # Inconsistent number of coefficients. Don't keep the data. 295 err_msg = "InversionState.fromXML: inconsistant number of coefficients: " 296 err_msg += "%d %d" % (len(self.coefficients), self.nfunc) 303 # Inconsistent number of coefficients. 304 # Don't keep the data. 305 err_msg = "InversionState.fromXML: inconsistant " 306 err_msg += "number of coefficients: " 307 err_msg += "%d %d" % (len(self.coefficients), 308 self.nfunc) 297 309 logging.error(err_msg) 298 310 self.coefficients = None … … 328 340 # Inconsistent dimensions of the covariance matrix. 329 341 # Don't keep the data. 330 err_msg = "InversionState.fromXML: inconsistant dimensions of the covariance matrix: " 342 err_msg = "InversionState.fromXML: " 343 err_msg += "inconsistant dimensions of the " 344 err_msg += " covariance matrix: " 331 345 err_msg += "%d %d" % (len(self.covariance), self.nfunc) 332 346 logging.error(err_msg) … … 344 358 "SANSView files (*.svs)|*.svs"] 345 359 ## List of allowed extensions 346 ext =['.prv', '.PRV', '.svs', '.SVS']360 ext = ['.prv', '.PRV', '.svs', '.SVS'] 347 361 348 362 def __init__(self, call_back, cansas=True): … … 406 420 # Locate the P(r) node 407 421 try: 408 nodes = entry.xpath('ns:%s' % PRNODE_NAME, namespaces={'ns': CANSAS_NS}) 422 nodes = entry.xpath('ns:%s' % PRNODE_NAME, 423 namespaces={'ns': CANSAS_NS}) 409 424 if nodes !=[]: 410 425 # Create an empty state … … 412 427 state.fromXML(node=nodes[0]) 413 428 except: 414 logging.info("XML document does not contain P(r) information.\n %s" % sys.exc_value) 429 msg = "XML document does not contain P(r) " 430 msg += "information.\n %s" % sys.exc_value 431 logging.info(msg) 415 432 416 433 return state … … 437 454 #TODO: eventually remove the check for .xml once 438 455 # the P(r) writer/reader is truly complete. 439 if extension.lower() in self.ext or \ 440 extension.lower() == '.xml': 456 if extension.lower() in self.ext or extension.lower() == '.xml': 441 457 442 458 tree = etree.parse(path, parser=etree.ETCompatXMLParser()) 443 459 # Check the format version number 444 # Specifying the namespace will take care of the file format version 460 # Specifying the namespace will take care of the file 461 #format version 445 462 root = tree.getroot() 446 463 447 entry_list = root.xpath('/ns:SASroot/ns:SASentry', namespaces={'ns': CANSAS_NS}) 464 entry_list = root.xpath('/ns:SASroot/ns:SASentry', 465 namespaces={'ns': CANSAS_NS}) 448 466 449 467 for entry in entry_list: … … 460 478 461 479 # Return output consistent with the loader's api 462 if len(output) ==0:480 if len(output) == 0: 463 481 return None 464 elif len(output) ==1:482 elif len(output) == 1: 465 483 # Call back to post the new state 466 484 self.call_back(output[0].meta_data['prstate'], datainfo = output[0]) … … 498 516 datainfo = DataLoader.data_info.Data1D(x=[], y=[]) 499 517 elif not issubclass(datainfo.__class__, DataLoader.data_info.Data1D): 500 raise RuntimeError, "The cansas writer expects a Data1D instance: %s" % str(datainfo.__class__.__name__) 518 msg = "The cansas writer expects a Data1D " 519 msg += "instance: %s" % str(datainfo.__class__.__name__) 520 raise RuntimeError, msg 501 521 502 522 # Create basic XML document -
prview/perspectives/pr/pr.py
rb35d3d1 r3e41f43 38 38 (NewPrFileEvent, EVT_PR_FILE) = wx.lib.newevent.NewEvent() 39 39 40 41 class Plugin: 40 from sans.guiframe.plugin_base import PluginBase 41 42 class Plugin(PluginBase): 42 43 """ 43 44 """ … … 47 48 48 49 def __init__(self, standalone=True): 49 """ 50 """ 51 ## Plug-in name 52 self.sub_menu = "Pr inversion" 53 54 ## Reference to the parent window 55 self.parent = None 56 50 PluginBase.__init__(self, name="Pr inversion", standalone=standalone) 57 51 ## Simulation window manager 58 52 self.simview = None 59 60 ## List of panels for the simulation perspective (names) 61 self.perspective = [] 62 53 63 54 ## State data 64 55 self.alpha = self.DEFAULT_ALPHA … … 1288 1279 """ 1289 1280 self.control_panel._change_file(None) 1290 1291 def get_perspective(self): 1292 """ 1293 Get the list of panel names for this perspective 1294 """ 1295 return self.perspective 1296 1297 def on_perspective(self, event): 1298 """ 1299 Call back function for the perspective menu item. 1300 We notify the parent window that the perspective 1301 has changed. 1302 """ 1303 self.parent.set_perspective(self.perspective) 1304 1281 1305 1282 def post_init(self): 1306 1283 """ … … 1308 1285 [Somehow openGL needs this call] 1309 1286 """ 1310 if self.standalone ==True:1287 if self.standalone: 1311 1288 self.parent.set_perspective(self.perspective) 1312 1289
Note: See TracChangeset
for help on using the changeset viewer.