Changeset 2290


Ignore:
Timestamp:
May 25, 2016 3:39:41 PM (6 years ago)
Author:
vondreele
Message:

complex problem - fix summing of GE images; needed new item in Image Controls to save which reader was used. Change to OnImportGeneric? to keep self.formatName; GetImageData? put it in the call & check it with the available readers & GetImageZ to get it out of the Image Controls & apply it in GetImageData?.
Add a test on file size for GE files.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r2275 r2290  
    525525                    if flag: # this read succeeded
    526526                        rd.readfilename = filename
    527                         if load2Tree:
     527                        if load2Tree:   #images only
    528528                            if rd.repeatcount == 1 and not rd.repeat: # skip image number if only one in set
    529529                                rd.Data['ImageTag'] = None
    530530                            else:
    531531                                rd.Data['ImageTag'] = rd.repeatcount
     532                            rd.Data['formatName'] = rd.formatName
    532533                            G2IO.LoadImage2Tree(rd.readfilename,self,rd.Comments,rd.Data,rd.Npix,rd.Image)
    533534                            rd_list.append(True) # save a stub the result before it is written over
  • trunk/GSASIIIO.py

    r2289 r2290  
    345345    G2frame.Image = Id
    346346
    347 def GetImageData(G2frame,imagefile,imageOnly=False,ImageTag=None):
     347def GetImageData(G2frame,imagefile,imageOnly=False,ImageTag=None,FormatName=''):
    348348    '''Read a single image with an image importer.
    349349
     
    354354    :param int/str ImageTag: specifies a particular image to be read from a file.
    355355      First image is read if None (default).
     356    :param str formatName: the image reader formatName
    356357
    357358    :returns: an image as a numpy array or a list of four items:
     
    367368            secondaryReaders.append(rd)
    368369        elif flag:
    369             primaryReaders.append(rd)
     370            if not FormatName:
     371                primaryReaders.append(rd)
     372            elif FormatName == rd.formatName:
     373                primaryReaders.append(rd)
    370374    if len(secondaryReaders) + len(primaryReaders) == 0:
    371375        print('Error: No matching format for file '+filename)
  • trunk/GSASIIimgGUI.py

    r2288 r2290  
    6060    Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(G2frame.Image)
    6161    imagefile = G2IO.CheckImageFile(G2frame,imagefile)
    62     sumImg = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)
     62    formatName = data.get('formatName','')
     63    sumImg = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag,FormatName=formatName)
    6364    if not 'dark image' in data:
    6465        return sumImg
     
    6667    if darkImg:
    6768        Did = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, darkImg)
     69        Ddata = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Did,'Image Controls'))
     70        dformatName = Ddata.get('formatName','')
    6871        if Did:
    6972            Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(Did)
    7073            imagefile = G2IO.CheckImageFile(G2frame,imagefile)
    71             darkImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)
     74            darkImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag,FormatName=dformatName)
    7275            sumImg += np.array(darkImage*darkScale,dtype='int32')
    7376    if not 'background image' in data:
     
    7982            Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(Bid)
    8083            imagefile = G2IO.CheckImageFile(G2frame,imagefile)
    81             backImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)
    8284            Bdata = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Bid,'Image Controls'))
     85            bformatName = Bdata.get('formatName','')
     86            backImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag,FormatName=bformatName)
    8387            if darkImg:
    8488                Did = G2gd.GetPatternTreeItemId(G2frame, G2frame.root,darkImg)
     89                Ddata = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Did,'Image Controls'))
     90                dformatName = Ddata.get('formatName','')
    8591                Npix,imagefile,imagetag = G2frame.PatternTree.GetImageLoc(Did)
    8692                imagefile = G2IO.CheckImageFile(G2frame,imagefile)
    87                 darkImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag)
     93                darkImage = G2IO.GetImageData(G2frame,imagefile,True,ImageTag=imagetag,FormatName=dformatName)
    8894                backImage += np.array(darkImage*darkScale,dtype='int32')               
    8995            sumImg += np.array(backImage*backScale,dtype='int32')
  • trunk/imports/G2img_GE.py

    r2228 r2290  
    4141
    4242    def ContentsValidator(self, filepointer):
    43         '''no test at this time
     43        '''just a test on file size
    4444        '''
     45        if '.sum' not in str(filepointer):
     46            try:
     47                statinfo = os.stat(str(filepointer).split("'")[1])
     48                fsize = statinfo.st_size
     49                self.nimages = (fsize-8192)/(2*2048**2)
     50            except:
     51                return False    #bad file size
    4552        return True
    4653       
     
    5259        #sum = kwarg.get('sum')
    5360        if imagenum is None: imagenum = 1
    54         self.Comments,self.Data,self.Npix,self.Image,more = GetGEsumData(filename,imagenum=imagenum)
     61        self.Comments,self.Data,self.Npix,self.Image,more = \
     62            GetGEsumData(filename,imagenum=imagenum)
    5563        if self.Npix == 0 or not self.Comments:
    5664            return False
     
    6068        return True
    6169
    62 class GE_sumReaderClass(G2IO.ImportImage):
     70class GEsum_ReaderClass(G2IO.ImportImage):
    6371    '''Routine to read multiple GE images & sum them, typically from APS Sector 1.
    6472       
     
    7987
    8088    def ContentsValidator(self, filepointer):
    81         '''no test at this time
     89        '''just a test on file size
    8290        '''
     91        try:
     92            statinfo = os.stat(str(filepointer).split("'")[1])
     93            fsize = statinfo.st_size
     94            nimages = (fsize-8192)/(2*2048**2)
     95        except:
     96            return False    #bad file size
    8397        return True
    8498       
     
    89103        imagenum = kwarg.get('blocknum')
    90104        if imagenum is None: imagenum = 1
    91         self.Comments,self.Data,self.Npix,self.Image,more = GetGEsumData(filename,imagenum=imagenum,sum=True)
     105        self.Comments,self.Data,self.Npix,self.Image,more = \
     106            GetGEsumData(filename,imagenum=imagenum,sum=True)
    92107        if self.Npix == 0 or not self.Comments:
    93108            return False
     
    140155        if sum:    #will ignore imagenum
    141156            while nframes > 1: #OK, this will sum the frames.
    142         #      print 'adding'
    143157                image += np.array(ar.array('H',File.read(2*Npix)),dtype=np.int32)
    144158                nframes -= 1
Note: See TracChangeset for help on using the changeset viewer.