Changeset 91 for Xml/Validator/Backend/OmeValidator.py
- Timestamp:
- 09/13/07 14:23:16 (15 months ago)
- Files:
-
- 1 modified
-
Xml/Validator/Backend/OmeValidator.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Xml/Validator/Backend/OmeValidator.py
r87 r91 133 133 unresolvedList = None 134 134 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 135 152 def __init__(self): 136 153 """ … … 144 161 # build the blank dom 145 162 self.theDom = None 163 146 164 147 165 def __str__(self): … … 268 286 if reference not in handlerContent.ids: 269 287 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 270 296 271 297 # store the namespace … … 349 375 # create a file object to represent the xml string 350 376 theFileString = StringIO(theXml) 377 # print theXml 378 351 379 # parse the new string/file object into the report and validate it 352 380 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 353 392 return theTiffReport 354 393 validateTiff = classmethod(validateTiff) 355 394 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")) 356 442 357 443 # Used by sax parser to handle errors when processing Elements … … 392 478 self.inBinDataContent = False 393 479 self.shortFormXml = "" 480 # internal check counters 394 481 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 395 488 396 489 # Setup the DOM chunk … … 474 567 if name[-7:] == "BinData": 475 568 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 476 617 self.domify(name, attribs) 477 618 … … 544 685 545 686 if __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 """ 551 693 552 694 for aFilename in ["samples/4d2wOME.tif", "samples/4d2wOME-fixed.tif",
