Changeset 2867


Ignore:
Timestamp:
Jun 18, 2017 4:09:14 PM (4 years ago)
Author:
toby
Message:

fix sequential exports

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r2863 r2867  
    17351735            fp = self.fp
    17361736            self.fp = None
    1737         fp.close()
     1737        if fp is not None: fp.close()
    17381738       
    17391739    def SetSeqRef(self,data,hist):
     
    19731973                mode = 'a'
    19741974        print('...done')
    1975     elif exporttype == 'Project':
     1975    elif exporttype == 'Project':  # note that the CIF exporter is not yet ready for this
     1976        filename = obj.askSaveFile()
     1977        if not filename: return True
     1978        obj.dirname,obj.filename = os.path.split(filename)
     1979        print('Writing output to file '+str(obj.filename)+"...")
     1980        mode = 'w'
     1981        for h in histlist:
     1982            obj.SetSeqRef(data,h)
     1983            obj.Writer(h,mode=mode)
     1984            print('\t'+str(h)+' written')
     1985            mode = 'a'
     1986        print('...done')
     1987    elif exporttype == 'Powder':
    19761988        filename = obj.askSaveFile()
    19771989        if not filename: return True
  • trunk/GSASIIgrid.py

    r2857 r2867  
    18131813            help='Perform a parametric minimization')
    18141814        # fill sequential Export menu
     1815        # for an exporter to be used for sequential exports, it must have a Writer method and
     1816        # that Writer method must offer a mode argument.
    18151817        self.SeqExportLookup = {}
    18161818        self.SequentialEx = wx.Menu(title='')
    18171819        self.SequentialMenu.Append(menu=self.SequentialEx, title='Seq Export')
     1820        import inspect
    18181821        for lbl,txt in (('Phase','Export selected phase(s)'),
    1819                         ('Project','Export entire sequential fit')):
     1822                        ('Project','Export entire sequential fit'),
     1823                        ('Powder','Export selected powder histogram(s)')
     1824                        ):
    18201825            objlist = []
    18211826            for obj in self.G2frame.exporterlist:
     
    18251830                    except AttributeError:
    18261831                        continue
    1827                     objlist.append(obj)
     1832                    if 'mode' in inspect.getargspec(obj.Writer)[0]:
     1833                        objlist.append(obj)
    18281834            if objlist:
    18291835                submenu = wx.Menu()
  • trunk/exports/G2export_CIF.py

    r2819 r2867  
    6565            return True
    6666                     
    67     def _Exporter(self,event=None,phaseOnly=None,histOnly=None):
     67    def _Exporter(self,event=None,phaseOnly=None,histOnly=None,IncludeOnlyHist=None):
    6868        '''Basic code to export a CIF. Export can be full or simple, as set by
    6969        phaseOnly and histOnly which skips distances & angles, etc.
     70
     71          phaseOnly: used to export only one phase
     72          histOnly: used to export only one histogram
     73          IncludeOnlyHist: used for a full CIF that includes only one of the
     74            histograms (from a sequential fit) TODO: needs lots of work!
    7075        '''
    7176
     
    16521657        if phaseOnly: #====Phase only CIF ================================
    16531658            print('Writing CIF output to file '+self.filename)
    1654             self.OpenFile()
     1659            #self.OpenFile()
    16551660            oneblock = True
    16561661            self.quickmode = True
     
    16611666            # report the phase info
    16621667            WritePhaseInfo(phaseOnly)
    1663             self.CloseFile()
     1668            #self.CloseFile()
    16641669            return
    16651670        elif histOnly: #====Histogram only CIF ================================
    16661671            print('Writing CIF output to file '+self.filename)
    1667             self.OpenFile()
     1672            #self.OpenFile()
    16681673            hist = histOnly
    1669             histname = histOnly.replace(' ','')
     1674            #histname = histOnly.replace(' ','')
    16701675            oneblock = True
    16711676            self.quickmode = True
     
    17041709            #writeCIFtemplate(histblk,'powder',histblk['InstrName']) # write powder template
    17051710            WritePowderData(hist)
    1706             self.CloseFile()
     1711            #self.CloseFile()
    17071712            return
     1713        #elif IncludeOnlyHist is not None: # truncate histogram list to only selected (for sequential export)
     1714        #    self.Histograms = {IncludeOnlyHist:self.Histograms[IncludeOnlyHist]}
     1715       
    17081716        #===============================================================================
    17091717        # the export process for a full CIF starts here
     
    17601768                invalid += 1
    17611769        if invalid:
    1762             msg = ""
    1763             if invalid > 3: msg = (
    1764                 "\n\nNote: it may be faster to set the name for\n"
    1765                 "one histogram for each instrument and use the\n"
    1766                 "File/Copy option to duplicate the name"
    1767                 )
     1770            #msg = ""
     1771            #if invalid > 3: msg = (
     1772            #    "\n\nNote: it may be faster to set the name for\n"
     1773            #    "one histogram for each instrument and use the\n"
     1774            #    "File/Copy option to duplicate the name"
     1775            #    )
    17681776            if not EditInstNames(): return
    17691777           
     
    18411849        #======================================================================
    18421850        print('Writing CIF output to file '+self.filename+"...")
    1843         self.OpenFile()
     1851        #self.OpenFile()
    18441852        if self.currentExportType == 'single' or self.currentExportType == 'powder':
    18451853            #======Data only CIF (powder/xtal) ====================================
     
    20172025
    20182026        WriteCIFitem('#--' + 15*'eof--' + '#')
    2019         self.CloseFile()
     2027        #self.CloseFile()
    20202028        print("...export completed")
    20212029        print('file '+self.fullpath)
     
    20372045       
    20382046    def Exporter(self,event=None):
     2047        self.OpenFile()
    20392048        self._Exporter(event=event)
    2040 
    2041     def Writer(self,hist,mode='w'):
    2042         # set the project file name
    2043         self.CIFname = os.path.splitext(
    2044             os.path.split(self.G2frame.GSASprojectfile)[1]
    2045             )[0]+'_'+hist
    2046         self.CIFname = self.CIFname.replace(' ','')
    2047         self.OpenFile(mode=mode)
    2048         self._Exporter(histOnly=hist)
    2049         if mode == 'w':
    2050             print('CIF written to file '+self.fullpath)
    20512049        self.CloseFile()
     2050
     2051    # def Writer(self,hist,mode='w'):
     2052    #     '''Used for full project CIF export of a sequential fit.
     2053    #     TODO: Needs extensive work
     2054    #     '''
     2055    #     # set the project file name
     2056    #     self.CIFname = os.path.splitext(
     2057    #         os.path.split(self.G2frame.GSASprojectfile)[1]
     2058    #         )[0]+'_'+hist
     2059    #     self.CIFname = self.CIFname.replace(' ','')
     2060    #     self.OpenFile(mode=mode)
     2061    #     self._Exporter(IncludeOnlyHist=hist)
     2062    #     if mode == 'w':
     2063    #         print('CIF written to file '+self.fullpath)
     2064    #     self.CloseFile()
    20522065       
    20532066class ExportPhaseCIF(ExportCIF):
     
    20802093        self.currentExportType = 'phase'
    20812094        if self.ExportSelect('ask'): return
     2095        self.OpenFile()
    20822096        self._Exporter(event=event,phaseOnly=self.phasenam[0])
     2097        self.CloseFile()
    20832098
    20842099    def Writer(self,hist,phasenam,mode='w'):
     
    21242139        self._Exporter(event=event,histOnly=self.histnam[0])
    21252140
     2141    def Writer(self,hist,mode='w'):
     2142        '''Used for histogram CIF export of a sequential fit.
     2143        '''
     2144        # set the project file name
     2145        self.CIFname = os.path.splitext(
     2146            os.path.split(self.G2frame.GSASprojectfile)[1]
     2147            )[0]+'_'+hist
     2148        self.CIFname = self.CIFname.replace(' ','')
     2149        self.OpenFile(mode=mode)
     2150        self._Exporter(histOnly=hist)
     2151        if mode == 'w':
     2152            print('CIF written to file '+self.fullpath)
     2153        self.CloseFile()
     2154       
    21262155class ExportHKLCIF(ExportCIF):
    21272156    '''Used to create a simple CIF containing diffraction data only. Uses exact same code as
Note: See TracChangeset for help on using the changeset viewer.