Changeset be6e99a in sasview for calculatorview


Ignore:
Timestamp:
Apr 8, 2011 11:19:10 AM (13 years ago)
Author:
Jae Cho <jhjcho@…>
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:
ef73618
Parents:
cdb3a9a
Message:

fixed problems in the estimator

Location:
calculatorview
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • calculatorview/perspectives/calculator/resolution_calculator_panel.py

    rc83a5af rbe6e99a  
    3232#Slit length panel size  
    3333if sys.platform.count("win32") > 0: 
    34     PANEL_WIDTH = 535 
     34    PANEL_WIDTH = 525 
    3535    PANEL_HEIGHT = 653 
    3636    FONT_VARIANT = 0 
     
    3939    PANEL_HEIGHT = 692 
    4040    FONT_VARIANT = 1 
    41   
     41 
     42_SOURCE_MASS = {'Alpha':6.64465620E-24, 
     43                'Deuteron':3.34358320E-24, 
     44                'Neutron':1.67492729E-24,  
     45                'Photon': 0.0, 
     46                'Proton':1.67262137E-24, 
     47                'Triton':5.00826667E-24} 
     48 
    4249class ResolutionCalculatorPanel(ScrolledPanel): 
    4350    """ 
     
    7178        # Object that receive status event 
    7279        self.resolution = ResolutionCalculator() 
    73       
     80        # Source selection dic 
     81        self.source_mass = _SOURCE_MASS 
    7482        #layout attribute 
    7583        self.hint_sizer = None 
    7684        # detector coordinate of estimation of sigmas 
    77         self.det_coordinate = 'polar' 
     85        self.det_coordinate = 'cartesian' 
    7886 
    7987        self._do_layout() 
     
    116124        # get the mass 
    117125        mass_value = str(self.resolution.mass) 
    118         mass_unit_txt = wx.StaticText(self, -1, '[g]') 
    119         mass_txt = wx.StaticText(self, -1,  
    120                                 'Mass: ') 
    121         self.mass_tcl = InputTextCtrl(self, -1,  
    122                                          size=(_BOX_WIDTH,-1)) 
    123         mass_hint = "Mass of Neutrons" 
    124         self.mass_tcl.SetValue(mass_value) 
    125         self.mass_tcl.SetToolTipString(mass_hint) 
    126         self.mass_sizer.AddMany([(mass_txt, 0, wx.LEFT, 15), 
    127                                     (self.mass_tcl, 0, wx.LEFT, 15), 
    128                                     (mass_unit_txt,0, wx.LEFT, 10)])    
     126        self.mass_txt = wx.StaticText(self, -1,  
     127                                'Source: ') 
     128        self.mass_hint = "Mass of Neutrons m = %s [g]"\ 
     129                                 % str(self.resolution.mass) 
     130        self.source_cb = wx.ComboBox(self, -1, 
     131                                style=wx.CB_READONLY|wx.CB_SORT, 
     132                                name = '%s'%mass_value) 
     133        for key, value in self.source_mass.iteritems(): 
     134            name_source = str(key) 
     135            self.source_cb.Append(name_source, name_source) 
     136            self.source_cb.SetStringSelection("Neutron")  
     137        wx.EVT_COMBOBOX(self.source_cb,-1, self._on_source_selection)       
     138        source_hint = "Source Selection: Affect on" 
     139        source_hint += " the gravitational contribution.\n" 
     140        source_hint += "Mass of %s: m = %s [g]" % \ 
     141                            ('Neutron', str(self.resolution.mass)) 
     142        self.mass_txt.SetToolTipString(source_hint) 
     143        self.mass_sizer.AddMany([(self.mass_txt, 0, wx.LEFT, 15), 
     144                                    (self.source_cb, 0, wx.LEFT, 15)])    
    129145         
    130146    def _layout_intensity(self): 
     
    402418        sigma_unit = '['+'1/A' +']' 
    403419        self.sigma_r_txt = wx.StaticText(self, -1,  
    404                                            'Sigma_r:   ') 
     420                                           'Sigma_x:   ') 
    405421        self.sigma_r_tcl = OutputTextCtrl(self, -1,  
    406                                                  size=(_BOX_WIDTH,-1)) 
     422                                                 size=(_BOX_WIDTH*0.8,-1)) 
    407423        self.sigma_phi_txt = wx.StaticText(self, -1,  
    408                                            'Sigma_phi:') 
     424                                           'Sigma_y:') 
    409425        self.sigma_phi_tcl = OutputTextCtrl(self, -1,  
    410                                                  size=(_BOX_WIDTH,-1)) 
     426                                                 size=(_BOX_WIDTH*0.8,-1)) 
     427        self.sigma_lamd_txt = wx.StaticText(self, -1,  
     428                                           'Sigma_lamd:') 
     429        self.sigma_lamd_tcl = OutputTextCtrl(self, -1,  
     430                                                 size=(_BOX_WIDTH*0.7,-1)) 
    411431        sigma_1d_txt = wx.StaticText(self, -1, '( 1D:   Sigma:') 
    412432        self.sigma_1d_tcl = OutputTextCtrl(self, -1,  
    413                                                  size=(_BOX_WIDTH,-1)) 
    414         sigma_hint = " dQ_r or dQ_x, and dQ_phi or dQ_y" 
    415         sigma_hint_1d = " dQ for 1-dimension" 
    416         self.sigma_r_tcl.SetToolTipString(sigma_hint) 
    417         self.sigma_phi_tcl.SetToolTipString(sigma_hint) 
     433                                                 size=(_BOX_WIDTH*0.7,-1)) 
     434        sigmax_hint = " The x component of the geometric resolution," 
     435        sigmax_hint +=  " excluding sigma_lamda." 
     436        sigmay_hint = " The y component of the geometric resolution," 
     437        sigmay_hint +=  " excluding sigma_lamda." 
     438        sigma_hint_lamd = " The wavelength contribution in the radial direction" 
     439        sigma_hint_lamd += ".\n Note: The phi component is always zero." 
     440        sigma_hint_1d = " Resolution in 1-dimension (for 1D data)." 
     441        self.sigma_r_tcl.SetToolTipString(sigmax_hint) 
     442        self.sigma_phi_tcl.SetToolTipString(sigmay_hint) 
     443        self.sigma_lamd_tcl.SetToolTipString(sigma_hint_lamd) 
    418444        self.sigma_1d_tcl.SetToolTipString(sigma_hint_1d) 
    419445        sigma_r_unit_txt = wx.StaticText(self, -1, sigma_unit) 
    420446        sigma_phi_unit_txt = wx.StaticText(self, -1, sigma_unit) 
     447        sigma_lamd_unit_txt = wx.StaticText(self, -1, sigma_unit) 
    421448        sigma_1d_unit_txt = wx.StaticText(self, -1, sigma_unit+' )') 
    422449        outputQxy_sizer.AddMany([(self.sigma_r_txt, 0, wx.LEFT, 15), 
     
    426453                                    (self.sigma_phi_tcl, 0, wx.LEFT, 15), 
    427454                                    (sigma_phi_unit_txt, 0, wx.LEFT, 15)]) 
    428         outputQ_sizer.AddMany([(sigma_1d_txt, 0, wx.LEFT, 15), 
     455        outputQ_sizer.AddMany([(self.sigma_lamd_txt, 0, wx.LEFT, 15), 
     456                                    (self.sigma_lamd_tcl, 0, wx.LEFT, 15), 
     457                                    (sigma_lamd_unit_txt, 0, wx.LEFT, 15), 
     458                                    (sigma_1d_txt, 0, wx.LEFT, 15), 
    429459                                    (self.sigma_1d_tcl, 0, wx.LEFT, 15), 
    430460                                    (sigma_1d_unit_txt, 0, wx.LEFT, 15)]) 
     
    452482        """  
    453483        #outerbox_txt = wx.StaticText(self, -1, 'Outer Box') 
    454         self.x_y_rb = wx.RadioButton(self, -1,"Cartesian") 
    455         self.Bind(wx.EVT_RADIOBUTTON, 
    456                   self._on_xy_coordinate, id=self.x_y_rb.GetId()) 
    457         self.r_phi_rb = wx.RadioButton(self, -1,"Polar") 
    458         self.Bind(wx.EVT_RADIOBUTTON, 
    459                   self._on_rp_coordinate, id=self.r_phi_rb.GetId()) 
    460         self.r_phi_rb.SetValue(True) 
     484        #self.x_y_rb = wx.RadioButton(self, -1,"Cartesian") 
     485        #self.Bind(wx.EVT_RADIOBUTTON, 
     486        #          self._on_xy_coordinate, id=self.x_y_rb.GetId()) 
     487        #self.r_phi_rb = wx.RadioButton(self, -1,"Polar") 
     488        #self.Bind(wx.EVT_RADIOBUTTON, 
     489        #          self._on_rp_coordinate, id=self.r_phi_rb.GetId()) 
     490        #self.r_phi_rb.SetValue(True) 
    461491        #reset button 
    462492        id = wx.NewId() 
     
    475505        self.bt_close.Bind(wx.EVT_BUTTON, self.on_close) 
    476506        self.bt_close.SetToolTipString("Close this window.") 
     507        """ 
    477508        self.button_sizer.AddMany([(self.r_phi_rb,  0, wx.LEFT, 15), 
    478509                                   (self.x_y_rb,  0, wx.LEFT, 15), 
     
    480511                                   (self.compute_button, 0, wx.LEFT, 15), 
    481512                                   (self.bt_close, 0, wx.LEFT, 15)])#370)]) 
     513        """ 
     514        self.button_sizer.Add((110, -1)) 
     515        self.button_sizer.AddMany([(self.reset_button, 0, wx.LEFT, 50), 
     516                                   (self.compute_button, 0, wx.LEFT, 15), 
     517                                   (self.bt_close, 0, wx.LEFT, 15)]) 
    482518        self.compute_button.SetFocus() 
    483519         
     
    644680        wavelength = self.wavelength_tcl.GetValue() 
    645681        self.resolution.set_wavelength(float(wavelength)) 
    646         mass = self.mass_tcl.GetValue() 
     682        source = self.source_cb.GetValue() 
     683        mass = self.source_mass[str(source)] 
    647684        self.resolution.set_neutron_mass(float(mass)) 
    648685        wavelength_spread = self.wavelength_spread_tcl.GetValue() 
     
    672709        self.qy = self._string2inputlist(self.qy_tcl.GetValue()) 
    673710         
    674         # Find min max of qs 
    675         xmin = min(self.qx) 
    676         xmax = max(self.qx) 
    677         ymin = min(self.qy) 
    678         ymax = max(self.qy) 
     711        try: 
     712            # Find min max of qs 
     713            xmin = min(self.qx) 
     714            xmax = max(self.qx) 
     715            ymin = min(self.qy) 
     716            ymax = max(self.qy) 
     717        except: 
     718            msg = "An error occured during the resolution computation." 
     719            msg += "Please check your inputs..." 
     720            self._status_info(msg, status_type) 
     721            raise ValueError, "Invalid Q Input..." 
    679722 
    680723        # Validate the q inputs 
     
    719762        sigma_r = self.format_number(self.resolution.sigma_1) 
    720763        sigma_phi = self.format_number(self.resolution.sigma_2) 
     764        sigma_lamd = self.format_number(self.resolution.sigma_lamd) 
    721765        sigma_1d =  self.format_number(self.resolution.sigma_1d) 
    722766 
     
    724768        self.sigma_r_tcl.SetValue(str(sigma_r)) 
    725769        self.sigma_phi_tcl.SetValue(str(sigma_phi)) 
     770        self.sigma_lamd_tcl.SetValue(str(sigma_lamd)) 
    726771        self.sigma_1d_tcl.SetValue(str(sigma_1d)) 
    727772         
     
    835880        self.resolution.get_all_instrument_params() 
    836881        # reset all param values 
    837         self.mass_tcl.SetValue(str(self.resolution.mass)) 
     882        self.source_cb.SetValue('Neutron') 
     883        self._on_source_selection(None) 
    838884        #self.intensity_tcl.SetValue(str(self.resolution.intensity)) 
    839885        self.wavelength_tcl.SetValue(str(self.resolution.wavelength)) 
     
    882928        self.sigma_1d_tcl.SetValue('') 
    883929        # reset radio button 
    884         self.det_coordinate = 'polar' 
    885         self.r_phi_rb.SetValue(True) 
     930        #self.r_phi_rb.SetValue(True) 
    886931        # Finally re-compute 
    887932        self.on_compute() 
     
    9871032        self.on_compute() 
    9881033         
     1034    def _on_source_selection(self, event = None): 
     1035        """ 
     1036        On source combobox selection 
     1037        """ 
     1038        if event != None: 
     1039            combo = event.GetEventObject() 
     1040            event.Skip() 
     1041        else: 
     1042            combo = self.source_cb 
     1043        selection = combo.GetValue() 
     1044        mass = self.source_mass[selection] 
     1045        self.resolution.set_neutron_mass(mass)    
     1046        source_hint = "Source Selection: Affect on" 
     1047        source_hint += " the gravitational contribution.\n" 
     1048        source_hint += "Mass of %s: m = %s [g]" % \ 
     1049                            (selection, str(self.resolution.get_neutron_mass())) 
     1050        #source_tip.SetTip(source_hint) 
     1051        self.mass_txt.ToolTip.SetTip(source_hint) 
    9891052         
    9901053class ResolutionWindow(wx.Frame): 
Note: See TracChangeset for help on using the changeset viewer.