Changeset 272d91e in sasview for invariantview
- Timestamp:
- Mar 1, 2010 4:45:10 PM (15 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:
- abf6771
- Parents:
- 6f59a98
- Location:
- invariantview/perspectives/invariant
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
invariantview/perspectives/invariant/__init__.py
rc128284 r272d91e 1 1 PLUGIN_ID = "Invariant plug-in 1.0" 2 from primport *2 from invariant import * -
invariantview/perspectives/invariant/invariant.py
rc128284 r272d91e 8 8 copyright 2009, University of Tennessee 9 9 """ 10 import wx 10 11 from sans.invariant import invariant 11 12 … … 63 64 self.parent = parent 64 65 #add error back to the data 65 self.parent.Bind( 66 self.parent.Bind(ERR_DATA, self._on_data_error) 66 67 from invariant_panel import InvariantPanel 67 68 self.invariant_panel = InvariantPanel(parent=self.parent) … … 188 189 else: 189 190 data = plottable 190 self.invariant_panel.set_data_name(data_name=data.name) 191 data_qmin = min (data.x) 192 data_qmax = max (data.x) 193 data_range = "[%s - %s]"%(str(data_qmin), str(data_qmax)) 194 self.invariant_panel.set_range(data_range=data_range) 195 #set an invariant calculator for the panel 196 inv = invariant.InvariantCalculator(data=data) 197 self.invariant_panel.set_invariant(inv) 191 #set the data for the panel 192 self.invariant_panel.set_data(data=data) 198 193 199 def _plot_data(self, data, name="Unknown"): 194 195 def _plot_data(self, reel_data, extra_data, name="Unknown"): 200 196 """ 201 197 Receive a data and post a NewPlotEvent to parent … … 211 207 # Create a plottable data 212 208 new_plot = Data1D(x=[], y=[], dx=None, dy=None) 213 self._plot_helper(new_plot=new_plot, data=data) 214 215 def _plot_theory(self, data=None, name="Unknown"): 209 self._plot_helper(new_plot=new_plot, 210 reel_data=reel_data, 211 extra_data=extra_data, name=name) 212 213 def _plot_theory(self, reel_data, extra_data, name="Unknown"): 216 214 """ 217 215 Receive a data and post a NewPlotEvent to parent … … 226 224 # Create a plottable data 227 225 new_plot = Theory1D(x=[], y=[], dy=None) 228 self._plot_helper(new_plot=new_plot, data=data) 229 230 def _plot_helper(self, new_plot, data): 231 """ 232 Complete information for the new plottable given a previous plottable 233 and set to plot 234 """ 235 new_plot.copy_from_datainfo(data) 236 data.clone_without_data(clone=new_plot) 226 self._plot_helper(new_plot=new_plot, 227 reel_data=reel_data, 228 extra_data=extra_data, name=name) 229 230 def _plot_helper(self, new_plot, reel_data, extra_data, name): 231 """ 232 Put value of extra_data (created data) into a new plottable 233 (new_plot) and assign value of a plotpael of the reel data to 234 the new plottable so that the new plottable is plot on the sama panel 235 of the data used for invariant. 236 """ 237 238 new_plot.copy_from_datainfo(extra_data) 239 extra_data.clone_without_data(clone=new_plot) 237 240 238 241 new_plot.name = name 239 title = self.data.name240 new_plot.xaxis( self.data._xaxis, self.data._xunit)241 new_plot.yaxis( self.data._yaxis, self.data._yunit)242 new_plot.group_id = self.data.group_id243 new_plot.id = self.data.id + name242 title = reel_data.name 243 new_plot.xaxis(reel_data._xaxis, reel_data._xunit) 244 new_plot.yaxis(reel_data._yaxis, reel_data._yunit) 245 new_plot.group_id = reel_data.group_id 246 new_plot.id = reel_data.id + name 244 247 ##post data to plot 245 248 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=title)) -
invariantview/perspectives/invariant/invariant_panel.py
rc128284 r272d91e 6 6 import wx 7 7 import sys 8 9 from sans.invariant import invariant 8 10 9 11 from sans.guiframe.utils import format_number, check_float … … 47 49 ## Flag to tell the AUI manager to put this panel in the center pane 48 50 CENTER_PANE = True 49 def __init__(self, parent, manager=None, invariant=None):51 def __init__(self, parent, data=None, manager=None): 50 52 wx.ScrolledWindow.__init__(self, parent, style= wx.FULL_REPAINT_ON_RESIZE ) 51 53 #Font size … … 53 55 #Object that receive status event 54 56 self.parent = parent 55 self.manager = manager56 self. invariant = invariant57 #plug-in using this panel 58 self._manager = manager 57 59 #Default power value 58 60 self.power_law_exponant = 4 59 # Name of the data to display60 self. data_name = ""61 #Data uses for computation 62 self._data = data 61 63 #Draw the panel 62 64 self._do_layout() … … 64 66 self.SetAutoLayout(True) 65 67 self.Layout() 68 69 def set_data(self, data): 70 """ 71 Set the data 72 """ 73 self._data = data 74 #edit the panel 75 if self._data is not None: 76 data_name = self._data.name 77 data_qmin = min (self._data.x) 78 data_qmax = max (self._data.x) 79 data_range = "[%s - %s]"%(str(data_qmin), str(data_qmax)) 80 81 self.data_name_txt.SetLabel('Data : '+str(data_name)) 82 self.data_range_value_txt.SetLabel(str(data_range)) 66 83 67 def set_invariant(self, invariant):68 """69 set the value of the invariant70 """71 self.invariant = invariant72 73 def set_range(self, data_range ="[? - ?]"):74 """75 Display the range of data76 """77 self.data_range_value_txt.SetLabel(str(data_range))78 79 def set_data_name(self, data_name=""):80 """81 set value for data82 """83 self.data_name = str(data_name)84 self.data_name_txt.SetLabel("Data : "+self.data_name)85 86 def get_data(self):87 """88 return data89 """90 return self.data91 92 84 def set_manager(self, manager): 93 85 """ 94 Define the manager of this panel95 """ 96 self. manager = manager86 set value for the manager 87 """ 88 self._manager = manager 97 89 98 90 def compute_invariant(self, event): … … 100 92 compute invariant 101 93 """ 102 #check if the panel has an invariant calculator103 if self.invariant is None:104 msg = "No invariant calculator available! Hint: Add data?"105 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop"))106 return107 94 #clear outputs textctrl 108 95 self._reset_output() … … 114 101 scale = 1 115 102 if check_float(self.background_ctl) and check_float(self.scale_ctl): 116 103 inv = invariant.InvariantCalculator(data=self._data, 104 background=float(background), 105 scale=float(scale)) 106 117 107 #Get the number of points to extrapolated 118 108 npts_low = self.npts_low_ctl.GetValue() … … 150 140 151 141 #Set the invariant calculator 152 self.invariant.set_extrapolation(range="low", npts=npts_low,142 inv.set_extrapolation(range="low", npts=npts_low, 153 143 function=function_low, power=power_low) 154 self.invariant.set_extrapolation(range="high", npts=npts_high,144 inv.set_extrapolation(range="high", npts=npts_high, 155 145 function=function_high, power=power_high) 156 146 #Compute invariant 157 147 try: 158 qstar, qstar_err = self.invariant.get_qstar_with_error()148 qstar, qstar_err = inv.get_qstar_with_error() 159 149 self.invariant_ctl.SetValue(format_number(qstar)) 160 150 self.invariant_err_ctl.SetValue(format_number(qstar)) 161 check_float(self.invariant_ctl)162 check_float(self.invariant_err_ctl)163 151 except: 164 152 msg= "Error occurs for invariant: %s"%sys.exc_value … … 167 155 #Compute qstar extrapolated to low q range 168 156 #Clear the previous extrapolated plot 169 170 157 if low_q: 171 158 try: 172 qstar_low = self.invariant.get_qstar_low()159 qstar_low = inv.get_qstar_low() 173 160 self.invariant_low_ctl.SetValue(format_number(qstar_low)) 174 check_float(self.invariant_low_ctl)175 161 #plot data 176 low_out_data, low_in_data = self.invariant.get_extra_data_low()177 theory_name_low = self.data_name+" Extra_low_Q"178 self.manager._plot_theory(data=low_out_data,179 name=theory_name_low)180 data_name_low = self.data_name+"Fitted data for low_Q"181 self.manager._plot_data(data=low_in_data,182 name=data_name_low)162 low_out_data, low_in_data = inv.get_extra_data_low() 163 self._manager._plot_theory(reel_data=self._data, 164 extra_data=low_out_data, 165 name=self._data.name+" Extra_low_Q") 166 self._manager._plot_data(reel_data=self._data, 167 extra_data=low_in_data, 168 name=self._data.name+"Fitted data for low_Q") 183 169 except: 184 170 msg= "Error occurs for low q invariant: %s"%sys.exc_value 185 wx.PostEvent(self.parent, StatusEvent(status= msg, 186 type="stop")) 171 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 187 172 if high_q: 188 173 try: 189 qstar_high = self.invariant.get_qstar_high()174 qstar_high = inv.get_qstar_high() 190 175 self.invariant_high_ctl.SetValue(format_number(qstar_high)) 191 check_float(self.invariant_high_ctl)192 176 #plot data 193 high_out_data, high_in_data = self.invariant.get_extra_data_high(q_end=Q_MAXIMUM_PLOT)194 theory_name_high = self.data_name + " Extra_high_Q"195 self.manager._plot_theory(data=high_out_data,196 name=theory_name_high)197 data_name_low = self.data_name + "Fitted data for high_Q"198 self.manager._plot_data(data=high_in_data,199 name=data_name_low)177 high_out_data, high_in_data = inv.get_extra_data_high(q_end=Q_MAXIMUM_PLOT) 178 self._manager._plot_theory(reel_data=self._data, 179 extra_data=high_out_data, 180 name=self._data.name+" Extra_high_Q") 181 self._manager._plot_data(reel_data=self._data, 182 extra_data=high_in_data, 183 name=self._data.name+"Fitted data for high_Q") 200 184 except: 201 185 msg= "Error occurs for high q invariant: %s"%sys.exc_value 202 186 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 203 187 try: 204 qstar_total, qstar_total_err = self.invariant.get_qstar_with_error(extrapolation)188 qstar_total, qstar_total_err = inv.get_qstar_with_error(extrapolation) 205 189 self.invariant_total_ctl.SetValue(format_number(qstar_total)) 206 190 self.invariant_total_err_ctl.SetValue(format_number(qstar_total)) … … 209 193 except: 210 194 msg= "Error occurs for total invariant: %s"%sys.exc_value 211 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 212 195 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 196 197 porod_const = self.porod_const_ctl.GetValue().lstrip().rstrip() 198 if porod_const == "": 199 porod_const = None 200 if not (porod_const is None): 201 if check_float(self.porod_const_ctl): 202 porod_const = float(porod_const) 203 try: 204 v, dv = inv.get_volume_fraction_with_error(contrast=contrast) 205 self.volume_ctl.SetValue(format_number(v)) 206 self.volume_err_ctl.SetValue(format_number(dv)) 207 except: 208 msg= "Error occurs for volume fraction: %s"%sys.exc_value 209 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 213 210 contrast = self.contrast_ctl.GetValue().lstrip().rstrip() 214 if not check_float(self.contrast_ctl):211 if contrast == "": 215 212 contrast = None 216 else: 217 contrast = float(contrast) 218 porod_const = self.porod_const_ctl.GetValue().lstrip().rstrip() 219 if not check_float(self.porod_const_ctl): 220 porod_const = None 221 else: 222 porod_const = float(porod_const) 223 try: 224 v, dv = self.invariant.get_volume_fraction_with_error(contrast=contrast) 225 self.volume_ctl.SetValue(format_number(v)) 226 self.volume_err_ctl.SetValue(format_number(dv)) 227 check_float(self.volume_ctl) 228 check_float(self.volume_err_ctl) 229 except: 230 msg= "Error occurs for volume fraction: %s"%sys.exc_value 231 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 232 try: 233 s, ds = self.invariant.get_surface_with_error(contrast=contrast, 234 porod_const=porod_const) 235 self.surface_ctl.SetValue(format_number(s)) 236 self.surface_err_ctl.SetValue(format_number(ds)) 237 check_float(self.surface_ctl) 238 check_float(self.surface_err_ctl) 239 except: 240 msg= "Error occurs for surface: %s"%sys.exc_value 241 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 242 213 if not (contrast is None): 214 if check_float(self.contrast_ctl): 215 contrast = float(contrast) 216 try: 217 if not (porod_const is None): 218 s, ds = inv.get_surface_with_error(contrast=contrast, 219 porod_const=porod_const) 220 self.surface_ctl.SetValue(format_number(s)) 221 self.surface_err_ctl.SetValue(format_number(ds)) 222 except: 223 msg= "Error occurs for surface: %s"%sys.exc_value 224 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 225 243 226 else: 244 227 msg= "invariant: Need float for background and scale" 245 228 wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) 246 229 return 247 248 230 249 231 def _reset_output(self): 250 232 """ … … 285 267 sizer3.SetMinSize((_STATICBOX_WIDTH, -1)) 286 268 #---------inputs---------------- 287 288 self.data_name = "" 269 data_name = "" 289 270 data_range = "[? - ?]" 290 self.data_name_txt = wx.StaticText(self, -1,"Data : "+str(self.data_name)) 271 if self._data is not None: 272 data_name = self._data.name 273 data_qmin = min (self._data.x) 274 data_qmax = max (self._data.x) 275 data_range = "[%s - %s]"%(str(data_qmin), str(data_qmax)) 276 277 self.data_name_txt = wx.StaticText(self, -1, 'Data : '+str(data_name)) 291 278 data_range_txt = wx.StaticText(self, -1, "Range : ") 292 279 self.data_range_value_txt = wx.StaticText(self, -1, str(data_range)) … … 309 296 self.porod_const_ctl.SetToolTipString(str(msg_hint)) 310 297 311 312 sizer_input.Add(self.data_name_txt, wx.LEFT, 5) 313 sizer_input.Add((20,20)) 298 sizer_input.Add(self.data_name_txt, 0, wx.LEFT, 5) 299 sizer_input.Add((10,10), 0, wx.LEFT, 5) 314 300 sizer_input.Add(data_range_txt, 0, wx.LEFT, 10) 315 301 sizer_input.Add(self.data_range_value_txt) … … 339 325 (10, 10),style=wx.RB_GROUP) 340 326 self.power_law_low = wx.RadioButton(self, -1, 'Power_law', (10, 10)) 341 #self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param,342 # id=self.guinier.GetId())343 #self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param,344 # id=self.power_law_law.GetId())345 #MAC needs SetValue346 327 self.guinier.SetValue(True) 347 328 … … 429 410 extra_enable_hint = "Hint: Check any box to enable a specific extrapolation !" 430 411 extra_enable_hint_txt= wx.StaticText(self, -1, extra_enable_hint ) 431 #enable_sizer = wx.BoxSizer(wx.HORIZONTAL)412 432 413 enable_sizer = wx.GridBagSizer(5,5) 433 #enable_sizer.Add(extra_hint_txt, 0, wx.ALL, 5) 434 #enable_sizer.Add(extra_range_value_txt, 0, wx.ALL, 5) 435 414 436 415 iy = 0 437 416 ix = 0 … … 624 603 class InvariantDialog(wx.Dialog): 625 604 def __init__(self, parent=None, id=1,graph=None, 626 data=None, title="Invariant" ):627 wx.Dialog.__init__(self, parent, id, title, size=( 605 data=None, title="Invariant",base=None): 606 wx.Dialog.__init__(self, parent, id, title, size=(PANEL_WIDTH, 628 607 PANEL_HEIGHT)) 629 self.panel = InvariantPanel(self ,invariant=None)608 self.panel = InvariantPanel(self) 630 609 self.Centre() 631 610 self.Show(True) 632 611 633 612 class InvariantWindow(wx.Frame): 634 def __init__(self, parent=None, id=1, 635 data=None, title="Invariant", ):636 637 wx.Frame.__init__(self, parent, id, title, size=( 613 def __init__(self, parent=None, id=1,graph=None, 614 data=None, title="Invariant",base=None): 615 616 wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH, 638 617 PANEL_HEIGHT)) 639 618 640 self.panel = InvariantPanel(self ,invariant=None)619 self.panel = InvariantPanel(self) 641 620 self.Centre() 642 621 self.Show(True) … … 650 629 651 630 return True 652 #wx.InitAllImageHandlers() 653 #dialog = InvariantDialog(None) 654 #if dialog.ShowModal() == wx.ID_OK: 655 # pass 656 #dialog.Destroy() 657 #return 1 658 631 659 632 # end of class MyApp 660 633
Note: See TracChangeset
for help on using the changeset viewer.