Changeset cb44d66 in sasview for src/sas/sasgui/perspectives/fitting
- Timestamp:
- Mar 6, 2019 6:18:51 PM (6 years ago)
- Branches:
- ticket-1094-headless
- Children:
- f0b9bce
- Parents:
- ffbf35ee (diff), f205d3a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- src/sas/sasgui/perspectives/fitting
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/fitpage.py
r1dc134e6 rcb44d66 13 13 import time 14 14 import traceback 15 import logging 15 16 16 17 from sasmodels.weights import MODELS as POLYDISPERSITY_MODELS 17 18 18 19 from sas.sascalc.fit.qsmearing import smear_selection 20 from sas.sascalc.dataloader.data_info import Data1D, Data2D 19 21 20 22 from sas.sasgui.guiframe.events import StatusEvent, NewPlotEvent, \ … … 28 30 PageInfoEvent 29 31 from .basepage import ModelTextCtrl 32 33 logger = logging.getLogger(__name__) 30 34 31 35 (Chi2UpdateEvent, EVT_CHI2_UPDATE) = wx.lib.newevent.NewEvent() … … 183 187 :return: True or False 184 188 """ 185 if self.data.__class__.__name__ == "Data2D" or \ 186 self.enable2D: 189 if isinstance(self.data, Data2D) or self.enable2D: 187 190 return True 188 191 return False … … 198 201 199 202 # Check if data is 2D 200 if self.data.__class__.__name__ == "Data2D" or \ 201 self.enable2D: 203 if isinstance(self.data, Data2D) or self.enable2D: 202 204 is_2d_data = True 203 205 … … 212 214 smear_message_new_psmear = \ 213 215 "Please enter a fixed percentage to be applied to all Q values..." 214 smear_message_2d_x_title = "<dQp>[1/A]:" 215 smear_message_2d_y_title = "<dQs>[1/A]:" 216 smear_message_pinhole_percent_title = "dQ[%]:" 216 smear_message_2d_x_title = "<dQ/Q>_r[%]:" 217 smear_message_2d_y_title = "<dQ/Q>_phi[%]:" 218 smear_message_pinhole_percent_min_title = "[dQ/Q]min(%):" 219 smear_message_pinhole_percent_max_title = "[dQ/Q]max(%):" 220 smear_message_pinhole_percent_title = "dQ/Q(%):" 217 221 smear_message_slit_height_title = "Slit height[1/A]:" 218 222 smear_message_slit_width_title = "Slit width[1/A]:" … … 417 421 smear_message_2d_x_title, style=wx.ALIGN_LEFT) 418 422 self.smear_description_2d_x.SetToolTipString( 419 " dQ p(parallel) in q_r direction.")423 " dQ_r q_r in polar coordinates.") 420 424 self.smear_description_2d_y = wx.StaticText(self, wx.ID_ANY, 421 425 smear_message_2d_y_title, style=wx.ALIGN_LEFT) 422 426 self.smear_description_2d_y.SetToolTipString( 423 " dQs(perpendicular) in q_phi direction.") 427 " dQ_phi q_phi in polar coordinates.") 428 self.smear_description_pin_percent_min = wx.StaticText(self, wx.ID_ANY, 429 smear_message_pinhole_percent_min_title, 430 style=wx.ALIGN_LEFT) 431 self.smear_description_pin_percent_max = wx.StaticText(self, wx.ID_ANY, 432 smear_message_pinhole_percent_max_title, 433 style=wx.ALIGN_LEFT) 424 434 self.smear_description_pin_percent = wx.StaticText(self, wx.ID_ANY, 425 435 smear_message_pinhole_percent_title, … … 448 458 self.sizer_new_smear.Add((15, -1)) 449 459 self.sizer_new_smear.Add(self.smear_description_2d_x, 0, wx.CENTER, 10) 460 self.sizer_new_smear.Add(self.smear_description_pin_percent_min, 461 0, wx.CENTER, 10) 462 self.sizer_new_smear.Add(self.smear_description_pin_percent, 463 0, wx.CENTER, 10) 450 464 self.sizer_new_smear.Add(self.smear_description_slit_height, 451 465 0, wx.CENTER, 10) 452 466 467 self.sizer_new_smear.Add(self.smear_pinhole_percent, 0, wx.CENTER, 10) 453 468 self.sizer_new_smear.Add(self.smear_slit_height, 0, wx.CENTER, 10) 454 469 self.sizer_new_smear.Add(self.smear_data_left, 0, wx.CENTER, 10) … … 456 471 self.sizer_new_smear.Add(self.smear_description_2d_y, 457 472 0, wx.CENTER, 10) 458 self.sizer_new_smear.Add(self.smear_description_pin_percent ,473 self.sizer_new_smear.Add(self.smear_description_pin_percent_max, 459 474 0, wx.CENTER, 10) 460 475 self.sizer_new_smear.Add(self.smear_description_slit_width, 461 476 0, wx.CENTER, 10) 462 477 463 self.sizer_new_smear.Add(self.smear_pinhole_percent, 0, wx.CENTER, 10)464 478 self.sizer_new_smear.Add(self.smear_slit_width, 0, wx.CENTER, 10) 465 479 self.sizer_new_smear.Add(self.smear_data_right, 0, wx.CENTER, 10) … … 502 516 503 517 # check if it is 2D data 504 if self.data.__class__.__name__ == "Data2D"or self.enable2D:518 if isinstance(self.data, Data2D) or self.enable2D: 505 519 is_2d_data = True 506 520 … … 805 819 self.sizer4_4.Add(cb, (iy, ix), (1, 1), 806 820 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 807 if self.data.__class__.__name__ == "Data2D" or \ 808 self.enable2D: 821 if isinstance(self.data, Data2D) or self.enable2D: 809 822 cb.Show(True) 810 823 elif cb.IsShown(): … … 818 831 ctl1.SetToolTipString(poly_tip) 819 832 ctl1.SetValue(str(format_number(value, True))) 820 if self.data.__class__.__name__ == "Data2D" or \ 821 self.enable2D: 833 if isinstance(self.data, Data2D) or self.enable2D: 822 834 if first_orient: 823 835 values.SetLabel('PD[ratio], Sig[deg]') … … 853 865 854 866 ctl2.Hide() 855 if self.data.__class__.__name__ == "Data2D" or \ 856 self.enable2D: 867 if isinstance(self.data, Data2D) or self.enable2D: 857 868 if self.is_mac: 858 869 text2.Show(True) … … 879 890 ctl4.Hide() 880 891 881 if self.data.__class__.__name__ == "Data2D" or \ 882 self.enable2D: 892 if isinstance(self.data, Data2D) or self.enable2D: 883 893 ctl3.Show(True) 884 894 ctl4.Show(True) … … 892 902 893 903 Tctl.SetValue(str(format_number(value))) 894 if self.data.__class__.__name__ == "Data2D" or \ 895 self.enable2D: 904 if isinstance(self.data, Data2D) or self.enable2D: 896 905 Tctl.Show(True) 897 906 else: … … 912 921 913 922 Tct2.SetValue(str(format_number(value))) 914 if self.data.__class__.__name__ == "Data2D" or \ 915 self.enable2D: 923 if isinstance(self.data, Data2D) or self.enable2D: 916 924 Tct2.Show(True) 917 925 else: … … 940 948 text2, ctl2, ctl3, ctl4, disp_box]) 941 949 942 if self.data.__class__.__name__ == "Data2D" or \ 943 self.enable2D: 950 if isinstance(self.data, Data2D) or self.enable2D: 944 951 disp_box.Show(True) 945 952 else: … … 1326 1333 flag1 = self.update_pinhole_smear() 1327 1334 flag = flag or flag1 1328 elif self.data.__class__.__name__ != "Data2D" and \ 1329 not self.enable2D: 1335 elif not isinstance(self.data, Data2D) and not self.enable2D: 1330 1336 enable_smearer = not self.disable_smearer.GetValue() 1331 1337 self._manager.set_smearer(smearer=temp_smearer, … … 1400 1406 if event is not None: 1401 1407 event.Skip() 1402 if self.data.__class__.__name__ == "Data2D":1408 if isinstance(self.data, Data2D): 1403 1409 return 1404 1410 is_click = event.LeftDown() … … 1418 1424 if event is not None: 1419 1425 event.Skip() 1420 if self.data.__class__.__name__ == "Data2D":1426 if isinstance(self.data, Data2D): 1421 1427 return 1422 1428 act_ctrl = event.GetEventObject() … … 1434 1440 """ 1435 1441 event.Skip() 1436 if self.data.__class__.__name__ == "Data2D":1442 if isinstance(self.data, Data2D): 1437 1443 return 1438 1444 ctrl = event.GetEventObject() … … 1495 1501 # Check if # of points for theory model are valid(>0). 1496 1502 # check for 2d 1497 if self.data.__class__.__name__ == "Data2D" or \ 1498 self.enable2D: 1503 if isinstance(self.data, Data2D) or self.enable2D: 1499 1504 # set mask 1500 1505 radius = np.sqrt(self.data.qx_data * self.data.qx_data + … … 1548 1553 if item[0].IsShown(): 1549 1554 # Skip the angle parameters if 1D data 1550 if self.data.__class__.__name__ != "Data2D" and \ 1551 not self.enable2D: 1555 if not isinstance(self.data, Data2D) and not self.enable2D: 1552 1556 if item in self.orientation_params: 1553 1557 continue … … 1567 1571 if item[0].IsShown(): 1568 1572 # Skip the angle parameters if 1D data 1569 if self.data.__class__.__name__ != "Data2D" and \ 1570 not self.enable2D: 1573 if not isinstance(self.data, Data2D) and not self.enable2D: 1571 1574 if item in self.orientation_params: 1572 1575 continue … … 1600 1603 1601 1604 :return: self.smear_type, self.dq_l and self.dq_r, 1602 respectively the type of the smear, dq_min and 1603 dq_max for pinhole smear data 1604 while dxl and dxw for slit smear 1605 """ 1606 # default 1605 respectively the type of the smear, The average <dq/q> radial(p) 1606 and <dq/q> theta (s)s for 2D pinhole resolution in % (slit is not 1607 currently supported in 2D), (dq/q)_min and (dq/q)_max for 1D pinhole 1608 smeared data, again in %, and dxl and/or dxw for slit smeared data 1609 given in 1/A and assumed constant. 1610 """ 1611 # set up defaults 1607 1612 self.smear_type = None 1608 1613 self.dq_l = None 1609 1614 self.dq_r = None 1610 1615 data = self.data 1616 #sanity check - this should only be called if data exits 1611 1617 if self.data is None: 1612 1618 return 1613 elif self.data.__class__.__name__ == "Data2D" or \1614 self.enable2D:1615 if data.dqx_data is None or data.dqy_data is None:1616 return1617 elif self.current_smearer is not None \1618 and data.dqx_data.any() != 0\1619 and data.dqx_data.any() != 0:1619 #First check if data is 2D 1620 #If so check that data set has smearing info and that none are zero. 1621 #Otherwise no smearing can be applied using smear from data (a Gaussian 1622 #width of zero will cause a divide by zero error) 1623 if isinstance(self.data, Data2D): 1624 if data.dqx_data is not None and data.dqy_data is not None \ 1625 and data.dqx_data.all()and data.dqy_data.all(): 1620 1626 self.smear_type = "Pinhole2d" 1621 self.dq_l = format_number(np.average(data.dqx_data)) 1622 self.dq_r = format_number(np.average(data.dqy_data)) 1623 return 1627 #report as average dQ/Q % as for 1D pinhole 1628 self.dq_l = format_number(np.average(data.dqx_data 1629 / abs(data.qx_data)) * 100) 1630 self.dq_r = format_number(np.average(data.dqy_data 1631 / abs(data.qy_data)) * 100) 1632 #if not then log that data did not contain resolutin info / abs(data.qy_data)) * 100) 1624 1633 else: 1625 return 1626 # check if it is pinhole smear and get min max if it is. 1627 if data.dx is not None and np.any(data.dx): 1628 self.smear_type = "Pinhole" 1629 self.dq_l = data.dx[0] 1630 self.dq_r = data.dx[-1] 1631 1632 # check if it is slit smear and get min max if it is. 1633 elif data.dxl is not None or data.dxw is not None: 1634 self.smear_type = "Slit" 1635 if data.dxl is not None and np.all(data.dxl, 0): 1636 self.dq_l = data.dxl[0] 1637 if data.dxw is not None and np.all(data.dxw, 0): 1638 self.dq_r = data.dxw[0] 1634 self.msg = "2D Data did not contain recognizable " \ 1635 "resolution info." 1636 logger.info(self.msg) 1637 #If not check that data is 1D 1638 #If so check for pinhole vs slit by veryfing whehter dx or dxl or dxw 1639 #have data (currently sasview only supports either dx or dxl/dxw but 1640 #not both simultaneously) and, as for 2D, are non zero . 1641 #Otherwise no smearing can be applied using smear from data (a Gaussian 1642 #width of zero will cause a divide by zero error) 1643 elif isinstance(self.data, Data1D): 1644 #is it valid 1D pinhole resolution data? 1645 if data.dx is not None and np.all(data.dx): 1646 self.smear_type = "Pinhole" 1647 #report in % for display makes more sense than absolute value 1648 #for pinhole smearing .. but keep old names of dq_l 1649 self.dq_l = format_number(data.dx[0] / data.x[0] * 100,1) 1650 self.dq_r = format_number(data.dx[-1] / data.x[-1] * 100,1) 1651 #If not, is it valid 1D slit resolution data? 1652 elif (data.dxl is not None or data.dxw is not None) \ 1653 and (np.all(data.dxl, 0) or np.all(data.dxw, 0)): 1654 self.smear_type = "Slit" 1655 #for slit units of 1/A make most sense 1656 if data.dxl is not None and np.all(data.dxl, 0): 1657 self.dq_l = format_number(data.dxl[0],1) 1658 if data.dxw is not None and np.all(data.dxw, 0): 1659 self.dq_r = format_number(data.dxw[0],1) 1660 #otherwise log that the data did not conatain resolution info 1661 else: 1662 self.msg = "1D Data did not contain recognizable " \ 1663 "resolution info." 1664 logger.info(self.msg) 1665 #If drops to here it is neither data1D or data2D so log that 1666 else: 1667 self.msg = "Data was not recognized as either 1D or 2D data." 1668 logger.info(self.msg) 1639 1669 # return self.smear_type,self.dq_l,self.dq_r 1640 1670 … … 1643 1673 Show only the sizers depending on smear selection 1644 1674 """ 1645 # smear disabled 1675 # smear disabled = No Smearing used 1646 1676 if self.disable_smearer.GetValue(): 1647 1677 self.smear_description_none.Show(True) 1648 # 2Dsmear 1678 # 2Dsmearing - for use with 2D data only 1649 1679 elif self._is_2D(): 1650 1680 self.smear_description_accuracy_type.Show(True) 1651 1681 self.smear_accuracy.Show(True) 1652 self.smear_description_accuracy_type.Show(True)1653 1682 self.smear_description_2d.Show(True) 1654 self.smear_description_2d_x.Show(True) 1655 self.smear_description_2d_y.Show(True) 1683 #2D custom pinhole smearing 1656 1684 if self.pinhole_smearer.GetValue(): 1685 self.smear_description_pin_percent.Show(True) 1657 1686 self.smear_pinhole_percent.Show(True) 1658 # smear from data 1687 #get 2D smearing from data 1688 elif self.enable_smearer.GetValue(): 1689 self.smear_description_2d_x.Show(True) 1690 self.smear_description_2d_y.Show(True) 1691 self.smear_data_left.Show(True) 1692 self.smear_data_right.Show(True) 1693 #Currently 2D custom slit smearing is not currently supported 1694 else: 1695 logger.error("2D custom smearing cannot use slit smearing") 1696 1697 # 1D smearing from data 1659 1698 elif self.enable_smearer.GetValue(): 1660 1661 1699 self.smear_description_dqdata.Show(True) 1662 1700 if self.smear_type is not None: 1663 1701 self.smear_description_smear_type.Show(True) 1702 #1D data has slit smearing 1664 1703 if self.smear_type == 'Slit': 1665 1704 self.smear_description_slit_height.Show(True) 1666 1705 self.smear_description_slit_width.Show(True) 1706 #1D data has pinhole smearing 1667 1707 elif self.smear_type == 'Pinhole': 1668 self.smear_description_pin_percent.Show(True) 1708 self.smear_description_pin_percent_min.Show(True) 1709 self.smear_description_pin_percent_max.Show(True) 1669 1710 self.smear_description_smear_type.Show(True) 1670 1711 self.smear_description_type.Show(True) 1671 1712 self.smear_data_left.Show(True) 1672 1713 self.smear_data_right.Show(True) 1673 # custom pinhole smear1714 # 1D custom pinhole smearing 1674 1715 elif self.pinhole_smearer.GetValue(): 1675 if self.smear_type == 'Pinhole': 1676 self.smear_message_new_p.Show(True) 1677 self.smear_description_pin_percent.Show(True) 1678 1716 self.smear_message_new_p.Show(True) 1717 self.smear_description_pin_percent.Show(True) 1679 1718 self.smear_pinhole_percent.Show(True) 1680 # custom slit smear1719 # 1D custom slit smear 1681 1720 elif self.slit_smearer.GetValue(): 1682 1721 self.smear_message_new_s.Show(True) … … 1685 1724 self.smear_description_slit_width.Show(True) 1686 1725 self.smear_slit_width.Show(True) 1726 else: 1727 logger.error("smearing type is not defined") 1687 1728 1688 1729 def _hide_all_smear_info(self): … … 1702 1743 self.smear_data_left.Hide() 1703 1744 self.smear_data_right.Hide() 1745 self.smear_description_pin_percent_min.Hide() 1746 self.smear_description_pin_percent_max.Hide() 1704 1747 self.smear_description_pin_percent.Hide() 1705 1748 self.smear_pinhole_percent.Hide() … … 1919 1962 di_flag = False 1920 1963 dq_flag = False 1921 if self.data.__class__.__name__ == "Data2D" or \ 1922 self.enable2D: 1964 if isinstance(self.data, Data2D) or self.enable2D: 1923 1965 self.slit_smearer.Disable() 1924 1966 self.pinhole_smearer.Enable(True) … … 2005 2047 # update model plot with new data information 2006 2048 if flag: 2007 if self.data.__class__.__name__ == "Data2D":2049 if isinstance(self.data, Data2D): 2008 2050 self.enable2D = True 2009 2051 self.model_view.SetLabel("2D Mode") … … 2072 2114 npts2fit = 0 2073 2115 qmin, qmax = self.get_range() 2074 if self.data.__class__.__name__ == "Data2D" or \ 2075 self.enable2D: 2116 if isinstance(self.data, Data2D) or self.enable2D: 2076 2117 radius = np.sqrt(self.data.qx_data * self.data.qx_data + 2077 2118 self.data.qy_data * self.data.qy_data) … … 2463 2504 of the values entered for slit smear 2464 2505 """ 2465 if self.data.__class__.__name__ == "Data2D"or self.enable2D:2506 if isinstance(self.data, Data2D) or self.enable2D: 2466 2507 return 2467 2508 # make sure once more if it is smearer … … 2659 2700 for item in self.parameters: 2660 2701 # Skip t ifhe angle parameters if 1D data 2661 if self.data.__class__.__name__ != "Data2D" and\ 2662 not self.enable2D: 2702 if not isinstance(self.data, Data2D) and not self.enable2D: 2663 2703 if item in self.orientation_params: 2664 2704 continue … … 2676 2716 for item in self.fittable_param: 2677 2717 # Skip t ifhe angle parameters if 1D data 2678 if self.data.__class__.__name__ != "Data2D" and\ 2679 not self.enable2D: 2718 if not isinstance(self.data, Data2D) and not self.enable2D: 2680 2719 if item in self.orientation_params: 2681 2720 continue … … 2689 2728 2690 2729 # Calculate num. of angle parameters 2691 if self.data.__class__.__name__ == "Data2D" or \ 2692 self.enable2D: 2730 if isinstance(self.data, Data2D) or self.enable2D: 2693 2731 len_orient_para = 0 2694 2732 else: … … 2983 3021 if not self._has_magnetic: 2984 3022 mag_on_button.Show(False) 2985 elif not self.data.__class__.__name__ == "Data2D":3023 elif not isinstance(self.data, Data2D): 2986 3024 mag_on_button.Show(False) 2987 3025 else: … … 2999 3037 mag_angle_help_button.Show(False) 3000 3038 3001 if not self.data.__class__.__name__ == "Data2D" and \ 3002 not self.enable2D: 3039 if not isinstance(self.data, Data2D) and not self.enable2D: 3003 3040 orient_angle.Hide() 3004 3041 else: … … 3024 3061 cb.SetToolTipString("Check mark to fit") 3025 3062 wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) 3026 if self.data.__class__.__name__ == "Data2D" or \ 3027 self.enable2D: 3063 if isinstance(self.data, Data2D) or self.enable2D: 3028 3064 cb.Show(True) 3029 3065 else: … … 3040 3076 "Hit 'Enter' after typing to update the plot.") 3041 3077 ctl1.SetValue(format_number(value, True)) 3042 if self.data.__class__.__name__ == "Data2D" or \ 3043 self.enable2D: 3078 if isinstance(self.data, Data2D) or self.enable2D: 3044 3079 ctl1.Show(True) 3045 3080 else: … … 3081 3116 ctl4.Hide() 3082 3117 3083 if self.data.__class__.__name__ == "Data2D" or \ 3084 self.enable2D: 3118 if isinstance(self.data, Data2D) or self.enable2D: 3085 3119 if self.is_mac: 3086 3120 text2.Show(True) … … 3098 3132 units = wx.StaticText(self, -1, "", 3099 3133 style=wx.ALIGN_LEFT) 3100 if self.data.__class__.__name__ == "Data2D" or \ 3101 self.enable2D: 3134 if isinstance(self.data, Data2D) or self.enable2D: 3102 3135 units.Show(True) 3103 3136 else: … … 3178 3211 """ 3179 3212 # more disables for 2D 3180 if self.data.__class__.__name__ == "Data2D" or \ 3181 self.enable2D: 3213 if isinstance(self.data, Data2D) or self.enable2D: 3182 3214 self.slit_smearer.Disable() 3183 self.pinhole_smearer.Enable(True)3184 3215 self.default_mask = copy.deepcopy(self.data.mask) 3185 else: 3186 self.slit_smearer.Enable(True) 3187 self.pinhole_smearer.Enable(True) 3216 if self.model is not None: 3217 self.pinhole_smearer.Enable(True) 3218 3219 elif isinstance(self.data, Data1D): 3220 if self.model is not None: 3221 self.slit_smearer.Enable(True) 3222 self.pinhole_smearer.Enable(True) 3223 else: 3224 msg="data is not recognized as either 1D or 2D" 3225 logger.info(msg) 3188 3226 3189 3227 -
src/sas/sasgui/perspectives/fitting/fitting.py
raba4559 ra5cffe5 776 776 :param weight: current dy data 777 777 """ 778 # If we are not dealing with a specific fit problem, then 779 # there is no point setting the weights. 780 if fid is None: 781 return 778 # Note: this is used to set the data weights for the fit based on 779 # the weight selection in the GUI. 782 780 if uid in self.page_finder.keys(): 783 781 self.page_finder[uid].set_weight(flag=flag, is2d=is2d) -
src/sas/sasgui/perspectives/fitting/gpu_options.py
r8e109f9 r895703d 23 23 import sasmodels 24 24 import sasmodels.model_test 25 import sasmodels. kernelcl25 import sasmodels.sasview_model 26 26 27 27 from sas.sasgui.guiframe.documentation_window import DocumentationWindow … … 239 239 if "SAS_OPENCL" in os.environ: 240 240 del os.environ["SAS_OPENCL"] 241 sasmodels. kernelcl.reset_environment()241 sasmodels.sasview_model.reset_environment() 242 242 event.Skip() 243 243 … … 265 265 if "SAS_OPENCL" in os.environ: 266 266 del os.environ["SAS_OPENCL"] 267 sasmodels. kernelcl.reset_environment()267 sasmodels.sasview_model.reset_environment() 268 268 269 269 try:
Note: See TracChangeset
for help on using the changeset viewer.