Changeset 3d5e629 in sasview for src/sas/sasgui
- Timestamp:
- Jan 23, 2019 11:06:46 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:
- 5bba43d, 647d66b6
- Parents:
- a13c41b (diff), ef74a8b (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. - git-author:
- Steve K <smk78@…> (01/23/19 11:06:46)
- git-committer:
- GitHub <noreply@…> (01/23/19 11:06:46)
- Location:
- src/sas/sasgui/perspectives
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/corfunc/corfunc_panel.py
r5652efc ref74a8b 277 277 self._transformed_data = transforms 278 278 (transform1, transform3, idf) = transforms 279 plot_x = transform1.x[transform1.x <= 200]280 plot_y = transform1.y[transform1.x <= 200]279 plot_x = transform1.x[transform1.x <= 1000] 280 plot_y = transform1.y[transform1.x <= 1000] 281 281 self._manager.show_data(Data1D(plot_x, plot_y), TRANSFORM_LABEL1) 282 # No need to shorten gamma3 as it's only calculated up to x= 200282 # No need to shorten gamma3 as it's only calculated up to x=1000 283 283 self._manager.show_data(transform3, TRANSFORM_LABEL3) 284 284 285 plot_x = idf.x[idf.x <= 200]286 plot_y = idf.y[idf.x <= 200]285 plot_x = idf.x[idf.x <= 1000] 286 plot_y = idf.y[idf.x <= 1000] 287 287 self._manager.show_data(Data1D(plot_x, plot_y), IDF_LABEL) 288 288 -
src/sas/sasgui/perspectives/fitting/fitpage.py
rba1c145 rca4f40d 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() … … 184 188 :return: True or False 185 189 """ 186 if self.data.__class__.__name__ == "Data2D" or \ 187 self.enable2D: 190 if isinstance(self.data, Data2D) or self.enable2D: 188 191 return True 189 192 return False … … 199 202 200 203 # Check if data is 2D 201 if self.data.__class__.__name__ == "Data2D" or \ 202 self.enable2D: 204 if isinstance(self.data, Data2D) or self.enable2D: 203 205 is_2d_data = True 204 206 … … 213 215 smear_message_new_psmear = \ 214 216 "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]:" 217 smear_message_pinhole_percent_title = "dQ[%]:" 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(%):" 218 222 smear_message_slit_height_title = "Slit height[1/A]:" 219 223 smear_message_slit_width_title = "Slit width[1/A]:" … … 418 422 smear_message_2d_x_title, style=wx.ALIGN_LEFT) 419 423 self.smear_description_2d_x.SetToolTipString( 420 " dQ p(parallel) in q_r direction.")424 " dQ_r q_r in polar coordinates.") 421 425 self.smear_description_2d_y = wx.StaticText(self, wx.ID_ANY, 422 426 smear_message_2d_y_title, style=wx.ALIGN_LEFT) 423 427 self.smear_description_2d_y.SetToolTipString( 424 " dQs(perpendicular) in q_phi direction.") 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) 425 435 self.smear_description_pin_percent = wx.StaticText(self, wx.ID_ANY, 426 436 smear_message_pinhole_percent_title, … … 449 459 self.sizer_new_smear.Add((15, -1)) 450 460 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) 451 465 self.sizer_new_smear.Add(self.smear_description_slit_height, 452 466 0, wx.CENTER, 10) 453 467 468 self.sizer_new_smear.Add(self.smear_pinhole_percent, 0, wx.CENTER, 10) 454 469 self.sizer_new_smear.Add(self.smear_slit_height, 0, wx.CENTER, 10) 455 470 self.sizer_new_smear.Add(self.smear_data_left, 0, wx.CENTER, 10) … … 457 472 self.sizer_new_smear.Add(self.smear_description_2d_y, 458 473 0, wx.CENTER, 10) 459 self.sizer_new_smear.Add(self.smear_description_pin_percent ,474 self.sizer_new_smear.Add(self.smear_description_pin_percent_max, 460 475 0, wx.CENTER, 10) 461 476 self.sizer_new_smear.Add(self.smear_description_slit_width, 462 477 0, wx.CENTER, 10) 463 478 464 self.sizer_new_smear.Add(self.smear_pinhole_percent, 0, wx.CENTER, 10)465 479 self.sizer_new_smear.Add(self.smear_slit_width, 0, wx.CENTER, 10) 466 480 self.sizer_new_smear.Add(self.smear_data_right, 0, wx.CENTER, 10) … … 503 517 504 518 # check if it is 2D data 505 if self.data.__class__.__name__ == "Data2D"or self.enable2D:519 if isinstance(self.data, Data2D) or self.enable2D: 506 520 is_2d_data = True 507 521 … … 806 820 self.sizer4_4.Add(cb, (iy, ix), (1, 1), 807 821 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) 808 if self.data.__class__.__name__ == "Data2D" or \ 809 self.enable2D: 822 if isinstance(self.data, Data2D) or self.enable2D: 810 823 cb.Show(True) 811 824 elif cb.IsShown(): … … 819 832 ctl1.SetToolTipString(poly_tip) 820 833 ctl1.SetValue(str(format_number(value, True))) 821 if self.data.__class__.__name__ == "Data2D" or \ 822 self.enable2D: 834 if isinstance(self.data, Data2D) or self.enable2D: 823 835 if first_orient: 824 836 values.SetLabel('PD[ratio], Sig[deg]') … … 854 866 855 867 ctl2.Hide() 856 if self.data.__class__.__name__ == "Data2D" or \ 857 self.enable2D: 868 if isinstance(self.data, Data2D) or self.enable2D: 858 869 if self.is_mac: 859 870 text2.Show(True) … … 880 891 ctl4.Hide() 881 892 882 if self.data.__class__.__name__ == "Data2D" or \ 883 self.enable2D: 893 if isinstance(self.data, Data2D) or self.enable2D: 884 894 ctl3.Show(True) 885 895 ctl4.Show(True) … … 893 903 894 904 Tctl.SetValue(str(format_number(value))) 895 if self.data.__class__.__name__ == "Data2D" or \ 896 self.enable2D: 905 if isinstance(self.data, Data2D) or self.enable2D: 897 906 Tctl.Show(True) 898 907 else: … … 913 922 914 923 Tct2.SetValue(str(format_number(value))) 915 if self.data.__class__.__name__ == "Data2D" or \ 916 self.enable2D: 924 if isinstance(self.data, Data2D) or self.enable2D: 917 925 Tct2.Show(True) 918 926 else: … … 941 949 text2, ctl2, ctl3, ctl4, disp_box]) 942 950 943 if self.data.__class__.__name__ == "Data2D" or \ 944 self.enable2D: 951 if isinstance(self.data, Data2D) or self.enable2D: 945 952 disp_box.Show(True) 946 953 else: … … 1327 1334 flag1 = self.update_pinhole_smear() 1328 1335 flag = flag or flag1 1329 elif self.data.__class__.__name__ != "Data2D" and \ 1330 not self.enable2D: 1336 elif not isinstance(self.data, Data2D) and not self.enable2D: 1331 1337 enable_smearer = not self.disable_smearer.GetValue() 1332 1338 self._manager.set_smearer(smearer=temp_smearer, … … 1401 1407 if event is not None: 1402 1408 event.Skip() 1403 if self.data.__class__.__name__ == "Data2D":1409 if isinstance(self.data, Data2D): 1404 1410 return 1405 1411 is_click = event.LeftDown() … … 1419 1425 if event is not None: 1420 1426 event.Skip() 1421 if self.data.__class__.__name__ == "Data2D":1427 if isinstance(self.data, Data2D): 1422 1428 return 1423 1429 act_ctrl = event.GetEventObject() … … 1435 1441 """ 1436 1442 event.Skip() 1437 if self.data.__class__.__name__ == "Data2D":1443 if isinstance(self.data, Data2D): 1438 1444 return 1439 1445 ctrl = event.GetEventObject() … … 1496 1502 # Check if # of points for theory model are valid(>0). 1497 1503 # check for 2d 1498 if self.data.__class__.__name__ == "Data2D" or \ 1499 self.enable2D: 1504 if isinstance(self.data, Data2D) or self.enable2D: 1500 1505 # set mask 1501 1506 radius = np.sqrt(self.data.qx_data * self.data.qx_data + … … 1549 1554 if item[0].IsShown(): 1550 1555 # Skip the angle parameters if 1D data 1551 if self.data.__class__.__name__ != "Data2D" and \ 1552 not self.enable2D: 1556 if not isinstance(self.data, Data2D) and not self.enable2D: 1553 1557 if item in self.orientation_params: 1554 1558 continue … … 1568 1572 if item[0].IsShown(): 1569 1573 # Skip the angle parameters if 1D data 1570 if self.data.__class__.__name__ != "Data2D" and \ 1571 not self.enable2D: 1574 if not isinstance(self.data, Data2D) and not self.enable2D: 1572 1575 if item in self.orientation_params: 1573 1576 continue … … 1601 1604 1602 1605 :return: self.smear_type, self.dq_l and self.dq_r, 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 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 1608 1613 self.smear_type = None 1609 1614 self.dq_l = None 1610 1615 self.dq_r = None 1611 1616 data = self.data 1617 #sanity check - this should only be called if data exits 1612 1618 if self.data is None: 1613 1619 return 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 return1618 elif self.current_smearer is not None \1619 and data.dqx_data.any() != 0\1620 and data.dqx_data.any() != 0:1620 #First check if data is 2D 1621 #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 Gaussian 1623 #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(): 1621 1627 self.smear_type = "Pinhole2d" 1622 self.dq_l = format_number(np.average(data.dqx_data)) 1623 self.dq_r = format_number(np.average(data.dqy_data)) 1624 return 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) 1625 1634 else: 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] 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) 1640 1670 # return self.smear_type,self.dq_l,self.dq_r 1641 1671 … … 1644 1674 Show only the sizers depending on smear selection 1645 1675 """ 1646 # smear disabled 1676 # smear disabled = No Smearing used 1647 1677 if self.disable_smearer.GetValue(): 1648 1678 self.smear_description_none.Show(True) 1649 # 2Dsmear 1679 # 2Dsmearing - for use with 2D data only 1650 1680 elif self._is_2D(): 1651 1681 self.smear_description_accuracy_type.Show(True) 1652 1682 self.smear_accuracy.Show(True) 1653 self.smear_description_accuracy_type.Show(True)1654 1683 self.smear_description_2d.Show(True) 1655 self.smear_description_2d_x.Show(True) 1656 self.smear_description_2d_y.Show(True) 1684 #2D custom pinhole smearing 1657 1685 if self.pinhole_smearer.GetValue(): 1686 self.smear_description_pin_percent.Show(True) 1658 1687 self.smear_pinhole_percent.Show(True) 1659 # smear from data 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 1660 1699 elif self.enable_smearer.GetValue(): 1661 1662 1700 self.smear_description_dqdata.Show(True) 1663 1701 if self.smear_type is not None: 1664 1702 self.smear_description_smear_type.Show(True) 1703 #1D data has slit smearing 1665 1704 if self.smear_type == 'Slit': 1666 1705 self.smear_description_slit_height.Show(True) 1667 1706 self.smear_description_slit_width.Show(True) 1707 #1D data has pinhole smearing 1668 1708 elif self.smear_type == 'Pinhole': 1669 self.smear_description_pin_percent.Show(True) 1709 self.smear_description_pin_percent_min.Show(True) 1710 self.smear_description_pin_percent_max.Show(True) 1670 1711 self.smear_description_smear_type.Show(True) 1671 1712 self.smear_description_type.Show(True) 1672 1713 self.smear_data_left.Show(True) 1673 1714 self.smear_data_right.Show(True) 1674 # custom pinhole smear1715 # 1D custom pinhole smearing 1675 1716 elif self.pinhole_smearer.GetValue(): 1676 if self.smear_type == 'Pinhole': 1677 self.smear_message_new_p.Show(True) 1678 self.smear_description_pin_percent.Show(True) 1679 1717 self.smear_message_new_p.Show(True) 1718 self.smear_description_pin_percent.Show(True) 1680 1719 self.smear_pinhole_percent.Show(True) 1681 # custom slit smear1720 # 1D custom slit smear 1682 1721 elif self.slit_smearer.GetValue(): 1683 1722 self.smear_message_new_s.Show(True) … … 1686 1725 self.smear_description_slit_width.Show(True) 1687 1726 self.smear_slit_width.Show(True) 1727 else: 1728 logger.error("smearing type is not defined") 1688 1729 1689 1730 def _hide_all_smear_info(self): … … 1703 1744 self.smear_data_left.Hide() 1704 1745 self.smear_data_right.Hide() 1746 self.smear_description_pin_percent_min.Hide() 1747 self.smear_description_pin_percent_max.Hide() 1705 1748 self.smear_description_pin_percent.Hide() 1706 1749 self.smear_pinhole_percent.Hide() … … 1920 1963 di_flag = False 1921 1964 dq_flag = False 1922 if self.data.__class__.__name__ == "Data2D" or \ 1923 self.enable2D: 1965 if isinstance(self.data, Data2D) or self.enable2D: 1924 1966 self.slit_smearer.Disable() 1925 1967 self.pinhole_smearer.Enable(True) … … 2006 2048 # update model plot with new data information 2007 2049 if flag: 2008 if self.data.__class__.__name__ == "Data2D":2050 if isinstance(self.data, Data2D): 2009 2051 self.enable2D = True 2010 2052 self.model_view.SetLabel("2D Mode") … … 2073 2115 npts2fit = 0 2074 2116 qmin, qmax = self.get_range() 2075 if self.data.__class__.__name__ == "Data2D" or \ 2076 self.enable2D: 2117 if isinstance(self.data, Data2D) or self.enable2D: 2077 2118 radius = np.sqrt(self.data.qx_data * self.data.qx_data + 2078 2119 self.data.qy_data * self.data.qy_data) … … 2464 2505 of the values entered for slit smear 2465 2506 """ 2466 if self.data.__class__.__name__ == "Data2D"or self.enable2D:2507 if isinstance(self.data, Data2D) or self.enable2D: 2467 2508 return 2468 2509 # make sure once more if it is smearer … … 2660 2701 for item in self.parameters: 2661 2702 # Skip t ifhe angle parameters if 1D data 2662 if self.data.__class__.__name__ != "Data2D" and\ 2663 not self.enable2D: 2703 if not isinstance(self.data, Data2D) and not self.enable2D: 2664 2704 if item in self.orientation_params: 2665 2705 continue … … 2677 2717 for item in self.fittable_param: 2678 2718 # Skip t ifhe angle parameters if 1D data 2679 if self.data.__class__.__name__ != "Data2D" and\ 2680 not self.enable2D: 2719 if not isinstance(self.data, Data2D) and not self.enable2D: 2681 2720 if item in self.orientation_params: 2682 2721 continue … … 2690 2729 2691 2730 # Calculate num. of angle parameters 2692 if self.data.__class__.__name__ == "Data2D" or \ 2693 self.enable2D: 2731 if isinstance(self.data, Data2D) or self.enable2D: 2694 2732 len_orient_para = 0 2695 2733 else: … … 2984 3022 if not self._has_magnetic: 2985 3023 mag_on_button.Show(False) 2986 elif not self.data.__class__.__name__ == "Data2D":3024 elif not isinstance(self.data, Data2D): 2987 3025 mag_on_button.Show(False) 2988 3026 else: … … 3000 3038 mag_angle_help_button.Show(False) 3001 3039 3002 if not self.data.__class__.__name__ == "Data2D" and \ 3003 not self.enable2D: 3040 if not isinstance(self.data, Data2D) and not self.enable2D: 3004 3041 orient_angle.Hide() 3005 3042 else: … … 3025 3062 cb.SetToolTipString("Check mark to fit") 3026 3063 wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) 3027 if self.data.__class__.__name__ == "Data2D" or \ 3028 self.enable2D: 3064 if isinstance(self.data, Data2D) or self.enable2D: 3029 3065 cb.Show(True) 3030 3066 else: … … 3041 3077 "Hit 'Enter' after typing to update the plot.") 3042 3078 ctl1.SetValue(format_number(value, True)) 3043 if self.data.__class__.__name__ == "Data2D" or \ 3044 self.enable2D: 3079 if isinstance(self.data, Data2D) or self.enable2D: 3045 3080 ctl1.Show(True) 3046 3081 else: … … 3082 3117 ctl4.Hide() 3083 3118 3084 if self.data.__class__.__name__ == "Data2D" or \ 3085 self.enable2D: 3119 if isinstance(self.data, Data2D) or self.enable2D: 3086 3120 if self.is_mac: 3087 3121 text2.Show(True) … … 3099 3133 units = wx.StaticText(self, -1, "", 3100 3134 style=wx.ALIGN_LEFT) 3101 if self.data.__class__.__name__ == "Data2D" or \ 3102 self.enable2D: 3135 if isinstance(self.data, Data2D) or self.enable2D: 3103 3136 units.Show(True) 3104 3137 else: … … 3179 3212 """ 3180 3213 # more disables for 2D 3181 if self.data.__class__.__name__ == "Data2D" or \ 3182 self.enable2D: 3214 if isinstance(self.data, Data2D) or self.enable2D: 3183 3215 self.slit_smearer.Disable() 3184 self.pinhole_smearer.Enable(True)3185 3216 self.default_mask = copy.deepcopy(self.data.mask) 3186 else: 3187 self.slit_smearer.Enable(True) 3188 self.pinhole_smearer.Enable(True) 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 else: 3225 msg="data is not recognized as either 1D or 2D" 3226 logger.info(msg) 3189 3227 3190 3228
Note: See TracChangeset
for help on using the changeset viewer.