Changeset 5062bbf in sasview for sansview/perspectives/fitting/fitpage.py
- Timestamp:
- Jun 7, 2010 10:26:43 AM (14 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- b94945d
- Parents:
- 79ac6f8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/fitpage.py
rcb190a19 r5062bbf 33 33 class FitPage(BasicPage): 34 34 """ 35 FitPanel class contains fields allowing to display results when 36 fitting a model and one data 37 @note: For Fit to be performed the user should check at least one parameter 35 FitPanel class contains fields allowing to display results when 36 fitting a model and one data 37 38 :note: For Fit to be performed the user should check at least one parameter 38 39 on fit Panel window. 39 40 40 """ 41 41 42 42 def __init__(self,parent, page_info): 43 """ 44 Initialization of the Panel 45 """ 43 46 BasicPage.__init__(self, parent, page_info) 44 45 """46 Initialization of the Panel47 """48 47 ## total number of point: float 49 48 self.npts=None … … 98 97 def _on_fit_complete(self, event): 99 98 """ 100 99 When fit is complete ,reset the fit button label. 101 100 """ 102 101 #self.btFit.SetLabel("Fit") … … 107 106 def _is_2D(self): 108 107 """ 109 Check if data_name is Data2D 110 @return: True or False 108 Check if data_name is Data2D 109 110 :return: True or False 111 111 112 """ 112 113 … … 117 118 def _on_engine_change(self, event): 118 119 """ 119 get an event containing the current name of the fit engine type 120 @param event: FitterTypeEvent containing the name of the current engine 120 get an event containing the current name of the fit engine type 121 122 :param event: FitterTypeEvent containing the name of the current engine 123 121 124 """ 122 125 self.engine_type = event.type … … 186 189 def _fill_range_sizer(self): 187 190 """ 188 189 191 Fill the sizer containing the plotting range 192 add access to npts 190 193 """ 191 194 is_2Ddata = False … … 231 234 self.smear_accuracy.SetToolTipString("'Higher' uses more Gaussian points for smearing computation.") 232 235 233 234 235 236 wx.EVT_COMBOBOX(self.smear_accuracy,-1, self._on_select_accuracy) 236 237 … … 390 391 def _fill_datainfo_sizer(self): 391 392 """ 392 393 fill sizer 0 with data info 393 394 """ 394 395 ## no loaded data , don't fill the sizer … … 455 456 def _fill_model_sizer(self, sizer): 456 457 """ 457 458 fill sizer containing model info 458 459 """ 459 460 ##Add model function Details button in fitpanel. … … 470 471 ## class base method to add view 2d button 471 472 self._set_model_sizer(sizer=sizer, box_sizer=boxsizer1, title="Model",object=self.model_help ) 472 473 473 474 474 def _set_sizer_dispersion(self, dispersity): 475 475 """ 476 476 draw sizer with gaussian dispersity parameters 477 477 """ 478 478 self.fittable_param=[] … … 749 749 ,None,None, None, None,None]) 750 750 751 752 751 self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) 753 752 … … 769 768 self.Layout() 770 769 771 772 770 def _onFit(self, event): 773 771 """ 774 772 Allow to fit 775 773 """ 776 774 #make sure all parameter values are updated. … … 796 794 return 797 795 798 799 796 self.select_param(event =None) 800 797 … … 820 817 # self.btFit.Bind(event= wx.EVT_BUTTON, handler=self._onFit, id=self.btFit.GetId()) 821 818 822 823 824 819 def _StopFit(self, event): 825 820 """ 826 821 Stop fit 827 822 """ 828 823 self.btFit.SetLabel("Fit") … … 835 830 def _on_select_model(self, event): 836 831 """ 837 832 call back for model selection 838 833 """ 839 834 self._on_select_model_helper() … … 879 874 event = PageInfoEvent(page = self) 880 875 wx.PostEvent(self.parent, event) 881 882 876 883 877 def _onparamEnter(self,event): 884 878 """ 885 879 when enter value on panel redraw model according to changed 886 880 """ 887 881 if self.model ==None: … … 941 935 def _onparamRangeEnter(self, event): 942 936 """ 943 937 Check validity of value enter in the parameters range field 944 938 """ 945 939 if self.check_invalid_panel(): … … 974 968 def _onQrangeEnter(self, event): 975 969 """ 976 970 Check validity of value enter in the Q range field 977 971 """ 978 972 if self.check_invalid_panel(): … … 1040 1034 wx.PostEvent(self.parent, event) 1041 1035 self.state_change= False 1042 1043 1036 return 1037 1044 1038 def _clear_Err_on_Fit(self): 1045 1039 """ 1046 1047 1040 hide the error text control shown 1041 after fitting 1048 1042 """ 1049 1043 … … 1084 1078 def _get_defult_custom_smear(self): 1085 1079 """ 1086 Get the defult values for custum smearing. 1087 """ 1088 1080 Get the defult values for custum smearing. 1081 """ 1089 1082 # get the default values 1090 1083 if self.dxl == None: self.dxl = 0.0 … … 1095 1088 def _get_smear_info(self): 1096 1089 """ 1097 Get the smear info from data. 1098 @return: self.smear_type, self.dq_l and self.dq_r, 1090 Get the smear info from data. 1091 1092 :return: self.smear_type, self.dq_l and self.dq_r, 1099 1093 respectively the type of the smear, dq_min and dq_max for pinhole smear data 1100 1094 while dxl and dxw for slit smear 1095 1101 1096 """ 1102 1097 … … 1118 1113 else: 1119 1114 return 1120 1121 1122 1123 1115 # check if it is pinhole smear and get min max if it is. 1124 1116 if data.dx != None and all(data.dx !=0): … … 1133 1125 self.dq_l = data.dxl[0] 1134 1126 if data.dxw != None and all(data.dxw !=0): 1135 self.dq_r = data.dxw[0] 1136 1127 self.dq_r = data.dxw[0] 1137 1128 #return self.smear_type,self.dq_l,self.dq_r 1138 1129 1139 1130 def _show_smear_sizer(self): 1140 1131 """ 1141 1132 Show only the sizers depending on smear selection 1142 1133 """ 1143 1134 # smear disabled … … 1190 1181 def _hide_all_smear_info(self): 1191 1182 """ 1192 1183 Hide all smearing messages in the set_smearer sizer 1193 1184 """ 1194 1185 self.smear_description_none.Hide() … … 1217 1208 def _set_accuracy_list(self): 1218 1209 """ 1219 1210 Set the list of an accuracy in 2D custum smear: Xhigh, High, Med, or Low 1220 1211 """ 1221 1212 # list of accuracy choices … … 1226 1217 def _on_select_accuracy(self,event): 1227 1218 """ 1228 1219 Select an accuracy in 2D custom smear: Xhigh, High, Med, or Low 1229 1220 """ 1230 1221 #event.Skip() 1231 1232 1222 # Check if the accuracy is same as before 1233 1234 1223 #self.smear2d_accuracy = event.GetEventObject().GetValue() 1235 1224 self.smear2d_accuracy = self.smear_accuracy.GetValue() … … 1239 1228 self.onSmear(event=None) 1240 1229 if self.current_smearer != None: 1241 self.current_smearer.set_accuracy(accuracy = self.smear2d_accuracy) 1242 1230 self.current_smearer.set_accuracy(accuracy = self.smear2d_accuracy) 1243 1231 event.Skip() 1244 1232 1245 1233 def _onMask(self, event): 1246 1234 """ 1247 1235 Build a panel to allow to edit Mask 1248 1236 """ 1249 1237 … … 1279 1267 def set_data(self, data): 1280 1268 """ 1281 1269 reset the current data 1282 1270 """ 1283 1271 self.data = data 1284 1285 1286 1272 if self.data is None: 1287 1273 data_min = "" … … 1302 1288 self.slit_smearer.Disable() 1303 1289 self.default_mask = copy.deepcopy(self.data.mask) 1304 1305 1290 1306 1291 self.formfactorbox.Enable() … … 1332 1317 self.btEditMask.Enable() 1333 1318 self.EditMask_title.Enable() 1334 1335 1336 1319 self.dataSource.SetValue(data_name) 1337 1320 self.qmin_x = data_min … … 1347 1330 self.state.qmax = self.qmax_x 1348 1331 1349 1350 1332 def reset_page(self, state,first=False): 1351 1333 """ 1352 1334 reset the state 1353 1335 """ 1354 1336 self.reset_page_helper(state) … … 1368 1350 def get_range(self): 1369 1351 """ 1370 1352 return the fitting range 1371 1353 """ 1372 1354 return float(self.qmin_x) , float(self.qmax_x) … … 1374 1356 def get_npts2fit(self): 1375 1357 """ 1376 return numbers of data points within qrange 1377 Note: This is for Park where chi2 is not normalized by Npts of fit 1358 return numbers of data points within qrange 1359 1360 :Note: This is for Park where chi2 is not normalized by Npts of fit 1361 1378 1362 """ 1379 1363 npts2fit = 0 … … 1393 1377 def set_npts2fit(self): 1394 1378 """ 1395 1379 setValue Npts for fitting 1396 1380 """ 1397 1381 self.Npts_fit.SetValue(str(self.get_npts2fit())) 1398 1382 1399 1400 1383 def get_chi2(self): 1401 1384 """ 1402 1385 return the current chi2 1403 1386 """ 1404 1387 return self.tcChi.GetValue() … … 1406 1389 def get_param_list(self): 1407 1390 """ 1408 @return self.param_toFit: list containing references to TextCtrl1391 :return self.param_toFit: list containing references to TextCtrl 1409 1392 checked.Theses TextCtrl will allow reference to parameters to fit. 1410 @raise: if return an empty list of parameter fit will nnote work 1393 1394 :raise: if return an empty list of parameter fit will nnote work 1411 1395 properly so raise ValueError,"missing parameter to fit" 1412 1396 """ … … 1418 1402 def onsetValues(self,chisqr,p_name, out,cov): 1419 1403 """ 1420 Build the panel from the fit result 1421 @param chisqr:Value of the goodness of fit metric 1422 @p_name: the name of parameters 1423 @param out:list of parameter with the best value found during fitting 1424 @param cov:Covariance matrix 1425 1404 Build the panel from the fit result 1405 1406 :param chisqr: Value of the goodness of fit metric 1407 :param p_name: the name of parameters 1408 :param out: list of parameter with the best value found during fitting 1409 :param cov: Covariance matrix 1410 1426 1411 """ 1427 1412 if out == None or not numpy.isfinite(chisqr): … … 1545 1530 def onPinholeSmear(self, event): 1546 1531 """ 1547 Create a custom pinhole smear object that will change the way residuals 1548 are compute when fitting 1549 @ accuracy: given by strings'High','Med', 'Low' FOR 2d, None for 1D 1532 Create a custom pinhole smear object that will change the way residuals 1533 are compute when fitting 1534 1535 :Note: accuracy is given by strings'High','Med', 'Low' FOR 2d, 1536 None for 1D 1537 1550 1538 """ 1551 1539 … … 1601 1589 def _is_changed_pinhole(self): 1602 1590 """ 1603 check if any of pinhole smear is changed 1604 return: True or False 1591 check if any of pinhole smear is changed 1592 1593 :return: True or False 1594 1605 1595 """ 1606 1596 # get the values … … 1627 1617 def _set_pinhole_smear(self): 1628 1618 """ 1629 Set custom pinhole smear 1630 return: msg 1619 Set custom pinhole smear 1620 1621 :return: msg 1622 1631 1623 """ 1632 1624 # copy data … … 1695 1687 def update_pinhole_smear(self): 1696 1688 """ 1697 called by kill_focus on pinhole TextCntrl 1698 to update the changes 1699 return: msg: False when wrong value was entered 1689 called by kill_focus on pinhole TextCntrl 1690 to update the changes 1691 1692 :return: False when wrong value was entered 1693 1700 1694 """ 1701 1695 # msg default … … 1714 1708 def onSlitSmear(self, event): 1715 1709 """ 1716 1717 1710 Create a custom slit smear object that will change the way residuals 1711 are compute when fitting 1718 1712 """ 1719 1713 … … 1770 1764 wx.PostEvent(self.manager.parent, StatusEvent(status = msg)) 1771 1765 1772 1773 1766 def _is_changed_slit(self): 1774 1767 """ 1775 check if any of slit lengths is changed 1776 return: True or False 1777 """ 1778 1768 check if any of slit lengths is changed 1769 1770 :return: True or False 1771 1772 """ 1779 1773 # get the values 1780 1774 width = self.smear_slit_width.GetValue() … … 1814 1808 def _set_slit_smear(self): 1815 1809 """ 1816 Set custom slit smear 1817 return: msg 1810 Set custom slit smear 1811 1812 :return: message to inform the user about the validity 1813 of the values entered for slit smear 1818 1814 """ 1819 1815 temp_smearer = None … … 1853 1849 ## set smearing value whether or not the data contain the smearing info 1854 1850 self.manager.set_smearer(smearer=self.current_smearer, qmin= float(self.qmin_x), qmax= float(self.qmax_x)) 1855 1856 1851 return msg 1857 1852 1858 1859 1853 def update_slit_smear(self): 1860 1854 """ 1861 called by kill_focus on pinhole TextCntrl 1862 to update the changes 1863 return: msg: False when wrong value was entered 1855 called by kill_focus on pinhole TextCntrl 1856 to update the changes 1857 1858 :return: False when wrong value was entered 1859 1864 1860 """ 1865 1861 # msg default … … 1876 1872 return True 1877 1873 1878 1879 1874 def onSmear(self, event): 1880 1875 """ 1881 1882 1876 Create a smear object that will change the way residuals 1877 are compute when fitting 1883 1878 """ 1884 1879 if event != None: … … 1950 1945 def on_complete_chisqr(self, event): 1951 1946 """ 1952 print result chisqr 1953 @event: activated by fitting/ complete after draw 1947 print result chisqr 1948 1949 :event: activated by fitting/ complete after draw 1950 1954 1951 """ 1955 1952 try: … … 1964 1961 pass 1965 1962 1966 1963 1967 1964 def select_all_param(self,event): 1968 1965 """ 1969 1966 set to true or false all checkBox given the main checkbox value cb1 1970 1967 """ 1971 1972 1968 self.param_toFit=[] 1973 1969 if self.parameters !=[]: … … 2008 2004 wx.PostEvent(self.parent, event) 2009 2005 2010 2011 2012 2006 def select_param(self,event): 2013 2007 """ 2014 2015 2008 Select TextCtrl checked for fitting purpose and stores them 2009 in self.param_toFit=[] list 2016 2010 """ 2017 2011 self.param_toFit=[] … … 2063 2057 event = PageInfoEvent(page = self) 2064 2058 wx.PostEvent(self.parent, event) 2065 2066 2059 2067 2068 2060 def set_model_param_sizer(self, model): 2069 2061 """ 2070 Build the panel from the model content 2071 @param model: the model selected in combo box for fitting purpose 2062 Build the panel from the model content 2063 2064 :param model: the model selected in combo box for fitting purpose 2065 2072 2066 """ 2073 2067 self.sizer3.Clear(True) … … 2087 2081 self.engine_type= self.manager._return_engine_type() 2088 2082 2089 2090 2083 box_description= wx.StaticBox(self, -1,str("Model Parameters")) 2091 2084 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) … … 2326 2319 self.Refresh() 2327 2320 self.SetScrollbars(20,20,25,65) 2321 2328 2322 2329 2323 class BGTextCtrl(wx.TextCtrl): 2330 2324 """ 2331 2332 2333 2325 Text control used to display outputs. 2326 No editing allowed. The background is 2327 grayed out. User can't select text. 2334 2328 """ 2335 2329 def __init__(self, *args, **kwds): … … 2345 2339 def _click(self, event): 2346 2340 """ 2347 2348 2341 Prevent further handling of the mouse event 2342 by not calling Skip(). 2349 2343 """ 2350 2344 pass 2351 2352 class HelpWindow(wx.Frame): 2353 def __init__(self, parent, id, title): 2354 wx.Frame.__init__(self, parent, id, title, size=(570, 400)) 2355 2356 from sans.models.CylinderModel import CylinderModel 2357 model = CylinderModel() 2358 2359 from danse.common.plottools.plottables import Data1D 2360 data= Data1D(x=[1,2], y=[3,4], dy=[0.1, 0,1]) 2345 2346 """ 2347 Example: :: 2361 2348 2362 from fitpanel import PageInfo 2363 myinfo = PageInfo(self, model, data=data ) 2364 2365 ## add data 2366 2367 from models import ModelList 2368 mylist= ModelList() 2369 2370 from sans.models.SphereModel import SphereModel 2371 from sans.models.SquareWellStructure import SquareWellStructure 2372 from sans.models.DebyeModel import DebyeModel 2373 from sans.models.LineModel import LineModel 2374 name= "shapes" 2375 list1= [SphereModel] 2376 mylist.set_list( name, list1) 2377 2378 name= "Shape-independent" 2379 list1= [DebyeModel] 2380 mylist.set_list( name, list1) 2381 2382 name= "Structure Factors" 2383 list1= [SquareWellStructure] 2384 mylist.set_list( name, list1) 2385 2386 name= "Added models" 2387 list1= [LineModel] 2388 mylist.set_list( name, list1) 2389 2390 myinfo.model_list_box = mylist.get_list() 2391 2392 self.page = FitPage(self, myinfo) 2393 2394 self.Centre() 2395 self.Show(True) 2396 2397 if __name__=="__main__": 2398 app = wx.App() 2399 HelpWindow(None, -1, 'HelpWindow') 2400 app.MainLoop() 2401 2349 class HelpWindow(wx.Frame): 2350 def __init__(self, parent, id, title): 2351 wx.Frame.__init__(self, parent, id, title, size=(570, 400)) 2352 2353 from sans.models.CylinderModel import CylinderModel 2354 model = CylinderModel() 2355 2356 from danse.common.plottools.plottables import Data1D 2357 data= Data1D(x=[1,2], y=[3,4], dy=[0.1, 0,1]) 2358 2359 from fitpanel import PageInfo 2360 myinfo = PageInfo(self, model, data=data ) 2361 2362 ## add data 2363 2364 from models import ModelList 2365 mylist= ModelList() 2366 2367 from sans.models.SphereModel import SphereModel 2368 from sans.models.SquareWellStructure import SquareWellStructure 2369 from sans.models.DebyeModel import DebyeModel 2370 from sans.models.LineModel import LineModel 2371 name= "shapes" 2372 list1= [SphereModel] 2373 mylist.set_list( name, list1) 2374 2375 name= "Shape-independent" 2376 list1= [DebyeModel] 2377 mylist.set_list( name, list1) 2378 2379 name= "Structure Factors" 2380 list1= [SquareWellStructure] 2381 mylist.set_list( name, list1) 2382 2383 name= "Added models" 2384 list1= [LineModel] 2385 mylist.set_list( name, list1) 2386 2387 myinfo.model_list_box = mylist.get_list() 2388 2389 self.page = FitPage(self, myinfo) 2390 2391 self.Centre() 2392 self.Show(True) 2393 2394 if __name__=="__main__": 2395 app = wx.App() 2396 HelpWindow(None, -1, 'HelpWindow') 2397 app.MainLoop() 2398 """ 2399
Note: See TracChangeset
for help on using the changeset viewer.