- Timestamp:
- Mar 18, 2022 11:33:37 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/GSASIIdataGUI.py ¶
r5233 r5236 121 121 122 122 def SetDefaultDData(dType,histoName,NShkl=0,NDij=0): 123 ''' Sets default values for various histogram parameters 124 param: str dType: 3 letter histogram type, e.g. 'PNT' 125 param: str histoName: histogram name as it aoears in tree 126 param: NShkl int: number of generalized mustrain coefficients - depends on symmetry 127 param: NDij int: number of hydrostatic strain coefficients - depends on symmetry 128 129 returns dict: default data for histogram - found in data tab for phase/histogram 130 ''' 123 131 if dType in ['SXC','SNC']: 124 132 return {'Histogram':histoName,'Show':False,'Scale':[1.0,True],'Type':dType, … … 337 345 338 346 def convVersion(version): 339 '''Convert a version string ("x", "x.y", "x.y.z") into a series of 340 ints. 347 '''Convert a version string ("x", "x.y", "x.y.z") into a series of ints. 341 348 342 349 :returns: [i0, i1, i2] where None is used if a value is not specified … … 651 658 application.GetTopWindow().Show(True) 652 659 653 #### Create main frame (window) for GUI #######################################660 #### Create main frame (window) for GUI; main menu items here ####################################### 654 661 class GSASII(wx.Frame): 655 662 '''Define the main GSAS-II frame and its associated menu items. … … 663 670 log.InvokeMenuCommand(event.GetId(),self,event) 664 671 665 # def Bind(self,eventtype,handler,*args,**kwargs):666 # '''Override the Bind function so that we can wrap calls that will be logged.667 #668 # N.B. This is a bit kludgy. Menu bindings with an id are wrapped and669 # menu bindings with an object and no id are not.670 # '''671 # if eventtype == wx.EVT_MENU and 'id' in kwargs:672 # menulabels = log.SaveMenuCommand(kwargs['id'],self,handler)673 # if menulabels:674 # wx.Frame.Bind(self,eventtype,self.MenuBinding,*args,**kwargs)675 # return676 # wx.Frame.Bind(self,eventtype,handler,*args,**kwargs)677 678 672 def _Add_FileMenuItems(self, parent): 679 673 '''Add items to File menu … … 714 708 '''Add items to Data menu 715 709 ''' 716 # item = parent.Append(717 # help='',id=wx.ID_ANY,718 # kind=wx.ITEM_NORMAL,719 # text='Read image data...')720 # self.Bind(wx.EVT_MENU, self.OnImageRead, id=item.GetId())721 710 item = parent.Append(wx.ID_ANY,'Read Powder Pattern Peaks...','') 722 711 self.Bind(wx.EVT_MENU, self.OnReadPowderPeaks, id=item.GetId()) … … 758 747 759 748 def _Add_CalculateMenuItems(self,parent): 749 '''Add items to the Calculate menu 750 ''' 760 751 item = parent.Append(wx.ID_ANY,'Setup PDFs','Create PDF tree entries for selected powder patterns') 761 752 self.MakePDF.append(item) … … 1832 1823 u'Error opening/reading file {}'.format(instfile)) 1833 1824 def EnableRefineCommand(self): 1825 '''Check that phases are connected to histograms - if so then Refine is enabled 1826 ''' 1834 1827 haveData = False 1835 # check for phases connected to histograms1836 1828 sub = GetGPXtreeItemId(self,self.root,'Phases') 1837 1829 if sub: … … 1848 1840 self.dataWindow.DataMenu.Enable(G2G.wxID_DATADELETE,False) 1849 1841 for item in self.Refine: item.Enable(False) 1850 1851 1842 1852 1843 def OnImportPowder(self,event): … … 2452 2443 None for the last menu item, which is the "guess" option 2453 2444 where all appropriate formats will be tried. 2454 2445 Small angle data is presumed to be as QIE form for either x-rays or neutrons 2455 2446 ''' 2456 2447 2457 2448 def GetSASDIparm(reader): 2449 ''' Setup instrument parameters for small ang scattering data 2450 ''' 2458 2451 parm = reader.instdict 2459 2452 Iparm = {'Type':[parm['type'],parm['type'],0],'Lam':[parm['wave'], … … 2488 2481 Id = self.GPXtree.AppendItem(parent=self.root,text=HistName) 2489 2482 Iparm1,Iparm2 = GetSASDIparm(rd) 2490 # if 'T' in Iparm1['Type'][0]:2491 # if not rd.clockWd and rd.GSAS:2492 # rd.powderdata[0] *= 100. #put back the CW centideg correction2493 # cw = np.diff(rd.powderdata[0])2494 # rd.powderdata[0] = rd.powderdata[0][:-1]+cw/2.2495 # rd.powderdata[1] = rd.powderdata[1][:-1]/cw2496 # rd.powderdata[2] = rd.powderdata[2][:-1]*cw**2 #1/var=w at this point2497 # if 'Itype' in Iparm2:2498 # Ibeg = np.searchsorted(rd.powderdata[0],Iparm2['Tminmax'][0])2499 # Ifin = np.searchsorted(rd.powderdata[0],Iparm2['Tminmax'][1])2500 # rd.powderdata[0] = rd.powderdata[0][Ibeg:Ifin]2501 # YI,WYI = G2pwd.calcIncident(Iparm2,rd.powderdata[0])2502 # rd.powderdata[1] = rd.powderdata[1][Ibeg:Ifin]/YI2503 # var = 1./rd.powderdata[2][Ibeg:Ifin]2504 # var += WYI*rd.powderdata[1]**22505 # var /= YI**22506 # rd.powderdata[2] = 1./var2507 # rd.powderdata[3] = np.zeros_like(rd.powderdata[0])2508 # rd.powderdata[4] = np.zeros_like(rd.powderdata[0])2509 # rd.powderdata[5] = np.zeros_like(rd.powderdata[0])2510 2483 Tmin = min(rd.smallangledata[0]) 2511 2484 Tmax = max(rd.smallangledata[0]) … … 2563 2536 None for the last menu item, which is the "guess" option 2564 2537 where all appropriate formats will be tried. 2565 2538 Reflectometry data is presumed to be in QIE form for x-rays of neutrons 2566 2539 ''' 2567 2540 2568 2541 def GetREFDIparm(reader): 2542 ''' Setup reflectometry data instrument parameters 2543 ''' 2569 2544 parm = reader.instdict 2570 2545 Iparm = {'Type':[parm['type'],parm['type'],0],'Lam':[parm['wave'], … … 2599 2574 Id = self.GPXtree.AppendItem(parent=self.root,text=HistName) 2600 2575 Iparm1,Iparm2 = GetREFDIparm(rd) 2601 # if 'T' in Iparm1['Type'][0]:2602 # if not rd.clockWd and rd.GSAS:2603 # rd.powderdata[0] *= 100. #put back the CW centideg correction2604 # cw = np.diff(rd.powderdata[0])2605 # rd.powderdata[0] = rd.powderdata[0][:-1]+cw/2.2606 # rd.powderdata[1] = rd.powderdata[1][:-1]/cw2607 # rd.powderdata[2] = rd.powderdata[2][:-1]*cw**2 #1/var=w at this point2608 # if 'Itype' in Iparm2:2609 # Ibeg = np.searchsorted(rd.powderdata[0],Iparm2['Tminmax'][0])2610 # Ifin = np.searchsorted(rd.powderdata[0],Iparm2['Tminmax'][1])2611 # rd.powderdata[0] = rd.powderdata[0][Ibeg:Ifin]2612 # YI,WYI = G2pwd.calcIncident(Iparm2,rd.powderdata[0])2613 # rd.powderdata[1] = rd.powderdata[1][Ibeg:Ifin]/YI2614 # var = 1./rd.powderdata[2][Ibeg:Ifin]2615 # var += WYI*rd.powderdata[1]**22616 # var /= YI**22617 # rd.powderdata[2] = 1./var2618 # rd.powderdata[3] = np.zeros_like(rd.powderdata[0])2619 # rd.powderdata[4] = np.zeros_like(rd.powderdata[0])2620 # rd.powderdata[5] = np.zeros_like(rd.powderdata[0])2621 2576 Tmin = min(rd.reflectometrydata[0]) 2622 2577 Tmax = max(rd.reflectometrydata[0]) … … 2681 2636 None for the last menu item, which is the "guess" option 2682 2637 where all appropriate formats will be tried. 2683 2684 2638 ''' 2685 2639 … … 2734 2688 2735 2689 def AddToNotebook(self,text): 2690 '''Add entry to Notebook tree item 2691 ''' 2736 2692 Id = GetGPXtreeItemId(self,self.root,'Notebook') 2737 2693 data = self.GPXtree.GetItemPyData(Id) … … 3162 3118 #### init_vars ################################################################ 3163 3119 def init_vars(self): 3164 # initialize default values for GSAS-II "global" variables (saved in main Frame) 3120 ''' initialize default values for GSAS-II "global" variables (saved in main Frame) 3121 ''' 3165 3122 self.oldFocus = None 3166 3123 self.undofile = '' … … 3288 3245 3289 3246 def GetTreeItemsList(self,item): 3247 ''' returns a list of all GSAS-II tree items 3248 ''' 3290 3249 return self.GPXtree._getTreeItemsList(item) 3291 3250 … … 4139 4098 dlg.Destroy() 4140 4099 4141 def GetFileList(self,fileType,skip=None): #potentially useful? 4142 'Appears unused. Note routine of same name in GSASIIpwdGUI' 4100 def GetFileList(self,fileType,skip=None): 4101 ''' Get list of file names containing a particular string; can skip one of known GSAS-II id 4102 param: fileType str: any string within a file name 4103 param: skip int:default=None, a GSAS-II assigned id of a data item to skip in collecting the names 4104 returns: list of file names from GSAS-II tree 4105 returns: str name of file optionally skipped 4106 Appears unused, but potentially useful. 4107 Note routine of same name in GSASIIpwdGUI; it does not have the skip option 4108 ''' 4143 4109 fileList = [] 4144 4110 Source = '' … … 4312 4278 4313 4279 def OnFileReopen(self, event): 4280 ''' Creates a dialog box showing previously opened GSAS-II projects & offers to open one 4281 called by File/Reopen recent... menu item 4282 ''' 4314 4283 files = GSASIIpath.GetConfigValue('previous_GPX_files') 4315 4284 if not files: … … 4324 4293 # sellist.append("not found: {}".format(f)) 4325 4294 4326 dlg = G2G.G2SingleChoiceDialog(self, 4327 'Select previous project to open', 4328 'Select project',sellist) 4295 dlg = G2G.G2SingleChoiceDialog(self,'Select previous project to open', 4296 'Select project',sellist) 4329 4297 dlg.CenterOnParent() 4330 4298 if dlg.ShowModal() == wx.ID_OK: … … 4546 4514 4547 4515 def OnFileSaveas(self, event): 4548 '''Save the current project in response to the4549 File/Save as menu button 4516 '''Save the current project with a new name in response to the 4517 File/Save as menu button. The current project then has this new name 4550 4518 ''' 4551 4519 if GSASIIpath.GetConfigValue('Starting_directory'): … … 4811 4779 4812 4780 def OnExportPeakList(self,event): 4781 '''Exports a PWDR peak list as a text file 4782 ''' 4813 4783 pth = G2G.GetExportPath(self) 4814 4784 dlg = wx.FileDialog(self, 'Choose output peak list file name', pth, '', … … 4873 4843 4874 4844 def OnExportHKL(self,event): 4845 '''Exports a PWDR reflection list as a text file 4846 ''' 4875 4847 pth = G2G.GetExportPath(self) 4876 4848 dlg = wx.FileDialog(self, 'Choose output reflection list file name', pth, '', … … 5372 5344 5373 5345 def OnRefine(self,event): 5374 '''Perform a refinement or a sequential refinement (depending on controls setting)5346 '''Perform a single refinement or a sequential refinement (depending on controls setting) 5375 5347 Called from the Calculate/Refine menu. 5376 5348 ''' … … 5470 5442 5471 5443 def OnLeBail(self,event): 5472 Controls = self.GPXtree.GetItemPyData(GetGPXtreeItemId(self,self.root, 'Controls')) 5444 '''Do a 1 cycle LeBail refinement with no other variables; usually done upon initialization of a LeBail refinement 5445 either single or sequentially 5446 ''' 5473 5447 self.OnFileSave(event) 5474 5448 item = GetGPXtreeItemId(self,self.root,'Covariance') … … 5480 5454 5481 5455 dlg = G2G.RefinementProgress(parent=self) 5482 # dlg = wx.ProgressDialog('Residual','All data Rw =',101.0,5483 # style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_CAN_ABORT|wx.STAY_ON_TOP,parent=self)5484 # Size = dlg.GetSize()5485 # if 50 < Size[0] < 500: # sanity check on size, since this fails w/Win & wx3.05486 # dlg.SetSize((int(Size[0]*1.2),Size[1])) # increase size a bit along x5487 # dlg.CenterOnParent()5488 #dlg.Raise() # dangerous5489 5456 self.SaveTreeSetting() # save the current tree selection 5490 5457 self.GPXtree.SaveExposedItems() # save the exposed/hidden tree items … … 5687 5654 self.OnLeBail(event) 5688 5655 # select it 5689 dlgp = G2G.RefinementProgress('Residual for histogram 0','Powder profile Rwp =', 5690 parent=self) 5691 # dlgp = wx.ProgressDialog('Residual for histogram 0','Powder profile Rwp =',101.0, 5692 # style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_CAN_ABORT, 5693 # parent=self) 5694 # Size = dlgp.GetSize() 5695 # if 50 < Size[0] < 500: # sanity check on size, since this fails w/Win & wx3.0 5696 # dlgp.SetSize((int(Size[0]*1.2),Size[1])) # increase size a bit along x 5697 # dlgp.CenterOnParent() 5698 # dlgp.Show() 5656 dlgp = G2G.RefinementProgress('Residual for histogram 0','Powder profile Rwp =',parent=self) 5699 5657 self.PatternId = GetGPXtreeItemId(self,self.root,histNames[0]) 5700 5658 if self.PatternId and self.GPXtree.GetItemText(self.PatternId).startswith('PWDR '): … … 5727 5685 self.GPXtree.DeleteChildren(self.root) 5728 5686 if len(self.HKL): self.HKL = [] 5729 # if self.G2plotNB.plotList:5730 # self.G2plotNB.clear()5731 5687 G2IO.ProjFileOpen(self,False) 5732 5688 self.GPXtree.RestoreExposedItems() 5733 5689 self.ResetPlots() 5734 #self.PatternId = GetGPXtreeItemId(self,self.root,plotHist)5735 #SelectDataTreeItem(self,self.PatternId)5736 5690 sId = GetGPXtreeItemId(self,self.root,'Sequential results') 5737 5691 SelectDataTreeItem(self,sId) … … 5742 5696 dlg.Destroy() 5743 5697 5744 # self.SeqTblHideList = []5745 5698 else: 5746 5699 self.ErrorDialog('Sequential refinement error',Msg) 5747 5700 5748 5701 def OnRunFprime(self,event): 5702 '''Run Fprime''' 5749 5703 import fprime 5750 5704 self.fprime = fprime.Fprime(self) … … 5752 5706 5753 5707 def OnRunAbsorb(self,event): 5708 '''Run Absorb''' 5754 5709 import Absorb 5755 5710 self.absorb = Absorb.Absorb(self) … … 5757 5712 5758 5713 def OnRunPlotXNFF(self,evnt): 5714 '''Run PlotXNFF''' 5759 5715 import PlotXNFF 5760 5716 self.plotXNFF = PlotXNFF.PlotXNFF(self) … … 5793 5749 G2IO.ExportSequentialFullCIF(self,data,Controls) 5794 5750 5795 # Data window side of main GUI ################################################5751 #### Data window side of main GUI; menu definitions here ######################### 5796 5752 class G2DataWindow(wx.ScrolledWindow): #wxscroll.ScrolledPanel): 5797 5753 '''Create the data item window as well as the menu. Note that … … 5936 5892 menu.Append(menu=HelpMenu,title='&Help') 5937 5893 5894 #### Menu definitions here 5938 5895 def _initMenus(self): 5939 5896 '''define all GSAS-II data window menus. … … 5942 5899 ''' 5943 5900 5944 # G2G.Define_wxId('wxID_MCRON', 'wxID_MCRLIST', 'wxID_MCRSAVE', 'wxID_MCRPLAY',)5945 5901 ##### GSAS-II Menu items 5946 5902 # Main menu … … 6000 5956 'Show ISODISTORT mode values for all phases') 6001 5957 self.ConstraintEdit.Enable(G2G.wxID_SHOWISO,False) 6002 # for DEBUG only6003 #def OnShowISODISTORT(event):6004 # import imp6005 # imp.reload(G2cnstG) # for testing changes to GSASIIconstrGUI6006 # G2cnstG.ShowIsoDistortCalc(G2frame)6007 #G2frame.Bind(wx.EVT_MENU, OnShowISODISTORT, id=G2G.wxID_SHOWISO)6008 # end DEBUG6009 5958 6010 5959 self.PostfillDataMenu() … … 6926 6875 choices = [i for i in choices if i in usedHistograms] 6927 6876 if len(choices) == 0: 6928 G2G.G2MessageBox(G2frame, 6929 'No histograms in use found for a sequential fit.', 6930 'No Histograms') 6877 G2G.G2MessageBox(G2frame,'No histograms in use found for a sequential fit.','No Histograms') 6931 6878 return 6932 6879 sel = [] 6933 6880 try: 6934 6881 if 'Seq Data' in data: 6935 # for item in data['Seq Data']:6936 # sel.append(choices.index(item))6937 6882 sel = [choices.index(item) for item in data['Seq Data']] 6938 6883 except ValueError: #data changed somehow - start fresh 6939 6884 sel = [] 6940 6885 dlg = G2G.G2MultiChoiceDialog(G2frame, 6941 6942 6886 'Select datasets to include. Select no datasets to end sequential refinements.', 6887 'Sequential refinement selection',choices) 6943 6888 dlg.SetSelections(sel) 6944 6889 names = [] … … 7244 7189 7245 7190 def OnPlot1DHKL(event): 7191 '''Plots a 1D stick diagram of reflection intensities''' 7246 7192 refList = data[1]['RefList'] 7247 7193 G2plt.Plot1DSngl(G2frame,newPlot=True,hklRef=refList,Super=Super,Title=phaseName) 7248 7194 7249 7195 def OnPlot3DHKL(event): 7196 '''Plots in 3D reciprocal space with green dots proportional to F^2, etc. from single histogram''' 7250 7197 refList = data[1]['RefList'] 7251 7198 FoMax = np.max(refList.T[8+Super]) … … 7260 7207 7261 7208 def OnPlotAll3DHKL(event): 7209 '''Plots in 3D reciprocal space with green dots proportional to F^2, etc. from all SHKL histograms''' 7262 7210 choices = GetGPXtreeDataNames(G2frame,['HKLF',]) 7263 7211 dlg = G2G.G2MultiChoiceDialog(G2frame, 'Select reflection sets to plot', … … 7289 7237 G2plt.Plot3DSngl(G2frame,newPlot=True,Data=controls,hklRef=refList,Title=phaseName) 7290 7238 7291 def OnToggleExt(event):7292 print('TBD')7293 7294 7239 def OnMergeHKL(event): 7240 '''Merge HKLF data sets to unique set according to Laue symmetry''' 7295 7241 Name = G2frame.GPXtree.GetItemText(G2frame.PatternId) 7296 7242 Inst = G2frame.GPXtree.GetItemPyData(GetGPXtreeItemId(G2frame, … … 7392 7338 7393 7339 def OnErrorAnalysis(event): 7340 '''Plots an "Abrams" plot - sorted delta/sig across data set. 7341 Should be straight line of slope 1 - never is''' 7394 7342 G2plt.PlotDeltSig(G2frame,kind) 7395 7343 … … 7432 7380 # if kind == 'PWDR' and 'Compression' not in data[0]: 7433 7381 # data[0]['Compression'] = 1 7434 #if isinstance(data[1],list) and kind == 'HKLF':7435 7382 if 'list' in str(type(data[1])) and kind == 'HKLF': 7436 7383 RefData = {'RefList':[],'FF':[]} … … 7456 7403 if G2frame.dataWindow: 7457 7404 G2frame.dataWindow.ClearData() 7458 #G2frame.dataWindow.GetSizer() # don't use this since may be wx.HORIZONTAL or wx.VERTICAL7459 7405 mainSizer = wx.BoxSizer(wx.VERTICAL) 7460 7406 mainSizer.Add((5,5),) … … 7534 7480 data[0]['Magnification'][1:] = sorted(data[0]['Magnification'][1:],key=lambda x: x[0]) 7535 7481 if lenmag > 1: 7536 panel = wx.StaticBox(G2frame.dataWindow, wx.ID_ANY, 'Magnification regions', 7537 style=wx.ALIGN_CENTER) 7482 panel = wx.StaticBox(G2frame.dataWindow, wx.ID_ANY, 'Magnification regions',style=wx.ALIGN_CENTER) 7538 7483 mSizer = wx.StaticBoxSizer(panel,wx.VERTICAL) 7539 7484 magSizer = wx.FlexGridSizer(lenmag+1,3,0,0) … … 7779 7724 Nvars = len(data['varyList']) 7780 7725 Rvals = data['Rvals'] 7781 text = ('\nResiduals after last refinement: \n'+7726 text = ('\nResiduals after last refinement: \n'+ 7782 7727 '\twR = {:.3f}\n\tchi**2 = {:.1f}\n\tGOF = {:.2f}').format( 7783 7728 Rvals['Rwp'],Rvals['chisq'],Rvals['GOF']) -
TabularUnified trunk/GSASIIpwdGUI.py ¶
r5210 r5236 405 405 406 406 def GetFileList(G2frame,fileType): 407 ''' Get list of file names containing a particular string 408 param: fileType str: any string within a file name 409 returns: list of file names from GSAS-II tree 410 Note routine of same name in GSASIIdataGUI; it has a skip option 411 ''' 407 412 fileList = [] 408 413 Id, cookie = G2frame.GPXtree.GetFirstChild(G2frame.root)
Note: See TracChangeset
for help on using the changeset viewer.