Changeset 7003


Ignore:
Timestamp:
09/28/10 11:28:36 (9 years ago)
Author:
melissa
Message:

Merged metadata population fixes into 4.2: r6700, r6711, r6719, r6728, r6751, r6768, r6780, r6791, r6796, r6814, r6866, and r6978.

Location:
branches/4.2
Files:
36 edited

Legend:

Unmodified
Added
Removed
  • branches/4.2

  • branches/4.2/components/bio-formats/src/loci/formats/MetadataTools.java

    r6663 r7003  
    3636import loci.formats.meta.MetadataRetrieve; 
    3737import loci.formats.meta.MetadataStore; 
     38import loci.formats.ome.OMEXMLMetadataImpl; 
    3839import loci.formats.services.OMEXMLService; 
    3940 
     41import ome.xml.model.BinData; 
     42import ome.xml.model.OME; 
    4043import ome.xml.model.enums.DimensionOrder; 
    4144import ome.xml.model.enums.EnumerationException; 
    4245import ome.xml.model.enums.PixelType; 
    4346import ome.xml.model.primitives.NonNegativeInteger; 
     47import ome.xml.model.primitives.NonNegativeLong; 
    4448import ome.xml.model.primitives.PositiveInteger; 
    4549 
     
    116120      store.setPixelsSizeC(new PositiveInteger(r.getSizeC()), i); 
    117121      store.setPixelsSizeT(new PositiveInteger(r.getSizeT()), i); 
    118       store.setPixelsBinDataBigEndian(new Boolean(!r.isLittleEndian()), i, 0); 
     122 
     123      int tiffDataCount = 0; 
     124      OMEXMLService service = null; 
     125      try { 
     126        service = new ServiceFactory().getInstance(OMEXMLService.class); 
     127        if (service.isOMEXMLRoot(store.getRoot())) { 
     128          MetadataStore baseStore = r.getMetadataStore(); 
     129          if (service.isOMEXMLMetadata(baseStore)) { 
     130            ((OMEXMLMetadataImpl) baseStore).resolveReferences(); 
     131          } 
     132 
     133          OME root = (OME) store.getRoot(); 
     134          tiffDataCount = root.getImage(i).getPixels().sizeOfTiffDataList(); 
     135        } 
     136      } 
     137      catch (DependencyException exc) { 
     138        LOGGER.debug("Failed to set BinData.Length", exc); 
     139      } 
     140 
     141      if (tiffDataCount == 0) { 
     142        store.setPixelsBinDataBigEndian(new Boolean(!r.isLittleEndian()), i, 0); 
     143 
     144        if (service != null && service.isOMEXMLRoot(store.getRoot())) { 
     145          OME root = (OME) store.getRoot(); 
     146          BinData bin = root.getImage(i).getPixels().getBinData(0); 
     147          bin.setLength(new NonNegativeLong(0L)); 
     148          store.setRoot(root); 
     149        } 
     150      } 
     151 
    119152      try { 
    120153        store.setPixelsType(PixelType.fromString( 
     
    130163        for (int c=0; c<r.getEffectiveSizeC(); c++) { 
    131164          store.setChannelID(createLSID("Channel", i, c), i, c); 
    132           store.setChannelSamplesPerPixel(new PositiveInteger(sampleCount), i, c); 
     165          store.setChannelSamplesPerPixel( 
     166            new PositiveInteger(sampleCount), i, c); 
    133167        } 
    134168      } 
  • branches/4.2/components/bio-formats/src/loci/formats/in

  • branches/4.2/components/bio-formats/src/loci/formats/in/BDReader.java

    r7002 r7003  
    280280      Integer col = Integer.parseInt(name.substring(1)); 
    281281 
     282      store.setWellID(MetadataTools.createLSID("Well", 0, i), 0, i); 
    282283      store.setWellColumn(new NonNegativeInteger(col - 1), 0, i); 
    283284      store.setWellRow(new NonNegativeInteger(row.charAt(0) - 'A'), 0, i); 
    284285 
     286      String wellSampleID = MetadataTools.createLSID("WellSample", 0, i, 0); 
     287      store.setWellSampleID(wellSampleID, 0, i, 0); 
    285288      store.setWellSampleIndex(new NonNegativeInteger(i), 0, i, 0); 
    286289 
     
    347350      } 
    348351 
     352      store.setPlateID(MetadataTools.createLSID("Plate", 0), 0); 
    349353      store.setPlateRowNamingConvention(getNamingConvention("Letter"), 0); 
    350354      store.setPlateColumnNamingConvention(getNamingConvention("Number"), 0); 
     
    524528 
    525529      if (cols[2].trim().length() > 0) { 
     530        String rectangleID = MetadataTools.createLSID("Shape", i - firstRow, 0); 
     531        store.setRectangleID(rectangleID, i - firstRow, 0); 
    526532        store.setRectangleX(new Double(cols[2]), i - firstRow, 0); 
    527533        store.setRectangleY(new Double(cols[3]), i - firstRow, 0); 
  • branches/4.2/components/bio-formats/src/loci/formats/in/BaseTiffReader.java

    r6663 r7003  
    411411        store.setExperimenterLastName(lastName, 0); 
    412412        store.setExperimenterEmail(email, 0); 
     413        store.setExperimenterDisplayName(artist, 0); 
     414        store.setExperimenterID(MetadataTools.createLSID("Experimenter", 0), 0); 
    413415      } 
    414416 
  • branches/4.2/components/bio-formats/src/loci/formats/in/FlexReader.java

    r6663 r7003  
    437437      for (int col=0; col<wellColumns; col++) { 
    438438        int well = row * wellColumns + col; 
     439        store.setWellID(MetadataTools.createLSID("Well", 0, well), 0, well); 
    439440        store.setWellRow(new NonNegativeInteger(row), 0, well); 
    440441        store.setWellColumn(new NonNegativeInteger(col), 0, well); 
     
    460461        store.setWellColumn(col, pos[2], pos[1]); 
    461462      } 
     463      String wellSample = 
     464        MetadataTools.createLSID("WellSample", pos[2], well, pos[0]); 
     465      store.setWellSampleID(wellSample, pos[2], well, pos[0]); 
    462466      store.setWellSampleIndex(new NonNegativeInteger(i), pos[2], well, pos[0]); 
    463467      store.setWellSampleImageRef(imageID, pos[2], well, pos[0]); 
     
    470474      if (plateName == null) plateName = currentFile.getParentFile().getName(); 
    471475      if (plateBarcode != null) plateName = plateBarcode + " " + plateName; 
     476      store.setPlateID(MetadataTools.createLSID("Plate", 0), 0); 
    472477      store.setPlateName(plateName, 0); 
    473478      store.setPlateRowNamingConvention(getNamingConvention("Letter"), 0); 
  • branches/4.2/components/bio-formats/src/loci/formats/in/GatanDM2Reader.java

    r6663 r7003  
    189189      if (label.equals("Acquisition Date")) { 
    190190        date = value.toString(); 
     191        if (date != null && date.indexOf("/") != -1) { 
     192          // if the year is stored as a single digit, then it will be parsed 
     193          // literally, e.g. '7' -> '0007', when we want '7' -> '2007' 
     194          String year = date.substring(date.lastIndexOf("/") + 1); 
     195          if (year.length() < 2) { 
     196            year = "0" + year; 
     197          } 
     198          date = date.substring(0, date.lastIndexOf("/") + 1) + year; 
     199        } 
    191200      } 
    192201      else if (label.equals("Acquisition Time")) { 
     
    208217          store.setExperimenterLastName(experimenterName[1], 0); 
    209218        } 
     219        store.setExperimenterDisplayName(value.toString(), 0); 
    210220        String expID = MetadataTools.createLSID("Experimenter", 0); 
    211221        store.setExperimenterID(expID, 0); 
  • branches/4.2/components/bio-formats/src/loci/formats/in/GatanReader.java

    r6663 r7003  
    128128      gamma = mag = voltage = 0; 
    129129      info = null; 
     130      adjustEndianness = true; 
    130131    } 
    131132  } 
  • branches/4.2/components/bio-formats/src/loci/formats/in/ImaconReader.java

    r6663 r7003  
    181181      store.setExperimenterFirstName(firstName, 0); 
    182182      store.setExperimenterLastName(lastName, 0); 
     183      store.setExperimenterDisplayName(lastName + ", " + firstName, 0); 
    183184 
    184185      for (int i=0; i<getSeriesCount(); i++) { 
  • branches/4.2/components/bio-formats/src/loci/formats/in/InCellReader.java

    r7002 r7003  
    436436      int sampleIndex = (field - 1) * totalTimepoints + timepoint; 
    437437 
     438      String wellSampleID = 
     439        MetadataTools.createLSID("WellSample", 0, well, sampleIndex); 
     440      store.setWellSampleID(wellSampleID, 0 ,well, sampleIndex); 
    438441      store.setWellSampleIndex(new NonNegativeInteger(i), 0, well, sampleIndex); 
    439442      store.setWellSampleImageRef(imageID, 0, well, sampleIndex); 
     
    504507        Character.isDigit(colName.charAt(0)) ? "Number" : "Letter"; 
    505508 
     509      store.setPlateID(MetadataTools.createLSID("Plate", 0), 0); 
    506510      store.setPlateRowNamingConvention(getNamingConvention(rowNaming), 0); 
    507511      store.setPlateColumnNamingConvention(getNamingConvention(colNaming), 0); 
     
    873877          for (int c=0; c<wellCols; c++) { 
    874878            int well = r * wellCols + c; 
     879            String wellID = MetadataTools.createLSID("Well", nextPlate, well); 
     880            store.setWellID(wellID, nextPlate, well); 
    875881            store.setWellRow(new NonNegativeInteger(r), nextPlate, well); 
    876882            store.setWellColumn(new NonNegativeInteger(c), nextPlate, well); 
  • branches/4.2/components/bio-formats/src/loci/formats/in/LEOReader.java

    r6663 r7003  
    3030import loci.formats.FormatException; 
    3131import loci.formats.FormatTools; 
     32import loci.formats.MetadataTools; 
    3233import loci.formats.meta.MetadataStore; 
    3334import loci.formats.tiff.IFD; 
     
    6162    super("LEO", "sxm"); 
    6263    domains = new String[] {FormatTools.EM_DOMAIN}; 
     64    suffixSufficient = false; 
    6365  } 
    6466 
     
    121123      store.setPixelsPhysicalSizeX(xSize, 0); 
    122124      store.setPixelsPhysicalSizeY(xSize, 0); 
     125 
     126      String instrument = MetadataTools.createLSID("Instrument", 0); 
     127      store.setInstrumentID(instrument, 0); 
     128      store.setImageInstrumentRef(instrument, 0); 
     129 
     130      store.setObjectiveID(MetadataTools.createLSID("Objective", 0, 0), 0, 0); 
    123131      store.setObjectiveWorkingDistance(workingDistance, 0, 0); 
    124132      store.setObjectiveImmersion(getImmersion("Other"), 0, 0); 
  • branches/4.2/components/bio-formats/src/loci/formats/in/LIFReader.java

    r6822 r7003  
    394394        OME root = (OME) store.getRoot(); 
    395395        for (int i=0; i<getSeriesCount(); i++) { 
    396           setSeries(i); 
    397396          Pixels img = root.getImage(i).getPixels(); 
    398397          for (int c=0; c<img.sizeOfChannelList(); c++) { 
    399398            Channel channel = img.getChannel(c); 
    400             if (channel.getID() == null || c >= getEffectiveSizeC()) { 
    401               img.removeChannel(channel); 
    402             } 
     399            if (channel.getID() == null) img.removeChannel(channel); 
    403400          } 
    404401        } 
    405         setSeries(0); 
    406402      } 
    407403    } 
  • branches/4.2/components/bio-formats/src/loci/formats/in/LeicaHandler.java

    r6981 r7003  
    948948      // the center point of the image 
    949949 
    950       if (text != null) store.setTextValue(text, roi, 0); 
     950      store.setROIID(MetadataTools.createLSID("ROI", roi), roi); 
     951      store.setTextID(MetadataTools.createLSID("Shape", roi, 0), roi, 0); 
     952      if (text == null) text = ""; 
     953      store.setTextValue(text, roi, 0); 
    951954      if (fontSize != null) { 
    952955        store.setTextFontSize( 
     
    960963      double cornerY = y.get(0).doubleValue(); 
    961964 
     965      store.setTextX(cornerX, roi, 0); 
     966      store.setTextY(cornerY, roi, 0); 
     967 
    962968      int centerX = (core.get(series).sizeX / 2) - 1; 
    963969      int centerY = (core.get(series).sizeY / 2) - 1; 
     
    973979      // TODO : rotation/scaling not populated 
    974980 
     981      String shapeID = MetadataTools.createLSID("Shape", roi, 1); 
    975982      switch (type) { 
    976983        case POLYGON: 
     
    982989            if (i < x.size() - 1) points.append(" "); 
    983990          } 
     991          store.setPolylineID(shapeID, roi, 1); 
    984992          store.setPolylinePoints(points.toString(), roi, 1); 
    985993          store.setPolylineClosed(Boolean.TRUE, roi, 1); 
     
    988996        case TEXT: 
    989997        case RECTANGLE: 
     998          store.setRectangleID(shapeID, roi, 1); 
    990999          store.setRectangleX(roiX - Math.abs(cornerX), roi, 1); 
    9911000          store.setRectangleY(roiY - Math.abs(cornerY), roi, 1); 
     
    9991008        case ARROW: 
    10001009        case LINE: 
     1010          store.setLineID(shapeID, roi, 1); 
    10011011          store.setLineX1(roiX + x.get(0), roi, 1); 
    10021012          store.setLineY1(roiY + y.get(0), roi, 1); 
  • branches/4.2/components/bio-formats/src/loci/formats/in/LiFlimReader.java

    r6663 r7003  
    453453    for (int roi=0; roi<roiIndices.length; roi++) { 
    454454      ROI r = rois.get(roiIndices[roi]); 
     455      String polylineID = MetadataTools.createLSID("Shape", roi, 0); 
     456      store.setPolylineID(polylineID, roi, 0); 
    455457      store.setPolylinePoints(r.pointsToString(), roi, 0); 
    456458      store.setPolylineClosed(Boolean.TRUE, roi, 0); 
  • branches/4.2/components/bio-formats/src/loci/formats/in/MIASReader.java

    r6663 r7003  
    678678      char wellRow = (char) ('A' + row); 
    679679 
     680      store.setWellID(MetadataTools.createLSID("Well", 0, well), 0, well); 
    680681      store.setWellRow(new NonNegativeInteger(row), 0, well); 
    681682      store.setWellColumn(new NonNegativeInteger(wellCol - 1), 0, well); 
    682683 
    683684      String imageID = MetadataTools.createLSID("Image", well); 
     685      String wellSampleID = MetadataTools.createLSID("WellSample", 0, well, 0); 
     686      store.setWellSampleID(wellSampleID, 0, well, 0); 
    684687      store.setWellSampleIndex(new NonNegativeInteger(well), 0, well, 0); 
    685688 
     
    694697 
    695698    if (level != MetadataLevel.MINIMUM) { 
    696       store.setExperimentID("Experiment:" + experiment.getName(), 0); 
     699      String experimentID = MetadataTools.createLSID("Experiment", 0); 
     700      store.setExperimentID(experimentID, 0); 
    697701      store.setExperimentType(getExperimentType("Other"), 0); 
     702      store.setExperimentDescription(experiment.getName(), 0); 
    698703 
    699704      // populate SPW metadata 
     705      store.setPlateID(MetadataTools.createLSID("Plate", 0), 0); 
    700706      store.setPlateColumnNamingConvention(getNamingConvention("Number"), 0); 
    701707      store.setPlateRowNamingConvention(getNamingConvention("Letter"), 0); 
     
    709715      for (int well=0; well<nWells; well++) { 
    710716        // populate Image/Pixels metadata 
    711         store.setImageExperimentRef("Experiment:" + experiment.getName(), well); 
     717        store.setImageExperimentRef(experimentID, well); 
    712718 
    713719        String instrumentID = MetadataTools.createLSID("Instrument", 0); 
     
    849855    store.setImageROIRef(roiID, series, roi); 
    850856 
     857    store.setEllipseID(MetadataTools.createLSID("Shape", roi, 0), roi, 0); 
    851858    store.setEllipseTheT(new NonNegativeInteger(tv), roi, 0); 
    852859    store.setEllipseTheZ(new NonNegativeInteger(zv), roi, 0); 
     
    916923        } 
    917924        else if (key.equals("Objective_ID")) { 
     925          store.setObjectiveID( 
     926            MetadataTools.createLSID("Objective", 0, 0), 0, 0); 
    918927          store.setObjectiveModel(value, 0, 0); 
    919928        } 
     
    970979    for (int i=0; i<3; i++) { 
    971980      String roiId = MetadataTools.createLSID("ROI", series, roi + nOverlays); 
    972       String maskId = MetadataTools.createLSID("Mask", series, roi + nOverlays, 0); 
     981      String maskId = 
     982        MetadataTools.createLSID("Mask", series, roi + nOverlays, 0); 
    973983      overlayFiles.put(maskId, overlayTiff); 
    974984      overlayPlanes.put(maskId, new Integer(i)); 
     
    977987      if (validMask) { 
    978988        store.setROIID(roiId, roi + nOverlays); 
     989 
     990        String maskID = MetadataTools.createLSID("Shape", roi + nOverlays, 0); 
     991        store.setMaskID(maskID, roi + nOverlays, 0); 
    979992        store.setMaskX(new Double(0), roi + nOverlays, 0); 
    980993        store.setMaskY(new Double(0), roi + nOverlays, 0); 
  • branches/4.2/components/bio-formats/src/loci/formats/in/MetamorphReader.java

    r7002 r7003  
    102102  private double zStart; 
    103103  private Double sizeX = null, sizeY = null; 
     104  private double tempZ; 
     105  private boolean validZ; 
    104106 
    105107  private int mmPlanes; //number of metamorph planes 
    106108 
    107   private MetamorphReader stkReader; 
     109  private MetamorphReader[][] stkReaders; 
    108110 
    109111  /** List of STK files in the dataset. */ 
     
    176178    if (!noPixels) { 
    177179      for (String stk : stks[getSeries()]) { 
    178         if (new Location(stk).exists()) { 
     180        if (stk != null && new Location(stk).exists()) { 
    179181          v.add(stk); 
    180182        } 
     
    203205    // the original file is a .nd file, so we need to construct a new reader 
    204206    // for the constituent STK files 
    205     if (stkReader == null) { 
    206       stkReader = new MetamorphReader(); 
    207       stkReader.setCanLookForND(false); 
    208     } 
    209     stkReader.setId(file); 
     207    stkReaders[series][ndx].setId(file); 
    210208    int plane = stks[series].length == 1 ? no : coords[0]; 
    211     stkReader.openBytes(plane, buf, x, y, w, h); 
    212     stkReader.close(); 
     209    stkReaders[series][ndx].openBytes(plane, buf, x, y, w, h); 
    213210    return buf; 
    214211  } 
     
    217214  public void close(boolean fileOnly) throws IOException { 
    218215    super.close(fileOnly); 
    219     if (stkReader != null) stkReader.close(fileOnly); 
     216    if (stkReaders != null) { 
     217      for (MetamorphReader[] s : stkReaders) { 
     218        if (s != null) { 
     219          for (MetamorphReader reader : s) { 
     220            if (reader != null) reader.close(fileOnly); 
     221          } 
     222        } 
     223      } 
     224    } 
    220225    if (!fileOnly) { 
    221       stkReader = null; 
    222226      imageName = imageCreationDate = null; 
    223227      emWavelength = null; 
     
    235239      firstSeriesChannels = null; 
    236240      sizeX = sizeY = null; 
     241      tempZ = 0d; 
     242      validZ = false; 
     243      stkReaders = null; 
    237244    } 
    238245  } 
     
    499506    } 
    500507 
     508    if (stks == null) { 
     509      stkReaders = new MetamorphReader[1][1]; 
     510      stkReaders[0][0] = new MetamorphReader(); 
     511      stkReaders[0][0].setCanLookForND(false); 
     512    } 
     513    else { 
     514      stkReaders = new MetamorphReader[stks.length][]; 
     515      for (int i=0; i<stks.length; i++) { 
     516        stkReaders[i] = new MetamorphReader[stks[i].length]; 
     517        for (int j=0; j<stkReaders[i].length; j++) { 
     518          stkReaders[i][j] = new MetamorphReader(); 
     519          stkReaders[i][j].setCanLookForND(false); 
     520          if (j > 0) { 
     521            stkReaders[i][j].setMetadataOptions( 
     522              new DefaultMetadataOptions(MetadataLevel.MINIMUM)); 
     523          } 
     524        } 
     525      } 
     526    } 
     527 
    501528    Vector<String> timestamps = null; 
    502529    MetamorphHandler handler = null; 
     
    611638      int lastFile = -1; 
    612639      IFD lastIFD = null; 
     640      long[] lastOffsets = null; 
    613641 
    614642      double distance = zStart; 
     
    618646        Double deltaT = new Double(0); 
    619647        Double exposureTime = new Double(0); 
    620  
    621         if (coords[2] > 0 && stks != null && lastFile >= 0 && 
    622           stks[i][lastFile] != null) 
    623         { 
    624           int fileIndex = getIndex(0, 0, coords[2]) / getSizeZ(); 
    625           if (fileIndex != lastFile) { 
    626             lastFile = fileIndex; 
    627             RandomAccessInputStream stream = 
    628               new RandomAccessInputStream(stks[i][lastFile]); 
     648        Double xmlZPosition = null; 
     649 
     650        int fileIndex = getIndex(0, 0, coords[2]) / getSizeZ(); 
     651        if (fileIndex >= 0) { 
     652          String file = stks == null ? currentId : stks[i][fileIndex]; 
     653          if (file != null) { 
     654            RandomAccessInputStream stream = new RandomAccessInputStream(file); 
    629655            TiffParser tp = new TiffParser(stream); 
    630             lastIFD = tp.getFirstIFD(); 
     656            tp.checkHeader(); 
     657            if (fileIndex != lastFile) { 
     658              lastFile = fileIndex; 
     659              lastOffsets = tp.getIFDOffsets(); 
     660            } 
     661 
     662            lastIFD = tp.getIFD(lastOffsets[p % lastOffsets.length]); 
    631663            stream.close(); 
    632           } 
    633           comment = lastIFD.getComment(); 
    634           handler = new MetamorphHandler(getSeriesMetadata()); 
    635           if (comment != null && comment.startsWith("<MetaData>")) { 
    636             XMLTools.parseXML(comment, handler); 
    637           } 
    638           timestamps = handler.getTimestamps(); 
    639           exposureTimes = handler.getExposures(); 
     664            comment = lastIFD.getComment(); 
     665            if (comment != null) comment = comment.trim(); 
     666            handler = new MetamorphHandler(getSeriesMetadata()); 
     667            if (comment != null && comment.startsWith("<MetaData>")) { 
     668              XMLTools.parseXML(comment, handler); 
     669            } 
     670            timestamps = handler.getTimestamps(); 
     671            exposureTimes = handler.getExposures(); 
     672            Vector<Double> zPositions = handler.getZPositions(); 
     673            if (zPositions != null && zPositions.size() > 0) { 
     674              xmlZPosition = zPositions.get(0); 
     675            } 
     676          } 
    640677        } 
    641678 
     
    668705        } 
    669706        if (zDistances != null && p < zDistances.length) { 
    670           if (zDistances[p] != 0d) distance += zDistances[p]; 
    671           else distance += zDistances[0]; 
     707          if (p > 0) { 
     708            if (zDistances[p] != 0d) distance += zDistances[p]; 
     709            else distance += zDistances[0]; 
     710          } 
    672711          store.setPlanePositionZ(distance, i, p); 
     712        } 
     713        else if (xmlZPosition != null) { 
     714          store.setPlanePositionZ(xmlZPosition, i, p); 
    673715        } 
    674716      } 
     
    10541096    in.seek(uic4offset); 
    10551097    if (in.getFilePointer() + 2 >= in.length()) return; 
     1098 
     1099    tempZ = 0d; 
     1100    validZ = false; 
     1101 
    10561102    short id = in.readShort(); 
    10571103    while (id != 0) { 
     
    10681114          break; 
    10691115        case 40: 
    1070           readRationals(new String[] {"absoluteZ"}); 
     1116          readRationals(new String[] {"UIC4 absoluteZ"}); 
    10711117          break; 
    10721118        case 41: 
    10731119          readAbsoluteZValid(); 
    10741120          break; 
     1121        case 46: 
     1122          in.skipBytes(mmPlanes * 8); // TODO 
     1123          break; 
     1124        default: 
     1125          in.skipBytes(4); 
    10751126      } 
    10761127      id = in.readShort(); 
    10771128    } 
    10781129    in.seek(saveLoc); 
     1130 
     1131    if (validZ) zStart = tempZ; 
    10791132  } 
    10801133 
     
    10981151      for (int q=0; q<labels.length; q++) { 
    10991152        double v = readRational(in).doubleValue(); 
    1100         if (labels[q].equals("absoluteZ") && i == 0) { 
    1101           zStart = v; 
     1153        if (labels[q].endsWith("absoluteZ") && i == 0) { 
     1154          tempZ = v; 
    11021155        } 
    11031156        addSeriesMeta(labels[q] + "[" + pos + "]", v); 
     
    11181171  void readAbsoluteZValid() throws IOException { 
    11191172    for (int i=0; i<mmPlanes; i++) { 
    1120       addSeriesMeta("absoluteZValid[" + intFormatMax(i, mmPlanes) + "]", 
    1121         in.readInt()); 
     1173      int valid = in.readInt(); 
     1174      addSeriesMeta("absoluteZValid[" + intFormatMax(i, mmPlanes) + "]", valid); 
     1175      if (i == 0) { 
     1176        validZ = valid == 1; 
     1177      } 
    11221178    } 
    11231179  } 
     
    11411197    String thedate, thetime; 
    11421198    long lastOffset; 
     1199 
     1200    tempZ = 0d; 
     1201    validZ = false; 
    11431202    for (int i=0; i<uic1count; i++) { 
    11441203      if (in.getFilePointer() >= in.length()) break; 
     
    12361295          if (valOrOffset != 0) { 
    12371296            in.seek(valOrOffset); 
    1238             readRationals(new String[] {"absoluteZ"}); 
     1297            readRationals(new String[] {"UIC1 absoluteZ"}); 
    12391298          } 
    12401299          break; 
     
    12661325    } 
    12671326    in.seek(saveLoc); 
     1327 
     1328    if (validZ) zStart = tempZ; 
    12681329  } 
    12691330 
     
    13451406  private String getKey(int id) { 
    13461407    switch (id) { 
     1408      case 0: return "AutoScale"; 
    13471409      case 1: return "MinScale"; 
    13481410      case 2: return "MaxScale"; 
     
    13661428      case 20: return "grayPointCount"; 
    13671429      case 21: return "grayX"; 
    1368       case 22: return "gray"; 
     1430      case 22: return "grayY"; 
    13691431      case 23: return "grayMin"; 
    13701432      case 24: return "grayMax"; 
     
    13721434      case 26: return "StandardLUT"; 
    13731435      case 27: return "Wavelength"; 
     1436      case 28: return "StagePosition"; 
     1437      case 29: return "CameraChipOffset"; 
    13741438      case 30: return "OverlayMask"; 
    13751439      case 31: return "OverlayCompress"; 
     
    13811445      case 38: return "AutoScaleLoInfo"; 
    13821446      case 39: return "AutoScaleHiInfo"; 
     1447      case 40: return "AbsoluteZ"; 
     1448      case 41: return "AbsoluteZValid"; 
    13831449      case 42: return "Gamma"; 
    13841450      case 43: return "GammaRed"; 
     
    13861452      case 45: return "GammaBlue"; 
    13871453      case 46: return "CameraBin"; 
     1454      case 47: return "NewLUT"; 
     1455      case 48: return "ImagePropertyEx"; 
     1456      case 49: return "PlaneProperty"; 
     1457      case 50: return "UserLutTable"; 
     1458      case 51: return "RedAutoScaleInfo"; 
     1459      case 52: return "RedAutoScaleLoInfo"; 
     1460      case 53: return "RedAutoScaleHiInfo"; 
     1461      case 54: return "RedMinScaleInfo"; 
     1462      case 55: return "RedMaxScaleInfo"; 
     1463      case 56: return "GreenAutoScaleInfo"; 
     1464      case 57: return "GreenAutoScaleLoInfo"; 
     1465      case 58: return "GreenAutoScaleHiInfo"; 
     1466      case 59: return "GreenMinScaleInfo"; 
     1467      case 60: return "GreenMaxScaleInfo"; 
     1468      case 61: return "BlueAutoScaleInfo"; 
     1469      case 62: return "BlueAutoScaleLoInfo"; 
     1470      case 63: return "BlueAutoScaleHiInfo"; 
     1471      case 64: return "BlueMinScaleInfo"; 
     1472      case 65: return "BlueMaxScaleInfo"; 
     1473      case 66: return "OverlayPlaneColor"; 
    13881474    } 
    13891475    return null; 
  • branches/4.2/components/bio-formats/src/loci/formats/in/OMETiffReader.java

    r6706 r7003  
    4545import loci.formats.FormatTools; 
    4646import loci.formats.IFormatReader; 
     47import loci.formats.MetadataTools; 
    4748import loci.formats.MissingLibraryException; 
     49import loci.formats.meta.MetadataStore; 
    4850import loci.formats.ome.OMEXMLMetadata; 
    4951import loci.formats.services.OMEXMLService; 
     
    7981  private int lastPlane; 
    8082  private boolean hasSPW; 
     83 
     84  private OMEXMLService service; 
    8185 
    8286  // -- Constructor -- 
     
    104108    String xml = ifd.getComment(); 
    105109 
     110    if (service == null) setupService(); 
    106111    OMEXMLMetadata meta; 
    107112    try { 
    108       ServiceFactory factory = new ServiceFactory(); 
    109       OMEXMLService service = factory.getInstance(OMEXMLService.class); 
    110113      meta = service.createOMEXMLMetadata(xml); 
    111     } 
    112     catch (DependencyException de) { 
    113       throw new MissingLibraryException(NO_OME_XML_MSG, de); 
    114114    } 
    115115    catch (ServiceException se) { 
     
    144144 
    145145    try { 
    146       ServiceFactory factory = new ServiceFactory(); 
    147       OMEXMLService service = factory.getInstance(OMEXMLService.class); 
     146      if (service == null) setupService(); 
    148147      service.createOMEXMLMetadata(comment.trim()); 
    149148      return true; 
    150149    } 
    151     catch (DependencyException de) { } 
    152150    catch (ServiceException se) { } 
    153151    catch (NullPointerException e) { } 
     152    catch (FormatException e) { } 
    154153    return false; 
    155154  } 
     
    258257    String xml = firstIFD.getComment(); 
    259258 
     259    if (service == null) setupService(); 
    260260    OMEXMLMetadata meta; 
    261     OMEXMLService service; 
    262261    try { 
    263       ServiceFactory factory = new ServiceFactory(); 
    264       service = factory.getInstance(OMEXMLService.class); 
    265262      meta = service.createOMEXMLMetadata(xml); 
    266     } 
    267     catch (DependencyException de) { 
    268       throw new MissingLibraryException(NO_OME_XML_MSG, de); 
    269263    } 
    270264    catch (ServiceException se) { 
     
    608602    core = series.toArray(new CoreMetadata[series.size()]); 
    609603    info = planeInfo.toArray(new OMETiffPlane[0][0]); 
     604 
     605    MetadataTools.populatePixels(metadataStore, this); 
     606    metadataStore = getMetadataStoreForDisplay(); 
     607  } 
     608 
     609  // -- OMETiffReader API methods -- 
     610 
     611  /** 
     612   * Returns a MetadataStore that is populated in such a way as to 
     613   * produce valid OME-XML.  The returned MetadataStore cannot be used 
     614   * by an IFormatWriter, as it will not contain the required 
     615   * BinData.BigEndian attributes. 
     616   */ 
     617  public MetadataStore getMetadataStoreForDisplay() { 
     618    MetadataStore store = getMetadataStore(); 
     619    if (service.isOMEXMLMetadata(store)) { 
     620      service.removeBinData((OMEXMLMetadata) store); 
     621      for (int i=0; i<getSeriesCount(); i++) { 
     622        if (((OMEXMLMetadata) store).getTiffDataCount(i) == 0) { 
     623          service.addMetadataOnly((OMEXMLMetadata) store, i); 
     624        } 
     625      } 
     626    } 
     627    return store; 
     628  } 
     629 
     630  /** 
     631   * Returns a MetadataStore that is populated in such a way as to be 
     632   * usable by an IFormatWriter.  Any OME-XML generated from this 
     633   * MetadataStore is <em>very unlikely</em> to be valid, as more than 
     634   * likely both BinData and TiffData element will be present. 
     635   */ 
     636  public MetadataStore getMetadataStoreForConversion() { 
     637    MetadataStore store = getMetadataStore(); 
     638    int realSeries = getSeries(); 
     639    for (int i=0; i<getSeriesCount(); i++) { 
     640      setSeries(i); 
     641      store.setPixelsBinDataBigEndian(new Boolean(!isLittleEndian()), i, 0); 
     642    } 
     643    setSeries(realSeries); 
     644    return store; 
    610645  } 
    611646 
     
    616651     if (file.exists()) return file.getAbsolutePath(); 
    617652     return new Location(name).getAbsolutePath(); 
     653  } 
     654 
     655  private void setupService() throws FormatException { 
     656    try { 
     657      ServiceFactory factory = new ServiceFactory(); 
     658      service = factory.getInstance(OMEXMLService.class); 
     659    } 
     660    catch (DependencyException de) { 
     661      throw new MissingLibraryException(NO_OME_XML_MSG, de); 
     662    } 
    618663  } 
    619664 
  • branches/4.2/components/bio-formats/src/loci/formats/in/OMEXMLReader.java

    r6836 r7003  
    341341    // contents of the internal OME-XML metadata object 
    342342    MetadataStore store = getMetadataStore(); 
     343    MetadataTools.populatePixels(store, this); 
    343344    service.convertMetadata(omexmlMeta, store); 
    344     MetadataTools.populatePixels(store, this); 
    345345  } 
    346346 
  • branches/4.2/components/bio-formats/src/loci/formats/in/OxfordInstrumentsReader.java

    r6663 r7003  
    189189 
    190190    float scanTime = in.readInt() / 100f; 
    191     dateTime.append(String.valueOf((int) scanTime)); 
     191    dateTime.append(String.format("%02d", (int) scanTime)); 
    192192    addGlobalMeta("Scan time (s)", scanTime); 
    193193    return dateTime.toString(); 
  • branches/4.2/components/bio-formats/src/loci/formats/in/SBIGReader.java

    r6663 r7003  
    6868  /* @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */ 
    6969  public boolean isThisType(RandomAccessInputStream stream) throws IOException { 
    70     final int blockLen = 32; 
     70    final int blockLen = (int) HEADER_SIZE; 
     71    final int checkLen = 32; 
    7172    if (!FormatTools.validStream(stream, blockLen, false)) return false; 
    72     return stream.readString(blockLen).indexOf("Image") > 0; 
     73    return stream.readString(checkLen).indexOf("Image") > 0; 
    7374  } 
    7475 
  • branches/4.2/components/bio-formats/src/loci/formats/in/TCSReader.java

    r6663 r7003  
    416416      core[0].sizeT = (ifds.size() * tiffReaders.length) / c; 
    417417      core[0].imageCount = getSizeT() * c; 
     418      if (getSizeT() == 0) { 
     419        core[0].sizeT = 1; 
     420        core[0].imageCount = ifds.size() * tiffReaders.length; 
     421      } 
     422    } 
     423 
     424    if (getImageCount() == ifds.size() * getSizeZ() * getSizeT() && 
     425      ifds.size() > 1) 
     426    { 
     427      if (getSizeZ() == 1) { 
     428        core[0].sizeZ = ifds.size(); 
     429      } 
     430      else if (getSizeT() == 1) { 
     431        core[0].sizeT = ifds.size(); 
     432      } 
     433      else core[0].sizeZ *= ifds.size(); 
    418434    } 
    419435 
     
    471487 
    472488    Location current = new Location(currentId).getAbsoluteFile(); 
    473     if (checkSuffix(currentId, TiffReader.TIFF_SUFFIXES)) { 
     489    if (!checkSuffix(currentId, XML_SUFFIX)) { 
    474490      tiffs.add(current.getAbsolutePath()); 
    475491    } 
  • branches/4.2/components/bio-formats/src/loci/formats/in/TillVisionReader.java

    r7002 r7003  
    459459 
    460460        if (i < types.size()) { 
     461          store.setExperimentID(MetadataTools.createLSID("Experiment", i), i); 
    461462          store.setExperimentType(getExperimentType(types.get(i)), i); 
    462463        } 
  • branches/4.2/components/bio-formats/src/loci/formats/meta

  • branches/4.2/components/bio-formats/src/loci/formats/ome

  • branches/4.2/components/bio-formats/src/loci/formats/out/OMETiffWriter.java

    r6920 r7003  
    9797 
    9898        // remove any BinData elements from the OME-XML 
    99         removeBinData(omeMeta); 
     99        service.removeBinData(omeMeta); 
    100100 
    101101        for (int series=0; series<omeMeta.getImageCount(); series++) { 
     
    259259  } 
    260260 
    261   private void removeBinData(OMEXMLMetadata omeMeta) { 
    262     OME root = (OME) omeMeta.getRoot(); 
    263     List<Image> images = root.copyImageList(); 
    264     for (Image img : images) { 
    265       Pixels pix = img.getPixels(); 
    266       List<BinData> binData = pix.copyBinDataList(); 
    267       for (BinData bin : binData) { 
    268         pix.removeBinData(bin); 
    269       } 
    270     } 
    271     omeMeta.setRoot(root); 
    272   } 
    273  
    274261  private void populateTiffData(OMEXMLMetadata omeMeta, int[] zct, 
    275262    int ifd, int series, int plane) 
  • branches/4.2/components/bio-formats/src/loci/formats/out/OMEXMLWriter.java

    r6508 r7003  
    6969    super("OME-XML", "ome"); 
    7070    compressionTypes = 
    71       new String[] {"Uncompressed", "zlib", "J2K", "JPEG"}; 
     71      new String[] {"Uncompressed", "zlib"}; 
    7272    compression = compressionTypes[0]; 
    7373  } 
  • branches/4.2/components/bio-formats/src/loci/formats/readers.txt

    r6997 r7003  
    113113 
    114114# TIFF-based readers with unique file extensions 
    115 loci.formats.in.MetamorphReader       # stk 
    116115loci.formats.in.ZeissLSMReader        # lsm, mdb [MDB Tools] 
    117116loci.formats.in.SEQReader             # seq 
     
    131130loci.formats.in.FluoviewReader        # tif 
    132131loci.formats.in.PrairieReader         # xml, cfg, tif 
     132loci.formats.in.MetamorphReader       # stk, tif, nd 
    133133loci.formats.in.MicromanagerReader    # txt, tif 
    134134loci.formats.in.ImprovisionTiffReader # tif 
  • branches/4.2/components/bio-formats/src/loci/formats/services/OMEXMLService.java

    r6234 r7003  
    184184  public void convertMetadata(MetadataRetrieve src, MetadataStore dest); 
    185185 
     186  /** 
     187   * Remove all of the BinData elements from the given OME-XML metadata object. 
     188   */ 
     189  public void removeBinData(OMEXMLMetadata omexmlMeta); 
     190 
     191  /** 
     192   * Insert a MetadataOnly element under the Image specified by 'index' in the 
     193   * given OME-XML metadata object. 
     194   */ 
     195  public void addMetadataOnly(OMEXMLMetadata omexmlMeta, int image); 
     196 
    186197  // -- Utility methods - casting -- 
    187198 
  • branches/4.2/components/bio-formats/src/loci/formats/services/OMEXMLServiceImpl.java

    r6663 r7003  
    2525 
    2626import java.io.IOException; 
     27import java.util.List; 
    2728 
    2829import javax.xml.parsers.ParserConfigurationException; 
     
    4243import loci.formats.ome.OMEXMLMetadataImpl; 
    4344import ome.xml.OMEXMLFactory; 
     45import ome.xml.model.BinData; 
     46import ome.xml.model.Image; 
     47import ome.xml.model.MetadataOnly; 
    4448import ome.xml.model.OME; 
    4549import ome.xml.model.OMEModel; 
    4650import ome.xml.model.OMEModelImpl; 
    4751import ome.xml.model.OMEModelObject; 
     52import ome.xml.model.Pixels; 
    4853import ome.xml.model.StructuredAnnotations; 
    4954 
     
    402407            "Expecting OMEXMLMetadata instance."); 
    403408      } 
    404       // FIXME: What's below was in the ReflectedUniverse, the method no 
    405       // longer exists or has changed. 
    406       //((OMEXMLMetadata) dest).createRoot(xml); 
     409 
     410      dest.setRoot(ome); 
    407411    } 
    408412    else { 
     
    419423  public void convertMetadata(MetadataRetrieve src, MetadataStore dest) { 
    420424    MetadataConverter.convertMetadata(src, dest); 
     425  } 
     426 
     427  /* @see OMEXMLService#removeBinData(OMEXMLMetadata) */ 
     428  public void removeBinData(OMEXMLMetadata omexmlMeta) { 
     429    OME root = (OME) omexmlMeta.getRoot(); 
     430    List<Image> images = root.copyImageList(); 
     431    for (Image img : images) { 
     432      Pixels pix = img.getPixels(); 
     433      List<BinData> binData = pix.copyBinDataList(); 
     434      for (BinData bin : binData) { 
     435        pix.removeBinData(bin); 
     436      } 
     437    } 
     438    omexmlMeta.setRoot(root); 
     439  } 
     440 
     441  /* @see OMEXMLService#addMetadataOnly(OMEXMLMetadata, int) */ 
     442  public void addMetadataOnly(OMEXMLMetadata omexmlMeta, int image) { 
     443    MetadataOnly meta = new MetadataOnly(); 
     444    OME root = (OME) omexmlMeta.getRoot(); 
     445    Pixels pix = root.getImage(image).getPixels(); 
     446    pix.setMetadataOnly(meta); 
     447    omexmlMeta.setRoot(root); 
    421448  } 
    422449 
  • branches/4.2/components/bio-formats/src/loci/formats/tiff

  • branches/4.2/components/bio-formats/src/loci/formats/tiff/TiffParser.java

    r6730 r7003  
    3131import loci.common.RandomAccessInputStream; 
    3232import loci.common.Region; 
     33import loci.common.enumeration.EnumException; 
    3334import loci.formats.FormatException; 
    3435import loci.formats.codec.BitBuffer; 
     
    327328      in.seek(offset + baseOffset + bytesPerEntry * i); 
    328329 
    329       TiffIFDEntry entry = readTiffIFDEntry(); 
     330      TiffIFDEntry entry = null; 
     331      try { 
     332        entry = readTiffIFDEntry(); 
     333      } 
     334      catch (EnumException e) { 
     335        LOGGER.debug("", e); 
     336      } 
     337      if (entry == null) break; 
    330338      int count = entry.getValueCount(); 
    331339      int tag = entry.getTag(); 
  • branches/4.2/components/bio-formats/src/loci/formats/tools/ImageConverter.java

    r6996 r7003  
    4343import loci.formats.ImageWriter; 
    4444import loci.formats.MissingLibraryException; 
     45import loci.formats.ReaderWrapper; 
    4546import loci.formats.in.OMETiffReader; 
    4647import loci.formats.meta.MetadataRetrieve; 
     
    189190 
    190191    MetadataStore store = reader.getMetadataStore(); 
     192    IFormatReader base = reader;  
     193 
     194    if (base instanceof ReaderWrapper) { 
     195      base = ((ReaderWrapper) base).unwrap(); 
     196    } 
     197    if (base instanceof FileStitcher) { 
     198      base = ((FileStitcher) base).getReader(); 
     199    } 
     200    if (base instanceof ImageReader) { 
     201      base = ((ImageReader) base).getReader(); 
     202    } 
     203    if (base instanceof OMETiffReader) { 
     204      store = ((OMETiffReader) base).getMetadataStoreForConversion(); 
     205    } 
     206 
    191207    if (store instanceof MetadataRetrieve) { 
    192208      writer.setMetadataRetrieve((MetadataRetrieve) store); 
  • branches/4.2/components/bio-formats/src/loci/formats/tools/ImageInfo.java

    r7001 r7003  
    846846      String xml = service.getOMEXML((MetadataRetrieve) ms); 
    847847      LOGGER.info("{}", XMLTools.indentXML(xml, true)); 
    848       service.validateOMEXML(xml, true); 
     848      service.validateOMEXML(xml); 
    849849    } 
    850850    else { 
  • branches/4.2/components/bio-formats/test/loci/formats/utests

  • branches/4.2/components/ome-xml

  • branches/4.2/components/test-suite/src/loci/tests/testng/FormatReaderTest.java

    r6910 r7003  
    459459        } 
    460460 
    461         // if CreationDate is before 1995, it's probably invalid 
     461        // if CreationDate is before 1990, it's probably invalid 
    462462        String date = retrieve.getImageAcquiredDate(i); 
    463         if (date != null && DateTools.getTime(date, DateTools.ISO8601_FORMAT) < 
    464           DateTools.getTime("1995-01-01T00:00:00", DateTools.ISO8601_FORMAT)) 
    465         { 
    466           msg = "CreationDate"; 
     463        if (date != null) { 
     464          date = date.trim(); 
     465          long acquiredDate = DateTools.getTime(date, DateTools.ISO8601_FORMAT); 
     466          long saneDate = 
     467            DateTools.getTime("1990-01-01T00:00:00", DateTools.ISO8601_FORMAT); 
     468          long fileDate = new Location( 
     469            reader.getCurrentFile()).getAbsoluteFile().lastModified(); 
     470          if (acquiredDate < saneDate && fileDate >= saneDate) { 
     471            msg = "CreationDate"; 
     472          } 
    467473        } 
    468474      } 
     
    711717      MetadataRetrieve retrieve = omexmlService.asRetrieve(store); 
    712718      String xml = omexmlService.getOMEXML(retrieve); 
    713       success = xml != null && omexmlService.validateOMEXML(xml, true); 
     719      success = xml != null && omexmlService.validateOMEXML(xml); 
    714720    } 
    715721    catch (Throwable t) { 
     
    934940      reader = new BufferedImageReader(new FileStitcher()); 
    935941      reader.setNormalized(true); 
    936       reader.setOriginalMetadataPopulated(true); 
    937942      reader.setMetadataFiltered(true); 
    938943      MetadataStore store = null; 
Note: See TracChangeset for help on using the changeset viewer.