- Timestamp:
- Jan 8, 2019 6:00:45 AM (6 years ago)
- Branches:
- master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249
- Children:
- aa9928e
- Parents:
- bd3a3ae
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/fitpage.py
rbd3a3ae rf632247 13 13 import time 14 14 import traceback 15 import logging 15 16 16 17 from sasmodels.weights import MODELS as POLYDISPERSITY_MODELS … … 28 29 PageInfoEvent 29 30 from .basepage import ModelTextCtrl 31 32 logger = logging.getLogger(__name__) 30 33 31 34 (Chi2UpdateEvent, EVT_CHI2_UPDATE) = wx.lib.newevent.NewEvent() … … 213 216 smear_message_new_psmear = \ 214 217 "Please enter a fixed percentage to be applied to all Q values..." 215 smear_message_2d_x_title = "<dQ p>[1/A]:"216 smear_message_2d_y_title = "<dQ s>[1/A]:"218 smear_message_2d_x_title = "<dQ/Q>p[%]:" 219 smear_message_2d_y_title = "<dQ/Q>s[%]:" 217 220 smear_message_pinhole_percent_min_title = "[dQ/Q]min(%):" 218 221 smear_message_pinhole_percent_max_title = "[dQ/Q]max(%):" … … 1613 1616 1614 1617 :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 1620 1625 self.smear_type = None 1621 1626 self.dq_l = None 1622 1627 self.dq_r = None 1623 1628 data = self.data 1629 #sanity check - this should only be called if data exits 1624 1630 if self.data is None: 1625 1631 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 return1630 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(): 1633 1639 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) 1637 1646 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) 1656 1682 # return self.smear_type,self.dq_l,self.dq_r 1657 1683 … … 1660 1686 Show only the sizers depending on smear selection 1661 1687 """ 1662 # smear disabled 1688 # smear disabled = No Smearing used 1663 1689 if self.disable_smearer.GetValue(): 1664 1690 self.smear_description_none.Show(True) 1665 # 2Dsmear 1691 # 2Dsmearing - for use with 2D data only 1666 1692 elif self._is_2D(): 1667 1693 self.smear_description_accuracy_type.Show(True) 1668 1694 self.smear_accuracy.Show(True) 1669 self.smear_description_accuracy_type.Show(True)1670 1695 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 1673 1697 if self.pinhole_smearer.GetValue(): 1698 self.smear_description_pin_percent.Show(True) 1674 1699 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 1676 1711 elif self.enable_smearer.GetValue(): 1677 1678 1712 self.smear_description_dqdata.Show(True) 1679 1713 if self.smear_type is not None: 1680 1714 self.smear_description_smear_type.Show(True) 1715 #1D data has slit smearing 1681 1716 if self.smear_type == 'Slit': 1682 1717 self.smear_description_slit_height.Show(True) 1683 1718 self.smear_description_slit_width.Show(True) 1719 #1D data has pinhole smearing 1684 1720 elif self.smear_type == 'Pinhole': 1685 1721 self.smear_description_pin_percent_min.Show(True) … … 1689 1725 self.smear_data_left.Show(True) 1690 1726 self.smear_data_right.Show(True) 1691 # custom pinhole smear1727 # 1D custom pinhole smearing 1692 1728 elif self.pinhole_smearer.GetValue(): 1693 # if self.smear_type == 'Pinhole':1694 1729 self.smear_message_new_p.Show(True) 1695 1730 self.smear_description_pin_percent.Show(True) 1696 #note - was outside of above commented out if statement1697 1731 self.smear_pinhole_percent.Show(True) 1698 # custom slit smear1732 # 1D custom slit smear 1699 1733 elif self.slit_smearer.GetValue(): 1700 1734 self.smear_message_new_s.Show(True) … … 1703 1737 self.smear_description_slit_width.Show(True) 1704 1738 self.smear_slit_width.Show(True) 1739 else: 1740 logger.error("smearing type is not defined") 1705 1741 1706 1742 def _hide_all_smear_info(self):
Note: See TracChangeset
for help on using the changeset viewer.