Changes in / [3d5e629:ef74a8b] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/fitpage.py
rca4f40d rba1c145 13 13 import time 14 14 import traceback 15 import logging16 15 17 16 from sasmodels.weights import MODELS as POLYDISPERSITY_MODELS 18 17 19 18 from sas.sascalc.fit.qsmearing import smear_selection 20 from sas.sascalc.dataloader.data_info import Data1D, Data2D21 19 22 20 from sas.sasgui.guiframe.events import StatusEvent, NewPlotEvent, \ … … 30 28 PageInfoEvent 31 29 from .basepage import ModelTextCtrl 32 33 logger = logging.getLogger(__name__)34 30 35 31 (Chi2UpdateEvent, EVT_CHI2_UPDATE) = wx.lib.newevent.NewEvent() … … 188 184 :return: True or False 189 185 """ 190 if isinstance(self.data, Data2D) or self.enable2D: 186 if self.data.__class__.__name__ == "Data2D" or \ 187 self.enable2D: 191 188 return True 192 189 return False … … 202 199 203 200 # Check if data is 2D 204 if isinstance(self.data, Data2D) or self.enable2D: 201 if self.data.__class__.__name__ == "Data2D" or \ 202 self.enable2D: 205 203 is_2d_data = True 206 204 … … 215 213 smear_message_new_psmear = \ 216 214 "Please enter a fixed percentage to be applied to all Q values..." 217 smear_message_2d_x_title = "<dQ/Q>_r[%]:" 218 smear_message_2d_y_title = "<dQ/Q>_phi[%]:" 219 smear_message_pinhole_percent_min_title = "[dQ/Q]min(%):" 220 smear_message_pinhole_percent_max_title = "[dQ/Q]max(%):" 221 smear_message_pinhole_percent_title = "dQ/Q(%):" 215 smear_message_2d_x_title = "<dQp>[1/A]:" 216 smear_message_2d_y_title = "<dQs>[1/A]:" 217 smear_message_pinhole_percent_title = "dQ[%]:" 222 218 smear_message_slit_height_title = "Slit height[1/A]:" 223 219 smear_message_slit_width_title = "Slit width[1/A]:" … … 422 418 smear_message_2d_x_title, style=wx.ALIGN_LEFT) 423 419 self.smear_description_2d_x.SetToolTipString( 424 " dQ _r q_r in polar coordinates.")420 " dQp(parallel) in q_r direction.") 425 421 self.smear_description_2d_y = wx.StaticText(self, wx.ID_ANY, 426 422 smear_message_2d_y_title, style=wx.ALIGN_LEFT) 427 423 self.smear_description_2d_y.SetToolTipString( 428 " dQ_phi q_phi in polar coordinates.") 429 self.smear_description_pin_percent_min = wx.StaticText(self, wx.ID_ANY, 430 smear_message_pinhole_percent_min_title, 431 style=wx.ALIGN_LEFT) 432 self.smear_description_pin_percent_max = wx.StaticText(self, wx.ID_ANY, 433 smear_message_pinhole_percent_max_title, 434 style=wx.ALIGN_LEFT) 424 " dQs(perpendicular) in q_phi direction.") 435 425 self.smear_description_pin_percent = wx.StaticText(self, wx.ID_ANY, 436 426 smear_message_pinhole_percent_title, … … 459 449 self.sizer_new_smear.Add((15, -1)) 460 450 self.sizer_new_smear.Add(self.smear_description_2d_x, 0, wx.CENTER, 10) 461 self.sizer_new_smear.Add(self.smear_description_pin_percent_min,462 0, wx.CENTER, 10)463 self.sizer_new_smear.Add(self.smear_description_pin_percent,464 0, wx.CENTER, 10)465 451 self.sizer_new_smear.Add(self.smear_description_slit_height, 466 452 0, wx.CENTER, 10) 467 453 468 self.sizer_new_smear.Add(self.smear_pinhole_percent, 0, wx.CENTER, 10)469 454 self.sizer_new_smear.Add(self.smear_slit_height, 0, wx.CENTER, 10) 470 455 self.sizer_new_smear.Add(self.smear_data_left, 0, wx.CENTER, 10) … … 472 457 self.sizer_new_smear.Add(self.smear_description_2d_y, 473 458 0, wx.CENTER, 10) 474 self.sizer_new_smear.Add(self.smear_description_pin_percent _max,459 self.sizer_new_smear.Add(self.smear_description_pin_percent, 475 460 0, wx.CENTER, 10) 476 461 self.sizer_new_smear.Add(self.smear_description_slit_width, 477 462 0, wx.CENTER, 10) 478 463 464 self.sizer_new_smear.Add(self.smear_pinhole_percent, 0, wx.CENTER, 10) 479 465 self.sizer_new_smear.Add(self.smear_slit_width, 0, wx.CENTER, 10) 480 466 self.sizer_new_smear.Add(self.smear_data_right, 0, wx.CENTER, 10) … … 517 503 518 504 # check if it is 2D data 519 if isinstance(self.data, Data2D)or self.enable2D:505 if self.data.__class__.__name__ == "Data2D" or self.enable2D: 520 506 is_2d_data = True 521 507 … … 820 806 self.sizer4_4.Add(cb, (iy, ix), (1, 1), 821 807 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 822 if isinstance(self.data, Data2D) or self.enable2D: 808 if self.data.__class__.__name__ == "Data2D" or \ 809 self.enable2D: 823 810 cb.Show(True) 824 811 elif cb.IsShown(): … … 832 819 ctl1.SetToolTipString(poly_tip) 833 820 ctl1.SetValue(str(format_number(value, True))) 834 if isinstance(self.data, Data2D) or self.enable2D: 821 if self.data.__class__.__name__ == "Data2D" or \ 822 self.enable2D: 835 823 if first_orient: 836 824 values.SetLabel('PD[ratio], Sig[deg]') … … 866 854 867 855 ctl2.Hide() 868 if isinstance(self.data, Data2D) or self.enable2D: 856 if self.data.__class__.__name__ == "Data2D" or \ 857 self.enable2D: 869 858 if self.is_mac: 870 859 text2.Show(True) … … 891 880 ctl4.Hide() 892 881 893 if isinstance(self.data, Data2D) or self.enable2D: 882 if self.data.__class__.__name__ == "Data2D" or \ 883 self.enable2D: 894 884 ctl3.Show(True) 895 885 ctl4.Show(True) … … 903 893 904 894 Tctl.SetValue(str(format_number(value))) 905 if isinstance(self.data, Data2D) or self.enable2D: 895 if self.data.__class__.__name__ == "Data2D" or \ 896 self.enable2D: 906 897 Tctl.Show(True) 907 898 else: … … 922 913 923 914 Tct2.SetValue(str(format_number(value))) 924 if isinstance(self.data, Data2D) or self.enable2D: 915 if self.data.__class__.__name__ == "Data2D" or \ 916 self.enable2D: 925 917 Tct2.Show(True) 926 918 else: … … 949 941 text2, ctl2, ctl3, ctl4, disp_box]) 950 942 951 if isinstance(self.data, Data2D) or self.enable2D: 943 if self.data.__class__.__name__ == "Data2D" or \ 944 self.enable2D: 952 945 disp_box.Show(True) 953 946 else: … … 1334 1327 flag1 = self.update_pinhole_smear() 1335 1328 flag = flag or flag1 1336 elif not isinstance(self.data, Data2D) and not self.enable2D: 1329 elif self.data.__class__.__name__ != "Data2D" and \ 1330 not self.enable2D: 1337 1331 enable_smearer = not self.disable_smearer.GetValue() 1338 1332 self._manager.set_smearer(smearer=temp_smearer, … … 1407 1401 if event is not None: 1408 1402 event.Skip() 1409 if isinstance(self.data, Data2D):1403 if self.data.__class__.__name__ == "Data2D": 1410 1404 return 1411 1405 is_click = event.LeftDown() … … 1425 1419 if event is not None: 1426 1420 event.Skip() 1427 if isinstance(self.data, Data2D):1421 if self.data.__class__.__name__ == "Data2D": 1428 1422 return 1429 1423 act_ctrl = event.GetEventObject() … … 1441 1435 """ 1442 1436 event.Skip() 1443 if isinstance(self.data, Data2D):1437 if self.data.__class__.__name__ == "Data2D": 1444 1438 return 1445 1439 ctrl = event.GetEventObject() … … 1502 1496 # Check if # of points for theory model are valid(>0). 1503 1497 # check for 2d 1504 if isinstance(self.data, Data2D) or self.enable2D: 1498 if self.data.__class__.__name__ == "Data2D" or \ 1499 self.enable2D: 1505 1500 # set mask 1506 1501 radius = np.sqrt(self.data.qx_data * self.data.qx_data + … … 1554 1549 if item[0].IsShown(): 1555 1550 # Skip the angle parameters if 1D data 1556 if not isinstance(self.data, Data2D) and not self.enable2D: 1551 if self.data.__class__.__name__ != "Data2D" and \ 1552 not self.enable2D: 1557 1553 if item in self.orientation_params: 1558 1554 continue … … 1572 1568 if item[0].IsShown(): 1573 1569 # Skip the angle parameters if 1D data 1574 if not isinstance(self.data, Data2D) and not self.enable2D: 1570 if self.data.__class__.__name__ != "Data2D" and \ 1571 not self.enable2D: 1575 1572 if item in self.orientation_params: 1576 1573 continue … … 1604 1601 1605 1602 :return: self.smear_type, self.dq_l and self.dq_r, 1606 respectively the type of the smear, The average <dq/q> radial(p) 1607 and <dq/q> theta (s)s for 2D pinhole resolution in % (slit is not 1608 currently supported in 2D), (dq/q)_min and (dq/q)_max for 1D pinhole 1609 smeared data, again in %, and dxl and/or dxw for slit smeared data 1610 given in 1/A and assumed constant. 1611 """ 1612 # set up defaults 1603 respectively the type of the smear, dq_min and 1604 dq_max for pinhole smear data 1605 while dxl and dxw for slit smear 1606 """ 1607 # default 1613 1608 self.smear_type = None 1614 1609 self.dq_l = None 1615 1610 self.dq_r = None 1616 1611 data = self.data 1617 #sanity check - this should only be called if data exits1618 1612 if self.data is None: 1619 1613 return 1620 #First check if data is 2D1621 #If so check that data set has smearing info and that none are zero.1622 #Otherwise no smearing can be applied using smear from data (a Gaussian1623 #width of zero will cause a divide by zero error)1624 if isinstance(self.data, Data2D):1625 if data.dqx_data is not None and data.dqy_data is not None\1626 and data.dqx_data.all()and data.dqy_data.all():1614 elif self.data.__class__.__name__ == "Data2D" or \ 1615 self.enable2D: 1616 if data.dqx_data is None or data.dqy_data is None: 1617 return 1618 elif self.current_smearer is not None \ 1619 and data.dqx_data.any() != 0 \ 1620 and data.dqx_data.any() != 0: 1627 1621 self.smear_type = "Pinhole2d" 1628 #report as average dQ/Q % as for 1D pinhole 1629 self.dq_l = format_number(np.average(data.dqx_data 1630 / abs(data.qx_data)) * 100) 1631 self.dq_r = format_number(np.average(data.dqy_data 1632 / abs(data.qy_data)) * 100) 1633 #if not then log that data did not contain resolutin info / abs(data.qy_data)) * 100) 1622 self.dq_l = format_number(np.average(data.dqx_data)) 1623 self.dq_r = format_number(np.average(data.dqy_data)) 1624 return 1634 1625 else: 1635 self.msg = "2D Data did not contain recognizable " \ 1636 "resolution info." 1637 logger.info(self.msg) 1638 #If not check that data is 1D 1639 #If so check for pinhole vs slit by veryfing whehter dx or dxl or dxw 1640 #have data (currently sasview only supports either dx or dxl/dxw but 1641 #not both simultaneously) and, as for 2D, are non zero . 1642 #Otherwise no smearing can be applied using smear from data (a Gaussian 1643 #width of zero will cause a divide by zero error) 1644 elif isinstance(self.data, Data1D): 1645 #is it valid 1D pinhole resolution data? 1646 if data.dx is not None and np.all(data.dx): 1647 self.smear_type = "Pinhole" 1648 #report in % for display makes more sense than absolute value 1649 #for pinhole smearing .. but keep old names of dq_l 1650 self.dq_l = format_number(data.dx[0] / data.x[0] * 100,1) 1651 self.dq_r = format_number(data.dx[-1] / data.x[-1] * 100,1) 1652 #If not, is it valid 1D slit resolution data? 1653 elif (data.dxl is not None or data.dxw is not None) \ 1654 and (np.all(data.dxl, 0) or np.all(data.dxw, 0)): 1655 self.smear_type = "Slit" 1656 #for slit units of 1/A make most sense 1657 if data.dxl is not None and np.all(data.dxl, 0): 1658 self.dq_l = format_number(data.dxl[0],1) 1659 if data.dxw is not None and np.all(data.dxw, 0): 1660 self.dq_r = format_number(data.dxw[0],1) 1661 #otherwise log that the data did not conatain resolution info 1662 else: 1663 self.msg = "1D Data did not contain recognizable " \ 1664 "resolution info." 1665 logger.info(self.msg) 1666 #If drops to here it is neither data1D or data2D so log that 1667 else: 1668 self.msg = "Data was not recognized as either 1D or 2D data." 1669 logger.info(self.msg) 1626 return 1627 # check if it is pinhole smear and get min max if it is. 1628 if data.dx is not None and np.any(data.dx): 1629 self.smear_type = "Pinhole" 1630 self.dq_l = data.dx[0] 1631 self.dq_r = data.dx[-1] 1632 1633 # check if it is slit smear and get min max if it is. 1634 elif data.dxl is not None or data.dxw is not None: 1635 self.smear_type = "Slit" 1636 if data.dxl is not None and np.all(data.dxl, 0): 1637 self.dq_l = data.dxl[0] 1638 if data.dxw is not None and np.all(data.dxw, 0): 1639 self.dq_r = data.dxw[0] 1670 1640 # return self.smear_type,self.dq_l,self.dq_r 1671 1641 … … 1674 1644 Show only the sizers depending on smear selection 1675 1645 """ 1676 # smear disabled = No Smearing used1646 # smear disabled 1677 1647 if self.disable_smearer.GetValue(): 1678 1648 self.smear_description_none.Show(True) 1679 # 2Dsmear ing - for use with 2D data only1649 # 2Dsmear 1680 1650 elif self._is_2D(): 1681 1651 self.smear_description_accuracy_type.Show(True) 1682 1652 self.smear_accuracy.Show(True) 1653 self.smear_description_accuracy_type.Show(True) 1683 1654 self.smear_description_2d.Show(True) 1684 #2D custom pinhole smearing 1655 self.smear_description_2d_x.Show(True) 1656 self.smear_description_2d_y.Show(True) 1685 1657 if self.pinhole_smearer.GetValue(): 1686 self.smear_description_pin_percent.Show(True)1687 1658 self.smear_pinhole_percent.Show(True) 1688 #get 2D smearing from data 1689 elif self.enable_smearer.GetValue(): 1690 self.smear_description_2d_x.Show(True) 1691 self.smear_description_2d_y.Show(True) 1692 self.smear_data_left.Show(True) 1693 self.smear_data_right.Show(True) 1694 #Currently 2D custom slit smearing is not currently supported 1695 else: 1696 logger.error("2D custom smearing cannot use slit smearing") 1697 1698 # 1D smearing from data 1659 # smear from data 1699 1660 elif self.enable_smearer.GetValue(): 1661 1700 1662 self.smear_description_dqdata.Show(True) 1701 1663 if self.smear_type is not None: 1702 1664 self.smear_description_smear_type.Show(True) 1703 #1D data has slit smearing1704 1665 if self.smear_type == 'Slit': 1705 1666 self.smear_description_slit_height.Show(True) 1706 1667 self.smear_description_slit_width.Show(True) 1707 #1D data has pinhole smearing1708 1668 elif self.smear_type == 'Pinhole': 1709 self.smear_description_pin_percent_min.Show(True) 1710 self.smear_description_pin_percent_max.Show(True) 1669 self.smear_description_pin_percent.Show(True) 1711 1670 self.smear_description_smear_type.Show(True) 1712 1671 self.smear_description_type.Show(True) 1713 1672 self.smear_data_left.Show(True) 1714 1673 self.smear_data_right.Show(True) 1715 # 1D custom pinhole smearing1674 # custom pinhole smear 1716 1675 elif self.pinhole_smearer.GetValue(): 1717 self.smear_message_new_p.Show(True) 1718 self.smear_description_pin_percent.Show(True) 1676 if self.smear_type == 'Pinhole': 1677 self.smear_message_new_p.Show(True) 1678 self.smear_description_pin_percent.Show(True) 1679 1719 1680 self.smear_pinhole_percent.Show(True) 1720 # 1Dcustom slit smear1681 # custom slit smear 1721 1682 elif self.slit_smearer.GetValue(): 1722 1683 self.smear_message_new_s.Show(True) … … 1725 1686 self.smear_description_slit_width.Show(True) 1726 1687 self.smear_slit_width.Show(True) 1727 else:1728 logger.error("smearing type is not defined")1729 1688 1730 1689 def _hide_all_smear_info(self): … … 1744 1703 self.smear_data_left.Hide() 1745 1704 self.smear_data_right.Hide() 1746 self.smear_description_pin_percent_min.Hide()1747 self.smear_description_pin_percent_max.Hide()1748 1705 self.smear_description_pin_percent.Hide() 1749 1706 self.smear_pinhole_percent.Hide() … … 1963 1920 di_flag = False 1964 1921 dq_flag = False 1965 if isinstance(self.data, Data2D) or self.enable2D: 1922 if self.data.__class__.__name__ == "Data2D" or \ 1923 self.enable2D: 1966 1924 self.slit_smearer.Disable() 1967 1925 self.pinhole_smearer.Enable(True) … … 2048 2006 # update model plot with new data information 2049 2007 if flag: 2050 if isinstance(self.data, Data2D):2008 if self.data.__class__.__name__ == "Data2D": 2051 2009 self.enable2D = True 2052 2010 self.model_view.SetLabel("2D Mode") … … 2115 2073 npts2fit = 0 2116 2074 qmin, qmax = self.get_range() 2117 if isinstance(self.data, Data2D) or self.enable2D: 2075 if self.data.__class__.__name__ == "Data2D" or \ 2076 self.enable2D: 2118 2077 radius = np.sqrt(self.data.qx_data * self.data.qx_data + 2119 2078 self.data.qy_data * self.data.qy_data) … … 2505 2464 of the values entered for slit smear 2506 2465 """ 2507 if isinstance(self.data, Data2D)or self.enable2D:2466 if self.data.__class__.__name__ == "Data2D" or self.enable2D: 2508 2467 return 2509 2468 # make sure once more if it is smearer … … 2701 2660 for item in self.parameters: 2702 2661 # Skip t ifhe angle parameters if 1D data 2703 if not isinstance(self.data, Data2D) and not self.enable2D: 2662 if self.data.__class__.__name__ != "Data2D" and\ 2663 not self.enable2D: 2704 2664 if item in self.orientation_params: 2705 2665 continue … … 2717 2677 for item in self.fittable_param: 2718 2678 # Skip t ifhe angle parameters if 1D data 2719 if not isinstance(self.data, Data2D) and not self.enable2D: 2679 if self.data.__class__.__name__ != "Data2D" and\ 2680 not self.enable2D: 2720 2681 if item in self.orientation_params: 2721 2682 continue … … 2729 2690 2730 2691 # Calculate num. of angle parameters 2731 if isinstance(self.data, Data2D) or self.enable2D: 2692 if self.data.__class__.__name__ == "Data2D" or \ 2693 self.enable2D: 2732 2694 len_orient_para = 0 2733 2695 else: … … 3022 2984 if not self._has_magnetic: 3023 2985 mag_on_button.Show(False) 3024 elif not isinstance(self.data, Data2D):2986 elif not self.data.__class__.__name__ == "Data2D": 3025 2987 mag_on_button.Show(False) 3026 2988 else: … … 3038 3000 mag_angle_help_button.Show(False) 3039 3001 3040 if not isinstance(self.data, Data2D) and not self.enable2D: 3002 if not self.data.__class__.__name__ == "Data2D" and \ 3003 not self.enable2D: 3041 3004 orient_angle.Hide() 3042 3005 else: … … 3062 3025 cb.SetToolTipString("Check mark to fit") 3063 3026 wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) 3064 if isinstance(self.data, Data2D) or self.enable2D: 3027 if self.data.__class__.__name__ == "Data2D" or \ 3028 self.enable2D: 3065 3029 cb.Show(True) 3066 3030 else: … … 3077 3041 "Hit 'Enter' after typing to update the plot.") 3078 3042 ctl1.SetValue(format_number(value, True)) 3079 if isinstance(self.data, Data2D) or self.enable2D: 3043 if self.data.__class__.__name__ == "Data2D" or \ 3044 self.enable2D: 3080 3045 ctl1.Show(True) 3081 3046 else: … … 3117 3082 ctl4.Hide() 3118 3083 3119 if isinstance(self.data, Data2D) or self.enable2D: 3084 if self.data.__class__.__name__ == "Data2D" or \ 3085 self.enable2D: 3120 3086 if self.is_mac: 3121 3087 text2.Show(True) … … 3133 3099 units = wx.StaticText(self, -1, "", 3134 3100 style=wx.ALIGN_LEFT) 3135 if isinstance(self.data, Data2D) or self.enable2D: 3101 if self.data.__class__.__name__ == "Data2D" or \ 3102 self.enable2D: 3136 3103 units.Show(True) 3137 3104 else: … … 3212 3179 """ 3213 3180 # more disables for 2D 3214 if isinstance(self.data, Data2D) or self.enable2D: 3181 if self.data.__class__.__name__ == "Data2D" or \ 3182 self.enable2D: 3215 3183 self.slit_smearer.Disable() 3184 self.pinhole_smearer.Enable(True) 3216 3185 self.default_mask = copy.deepcopy(self.data.mask) 3217 if self.model is not None:3218 self.pinhole_smearer.Enable(True)3219 3220 elif isinstance(self.data, Data1D):3221 if self.model is not None:3222 self.slit_smearer.Enable(True)3223 self.pinhole_smearer.Enable(True)3224 3186 else: 3225 msg="data is not recognized as either 1D or 2D"3226 logger.info(msg)3187 self.slit_smearer.Enable(True) 3188 self.pinhole_smearer.Enable(True) 3227 3189 3228 3190
Note: See TracChangeset
for help on using the changeset viewer.