Changeset 1115
- Timestamp:
- Oct 18, 2013 4:00:32 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASII.py
r1106 r1115 30 30 import wx 31 31 import matplotlib as mpl 32 import wx.lib.inspection as wxeye33 32 try: 34 33 import OpenGL as ogl … … 1154 1153 singlemenu, help='Export single crystal histogram(s)') 1155 1154 1155 imagemenu = wx.Menu() 1156 item = menu.AppendMenu( 1157 wx.ID_ANY, 'Images as', 1158 imagemenu, help='Export powder image(s)') 1159 1160 mapmenu = wx.Menu() 1161 item = menu.AppendMenu( 1162 wx.ID_ANY, 'Maps as', 1163 mapmenu, help='Export density map(s)') 1164 1165 # pdfmenu = wx.Menu() 1166 # item = menu.AppendMenu( 1167 # wx.ID_ANY, 'PDFs as', 1168 # pdfmenu, help='Export pair distribution function(s)') 1169 1156 1170 # find all the exporter files 1157 1171 pathlist = sys.path … … 1202 1216 elif typ == "single": 1203 1217 submenu = singlemenu 1218 elif typ == "image": 1219 submenu = imagemenu 1220 elif typ == "map": 1221 submenu = mapmenu 1222 # elif typ == "pdf": 1223 # submenu = pdfmenu 1204 1224 else: 1205 1225 print("Error, unknown type in "+str(obj)) … … 1214 1234 #code to debug an Exporter. much is hard-coded below, but code is reloaded before 1215 1235 # each use allowing faster development 1216 # def Debug Text(event):1236 # def DebugExport(event): 1217 1237 # reload(G2IO) 1218 # import dev_export_example 1219 # reload(dev_export_example) 1220 # dev_export_example.ExportSingleText(self).Exporter(event) 1238 # #import dev_export as dev 1239 # import G2export_csv as dev 1240 # reload(dev) 1241 # #dev.ExportTest(self).Exporter(event) 1242 # dev.ExportPowderCSV(self).Exporter(event) 1243 # dev.ExportPowderReflCSV(self).Exporter(event) 1221 1244 # item = menu.Append( 1222 1245 # wx.ID_ANY,kind=wx.ITEM_NORMAL, 1223 # help="debug text",text="test Export") 1224 # self.Bind(wx.EVT_MENU, DebugText, id=item.GetId()) 1225 # self.ExportLookup[item.GetId()] = 'single' 1246 # help="debug exporter",text="test Export") 1247 # self.Bind(wx.EVT_MENU, DebugExport, id=item.GetId()) 1248 # #self.ExportLookup[item.GetId()] = 'image' 1249 # self.ExportLookup[item.GetId()] = 'powder' 1226 1250 1227 1251 def _Add_ExportMenuItems(self,parent): … … 2733 2757 # may want to do this if we can 2734 2758 application = GSASIImain(0) 2735 if wxInspector: wxeye.InspectionTool().Show() 2759 if wxInspector: 2760 import wx.lib.inspection as wxeye 2761 wxeye.InspectionTool().Show() 2736 2762 2737 2763 #application.main.OnRefine(None) -
trunk/GSASIIIO.py
r1110 r1115 156 156 file extension 157 157 158 :param wx.Frame G2frame: main GSAS-II Frame and data object 158 :param wx.Frame G2frame: main GSAS-II Frame and data object. Note: not used! 159 159 160 160 :param str imagefile: name of image file … … 1759 1759 self.powderDict = {} 1760 1760 self.xtalDict = {} 1761 # updated in SetupExport, when used1761 # updated in InitExport: 1762 1762 self.currentExportType = None # type of export that has been requested 1763 # updated in ExportSelect (when used): 1763 1764 self.phasenam = None # a list of selected phases 1764 1765 self.histnam = None # a list of selected histograms … … 1769 1770 # The following types are defined: 'project', "phase", "powder", "single" 1770 1771 self.multiple = False # set as True if the class can export multiple phases or histograms 1771 # ignored for "project" exports 1772 1773 def SetupExport(self,event,AskFile=True): 1774 '''Determines the type of menu that called the Exporter. Selects histograms 1775 or phases when needed. 1772 # self.multiple is ignored for "project" exports 1773 1774 def InitExport(self,event): 1775 '''Determines the type of menu that called the Exporter. 1776 ''' 1777 if event: 1778 self.currentExportType = self.G2frame.ExportLookup.get(event.Id) 1779 1780 def ExportSelect(self,AskFile=True): 1781 '''Selects histograms or phases when needed. Sets a default file name. 1776 1782 1777 1783 :param bool AskFile: if AskFile is True (default) get the name of the file … … 1779 1785 :returns: True in case of an error 1780 1786 ''' 1781 if event:1782 self.currentExportType = self.G2frame.ExportLookup.get(event.Id)1783 if AskFile:1784 self.filename = self.askSaveFile()1785 else:1786 self.filename = self.defaultSaveFile()1787 if not self.filename: return True1788 1787 1789 1788 if self.currentExportType == 'phase': … … 1791 1790 self.G2frame.ErrorDialog( 1792 1791 'Empty project', 1793 'Project does not contain any data or phases or they are not interconnected.')1792 'Project does not contain any phases.') 1794 1793 return True 1795 1794 elif self.multiple: … … 1813 1812 self.G2frame.ErrorDialog( 1814 1813 'Empty project', 1815 'Project does not contain any single crystal data or data is not connected to a phase.')1814 'Project does not contain any single crystal data.') 1816 1815 return True 1817 1816 elif self.multiple: … … 1835 1834 self.G2frame.ErrorDialog( 1836 1835 'Empty project', 1837 'Project does not contain any powder data or data is not connected to a phase.')1836 'Project does not contain any powder data.') 1838 1837 return True 1839 1838 elif self.multiple: … … 1853 1852 if hnum is None: return True 1854 1853 self.histnam = [choices[hnum]] 1854 elif self.currentExportType == 'image': 1855 if len(self.Histograms) == 0: 1856 self.G2frame.ErrorDialog( 1857 'Empty project', 1858 'Project does not contain any images.') 1859 return True 1860 elif len(self.Histograms) == 1: 1861 self.histnam = self.Histograms.keys() 1862 else: 1863 choices = sorted(self.Histograms.keys()) 1864 hnum = G2gd.ItemSelector(choices,self.G2frame,multiple=self.multiple) 1865 if hnum is None: return True 1866 if self.multiple: 1867 self.histnam = [choices[i] for i in hnum] 1868 else: 1869 self.histnam = [choices[hnum]] 1870 if AskFile: 1871 self.filename = self.askSaveFile() 1872 else: 1873 self.filename = self.defaultSaveFile() 1874 if not self.filename: return True 1875 1876 # def SetupExport(self,event,AskFile=True): 1877 # '''Determines the type of menu that called the Exporter. Selects histograms 1878 # or phases when needed. Better to replace with individual calls to 1879 # self.InitExport() and self.ExportSelect() so that the former can be called prior 1880 # to self.LoadTree() 1881 1882 # :param bool AskFile: if AskFile is True (default) get the name of the file 1883 # in a dialog 1884 # :returns: True in case of an error 1885 # ''' 1886 # self.ExportInit(event) 1887 # return self.ExportSelect(AskFile) 1855 1888 1856 1889 def loadParmDict(self): … … 1940 1973 ''' 1941 1974 self.OverallParms = {} 1975 self.powderDict = {} 1976 self.xtalDict = {} 1977 if self.G2frame.PatternTree.IsEmpty(): return # nothing to do 1978 histType = None 1979 if self.currentExportType == 'phase': 1980 # if exporting phases load them here 1981 sub = G2gd.GetPatternTreeItemId(self.G2frame,self.G2frame.root,'Phases') 1982 if not sub: 1983 print 'no phases found' 1984 return True 1985 item, cookie = self.G2frame.PatternTree.GetFirstChild(sub) 1986 while item: 1987 phaseName = self.G2frame.PatternTree.GetItemText(item) 1988 self.Phases[phaseName] = self.G2frame.PatternTree.GetItemPyData(item) 1989 item, cookie = self.G2frame.PatternTree.GetNextChild(sub, cookie) 1990 return 1991 elif self.currentExportType == 'single': 1992 histType = 'HKLF' 1993 elif self.currentExportType == 'powder': 1994 histType = 'PWDR' 1995 elif self.currentExportType == 'image': 1996 histType = 'IMG' 1997 1998 if histType: # Loading just one kind of tree entry 1999 item, cookie = self.G2frame.PatternTree.GetFirstChild(self.G2frame.root) 2000 while item: 2001 name = self.G2frame.PatternTree.GetItemText(item) 2002 if name.startswith(histType): 2003 if self.Histograms.get(name): # there is already an item with this name 2004 if name[-1] == '9': 2005 name = name[:-1] + '10' 2006 elif name[-1] in '012345678': 2007 name = name[:-1] + str(int(name[:-1])+1) 2008 else: 2009 name += '-1' 2010 self.Histograms[name] = {} 2011 self.Histograms[name]['Data'] = self.G2frame.PatternTree.GetItemPyData(item)[1] 2012 item2, cookie2 = self.G2frame.PatternTree.GetFirstChild(item) 2013 while item2: 2014 child = self.G2frame.PatternTree.GetItemText(item2) 2015 self.Histograms[name][child] = self.G2frame.PatternTree.GetItemPyData(item2) 2016 item2, cookie2 = self.G2frame.PatternTree.GetNextChild(item, cookie2) 2017 item, cookie = self.G2frame.PatternTree.GetNextChild(self.G2frame.root, cookie) 2018 # index powder and single crystal histograms by number 2019 for hist in self.Histograms: 2020 if hist.startswith("PWDR"): 2021 d = self.powderDict 2022 elif hist.startswith("HKLF"): 2023 d = self.xtalDict 2024 else: 2025 return 2026 i = self.Histograms[hist].get('hId') 2027 if i is None and not d.keys(): 2028 i = 0 2029 elif i is None or i in d.keys(): 2030 i = max(d.keys())+1 2031 d[i] = hist 2032 return 2033 # else standard load: using all interlinked phases and histograms 1942 2034 self.Histograms,self.Phases = self.G2frame.GetUsedHistogramsAndPhasesfromTree() 1943 if self.G2frame.PatternTree.IsEmpty(): return # nothing to do1944 2035 item, cookie = self.G2frame.PatternTree.GetFirstChild(self.G2frame.root) 1945 2036 while item: … … 1950 2041 item, cookie = self.G2frame.PatternTree.GetNextChild(self.G2frame.root, cookie) 1951 2042 # index powder and single crystal histograms 1952 self.powderDict = {}1953 self.xtalDict = {}1954 2043 for hist in self.Histograms: 1955 2044 i = self.Histograms[hist]['hId'] … … 2045 2134 cell values and `cellSig` has their uncertainties. 2046 2135 """ 2047 phasedict = self.Phases[phasenam] # pointer to current phase info 2048 pfx = str(phasedict['pId'])+'::' 2049 A,sigA = G2stIO.cellFill(pfx,phasedict['General']['SGData'],self.parmDict,self.sigDict) 2050 cellSig = G2stIO.getCellEsd(pfx, 2051 phasedict['General']['SGData'],A, 2052 self.OverallParms['Covariance']) # returns 7 vals, includes sigVol 2053 cellList = G2lat.A2cell(A) + (G2lat.calc_V(A),) 2054 return cellList,cellSig 2136 phasedict = self.Phases[phasenam] # pointer to current phase info 2137 try: 2138 pfx = str(phasedict['pId'])+'::' 2139 A,sigA = G2stIO.cellFill(pfx,phasedict['General']['SGData'],self.parmDict,self.sigDict) 2140 cellSig = G2stIO.getCellEsd(pfx, 2141 phasedict['General']['SGData'],A, 2142 self.OverallParms['Covariance']) # returns 7 vals, includes sigVol 2143 cellList = G2lat.A2cell(A) + (G2lat.calc_V(A),) 2144 return cellList,cellSig 2145 except KeyError: 2146 cell = phasedict['General']['Cell'][1:] 2147 return cell,7*[0] 2055 2148 2056 2149 def GetAtoms(self,phasenam): … … 2068 2161 their standard uncertainty (or a negative value) 2069 2162 * td is contains a list with either one or six pairs of numbers: 2070 if one number it is U\ :sub:`iso` and with six it is2163 if one number it is U\ :sub:`iso` and with six numbers it is 2071 2164 U\ :sub:`11`, U\ :sub:`22`, U\ :sub:`33`, U\ :sub:`12`, U\ :sub:`13` & U\ :sub:`23` 2072 2165 paired with their standard uncertainty (or a negative value) -
trunk/GSASIIgrid.py
r1110 r1115 1313 1313 ParentFrame,title, header, ChoiceList, 1314 1314 style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.OK|wx.CENTRE) 1315 pass 1315 # I would like to add a select all and toggle all button 1316 # to this dialog in some manner, but that is going to 1317 # require that I recode the entire dialog -- TODO someday 1316 1318 else: 1317 1319 if useCancel: … … 1325 1327 if dlg.ShowModal() == wx.ID_OK: 1326 1328 if multiple: 1329 dlg.Destroy() 1327 1330 return dlg.GetSelections() 1328 1331 else: 1332 dlg.Destroy() 1329 1333 return dlg.GetSelection() 1330 1334 else: 1335 dlg.Destroy() 1331 1336 return None 1332 1337 dlg.Destroy() -
trunk/exports/G2export_CIF.py
r1102 r1115 1516 1516 1517 1517 # the export process starts here 1518 self.InitExport(event) 1518 1519 # load all of the tree into a set of dicts 1519 1520 self.loadTree() 1520 1521 # create a dict with refined values and their uncertainties 1521 1522 self.loadParmDict() 1522 if self.SetupExport(event, # set export parameters 1523 AskFile=(self.mode=='simple') 1524 ): return 1523 if self.ExportSelect(AskFile=(self.mode=='simple')): # set export parameters 1524 return 1525 1525 # Someday: get restraint & constraint info 1526 1526 #restraintDict = self.OverallParms.get('Restraints',{}) … … 1842 1842 class ExportPhaseCIF(ExportCIF): 1843 1843 '''Used to create a simple CIF of at most one phase. Uses exact same code as 1844 :class:`ExportCIF` except that `self.mode` is set to "simple" . Shows up in menu as1845 Quick CIF1844 :class:`ExportCIF` except that `self.mode` is set to "simple" in `self.InitExport`. 1845 Shows up in menu as Quick CIF. 1846 1846 1847 1847 :param wx.Frame G2frame: reference to main GSAS-II frame … … 1862 1862 '''Used to create a simple CIF containing diffraction data only. Uses exact same code as 1863 1863 :class:`ExportCIF` except that `self.mode` is set to "simple" and `self.currentExportType` 1864 is set to "single" or "powder" in `self. SetupExport`. Shows up in menus as Data-only CIF.1864 is set to "single" or "powder" in `self.InitExport`. Shows up in menus as Data-only CIF. 1865 1865 1866 1866 :param wx.Frame G2frame: reference to main GSAS-II frame -
trunk/exports/G2export_PDB.py
r1102 r1115 116 116 117 117 # the export process starts here 118 self.InitExport(event) 118 119 # load all of the tree into a set of dicts 119 120 self.loadTree() 120 121 # create a dict with refined values and their uncertainties 121 122 self.loadParmDict() 122 if self. SetupExport(event,AskFile=True):# set export parameters123 if self.ExportSelect(AskFile=True): # set export parameters 123 124 return 124 125 for phasenam in self.phasenam: … … 213 214 ''' 214 215 # the export process starts here 216 self.InitExport(event) 215 217 # load all of the tree into a set of dicts 216 218 self.loadTree() 217 219 # create a dict with refined values and their uncertainties 218 220 self.loadParmDict() 219 if self. SetupExport(event,AskFile=True):# set export parameters221 if self.ExportSelect(AskFile=True): # set export parameters 220 222 return 221 223 for phasenam in self.phasenam: -
trunk/exports/G2export_examples.py
r1102 r1115 8 8 # $Id$ 9 9 ########### SVN repository information ################### 10 '''Code to demonstrate how export routines are created10 '''Code to demonstrate how GSAS-II data export routines are created 11 11 ''' 12 12 import os.path … … 30 30 super(self.__class__,self).__init__( # fancy way to say <parentclass>.__init__ 31 31 G2frame=G2frame, 32 formatName = ' text',32 formatName = 'Text file', 33 33 extension='.txt', 34 34 longFormatName = 'Export phase as text file' … … 41 41 ''' 42 42 # the export process starts here 43 self.InitExport(event) 43 44 # load all of the tree into a set of dicts 44 45 self.loadTree() 45 46 # create a dict with refined values and their uncertainties 46 47 self.loadParmDict() 47 if self.SetupExport( # set export parameters 48 event, 48 if self.ExportSelect( # set export parameters 49 49 AskFile=True # prompt the user for a file name 50 50 ): return … … 114 114 super(self.__class__,self).__init__( # fancy way to say <parentclass>.__init__ 115 115 G2frame=G2frame, 116 formatName = ' text',116 formatName = 'Text file', 117 117 extension='.txt', 118 118 longFormatName = 'Export powder data as text file' … … 125 125 ''' 126 126 # the export process starts here 127 # load all of the tree into a set of dicts 128 self.loadTree() 129 print 'Exporter',self.defaultSaveFile() 130 if self.SetupExport( # set export parameters 131 event, 127 self.InitExport(event) 128 # load all of the tree into a set of dicts 129 self.loadTree() 130 if self.ExportSelect( # set export parameters 132 131 AskFile=False # use the default file name 133 132 #AskFile=True … … 136 135 hist = self.histnam[0] # there should only be one histogram, in any case take the 1st 137 136 histblk = self.Histograms[hist] 138 #inst = histblk['Instrument Parameters'][0]139 #hId = histblk['hId']140 #pfx = ':' + str(hId) + ':'141 137 fmt = 2*"{:12.3f} " + "{:12.5f} " + 2*"{:12.3f} " 142 138 hfmt = 5*"{:>12s} " … … 171 167 '''Export a set of powder reflections as a text file 172 168 ''' 173 # load all of the tree into a set of dicts174 self.loadTree()175 if self.SetupExport( # set export parameters176 event,169 self.InitExport(event) 170 # load all of the tree into a set of dicts 171 self.loadTree() 172 if self.ExportSelect( # set export parameters 177 173 AskFile=False # use the default file name 178 174 #AskFile=True … … 204 200 super(self.__class__,self).__init__( # fancy way to say <parentclass>.__init__ 205 201 G2frame=G2frame, 206 formatName = ' reflection list as text',202 formatName = 'Text file', 207 203 extension='.txt', 208 204 longFormatName = 'Export reflection list as a text file' … … 215 211 ''' 216 212 # the export process starts here 217 # load all of the tree into a set of dicts218 self.loadTree()219 if self.SetupExport( # set export parameters220 event,213 self.InitExport(event) 214 # load all of the tree into a set of dicts 215 self.loadTree() 216 if self.ExportSelect( # set export parameters 221 217 AskFile=False # use the default file name 222 218 #AskFile=True -
trunk/exports/G2export_shelx.py
r1102 r1115 26 26 super(self.__class__,self).__init__( # fancy way to say <parentclass>.__init__ 27 27 G2frame=G2frame, 28 formatName = 'SHELX ',28 formatName = 'SHELX .ins', 29 29 extension='.ins', 30 30 longFormatName = 'Export phase as SHELX .ins file' … … 38 38 import re 39 39 # the export process starts here 40 self.InitExport(event) 40 41 # load all of the tree into a set of dicts 41 42 self.loadTree() 42 43 # create a dict with refined values and their uncertainties 43 44 self.loadParmDict() 44 if self.SetupExport(event, # set export parameters 45 AskFile=True 46 ): return 45 if self.ExportSelect( # set export parameters 46 AskFile=True): return 47 47 for phasenam in self.phasenam: 48 48 phasedict = self.Phases[phasenam] # pointer to current phase info … … 56 56 # title line 57 57 self.Write("TITL from "+str(self.G2frame.GSASprojectfile)+", phase "+str(phasenam)) 58 # get & write cell parameters 59 pfx = str(phasedict['pId'])+'::' 60 A,sigA = G2stIO.cellFill(pfx,phasedict['General']['SGData'],self.parmDict,self.sigDict) 61 self.Write("CELL 0.5 {:.5f} {:.5f} {:.5f} {:.3f} {:.3f} {:.3f}".format(*G2lat.A2cell(A))) 58 # get & write cell parameters 59 cell,sig = self.GetCell(phasenam) 60 self.Write("CELL 0.5 {:.5f} {:.5f} {:.5f} {:.3f} {:.3f} {:.3f}".format(*cell[:6])) 62 61 # Shelx lattice number 63 62 lattnum = {'P':1,'I':2,'R':2,'F':3,'A':4,'B':5,'C':6}.get(phasedict['General']['SGData']['SGLatt'],0)
Note: See TracChangeset
for help on using the changeset viewer.