Changeset 1115 for trunk/GSASIIIO.py


Ignore:
Timestamp:
Oct 18, 2013 4:00:32 PM (8 years ago)
Author:
toby
Message:

rework exports for new types

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r1110 r1115  
    156156    file extension
    157157
    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!
    159159
    160160    :param str imagefile: name of image file
     
    17591759        self.powderDict = {}
    17601760        self.xtalDict = {}
    1761         # updated in SetupExport, when used
     1761        # updated in InitExport:
    17621762        self.currentExportType = None # type of export that has been requested
     1763        # updated in ExportSelect (when used):
    17631764        self.phasenam = None # a list of selected phases
    17641765        self.histnam = None # a list of selected histograms
     
    17691770        # The following types are defined: 'project', "phase", "powder", "single"
    17701771        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.
    17761782
    17771783        :param bool AskFile: if AskFile is True (default) get the name of the file
     
    17791785        :returns: True in case of an error
    17801786        '''
    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 True
    17881787       
    17891788        if self.currentExportType == 'phase':
     
    17911790                self.G2frame.ErrorDialog(
    17921791                    'Empty project',
    1793                     'Project does not contain any data or phases or they are not interconnected.')
     1792                    'Project does not contain any phases.')
    17941793                return True
    17951794            elif self.multiple:
     
    18131812                self.G2frame.ErrorDialog(
    18141813                    '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.')
    18161815                return True
    18171816            elif self.multiple:
     
    18351834                self.G2frame.ErrorDialog(
    18361835                    '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.')
    18381837                return True
    18391838            elif self.multiple:
     
    18531852                    if hnum is None: return True
    18541853                    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)
    18551888                   
    18561889    def loadParmDict(self):
     
    19401973        '''
    19411974        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
    19422034        self.Histograms,self.Phases = self.G2frame.GetUsedHistogramsAndPhasesfromTree()
    1943         if self.G2frame.PatternTree.IsEmpty(): return # nothing to do
    19442035        item, cookie = self.G2frame.PatternTree.GetFirstChild(self.G2frame.root)
    19452036        while item:
     
    19502041            item, cookie = self.G2frame.PatternTree.GetNextChild(self.G2frame.root, cookie)
    19512042        # index powder and single crystal histograms
    1952         self.powderDict = {}
    1953         self.xtalDict = {}
    19542043        for hist in self.Histograms:
    19552044            i = self.Histograms[hist]['hId']
     
    20452134          cell values and `cellSig` has their uncertainties.
    20462135        """
    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]
    20552148   
    20562149    def GetAtoms(self,phasenam):
     
    20682161            their standard uncertainty (or a negative value)
    20692162          * 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 is
     2163            if one number it is U\ :sub:`iso` and with six numbers it is
    20712164            U\ :sub:`11`, U\ :sub:`22`, U\ :sub:`33`, U\ :sub:`12`, U\ :sub:`13` & U\ :sub:`23`
    20722165            paired with their standard uncertainty (or a negative value)
Note: See TracChangeset for help on using the changeset viewer.