• Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • ← Previous Changeset
  • Next Changeset →

Changeset 91

Show
Ignore:
Timestamp:
09/13/07 14:23:16 (12 months ago)
Author:
andrew
Message:

Added OME and TIFF image frame counting and basic comparison

Files:
1 modified

  • Xml/Validator/Backend/OmeValidator.py (modified) (7 diffs)

Legend:

Unmodified
Added
Removed
  • Xml/Validator/Backend/OmeValidator.py

    r87 r91  
    133133        unresolvedList = None 
    134134         
     135        """ 
     136        Create variables used to check internal consistency 
     137        """ 
     138        # count of TiffData elements founf in the XML 
     139        omeTiffDataCount = None 
     140        # count of image frames found in Tiff file 
     141        tiffFileFrames = None 
     142         
     143        # count of pixels 
     144        omePixelsCount = None 
     145        # count of planes 
     146        omePlanesCount = None 
     147        # count of Z * C * T 
     148        ome5dPlaneCount = None 
     149        # count of number of times a tiff data block has asked for "all available frames" - value of more then 1 indicates an error 
     150        theAllFrameCount = None 
     151         
    135152        def __init__(self): 
    136153                """ 
    … …  
    144161                # build the blank dom 
    145162                self.theDom = None 
     163         
    146164         
    147165        def __str__(self): 
    … …  
    268286                        if reference not in handlerContent.ids: 
    269287                                self.unresolvedList.append(ParseMessage(None, None, None, "UnresolvedID",None, reference)) 
     288                 
     289                # store the internal counters 
     290                self.omeTiffDataCount = handlerContent.omeTiffDataCount 
     291                self.omePixelsCount = handlerContent.omePixelsCount 
     292                self.omePlanesCount = handlerContent.omePlanesCount 
     293                self.ome5dPlaneCount = handlerContent.ome5dPlaneCount 
     294                self.omeTiffDataPlaneCount = handlerContent.omeTiffDataPlaneCount 
     295                self.theAllFrameCount = handlerContent.theAllFrameCount 
    270296                 
    271297                # store the namespace 
    … …  
    349375                                        # create a file object to represent the xml string 
    350376                                        theFileString = StringIO(theXml) 
     377                                        # print theXml 
     378                                         
    351379                                        # parse the new string/file object into the report and validate it  
    352380                                        theTiffReport.parse(theFileString) 
     381                                        theTiffReport.validateTiffImageData(image) 
     382                                        """ 
     383                                        print "Tiff Frames    : %s" % theTiffReport.tiffFileFrames       
     384                                        print "Ome Frames     : %s" % theTiffReport.omeTiffDataCount     
     385                                        print "Ome Pixels     : %s" % theTiffReport.omePixelsCount       
     386                                        print "Ome Planes     : %s" % theTiffReport.omePlanesCount       
     387                                        print "Ome 5dPlane    : %s" % theTiffReport.ome5dPlaneCount      
     388                                        print "Ome TiffPlane  : %s" % theTiffReport.omeTiffDataPlaneCount        
     389                                        print "Ome AllFrame   : %s" % theTiffReport.theAllFrameCount     
     390                                        """ 
     391                                         
    353392                return theTiffReport 
    354393        validateTiff = classmethod(validateTiff) 
    355394         
     395        def validateTiffImageData(self, inImage, ): 
     396                """ 
     397                Examines the tiff image data to compare with  
     398                """ 
     399                 
     400                """ code to look at the list of tiff image dimensions 
     401                theTiffWidth = None 
     402                theTiffHeight = None 
     403                try: 
     404                        #theTiffWidth = int(inImage.tag[256]) 
     405                        print inImage.tag[256] 
     406                except KeyError: 
     407                        pass 
     408                except ValueError: 
     409                        pass 
     410                try: 
     411                        theTiffHeight = int(inImage.tag[257]) 
     412                except KeyError: 
     413                        pass 
     414                except ValueError: 
     415                        pass 
     416                """ 
     417                 
     418                #look for frames 
     419                self.tiffFileFrames = 0 
     420                try: 
     421                    while True: 
     422                        inImage.seek( self.tiffFileFrames ) 
     423                        self.tiffFileFrames = self.tiffFileFrames + 1 
     424                except EOFError: 
     425                    inImage.seek( 0 ) 
     426                    pass 
     427                 
     428                # compare with values from xml and tiff 
     429                if self.tiffFileFrames > self.ome5dPlaneCount: 
     430                        self.warningList.append(ParseMessage(None, None, None, "TIFF", ("Frames %s needing %s" % (self.tiffFileFrames,self.ome5dPlaneCount)) , "Extra frames are present in this Tiff file")) 
     431 
     432                if self.tiffFileFrames < self.ome5dPlaneCount: 
     433                        self.warningList.append(ParseMessage(None, None, None, "TIFF", ("Frames %s out of %s" % (self.tiffFileFrames,self.ome5dPlaneCount)) , "Not all possible frames are present in this Tiff file")) 
     434 
     435                # compare with values from xml TiffData and tiff 
     436                totalTiffDataFrames = self.omeTiffDataPlaneCount + (self.tiffFileFrames * self.theAllFrameCount) 
     437                if self.tiffFileFrames > totalTiffDataFrames: 
     438                        self.warningList.append(ParseMessage(None, None, None, "TIFF", ("Frames %s referenced %s" % (self.tiffFileFrames,totalTiffDataFrames)) , "Unreferenced frames are present in this Tiff file")) 
     439 
     440                if self.tiffFileFrames < totalTiffDataFrames: 
     441                        self.errorList.append(ParseMessage(None, None, None, "TIFF", ("Frames %s out of %s" % (self.tiffFileFrames,totalTiffDataFrames)) , "Not all required frames are present in this Tiff file")) 
    356442 
    357443# Used by sax parser to handle errors when processing Elements 
    … …  
    392478                self.inBinDataContent = False 
    393479                self.shortFormXml = "" 
     480                # internal check counters 
    394481                self.skipCount = 0 
     482                self.omeTiffDataCount = 0 
     483                self.omePixelsCount = 0 
     484                self.omePlanesCount = 0 
     485                self.ome5dPlaneCount = 0 
     486                self.omeTiffDataPlaneCount = 0 
     487                self.theAllFrameCount = 0 
    395488                 
    396489                # Setup the DOM chunk 
    … …  
    474567                if name[-7:] == "BinData": 
    475568                        self.inBinData = True 
     569                 
     570                if name[-8:] == "TiffData": 
     571                        self.omeTiffDataCount = self.omeTiffDataCount + 1 
     572                        # omeTiffDataPlaneCount 
     573                        if "NumPlanes" in attribs: 
     574                                # use the number of planes specified 
     575                                self.omeTiffDataPlaneCount = self.omeTiffDataPlaneCount + int(attribs.getValue("NumPlanes")) 
     576                                if self.theAllFrameCount > 0: 
     577                                        self.errorList.append(ParseMessage(None, None, None, "OME","", "Inconsistent use of TiffData element [Type 1]")) 
     578                                 
     579                        else: 
     580                                if "IFD" in attribs: 
     581                                        # use one frame 
     582                                        self.omeTiffDataPlaneCount = self.omeTiffDataPlaneCount + 1 
     583                                        if self.theAllFrameCount > 0: 
     584                                                self.errorList.append(ParseMessage(None, None, None, "OME","", "Inconsistent use of TiffData element [Type 2]")) 
     585                                else: 
     586                                        # use all the frames in the tiff 
     587                                        self.theAllFrameCount = self.theAllFrameCount + 1 
     588                                        if (self.theAllFrameCount > 1) or (self.omeTiffDataPlaneCount > 0): 
     589                                                self.errorList.append(ParseMessage(None, None, None, "OME","", "Inconsistent use of TiffData element [Type 3]")) 
     590                         
     591                        """ 
     592                        IFD: Gives the IFD(s) for which this element is applicable. Indexed from 0. Default is 0 (the first IFD). 
     593                        FirstZ: Gives the Z position of the image plane at the specified IFD. Indexed from 0. Default is 0 (the first Z position). 
     594                        FirstT: Gives the T position of the image plane at the specified IFD. Indexed from 0. Default is 0 (the first T position). 
     595                        FirstC: Gives the C position of the image plane at the specified IFD. Indexed from 0. Default is 0 (the first C position). 
     596                        NumPlanes: Gives the number of IFDs affected. Dimension order of IFDs is given by the enclosing Pixels element's DimensionOrder attribute.  
     597                                           Default is the number of IFDs in the TIFF file, unless an IFD is specified, in which case the default is 1. 
     598                        """ 
     599                 
     600                if name[-6:] == "Pixels": 
     601                        self.omePixelsCount = self.omePixelsCount + 1 
     602                        try: 
     603                                # total up planes needed from Z, C and T 
     604                                theZ = int(attribs.getValue("SizeZ")) 
     605                                theC = int(attribs.getValue("SizeC")) 
     606                                theT = int(attribs.getValue("SizeT")) 
     607                                # print "Z: %s, C: %s, T: %s" % (theZ, theC, theT) 
     608                                self.ome5dPlaneCount = self.ome5dPlaneCount + (theZ * theC * theT) 
     609                        except KeyError: 
     610                                pass 
     611                        except ValueError: 
     612                                pass 
     613                 
     614                if name[-5:] == "Plane": 
     615                        self.omePlanesCount = self.omePlanesCount + 1 
     616                 
    476617                self.domify(name, attribs) 
    477618                         
    … …  
    544685 
    545686if __name__ == '__main__': 
    546         for aFilename in ["samples/completesamplenopre.xml","samples/completesample.xml","samples/completesamplenoenc.xml", 
    547                 "samples/sdub.ome", "samples/sdub-fix.ome", "samples/sdub-fix-pre.ome",  
    548                 "samples/tiny.ome", "samples/broke.ome"]: 
    549                 print "============ XML file %s ============ " % aFilename 
    550                 print XmlReport.validateFile(aFilename) 
     687        """     for aFilename in ["samples/completesamplenopre.xml","samples/completesample.xml","samples/completesamplenoenc.xml", 
     688                        "samples/sdub.ome", "samples/sdub-fix.ome", "samples/sdub-fix-pre.ome",  
     689                        "samples/tiny.ome", "samples/broke.ome"]: 
     690                        print "============ XML file %s ============ " % aFilename 
     691                        print XmlReport.validateFile(aFilename) 
     692        """ 
    551693         
    552694        for aFilename in ["samples/4d2wOME.tif", "samples/4d2wOME-fixed.tif", 

Download in other formats:

  • Unified Diff
  • Zip Archive

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/