Changeset f632247 in sasview


Ignore:
Timestamp:
Jan 8, 2019 8:00:45 AM (9 days ago)
Author:
butler
Branches:
ticket_1206
Children:
aa9928e
Parents:
bd3a3ae
Message:

Fix 2D smearing GUI

Make 2D from data as % of average. Fix input and message boxes to be
the right ones and fix some logic issues

addresses #1206

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/fitting/fitpage.py

    rbd3a3ae rf632247  
    1313import time 
    1414import traceback 
     15import logging 
    1516 
    1617from sasmodels.weights import MODELS as POLYDISPERSITY_MODELS 
     
    2829    PageInfoEvent 
    2930from .basepage import ModelTextCtrl 
     31 
     32logger = logging.getLogger(__name__) 
    3033 
    3134(Chi2UpdateEvent, EVT_CHI2_UPDATE) = wx.lib.newevent.NewEvent() 
     
    213216        smear_message_new_psmear = \ 
    214217              "Please enter a fixed percentage to be applied to all Q values..." 
    215         smear_message_2d_x_title = "<dQp>[1/A]:" 
    216         smear_message_2d_y_title = "<dQs>[1/A]:" 
     218        smear_message_2d_x_title = "<dQ/Q>p[%]:" 
     219        smear_message_2d_y_title = "<dQ/Q>s[%]:" 
    217220        smear_message_pinhole_percent_min_title = "[dQ/Q]min(%):" 
    218221        smear_message_pinhole_percent_max_title = "[dQ/Q]max(%):" 
     
    16131616 
    16141617        :return: self.smear_type, self.dq_l and self.dq_r, 
    1615             respectively the type of the smear, dq_min and 
    1616             dq_max for pinhole smear data 
    1617             while dxl and dxw for slit smear 
    1618         """ 
    1619         # default 
     1618            respectively the type of the smear, The average <dq/q> radial(p) 
     1619            and <dq/q> theta (s)s for 2D pinhole resolution in % (slit is not 
     1620            currently supported in 2D), (dq/q)_min and (dq/q)_max for 1D pinhole 
     1621            smeared data, again in %, and dxl and/or dxw for slit smeared data 
     1622            given in 1/A and assumed constant. 
     1623        """ 
     1624        # set up defaults 
    16201625        self.smear_type = None 
    16211626        self.dq_l = None 
    16221627        self.dq_r = None 
    16231628        data = self.data 
     1629        #sanity check - this should only be called if data exits 
    16241630        if self.data is None: 
    16251631            return 
    1626         elif self.data.__class__.__name__ == "Data2D" or \ 
    1627             self.enable2D: 
    1628             if data.dqx_data is None or data.dqy_data is None: 
    1629                 return 
    1630             elif self.current_smearer is not None \ 
    1631                 and data.dqx_data.any() != 0 \ 
    1632                 and data.dqy_data.any() != 0: 
     1632        #First check if data is 2D 
     1633        #If so check that data set has smearing info and that none are zero. 
     1634        #Otherwise no smearing can be applied using smear from data (a Gaussian 
     1635        #width of zero will cause a divide by zero error) 
     1636        if self.data.__class__.__name__ == "Data2D": 
     1637            if data.dqx_data is not None and data.dqy_data is not None \ 
     1638              and data.dqx_data.all()and data.dqy_data.all(): 
    16331639                self.smear_type = "Pinhole2d" 
    1634                 self.dq_l = format_number(np.average(data.dqx_data)) 
    1635                 self.dq_r = format_number(np.average(data.dqy_data)) 
    1636                 return 
     1640                #report as average dQ/Q % as for 1D pinhole 
     1641                self.dq_l = format_number(np.average(data.dqx_data 
     1642                                                     / abs(data.qx_data)) * 100) 
     1643                self.dq_r = format_number(np.average(data.dqy_data 
     1644                                                     / abs(data.qy_data)) * 100) 
     1645            #if not then log that data did not contain resolutin info                                         / abs(data.qy_data)) * 100) 
    16371646            else: 
    1638                 return 
    1639         # check if it is pinhole smear and get min max if it is. 
    1640         if data.dx is not None and np.any(data.dx): 
    1641             self.smear_type = "Pinhole" 
    1642             #report in % for display makes more sense than absolute value 
    1643             #for pinhole smearing.  Keep old names of dq_l rather than  
    1644             #dq_percent_l as it is close entough, minimizez changes, 
    1645             #particularly since both slit AND pinhole are using these variables. 
    1646             self.dq_l = data.dx[0] / data.x[0] * 100 
    1647             self.dq_r = data.dx[-1] / data.x[-1] * 100 
    1648  
    1649         # check if it is slit smear and get min max if it is. 
    1650         elif data.dxl is not None or data.dxw is not None: 
    1651             self.smear_type = "Slit" 
    1652             if data.dxl is not None and np.all(data.dxl, 0): 
    1653                 self.dq_l = data.dxl[0] 
    1654             if data.dxw is not None and np.all(data.dxw, 0): 
    1655                 self.dq_r = data.dxw[0] 
     1647                self.msg = "2D Data did not contain recognizable " \ 
     1648                           "resolution info." 
     1649                logger.info(self.msg) 
     1650        #If not check that data is 1D 
     1651        #If so check for pinhole vs slit by veryfing whehter dx or dxl or dxw 
     1652        #have data (currently sasview only supports either dx or dxl/dxw but 
     1653        #not both simultaneously) and as, for 2D, are non zero . 
     1654        #Otherwise no smearing can be applied using smear from data (a Gaussian 
     1655        #width of zero will cause a divide by zero error) 
     1656        elif self.data.__class__.__name__ == "Data1D": 
     1657            #is it valid 1D pinhole resolution data? 
     1658            if data.dx is not None and np.all(data.dx): 
     1659                self.smear_type = "Pinhole" 
     1660                #report in % for display makes more sense than absolute value 
     1661                #for pinhole smearing .. but keep old names of dq_l 
     1662                self.dq_l = data.dx[0] / data.x[0] * 100 
     1663                self.dq_r = data.dx[-1] / data.x[-1] * 100 
     1664            #If not, is it valid 1D slit resolution data? 
     1665            elif (data.dxl is not None or data.dxw is not None) \ 
     1666                and (np.all(data.dxl, 0) or np.all(data.dxw, 0)): 
     1667                self.smear_type = "Slit" 
     1668                #for slit units of 1/A make most sense 
     1669                if data.dxl is not None and np.all(data.dxl, 0): 
     1670                    self.dq_l = data.dxl[0] 
     1671                if data.dxw is not None and np.all(data.dxw, 0): 
     1672                    self.dq_r = data.dxw[0] 
     1673            #otherwise log that the data did not conatain resolution info 
     1674            else: 
     1675                self.msg = "1D Data did not contain recognizable " \ 
     1676                           "resolution info." 
     1677                logger.info(self.msg) 
     1678        #If drops to here it is neither data1D or data2D so log that 
     1679        else: 
     1680            self.msg = "Data was not recognized as either 1D or 2D data." 
     1681            logger.info(self.msg) 
    16561682        # return self.smear_type,self.dq_l,self.dq_r 
    16571683 
     
    16601686        Show only the sizers depending on smear selection 
    16611687        """ 
    1662         # smear disabled 
     1688        # smear disabled = No Smearing used 
    16631689        if self.disable_smearer.GetValue(): 
    16641690            self.smear_description_none.Show(True) 
    1665         # 2Dsmear 
     1691        # 2Dsmearing - for use with 2D data only 
    16661692        elif self._is_2D(): 
    16671693            self.smear_description_accuracy_type.Show(True) 
    16681694            self.smear_accuracy.Show(True) 
    1669             self.smear_description_accuracy_type.Show(True) 
    16701695            self.smear_description_2d.Show(True) 
    1671             self.smear_description_2d_x.Show(True) 
    1672             self.smear_description_2d_y.Show(True) 
     1696            #2D custom pinhole smearing 
    16731697            if self.pinhole_smearer.GetValue(): 
     1698                self.smear_description_pin_percent.Show(True) 
    16741699                self.smear_pinhole_percent.Show(True) 
    1675         # smear from data 
     1700            #get 2D smearing from data 
     1701            elif self.enable_smearer.GetValue(): 
     1702                self.smear_description_2d_x.Show(True) 
     1703                self.smear_description_2d_y.Show(True) 
     1704                self.smear_data_left.Show(True) 
     1705                self.smear_data_right.Show(True) 
     1706            #Currently 2D custom slit smearing is not currently supported 
     1707            else: 
     1708                logger.error("2D custom smearing cannot use slit smearing") 
     1709 
     1710        # 1D smearing from data 
    16761711        elif self.enable_smearer.GetValue(): 
    1677  
    16781712            self.smear_description_dqdata.Show(True) 
    16791713            if self.smear_type is not None: 
    16801714                self.smear_description_smear_type.Show(True) 
     1715                #1D data has slit smearing 
    16811716                if self.smear_type == 'Slit': 
    16821717                    self.smear_description_slit_height.Show(True) 
    16831718                    self.smear_description_slit_width.Show(True) 
     1719                #1D data has pinhole smearing 
    16841720                elif self.smear_type == 'Pinhole': 
    16851721                    self.smear_description_pin_percent_min.Show(True) 
     
    16891725                self.smear_data_left.Show(True) 
    16901726                self.smear_data_right.Show(True) 
    1691         # custom pinhole smear 
     1727        # 1D custom pinhole smearing 
    16921728        elif self.pinhole_smearer.GetValue(): 
    1693 #            if self.smear_type == 'Pinhole': 
    16941729            self.smear_message_new_p.Show(True) 
    16951730            self.smear_description_pin_percent.Show(True) 
    1696             #note - was outside of above commented out if statement 
    16971731            self.smear_pinhole_percent.Show(True) 
    1698         # custom slit smear 
     1732        # 1D custom slit smear 
    16991733        elif self.slit_smearer.GetValue(): 
    17001734            self.smear_message_new_s.Show(True) 
     
    17031737            self.smear_description_slit_width.Show(True) 
    17041738            self.smear_slit_width.Show(True) 
     1739        else: 
     1740            logger.error("smearing type is not defined") 
    17051741 
    17061742    def _hide_all_smear_info(self): 
Note: See TracChangeset for help on using the changeset viewer.