Changeset 2065


Ignore:
Timestamp:
Nov 22, 2015 5:56:33 PM (7 years ago)
Author:
toby
Message:

Allow reading of multiple images from single file

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r2061 r2065  
    331331    def OnImportGeneric(self,reader,readerlist,label,multiple=False,
    332332                        usedRanIdList=[],Preview=True):
    333         '''Used to import Phases or datasets using reader objects
    334         subclassed from :class:`GSASIIIO.ImportPhase`,
     333        '''Used for all imports, including Phases, datasets, images...
     334
     335        Called from :meth:`GSASII.OnImportPhase`, :meth:`GSASII.OnImportImage`,
     336        :meth:`GSASII.OnImportSfact`, :meth:`GSASII.OnImportPowder` and
     337        :meth:`GSASII.OnImportSmallAngle`
     338
     339        Uses reader_objects subclassed from :class:`GSASIIIO.ImportPhase`,
    335340        :class:`GSASIIIO.ImportStructFactor`,
    336341        :class:`GSASIIIO.ImportPowderData`,
     
    342347        selected in the Open File dialog.
    343348
    344         :param readerobject reader: This will be a reference to
     349        :param reader_object reader: This will be a reference to
    345350          a particular object to be used to read a file or None,
    346351          if every appropriate reader should be used.
     
    348353        :param list readerlist: a list of reader objects appropriate for
    349354          the current read attempt. At present, this will be either
    350           self.ImportPhaseReaderlist, self.ImportSfactReaderlist or
    351           self.ImportPowderReaderlist (defined in _init_Imports from
    352           the files found in the path), but in theory this list could
    353           be tailored. Used only when reader is None.
     355          self.ImportPhaseReaderlist, self.ImportSfactReaderlist
     356          self.ImportPowderReaderlist or self.ImportImageReaderlist
     357          (defined in _init_Imports from the files found in the path),
     358          but in theory this list could be tailored.
     359          Used only when reader is None.
    354360
    355361        :param str label: string to place on the open file dialog:
     
    22482254        self.Image = 0
    22492255        self.oldImagefile = '' # the name of the last image file read
     2256        self.oldImageTag = None # the name of the tag for multi-image files
    22502257        self.ImageZ = []  # this contains the image plotted and used for integration
    22512258        # self.ImageZ and self.oldImagefile are set in GSASIIplot.PlotImage
    2252         # and GSASIIIO.ReadImageData (GetImageData soon)
     2259        # and GSASIIIO.GetImageData
    22532260        # any changes to self.ImageZ should initialize self.oldImagefile to force a reread
    22542261        self.Integrate = 0
    22552262        self.imageDefault = {}
    22562263        self.IntgOutList = [] # list of integration tree item Ids created in G2IO.SaveIntegration
    2257         self.AutointPWDRnames = [] # list of autoint created PWDR tree item names
     2264        self.AutointPWDRnames = [] # list of autoint created PWDR tree item names (to be deleted on a reset)
    22582265        self.autoIntFrame = None
    2259         self.IntegratedList = [] # list of integrated image files
     2266        self.IntegratedList = [] # list of already integrated IMG tree items
    22602267        self.Sngl = False
    22612268        self.ifGetRing = False
     
    24252432                       
    24262433    def OnImageRead(self,event):
    2427         'Called to read in an image in any known format'
     2434        '''Called to read in an image in any known format. *** Depreciated. ***
     2435        Note: When removed, G2IO.ReadLoadImage can also be removed
     2436        '''
    24282437        G2G.G2MessageBox(self,'Please use the Import/Image/... menu item rather than this','depreciating menu item')
    24292438        self.CheckNotebook()
     
    27232732                if 'IMG' in name:
    27242733                    TextList.append([0.0,name])
    2725                     DataList.append(self.PatternTree.GetItemPyData(item))        #Size,Image
     2734                    DataList.append(self.PatternTree.GetImageLoc(item))        #Size,Image,Tag
    27262735                    Data = self.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(self,item,'Image Controls'))
    27272736                item, cookie = self.PatternTree.GetNextChild(self.root, cookie)
     
    27392748                    for i,item in enumerate(result[:-1]):
    27402749                        scale,name = item
    2741                         data = DataList[i]
    27422750                        if scale:
    27432751                            Found = True                               
    27442752                            Comments.append("%10.3f %s" % (scale,' * '+name))
    2745                             Npix,imagefile = data
    2746                             image = G2IO.GetImageData(self,imagefile,imageOnly=True)
     2753                            Npix,imagefile,imagetag = DataList[i]
     2754                            image = G2IO.GetImageData(self,imagefile,imageOnly=True,ImageTag=imagetag)
    27472755                            if First:
    27482756                                newImage = np.zeros_like(image)
  • trunk/GSASIIIO.py

    r2056 r2065  
    278278def ReadLoadImage(imagefile,G2frame):
    279279    '''Read a GSAS-II image file and load it into the data tree
     280    Called only from GSASII.OnImageRead (depreciated).
    280281    '''
    281282    # if a zip file, open and extract
     
    284285        if extractedfile is not None and extractedfile != imagefile:
    285286            imagefile = extractedfile
    286     Comments,Data,Npix,Image = GetImageData(G2frame,imagefile)
     287    Comments,Data,Npix,Image = GetImageData(G2frame,imagefile) # can only read 1st image
    287288    if Comments:
    288289        LoadImage2Tree(imagefile,G2frame,Comments,Data,Npix,Image)
    289290   
    290291def LoadImage2Tree(imagefile,G2frame,Comments,Data,Npix,Image):
    291     '''Load an image into the tree
     292    '''Load an image into the tree. Saves the location of the image, as well as the
     293    ImageTag (where there is more than one image in the file), if defined.
    292294    '''
    293    
    294295    ImgNames = []
    295296    if G2frame.PatternTree.GetCount(): # get a list of existing Image entries
     
    299300            if name.startswith('IMG'): ImgNames.append(name)       
    300301            item, cookie = G2frame.PatternTree.GetNextChild(G2frame.root, cookie)
    301     TreeName = G2obj.MakeUniqueLabel('IMG '+os.path.basename(imagefile),ImgNames)
     302    TreeLbl = 'IMG '+os.path.basename(imagefile)
     303    ImageTag = Data.get('ImageTag')
     304    if ImageTag:
     305        TreeLbl += ' #'+str(ImageTag)
     306        imageInfo = (imagefile,ImageTag)
     307    else:
     308        imageInfo = imagefile
     309    TreeName = G2obj.MakeUniqueLabel(TreeLbl,ImgNames)
    302310    Id = G2frame.PatternTree.AppendItem(parent=G2frame.root,text=TreeName)
    303311    G2frame.PatternTree.SetItemPyData(G2frame.PatternTree.AppendItem(Id,text='Comments'),Comments)
     
    354362    G2frame.PatternTree.SetItemPyData(G2frame.PatternTree.AppendItem(Id,text='Stress/Strain'),
    355363        {'Type':'True','d-zero':[],'Sample phi':0.0,'Sample z':0.0,'Sample load':0.0})
    356     G2frame.PatternTree.SetItemPyData(Id,[Npix,imagefile])
     364    G2frame.PatternTree.SetItemPyData(Id,[Npix,imageInfo])
    357365    G2frame.PickId = Id
    358366    G2frame.PickIdText = G2frame.GetTreeItemsList(G2frame.PickId)
    359367    G2frame.Image = Id
    360    
    361 def ReadImageData(G2frame,imagefile,imageOnly=False):
    362     '''Read a single image with an image importer. Replacement for GetImageData
     368
     369def GetImageData(G2frame,imagefile,imageOnly=False,ImageTag=None):
     370    '''Read a single image with an image importer.
    363371
    364372    :param wx.Frame G2frame: main GSAS-II Frame and data object.
     
    366374    :param bool imageOnly: If True return only the image,
    367375      otherwise  (default) return more (see below)
     376    :param int/str ImageTag: specifies a particular image to be read from a file.
     377      First image is read if None (default).
    368378
    369379    :returns: an image as a numpy array or a list of four items:
     
    394404            if rd.errors:
    395405                errorReport += ': '+rd.errors
    396                 continue 
     406                continue
    397407        rdbuffer = {} # create temporary storage for file reader
    398408        if imageOnly:
     
    401411            ParentFrame = G2frame
    402412        if GSASIIpath.GetConfigValue('debug'):
    403             flag = rd.Reader(imagefile,fp,ParentFrame)
     413            flag = rd.Reader(imagefile,fp,ParentFrame,blocknum=ImageTag)
    404414        else:
    405415            flag = False
    406416            try:
    407                 flag = rd.Reader(imagefile,fp,ParentFrame)
     417                flag = rd.Reader(imagefile,fp,ParentFrame,blocknum=ImageTag)
    408418            except rd.ImportException as detail:
    409419                rd.errors += "\n  Read exception: "+str(detail)
     
    427437        print('Error messages(s)\n'+errorReport)
    428438        raise Exception('No image read')   
    429 def GetImageData(G2frame,imagefile,imageOnly=False):
    430     return ReadImageData(G2frame,imagefile,imageOnly)
     439
     440def ReadImages(G2frame,imagefile):
     441    '''Read one or more images from a file and put them into the Tree
     442    using image importers. Called only in :meth:`AutoIntFrame.OnTimerLoop`.
     443
     444    :param wx.Frame G2frame: main GSAS-II Frame and data object.
     445    :param str imagefile: name of image file
     446
     447    :returns: a list of the id's of the IMG tree items created
     448    '''
     449    # determine which formats are compatible with this file
     450    primaryReaders = []
     451    secondaryReaders = []
     452    for rd in G2frame.ImportImageReaderlist:
     453        flag = rd.ExtensionValidator(imagefile)
     454        if flag is None:
     455            secondaryReaders.append(rd)
     456        elif flag:
     457            primaryReaders.append(rd)
     458    if len(secondaryReaders) + len(primaryReaders) == 0:
     459        print('Error: No matching format for file '+filename)
     460        raise Exception('No image read')
     461    errorReport = ''
     462    fp = open(imagefile,'Ur')
     463    rdbuffer = {} # create temporary storage for file reader
     464    for rd in primaryReaders+secondaryReaders:
     465        rd.ReInitialize() # purge anything from a previous read
     466        fp.seek(0)  # rewind
     467        rd.errors = "" # clear out any old errors
     468        if not rd.ContentsValidator(fp): # rejected on cursory check
     469            errorReport += "\n  "+rd.formatName + ' validator error'
     470            if rd.errors:
     471                errorReport += ': '+rd.errors
     472                continue
     473        ParentFrame = G2frame
     474        block = 0
     475        repeat = True
     476        CreatedIMGitems = []
     477        while repeat: # loop if the reader asks for another pass on the file
     478            block += 1
     479            repeat = False
     480            if GSASIIpath.GetConfigValue('debug'):
     481                flag = rd.Reader(imagefile,fp,ParentFrame,blocknum=block,Buffer=rdbuffer)
     482            else:
     483                flag = False
     484                try:
     485                    flag = rd.Reader(imagefile,fp,ParentFrame,blocknum=block,Buffer=rdbuffer)
     486                except rd.ImportException as detail:
     487                    rd.errors += "\n  Read exception: "+str(detail)
     488                except Exception as detail:
     489                    import traceback
     490                    rd.errors += "\n  Unhandled read exception: "+str(detail)
     491                    rd.errors += "\n  Traceback info:\n"+str(traceback.format_exc())
     492            if flag: # this read succeeded
     493                if rd.Image is None:
     494                    raise Exception('No image read. Strange!')
     495                if GSASIIpath.GetConfigValue('Transpose'):
     496                    print 'Transposing Image!'
     497                    rd.Image = rd.Image.T
     498                LoadImage2Tree(imagefile,G2frame,rd.Comments,rd.Data,rd.Npix,rd.Image)
     499                repeat = rd.repeat
     500            CreatedIMGitems.append(G2frame.Image)
     501        if CreatedIMGitems: return CreatedIMGitems
     502    else:
     503        print('Error reading file '+filename)
     504        print('Error messages(s)\n'+errorReport)
     505        return []
     506        #raise Exception('No image read')   
    431507       
    432508def PutG2Image(filename,Comments,Data,Npix,image):
     
    437513    return
    438514   
    439 def GetG2Image(filename):
    440     'Read an image as a python pickle'
    441     File = open(filename,'rb')
    442     Comments,Data,Npix,image = cPickle.load(File)
    443     File.close()
    444     return Comments,Data,Npix,image
    445    
     515# should get moved to importer when ready to test
    446516def GetEdfData(filename,imageOnly=False):   
    447517    'Read European detector data edf file'
     
    507577        return head,data,Npix,image
    508578       
     579# should get moved to importer when ready to test
    509580def GetRigaku(filename,imageOnly=False):
    510581    'Read Rigaku R-Axis IV image file'
     
    538609        return head,data,Npix,image
    539610   
    540 def GetGEsumData(filename,imageOnly=False):
    541     'Read SUM file as produced at 1-ID from G.E. images'
    542     import struct as st
    543     import array as ar
    544     if not imageOnly:
    545         print 'Read GE sum file: ',filename   
    546     File = open(filename,'rb')
    547     if '.sum' in filename or '.cor' in filename:
    548         head = ['GE detector sum or cor data from APS 1-ID',]
    549         sizexy = [2048,2048]
    550     elif '.avg' in filename or '.ge' in filename:
    551         head = ['GE detector avg or ge* data from APS 1-ID',]
    552         sizexy = [2048,2048]
    553     else:
    554         head = ['GE detector raw data from APS 1-ID',]
    555         File.seek(18)
    556         size,nframes = st.unpack('<ih',File.read(6))
    557         sizexy = [2048,2048]
    558         pos = 8192
    559         File.seek(pos)
    560     Npix = sizexy[0]*sizexy[1]
    561     if '.sum' in filename or '.cor' in filename:
    562         image = np.array(ar.array('f',File.read(4*Npix)),dtype=np.int32)
    563     elif '.avg' in filename or '.ge' in filename:
    564         image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
    565     else:
    566         image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
    567         while nframes > 1:
    568             image += np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
    569             nframes -= 1
    570     image = np.reshape(image,(sizexy[1],sizexy[0]))
    571     data = {'pixelSize':[200,200],'wavelength':0.15,'distance':250.0,'center':[204.8,204.8],'size':sizexy} 
    572     File.close()   
    573     if imageOnly:
    574         return image
    575     else:
    576         return head,data,Npix,image
    577        
     611# should get moved to importer when ready to test       
    578612def GetImgData(filename,imageOnly=False):
    579613    'Read an ADSC image file'
     
    627661        return lines[1:-2],data,Npix,image
    628662       
     663# should get moved to importer when ready to test
    629664def GetMAR345Data(filename,imageOnly=False):
    630665    'Read a MAR-345 image plate image'
     
    687722        return head,data,Npix,image
    688723       
     724# should get moved to importer when ready to test
    689725def GetPNGData(filename,imageOnly=False):
    690726    '''Read an image in a png format, assumes image is converted from CheMin tif file
     
    703739    else:
    704740        return Comments,Data,Npix,Image.T
    705 
    706741   
    707 #def GetTifData(filename,imageOnly=False):
    708 #    import struct as st
    709 #    import array as ar
    710 #    File = open(filename,'rb')
    711 #    dataType = 5
    712 #    try:
    713 #        Meta = open(filename+'.metadata','Ur')
    714 #        head = Meta.readlines()
    715 #        for line in head:
    716 #            line = line.strip()
    717 #            if 'dataType=' in line:
    718 #                dataType = int(line.split('=')[1])
    719 #        Meta.close()
    720 #    except IOError:
    721 #        print 'no metadata file found - will try to read file anyway'
    722 #        head = ['no metadata file found',]
    723 #       
    724 #    tag = File.read(2)
    725 #    byteOrd = '<'
    726 #    if tag == 'II' and int(st.unpack('<h',File.read(2))[0]) == 42:     #little endian
    727 #        IFD = int(st.unpack(byteOrd+'i',File.read(4))[0])
    728 #    elif tag == 'MM' and int(st.unpack('>h',File.read(2))[0]) == 42:   #big endian
    729 #        byteOrd = '>'
    730 #        IFD = int(st.unpack(byteOrd+'i',File.read(4))[0])       
    731 #    else:
    732 #        lines = ['not a detector tiff file',]
    733 #        return lines,0,0,0
    734 #    File.seek(IFD)                                                  #get number of directory entries
    735 #    NED = int(st.unpack(byteOrd+'h',File.read(2))[0])
    736 #    IFD = {}
    737 #    for ied in range(NED):
    738 #        Tag,Type = st.unpack(byteOrd+'Hh',File.read(4))
    739 #        nVal = st.unpack(byteOrd+'i',File.read(4))[0]
    740 #        if Type == 1:
    741 #            Value = st.unpack(byteOrd+nVal*'b',File.read(nVal))
    742 #        elif Type == 2:
    743 #            Value = st.unpack(byteOrd+'i',File.read(4))
    744 #        elif Type == 3:
    745 #            Value = st.unpack(byteOrd+nVal*'h',File.read(nVal*2))
    746 #            x = st.unpack(byteOrd+nVal*'h',File.read(nVal*2))
    747 #        elif Type == 4:
    748 #            Value = st.unpack(byteOrd+nVal*'i',File.read(nVal*4))
    749 #        elif Type == 5:
    750 #            Value = st.unpack(byteOrd+nVal*'i',File.read(nVal*4))
    751 #        elif Type == 11:
    752 #            Value = st.unpack(byteOrd+nVal*'f',File.read(nVal*4))
    753 #        IFD[Tag] = [Type,nVal,Value]
    754 ##        print Tag,IFD[Tag]
    755 #    sizexy = [IFD[256][2][0],IFD[257][2][0]]
    756 #    [nx,ny] = sizexy
    757 #    Npix = nx*ny
    758 #    if 272 in IFD:
    759 #        ifd = IFD[272]
    760 #        File.seek(ifd[2][0])
    761 #        S = File.read(ifd[1])
    762 #        if 'PILATUS' in S:
    763 #            tifType = 'Pilatus'
    764 #            dataType = 0
    765 #            pixy = (172,172)
    766 #            File.seek(4096)
    767 #            if not imageOnly:
    768 #                print 'Read Pilatus tiff file: ',filename
    769 #            image = ar.array('L',File.read(4*Npix))
    770 #            image = np.array(np.asarray(image),dtype=np.int32)
    771 #    elif 262 in IFD and IFD[262][2][0] > 4:
    772 #        tifType = 'DND'
    773 #        pixy = (158,158)
    774 #        File.seek(512)
    775 #        if not imageOnly:
    776 #            print 'Read DND SAX/WAX-detector tiff file: ',filename
    777 #        image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
    778 #    elif sizexy == [1536,1536]:
    779 #        tifType = 'APS Gold'
    780 #        pixy = (150,150)
    781 #        File.seek(64)
    782 #        if not imageOnly:
    783 #            print 'Read Gold tiff file:',filename
    784 #        image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
    785 #    elif sizexy == [2048,2048] or sizexy == [1024,1024] or sizexy == [3072,3072]:
    786 #        if IFD[273][2][0] == 8:
    787 #            if IFD[258][2][0] == 32:
    788 #                tifType = 'PE'
    789 #                pixy = (200,200)
    790 #                File.seek(8)
    791 #                if not imageOnly:
    792 #                    print 'Read APS PE-detector tiff file: ',filename
    793 #                if dataType == 5:
    794 #                    image = np.array(ar.array('f',File.read(4*Npix)),dtype=np.float32)
    795 #                else:
    796 #                    image = np.array(ar.array('I',File.read(4*Npix)),dtype=np.int32)
    797 #        elif IFD[273][2][0] == 4096:
    798 #            if sizexy[0] == 3072:
    799 #                pixy =  (73,73)
    800 #                tifType = 'MAR225'           
    801 #            else:
    802 #                pixy = (158,158)
    803 #                tifType = 'MAR325'           
    804 #            File.seek(4096)
    805 #            if not imageOnly:
    806 #                print 'Read MAR CCD tiff file: ',filename
    807 #            image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
    808 #        elif IFD[273][2][0] == 512:
    809 #            tiftype = '11-ID-C'
    810 #            pixy = [200,200]
    811 #            File.seek(512)
    812 #            if not imageOnly:
    813 #                print 'Read 11-ID-C tiff file: ',filename
    814 #            image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)           
    815 #    elif sizexy == [4096,4096]:
    816 #        if IFD[273][2][0] == 8:
    817 #            if IFD[258][2][0] == 16:
    818 #                tifType = 'scanCCD'
    819 #                pixy = (9,9)
    820 #                File.seek(8)
    821 #                if not imageOnly:
    822 #                    print 'Read APS scanCCD tiff file: ',filename
    823 #                image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
    824 #        elif IFD[273][2][0] == 4096:
    825 #            tifType = 'Rayonix'
    826 #            pixy = (73.242,73.242)
    827 #            File.seek(4096)
    828 #            if not imageOnly:
    829 #                print 'Read Rayonix MX300HE tiff file: ',filename
    830 #            image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
    831 ##    elif sizexy == [960,960]:
    832 ##        tiftype = 'PE-BE'
    833 ##        pixy = (200,200)
    834 ##        File.seek(8)
    835 ##        if not imageOnly:
    836 ##            print 'Read Gold tiff file:',filename
    837 ##        image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
    838 #           
    839 #    else:
    840 #        lines = ['not a known detector tiff file',]
    841 #        return lines,0,0,0
    842 #       
    843 #    image = np.reshape(image,(sizexy[1],sizexy[0]))
    844 #    center = [pixy[0]*sizexy[0]/2000,pixy[1]*sizexy[1]/2000]
    845 #    data = {'pixelSize':pixy,'wavelength':0.10,'distance':100.0,'center':center,'size':sizexy}
    846 #    File.close()   
    847 #    if imageOnly:
    848 #        return image
    849 #    else:
    850 #        return head,data,Npix,image
    851 #   
    852742def ProjFileOpen(G2frame):
    853743    'Read a GSAS-II project file and load into the G2 data tree'
     
    17611651    '''Defines a base class for the reading of images
    17621652
    1763     Structure factors are read with a call to :meth:`GSASII.GSASII.OnImportImage`
     1653    Images are intially read with a call to :meth:`GSASII.GSASII.OnImportImage`
    17641654    which in turn calls :meth:`GSASII.GSASII.OnImportGeneric`, which calls
    17651655    methods :meth:`ExtensionValidator`, :meth:`ContentsValidator` and
    1766     :meth:`Reader`.
     1656    :meth:`Reader`. Images are also reread with :func:`GSASIIIO.GetImageData`
    17671657
    17681658    See :ref:`Writing a Import Routine<Import_Routines>`
    17691659    for an explanation on how to use import classes in general. The specifics
    17701660    for reading an image requires that the ``Reader()`` routine in the import
    1771     class need to do only a few things:...
     1661    class should set:
    17721662   
    1773     (should load :attr:`RefDict` item ``'RefList'`` with the reflection list,
    1774     (and set :attr:`Parameters` with the instrument parameters
    1775     (initialized with :meth:`InitParameters` and set with :meth:`UpdateParameters`).
     1663      * :attr:`Comments` (a list of strings),
     1664      * :attr:`Data` (a dict defining image parameters),
     1665      * :attr:`Npix` (the number of pixels in the image)
     1666      * :attr:`Image` (the actual image)
     1667      * optionally: :attr:`repeat` (set to True if there are additional images to
     1668        read in the file)
     1669     
     1670     
     1671    Note that the above is initialized with :meth:`InitParameters`.
    17761672    '''
    17771673    def __init__(self,formatName,longFormatName=None,extensionlist=[],
     
    17921688        self.Npix = 0
    17931689        self.Image = None
    1794 
    1795     def LoadImage(self,ParentFrame,imagefile):
     1690        self.repeat = False
     1691
     1692    def LoadImage(self,ParentFrame,imagefile,imagetag=None):
    17961693        '''Optionally, call this after reading in an image to load it into the tree.
    1797         This does saves time by preventing a reread of the same information.
     1694        This saves time by preventing a reread of the same information.
    17981695        '''
    17991696        if ParentFrame:
    18001697            ParentFrame.ImageZ = self.Image   # store the image for plotting
    18011698            ParentFrame.oldImagefile = imagefile # save the name of the last image file read
    1802            
     1699            ParentFrame.oldImageTag = imagetag   # save the tag of the last image file read           
    18031700
    18041701######################################################################
  • trunk/GSASIIctrls.py

    r2036 r2065  
    208208        else:
    209209            raise Exception("No phases found ")
     210
     211    def GetImageLoc(self,TreeId):
     212        '''Get Image data from the Tree. Handles cases where the
     213        image name is specified, as well as where the image file name is
     214        a tuple containing the image file and an image number
     215        '''
     216       
     217        size,imagefile = self.GetItemPyData(TreeId)
     218        if type(imagefile) is tuple or type(imagefile) is list:
     219            return size,imagefile[0],imagefile[1]
     220        else:
     221            return size,imagefile,None
    210222
    211223################################################################################
  • trunk/GSASIIimgGUI.py

    r2060 r2065  
    143143            if darkImg:
    144144                Did = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, darkImg)
    145                 Npix,imagefile = G2frame.PatternTree.GetItemPyData(Did)
    146                 darkImage = G2IO.GetImageData(G2frame,imagefile,True)
     145                Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(Did)
     146                darkImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)
    147147                sumImg += darkImage*darkScale
    148148            backImg,backScale = data['background image']           
    149149            if backImg:     #ignores any transmission effect in the background image
    150150                Bid = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, backImg)
    151                 Npix,imagefile = G2frame.PatternTree.GetItemPyData(Bid)
    152                 backImage = G2IO.GetImageData(G2frame,imagefile,True)
     151                Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(Bid)
     152                backImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)
    153153                Bdata = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Bid,'Image Controls'))
    154154                BdarkImg,BdarkScale = Bdata['dark image']
    155155                if BdarkImg:
    156156                    BDid = G2gd.GetPatternTreeItemId(G2frame, G2frame.root,BdarkImg)
    157                     Npix,imagefile = G2frame.PatternTree.GetItemPyData(BDid)
    158                     BdarkImage = G2IO.GetImageData(G2frame,imagefile,True)
     157                    Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(BDid)
     158                    BdarkImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)
    159159                    backImage += BdarkImage*BdarkScale               
    160160                sumImg += backImage*backScale
     
    206206                            try:
    207207                                id = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, name)
    208                                 Npix,imagefile = G2frame.PatternTree.GetItemPyData(id)
    209                                 image = G2IO.GetImageData(G2frame,imagefile,True)
     208                                Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(id)
     209                                image = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)
    210210                                backImage = []
    211211                                if Data['background image'][0]:
     
    213213                                    backScale = Data['background image'][1]
    214214                                    id = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, backImg)
    215                                     Npix,imagefile = G2frame.PatternTree.GetItemPyData(id)
    216                                     backImage = G2IO.GetImageData(G2frame,imagefile,True)*backScale
     215                                    Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(id)
     216                                    backImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)*backScale
    217217                                FlatBkg = Data.get('Flat Bkg',0.0)
    218218                                try:
     
    16471647                    goodnames.append(name)
    16481648                    id = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, name)
    1649                     Npix,imagefile = G2frame.PatternTree.GetItemPyData(Id)
    1650                     image = G2IO.GetImageData(G2frame,imagefile,True)
     1649                    Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(Id)
     1650                    image = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)
    16511651                    dark = Controls['dark image']
    16521652                    if dark[0]:
    1653                         darkfile = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,
    1654                             G2frame.root,dark[0]))[1]
    1655                         darkImg = G2IO.GetImageData(G2frame,darkfile,imageOnly=True)
     1653                        id = G2gd.GetPatternTreeItemId(G2frame, G2frame.root,dark[0])
     1654                        Npix,darkfile,imagetag = G2frame.PatternTree.GetImageLoc(id)
     1655                        darkImg = G2IO.GetImageData(G2frame,darkfile,True,ImageTag=imagetag)
    16561656                        image += dark[1]*darkImg
    16571657                    G2img.FitStrSta(image,StaCtrls,Controls)
  • trunk/GSASIIplot.py

    r2062 r2065  
    39503950    except TypeError:
    39513951        pass
    3952     size,imagefile = G2frame.PatternTree.GetItemPyData(G2frame.Image)
     3952    size,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(G2frame.Image)
    39533953    dark = Data.get('dark image',[0,''])
    3954     if dark[0]:
    3955         darkfile = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,
    3956             G2frame.root,dark[0]))[1]
    3957     if imagefile != G2frame.oldImagefile or dark[0]: # always reread with dark correction
     3954    if imagefile != G2frame.oldImagefile or G2frame.oldImageTag != imagetag or dark[0]: # always reread to apply dark correction
    39583955        imagefile = G2IO.CheckImageFile(G2frame,imagefile)
    39593956        if not imagefile:
    39603957            G2frame.G2plotNB.Delete('2D Powder Image')
    39613958            return
    3962         G2frame.PatternTree.SetItemPyData(G2frame.Image,[size,imagefile])
    3963         G2frame.ImageZ = G2IO.GetImageData(G2frame,imagefile,imageOnly=True)
     3959        if imagetag:
     3960            G2frame.PatternTree.SetItemPyData(G2frame.Image,
     3961                                              [size,(imagefile,imagetag)])
     3962        else:
     3963            G2frame.PatternTree.SetItemPyData(G2frame.Image,[size,imagefile])         
     3964        G2frame.ImageZ = G2IO.GetImageData(G2frame,imagefile,imageOnly=True,ImageTag=imagetag)
    39643965        if dark[0]:
    3965             darkImg = G2IO.GetImageData(G2frame,darkfile,imageOnly=True)
     3966            dsize,darkfile,darktag = G2frame.PatternTree.GetImageLoc(
     3967                G2gd.GetPatternTreeItemId(G2frame,G2frame.root,dark[0]))
     3968            darkImg = G2IO.GetImageData(G2frame,darkfile,imageOnly=True,ImageTag=darktag)
    39663969            G2frame.ImageZ += dark[1]*darkImg
    39673970        G2frame.oldImagefile = imagefile # save name of the last image file read
     3971        G2frame.oldImageTag = imagetag   # save tag of the last image file read
    39683972    else:
    39693973        if GSASIIpath.GetConfigValue('debug'): print('Skipping image reread')
  • trunk/GSASIIpy3.py

    r2060 r2065  
    156156    else: # larger numbers, remove decimal places
    157157        decimals = sigfigs - 1 - int(np.log10(abs(val)))
    158         print decimals,maxdigits,val
    159158        if decimals <= 0:
    160159            fmt = "{" + (":{:d}.0f".format(maxdigits))+"}."
  • trunk/autoint.py

    r2048 r2065  
    3838            return
    3939
    40         # index of image tree items by file name:
    41         imageDict = {G2frame.PatternTree.GetItemPyData(
    42             G2gd.GetPatternTreeItemId(G2frame,G2frame.root,img))[1]:
    43             G2gd.GetPatternTreeItemId(G2frame,G2frame.root,img)
    44                      for img in G2gd.GetPatternTreeDataNames(G2frame,['IMG '])}
    45         createdImageIdList = []
    46         # loop over files that are found, reading in new ones
     40        # Create a list of image files that have already been read
     41        imageFileList = []
     42        for img in G2gd.GetPatternTreeDataNames(G2frame,['IMG ']):
     43            imgId = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,img)
     44            size,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(imgId)
     45            if imagefile not in imageFileList: imageFileList.append(imagefile)
     46        # loop over image files matching glob, reading in new ones
    4747        for newImage in self.currImageList:
    48             if newImage in self.G2frame.IntegratedList: continue # already integrated
    49             # has this image already been loaded?
    50             if newImage not in imageDict:
    51                 Comments,Data,Npix,Image = G2IO.GetImageData(G2frame,newImage)
    52                 if not Npix:
    53                     print('problem reading '+newImage)
    54                     continue
    55                 G2IO.LoadImage2Tree(newImage,G2frame,Comments,Data,Npix,Image)
    56             else:
    57                 G2frame.Image = imageDict[newImage]
    58             # update controls from master
    59             controlsDict = G2frame.PatternTree.GetItemPyData(
    60                 G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Image Controls'))
    61             controlsDict.update(self.ImageControls)
    62             # update masks from master
    63             ImageMasks = G2frame.PatternTree.GetItemPyData(
    64                 G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Masks'))
    65             createdImageIdList.append(G2frame.Image) # save IMG Id
    66             self.G2frame.IntegratedList.append(newImage) # save name of image so we don't process it again
    67             #print('debug: read '+newImage)
    68 
    69         # now integrate the images we have read
    70         for newImagId in createdImageIdList:
    71             G2frame.Image = newImagId
     48            if newImage in imageFileList: continue # already read
     49            for imgId in G2IO.ReadImages(G2frame,newImage):
     50                # update controls from master
     51                controlsDict = G2frame.PatternTree.GetItemPyData(
     52                    G2gd.GetPatternTreeItemId(G2frame,imgId, 'Image Controls'))
     53                controlsDict.update(self.ImageControls)
     54                # update masks from master
     55                ImageMasks = G2frame.PatternTree.GetItemPyData(
     56                    G2gd.GetPatternTreeItemId(G2frame,imgId, 'Masks'))
     57                ImageMasks.update(self.ImageMasks)
     58        # now integrate the images that have not already been processed before
     59        for img in G2gd.GetPatternTreeDataNames(G2frame,['IMG ']):
     60            if img in G2frame.IntegratedList: continue
     61            G2frame.IntegratedList.append(img)
     62            imgId = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,img)
     63            G2frame.Image = imgId
    7264            G2frame.PickId = G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Image Controls')
    7365            #  integrate in this entry
    74             size,imagefile = G2frame.PatternTree.GetItemPyData(G2frame.Image)
     66            size,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(imgId)
     67            G2frame.ImageZ = G2IO.GetImageData(G2frame,imagefile,True,imagetag)
    7568            masks = G2frame.PatternTree.GetItemPyData(
    7669                G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Masks'))
    7770            data = G2frame.PatternTree.GetItemPyData(G2frame.PickId)
    78             G2frame.ImageZ = G2IO.GetImageData(G2frame,imagefile,True)
    7971            self.oldImagefile = '' # mark image as changed; reread as needed
    8072            # simulate a Image Controls press, since that is where the
     
    9284            for Id in G2frame.IntgOutList:
    9385                treename = G2frame.PatternTree.GetItemText(Id)
    94                 self.G2frame.AutointPWDRnames.append(treename)
     86                G2frame.AutointPWDRnames.append(treename)
    9587                Sdata = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id, 'Sample Parameters'))
    9688                # determine the name for the current file
     
    122114        '''
    123115        print '\nStarting new autointegration\n'
     116        G2frame = self.G2frame
    124117        # show current IMG base
    125         self.ControlBaseLbl.SetLabel(self.G2frame.PatternTree.GetItemText(self.G2frame.Image))
     118        self.ControlBaseLbl.SetLabel(G2frame.PatternTree.GetItemText(G2frame.Image))
    126119        if self.params['Mode'] == 'file':
    127120            'get file info'
     
    131124            # items that should not be copied
    132125            self.ImageControls = copy.deepcopy(
    133                 self.G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(
    134                     self.G2frame,self.G2frame.Image, 'Image Controls')))
     126                G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(
     127                    G2frame,G2frame.Image, 'Image Controls')))
    135128            self.ImageControls['showLines'] = True
    136129            self.ImageControls['ring'] = []
     
    143136            # load copy of Image Masks, keep thresholds
    144137            self.ImageMasks = copy.deepcopy(
    145                 self.G2frame.PatternTree.GetItemPyData(
    146                     G2gd.GetPatternTreeItemId(self.G2frame,self.G2frame.Image, 'Masks')))
     138                G2frame.PatternTree.GetItemPyData(
     139                    G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Masks')))
    147140            self.Thresholds = self.ImageMasks['Thresholds'][:]
    148141        # make sure all output directories exist
     
    155148            if not os.path.exists(self.params['outdir']):
    156149                os.makedirs(self.params['outdir'])
    157         if self.Reset: # after Reset has been pressed, delete all PWDR items
    158             # created after last Start was pressed
    159             G2frame = self.G2frame
     150        if self.Reset: # special things to do after Reset has been pressed
     151            # reset controls and masks for all IMG items in tree to master
     152            for img in G2gd.GetPatternTreeDataNames(G2frame,['IMG ']):
     153                # update controls from master
     154                controlsDict = G2frame.PatternTree.GetItemPyData(
     155                    G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Image Controls'))
     156                controlsDict.update(self.ImageControls)
     157                # update masks from master
     158                ImageMasks = G2frame.PatternTree.GetItemPyData(
     159                    G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Masks'))
     160                ImageMasks.update(self.ImageMasks)
     161            # delete all PWDR items created after last Start was pressed
    160162            idlist = []
    161163            item, cookie = G2frame.PatternTree.GetFirstChild(G2frame.root)
    162164            while item:
    163165                itemName = G2frame.PatternTree.GetItemText(item)
    164                 if itemName in self.G2frame.AutointPWDRnames:
     166                if itemName in G2frame.AutointPWDRnames:
    165167                    idlist.append(item)
    166168                item, cookie = G2frame.PatternTree.GetNextChild(G2frame.root, cookie)
    167169            for item in idlist:
    168170                G2frame.PatternTree.Delete(item)
    169         self.Reset = False
    170         self.G2frame.AutointPWDRnames = [] # list of created PWDR tree item names
     171            self.Reset = False
     172        G2frame.AutointPWDRnames = [] # list of created PWDR tree item names
    171173
    172174    def __init__(self,G2frame,PollTime=60.0):
     
    306308
    307309        controlsId = G2frame.PatternTree.GetSelection()
    308         size,imagefile = G2frame.PatternTree.GetItemPyData(G2frame.Image)
     310        size,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(G2frame.Image)       
    309311        self.imagedir,fileroot = os.path.split(imagefile)
    310312        self.params['filter'] = '*'+os.path.splitext(fileroot)[1]
  • trunk/imports/G2img_1TIF.py

    r2044 r2065  
    6969        return True
    7070
    71 def GetTifData(filename,imageOnly=False):
     71def GetTifData(filename):
    7272    '''Read an image in a pseudo-tif format,
    7373    as produced by a wide variety of software, almost always
     
    135135    Npix = nx*ny
    136136    if 34710 in IFD:
    137         if not imageOnly:
    138             print 'Read MAR CCD tiff file: ',filename
     137        print 'Read MAR CCD tiff file: ',filename
    139138        marFrame = rmf.marFrame(File,byteOrd,IFD)
    140139        image = np.flipud(np.array(np.asarray(marFrame.image),dtype=np.int32))
     
    180179            pixy = [172,172]
    181180            File.seek(4096)
    182             if not imageOnly:
    183                 print 'Read Pilatus tiff file: ',filename
     181            print 'Read Pilatus tiff file: ',filename
    184182            image = ar.array('L',File.read(4*Npix))
    185183            image = np.array(np.asarray(image),dtype=np.int32)
     
    189187                pixy = [200,200]
    190188                File.seek(8)
    191                 if not imageOnly:
    192                     print 'Read GE-detector tiff file: ',filename
     189                print 'Read GE-detector tiff file: ',filename
    193190                image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
    194191            elif IFD[258][2][0] == 32:
     
    196193                pixy = [200,200]
    197194                File.seek(8)
    198                 if not imageOnly:
    199                     print 'Read CHESS-detector tiff file: ',filename
     195                print 'Read CHESS-detector tiff file: ',filename
    200196                image = np.array(ar.array('L',File.read(4*Npix)),dtype=np.int32)
    201197    elif 270 in IFD:
     
    207203            pixy = [200,200]*IFD[277][2][0]
    208204            File.seek(IFD[273][2][0])
    209             if not imageOnly:
    210                 print 'Read ImageJ tiff file: ',filename
     205            print 'Read ImageJ tiff file: ',filename
    211206            image = ar.array('H',File.read(2*Npix))
    212207            if '>' in byteOrd:
     
    217212        pixy = [158,158]
    218213        File.seek(512)
    219         if not imageOnly:
    220             print 'Read DND SAX/WAX-detector tiff file: ',filename
     214        print 'Read DND SAX/WAX-detector tiff file: ',filename
    221215        image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
    222216    elif sizexy == [1536,1536]:
     
    224218        pixy = [150,150]
    225219        File.seek(64)
    226         if not imageOnly:
    227             print 'Read Gold tiff file:',filename
     220        print 'Read Gold tiff file:',filename
    228221        image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
    229222    elif sizexy == [2048,2048] or sizexy == [1024,1024] or sizexy == [3072,3072]:
     
    233226                pixy = [200,200]
    234227                File.seek(8)
    235                 if not imageOnly:
    236                     print 'Read APS PE-detector tiff file: ',filename
     228                print 'Read APS PE-detector tiff file: ',filename
    237229                if dataType == 5:
    238230                    image = np.array(ar.array('f',File.read(4*Npix)),dtype=np.float32)
     
    243235                pixy = [46.9,46.9]
    244236                File.seek(8)
    245                 if not imageOnly:
    246                     print 'Read MedOptics D1 tiff file: ',filename
     237                print 'Read MedOptics D1 tiff file: ',filename
    247238                image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
    248239                 
     
    255246                tifType = 'MAR325'           
    256247            File.seek(4096)
    257             if not imageOnly:
    258                 print 'Read MAR CCD tiff file: ',filename
     248            print 'Read MAR CCD tiff file: ',filename
    259249            image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
    260250        elif IFD[273][2][0] == 512:
     
    262252            pixy = [200,200]
    263253            File.seek(512)
    264             if not imageOnly:
    265                 print 'Read 11-ID-C tiff file: ',filename
     254            print 'Read 11-ID-C tiff file: ',filename
    266255            image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
    267256                   
     
    272261                pixy = [9,9]
    273262                File.seek(8)
    274                 if not imageOnly:
    275                     print 'Read APS scanCCD tiff file: ',filename
     263                print 'Read APS scanCCD tiff file: ',filename
    276264                image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
    277265        elif IFD[273][2][0] == 4096:
     
    279267            pixy = [73.242,73.242]
    280268            File.seek(4096)
    281             if not imageOnly:
    282                 print 'Read Rayonix MX300HE tiff file: ',filename
     269            print 'Read Rayonix MX300HE tiff file: ',filename
    283270            image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
    284271#    elif sizexy == [960,960]:
     
    304291    data = {'pixelSize':pixy,'wavelength':wavelength,'distance':distance,'center':center,'size':sizexy}
    305292    File.close()   
    306     if imageOnly:
    307         return image
    308     else:
    309         return head,data,Npix,image
     293    return head,data,Npix,image
  • trunk/imports/G2img_GE.py

    r2015 r2065  
    1717import sys
    1818import os
     19import numpy as np
    1920import GSASIIIO as G2IO
    2021import GSASIIpath
     
    3435        return True
    3536       
    36     def Reader(self,filename,filepointer, ParentFrame=None, **unused):
    37         '''Read using Bob's routine
     37    def Reader(self,filename,filepointer, ParentFrame=None, **kwarg):
     38        '''Read using GE file reader
    3839        '''
    39         self.Comments,self.Data,self.Npix,self.Image = G2IO.GetGEsumData(filename)
     40        #rdbuffer = kwarg.get('buffer')
     41        imagenum = kwarg.get('blocknum')
     42        if imagenum is None: imagenum = 1
     43        self.Comments,self.Data,self.Npix,self.Image,more = GetGEsumData(filename,imagenum=imagenum)
    4044        if self.Npix == 0 or not self.Comments:
    4145            return False
    42         self.LoadImage(ParentFrame,filename)
     46        self.LoadImage(ParentFrame,filename,imagenum)
     47        self.repeat = more
    4348        return True
     49
     50def GetGEsumData(filename,imagenum=1):
     51    '''Read G.E. detector images from various files as produced at 1-ID and
     52    with Detector Pool detector.
     53    '''
     54    import struct as st
     55    import array as ar
     56    more = False
     57    File = open(filename,'rb')
     58    if '.sum' in filename or '.cor' in filename:
     59        head = ['GE detector sum or cor data from APS 1-ID',]
     60        sizexy = [2048,2048]
     61        Npix = sizexy[0]*sizexy[1]
     62        image = np.array(ar.array('f',File.read(4*Npix)),dtype=np.int32)
     63    elif '.avg' in filename:
     64        head = ['GE detector avg or ge* data from APS 1-ID',]
     65        sizexy = [2048,2048]
     66        Npix = sizexy[0]*sizexy[1]
     67        image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
     68    else:
     69        head = ['GE detector raw data',]
     70        File.seek(18)
     71        size,nframes = st.unpack('<ih',File.read(6))
     72        # number of frames seems to be 3 for single-image files
     73        if size != 2048:
     74            print('Warning GE image size unexpected: '+str(size))
     75            return 0,0,0,0,False # probably should quit now
     76        if imagenum > nframes:
     77            print('Error: attempt to read image #'+str(imagenum)+
     78                  ' from file with '+str(nframes)+' images.')
     79            return 0,0,0,0,False
     80        elif imagenum < nframes:
     81            more = True
     82        sizexy = [2048,2048]
     83        Npix = sizexy[0]*sizexy[1]
     84        pos = 8192 + (imagenum-1)*2*Npix
     85        File.seek(pos)
     86        image = np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
     87        if len(image) != sizexy[1]*sizexy[0]:
     88            print('not enough images while reading GE file: '+filename+'image #'+str(imagenum))
     89            return 0,0,0,0,False           
     90        head += ['file: '+filename+' image #'+str(imagenum),]
     91        #while nframes > 1:
     92        #    print 'adding'
     93        #    image += np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
     94        #    nframes -= 1
     95    image = np.reshape(image,(sizexy[1],sizexy[0]))
     96    data = {'pixelSize':[200,200],'wavelength':0.15,'distance':250.0,'center':[204.8,204.8],'size':sizexy}
     97    data['ImageTag'] = imagenum
     98    File.close()
     99    if GSASIIpath.GetConfigValue('debug'):
     100        print 'Read GE file: '+filename+' image #'+str(imagenum)
     101    return head,data,Npix,image,more
  • trunk/imports/G2img_SumG2.py

    r2015 r2065  
    1818import sys
    1919import os
     20import cPickle
    2021import GSASIIIO as G2IO
    2122import GSASIIpath
     
    4041        import scipy.misc
    4142        Fp = open(filename,'rb')
    42         self.Comments,self.Data,self.Npix,self.image = cPickle.load(Fp)
     43        self.Comments,self.Data,self.Npix,self.Image = cPickle.load(Fp)
    4344        Fp.close()
    4445        self.LoadImage(ParentFrame,filename)
    4546        return True
    46 # N.B. This replaces G2IO.GetG2Image
Note: See TracChangeset for help on using the changeset viewer.