Changeset 3571
- Timestamp:
- Aug 26, 2018 7:43:05 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIctrlGUI.py
r3565 r3571 3020 3020 3021 3021 ################################################################################ 3022 def GetImportFile(G2frame, message, defaultDir="", defaultFile="", style=wx.FD_OPEN, 3023 *args, **kwargs): 3022 def GetImportFile(G2frame, message, defaultDir="", defaultFile="", 3023 style=wx.FD_OPEN, parent=None, 3024 *args, **kwargs): 3024 3025 '''Uses a customized dialog that gets files from the appropriate import directory. 3025 3026 Arguments are used the same as in :func:`wx.FileDialog`. Selection of … … 3035 3036 :returns: a list of files or an empty list 3036 3037 ''' 3037 dlg = wx.FileDialog(G2frame, message, defaultDir, defaultFile, *args, 3038 if not parent: parent = G2frame 3039 dlg = wx.FileDialog(parent, message, defaultDir, defaultFile, *args, 3038 3040 style=style, **kwargs) 3039 3041 pth = GetImportPath(G2frame) … … 3965 3967 ##### Get an output file or directory 3966 3968 ################################################################################ 3967 def askSaveFile(G2frame,defnam,extension,longFormatName ):3969 def askSaveFile(G2frame,defnam,extension,longFormatName,parent=None): 3968 3970 '''Ask the user to supply a file name 3971 3972 :param wx.Frame G2frame: The main GSAS-II window 3973 :param str defnam: a default file name 3974 :param str extension: the default file extension beginning with a '.' 3975 :param str longFormatName: a description of the type of file 3976 :param wx.Frame parent: the parent window for the dialog. Defaults 3977 to G2frame. 3969 3978 3970 3979 :returns: a file name (str) or None if Cancel is pressed 3971 3980 ''' 3972 3981 3982 if not parent: parent = G2frame 3973 3983 pth = GetExportPath(G2frame) 3974 3984 dlg = wx.FileDialog( 3975 G2frame, 'Input name for file to write', pth, defnam,3985 parent, 'Input name for file to write', pth, defnam, 3976 3986 longFormatName+' (*'+extension+')|*'+extension, 3977 3987 wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) -
trunk/GSASIIdataGUI.py
r3570 r3571 70 70 import GSASIIpwd as G2pwd 71 71 import GSASIIstrMain as G2stMn 72 import defaultIparms as dI 73 import GSASIIfpaGUI as G2fpa 72 74 73 75 # trig functions in degrees … … 1200 1202 item = submenu.Append(wx.ID_ANY,'Simulate a dataset','Create a powder data set entry that will be simulated') 1201 1203 self.Bind(wx.EVT_MENU, self.OnDummyPowder, id=item.GetId()) 1204 item = submenu.Append(wx.ID_ANY,'Fit instr. profile from fundamental parms...','') 1205 self.Bind(wx.EVT_MENU, self.OnPowderFPA, id=item.GetId()) 1202 1206 1203 1207 def OpenPowderInstprm(self,instfile): … … 1386 1390 sind = lambda x: math.sin(x*math.pi/180.) 1387 1391 tand = lambda x: math.tan(x*math.pi/180.) 1388 import defaultIparms as dI1389 1392 while True: # loop until we get a choice 1390 1393 choices = [] … … 1949 1952 self.EnableRefineCommand() 1950 1953 return # success 1951 1954 1955 def AddSimulatedPowder(self,ttArr,intArr,HistName,Lam1,Lam2): 1956 '''Create a PDWR entry for a computed powder pattern 1957 ''' 1958 # get a list of existing histograms 1959 PWDRlist = [] 1960 if self.GPXtree.GetCount(): 1961 item, cookie = self.GPXtree.GetFirstChild(self.root) 1962 while item: 1963 name = self.GPXtree.GetItemText(item) 1964 if name.startswith('PWDR ') and name not in PWDRlist: 1965 PWDRlist.append(name) 1966 item, cookie = self.GPXtree.GetNextChild(self.root, cookie) 1967 # Initialize a base class reader 1968 rd = G2obj.ImportPowderData( 1969 extensionlist=tuple(), 1970 strictExtension=False, 1971 formatName = 'FPA Simulated dataset', 1972 longFormatName = 'Fundamental Parameters simulated pattern') 1973 rd.powderentry[0] = '' # no filename 1974 # #self.powderentry[1] = pos # bank offset (N/A here) 1975 rd.powderentry[2] = 1 # only one bank 1976 rd.comments.append('This is a powder pattern simulated with Fundamental Parameters') 1977 self.CheckNotebook() 1978 #self.zipfile = None 1979 # get instrument parameters for it 1980 rd.Sample.update({'Type':'Bragg-Brentano','Shift':[0.,False],'Transparency':[0.,False], 1981 'SurfRoughA':[0.,False],'SurfRoughB':[0.,False]}) 1982 Iparm1, Iparm2 = G2fil.ReadPowderInstprm(dI.defaultIparms[0],1,1,rd) 1983 rd.idstring = ' CW' 1984 simType = 'CW' 1985 # set wavelength 1986 if Lam2: 1987 Iparm1['Lam1'][0] = Lam1 1988 Iparm1['Lam2'][0] = Lam2 1989 Iparm1['Lam1'][1] = Lam1 1990 Iparm1['Lam2'][1] = Lam2 1991 else: 1992 Iparm1['Lam'] = Iparm1['Lam1'] 1993 del Iparm1['Lam1'],Iparm1['Lam2'] 1994 Iparm1['Lam'][0] = Lam1 1995 Iparm1['Lam'][1] = Lam1 1996 1997 rd.powderdata = [ 1998 np.array(ttArr), # x-axis values 1999 np.array(intArr), # powder pattern intensities 2000 np.ones_like(ttArr), # 1/sig(intensity)^2 values (weights) 2001 np.zeros_like(intArr), # calc. intensities (zero) 2002 np.zeros_like(ttArr), # calc. background (zero) 2003 np.zeros_like(ttArr), # obs-calc profiles 2004 ] 2005 Tmin = rd.powderdata[0][0] 2006 Tmax = rd.powderdata[0][-1] 2007 # data are read, now store them in the tree 2008 HistName = 'PWDR '+HistName 2009 HistName = G2obj.MakeUniqueLabel(HistName,PWDRlist) # make new histogram names unique 2010 Id = self.GPXtree.AppendItem(parent=self.root,text=HistName) 2011 Ymin = np.min(rd.powderdata[1]) 2012 Ymax = np.max(rd.powderdata[1]) 2013 valuesdict = { 2014 'wtFactor':1.0, 2015 'Dummy':True,'simType':simType, 2016 'ranId':ran.randint(0,sys.maxsize), 2017 'Offset':[0.0,0.0],'delOffset':0.02*Ymax,'refOffset':-.1*Ymax,'refDelt':0.1*Ymax, 2018 'Yminmax':[Ymin,Ymax] 2019 } 2020 self.GPXtree.SetItemPyData(Id,[valuesdict,rd.powderdata]) 2021 self.GPXtree.SetItemPyData( 2022 self.GPXtree.AppendItem(Id,text='Comments'), 2023 rd.comments) 2024 self.GPXtree.SetItemPyData( 2025 self.GPXtree.AppendItem(Id,text='Limits'), 2026 [(Tmin,Tmax),[Tmin,Tmax]]) 2027 self.PatternId = GetGPXtreeItemId(self,Id,'Limits') 2028 self.GPXtree.SetItemPyData( 2029 self.GPXtree.AppendItem(Id,text='Background'), 2030 [['chebyschev',True,3,1.0,0.0,0.0], 2031 {'nDebye':0,'debyeTerms':[],'nPeaks':0,'peaksList':[]}]) 2032 self.GPXtree.SetItemPyData( 2033 self.GPXtree.AppendItem(Id,text='Instrument Parameters'), 2034 [Iparm1,Iparm2]) 2035 self.GPXtree.SetItemPyData( 2036 self.GPXtree.AppendItem(Id,text='Sample Parameters'), 2037 rd.Sample) 2038 self.GPXtree.SetItemPyData( 2039 self.GPXtree.AppendItem(Id,text='Peak List') 2040 ,{'peaks':[],'sigDict':{}}) 2041 self.GPXtree.SetItemPyData( 2042 self.GPXtree.AppendItem(Id,text='Index Peak List'), 2043 [[],[]]) 2044 self.GPXtree.SetItemPyData( 2045 self.GPXtree.AppendItem(Id,text='Unit Cells List'), 2046 []) 2047 self.GPXtree.SetItemPyData( 2048 self.GPXtree.AppendItem(Id,text='Reflection Lists'), 2049 {}) 2050 self.GPXtree.Expand(Id) 2051 self.GPXtree.SelectItem(Id) 2052 print(u'Added simulation powder data {}'.format(HistName)) 2053 return Id 2054 1952 2055 def OnPreferences(self,event): 1953 2056 'Edit the GSAS-II configuration variables' … … 2905 3008 G2IO.testColumnMetadata(self) 2906 3009 3010 def OnPowderFPA(self,event): 3011 'Perform FPA simulation/peak fitting' 3012 G2fpa.GetFPAInput(self) 3013 2907 3014 def OnReadPowderPeaks(self,event): 2908 3015 'Bound to menu Data/Read Powder Peaks' … … 3716 3823 self.SetTitleByGPX() 3717 3824 self.EnableRefineCommand() 3825 self.init_vars() 3718 3826 finally: 3719 3827 dlg.Destroy() -
trunk/GSASIIplot.py
r3567 r3571 48 48 :func:`PlotRigidBody` show rigid body structures as balls & sticks 49 49 :func:`PlotLayers` show layer structures as balls & sticks 50 :func:`PlotFPAconvolutors` plots the convolutors from Fundamental Parameters 50 51 ============================ =========================================================================== 51 52 … … 8704 8705 Page.canvas.SetCurrent(Page.context) 8705 8706 wx.CallAfter(Draw,'main') 8707 8708 def PlotFPAconvolutors(G2frame,NISTpk): 8709 '''Plot the convolutions used for the current peak computed with 8710 :func:`GSASIIfpaGUI.doFPAcalc` 8711 ''' 8712 import NIST_profile as FP 8713 def clearHighlight(event): 8714 l,lm,lms = Page.timer.lineinfo 8715 l.set_marker(lm) 8716 l.set_markersize(lms) 8717 Page.canvas.draw() 8718 Page.timer = None 8719 8720 def onPick(event): 8721 '''When a line in the legend is selected, find the matching line 8722 in the plot and then highlight it by adding/enlarging markers. 8723 Set up a timer to make a reset after 2.5 seconds 8724 ''' 8725 plot = event.artist.get_figure().get_axes()[0] 8726 if event.artist not in plot.get_legend().get_lines(): # is this an item in the legend? 8727 return 8728 if Page.timer: # clear previous highlight 8729 Page.timer.Stop() 8730 clearHighlight(None) 8731 return # if this is removed, the selected item is automatically highlighted 8732 lbl = event.artist.get_label() 8733 for l in plot.get_lines(): 8734 if lbl == l.get_label(): 8735 Page.timer = wx.Timer() 8736 Page.timer.Bind(wx.EVT_TIMER, clearHighlight) 8737 Page.timer.lineinfo = (l,l.get_marker(),l.get_markersize()) 8738 # highlight the selected item 8739 if l.get_marker() == 'None': 8740 l.set_marker('o') 8741 else: 8742 l.set_markersize(2*l.get_markersize()) 8743 Page.canvas.draw() 8744 Page.timer.Start(5000,oneShot=True) 8745 break 8746 else: 8747 print('Warning: artist matching ',lbl,' not found') 8748 8749 new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('FPA convolutors','mpl') 8750 if new: 8751 Page.canvas.mpl_connect('pick_event',onPick) 8752 Page.timer = None 8753 Page.SetToolTipString('') 8754 cntr = NISTpk.twotheta_window_center_deg 8755 Plot.set_title('Peak convolution functions @ 2theta={:.3f}'.format(cntr)) 8756 Plot.set_xlabel(r'$\Delta 2\theta, deg$',fontsize=14) 8757 Plot.set_ylabel(r'Intensity (arbitrary)',fontsize=14) 8758 refColors=['b','r','c','g','m','k'] 8759 ttmin = ttmax = 0 8760 for i,conv in enumerate(NISTpk.convolvers): 8761 f = NISTpk.convolver_funcs[conv]() 8762 if f is None: continue 8763 FFT = FP.best_irfft(f) 8764 if f[1].real > 0: FFT = np.roll(FFT,int(len(FFT)/2.)) 8765 FFT /= FFT.max() 8766 ttArr = np.linspace(-NISTpk.twotheta_window_fullwidth_deg/2, 8767 NISTpk.twotheta_window_fullwidth_deg/2,len(FFT)) 8768 ttmin = min(ttmin,ttArr[np.argmax(FFT>.005)]) 8769 ttmax = max(ttmax,ttArr[::-1][np.argmax(FFT[::-1]>.005)]) 8770 color = refColors[i%len(refColors)] 8771 Plot.plot(ttArr,FFT,color,label=conv[5:]) 8772 legend = Plot.legend(loc='best') 8773 for line in legend.get_lines(): 8774 line.set_picker(4) 8775 Page.toolbar.push_current() 8776 Plot.set_xlim((ttmin,ttmax)) 8777 Page.toolbar.push_current() 8778 Page.toolbar.draw() 8779 Page.canvas.draw() -
trunk/GSASIIpwdGUI.py
r3570 r3571 1607 1607 ''' 1608 1608 pth = G2G.GetExportPath(G2frame) 1609 dlg = wx.FileDialog(G2frame, ' Choose GSAS-II instrument parameters file', pth, '',1609 dlg = wx.FileDialog(G2frame, 'Set name to save GSAS-II instrument parameters file', pth, '', 1610 1610 'instrument parameter files (*.instprm)|*.instprm',wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) 1611 1611 try: -
trunk/docs/source/GSASIIGUI.rst
r3000 r3571 28 28 .. automodule:: GSASIIexprGUI 29 29 :members: 30 31 .. automodule:: GSASIIfpaGUI 32 :members:
Note: See TracChangeset
for help on using the changeset viewer.