예제 #1
0
  private void populateMetadata() throws FormatException, IOException {
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this, true);

    String instrumentID = MetadataTools.createLSID("Instrument", 0);
    store.setInstrumentID(instrumentID, 0);

    for (int i = 0; i < positions.size(); i++) {
      Position p = positions.get(i);
      if (p.time != null) {
        String date = DateTools.formatDate(p.time, DATE_FORMAT);
        if (date != null) {
          store.setImageAcquisitionDate(new Timestamp(date), i);
        }
      }

      if (positions.size() > 1) {
        Location parent = new Location(p.metadataFile).getParentFile();
        store.setImageName(parent.getName(), i);
      }

      if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        store.setImageDescription(p.comment, i);

        // link Instrument and Image
        store.setImageInstrumentRef(instrumentID, i);

        for (int c = 0; c < p.channels.length; c++) {
          store.setChannelName(p.channels[c], i, c);
        }

        if (p.pixelSize != null && p.pixelSize > 0) {
          store.setPixelsPhysicalSizeX(new PositiveFloat(p.pixelSize), i);
          store.setPixelsPhysicalSizeY(new PositiveFloat(p.pixelSize), i);
        } else {
          LOGGER.warn("Expected positive value for PhysicalSizeX; got {}", p.pixelSize);
        }
        if (p.sliceThickness != null && p.sliceThickness > 0) {
          store.setPixelsPhysicalSizeZ(new PositiveFloat(p.sliceThickness), i);
        } else {
          LOGGER.warn("Expected positive value for PhysicalSizeZ; got {}", p.sliceThickness);
        }

        int nextStamp = 0;
        for (int q = 0; q < getImageCount(); q++) {
          store.setPlaneExposureTime(p.exposureTime, i, q);
          String tiff = positions.get(getSeries()).getFile(q);
          if (tiff != null && new Location(tiff).exists() && nextStamp < p.timestamps.length) {
            store.setPlaneDeltaT(p.timestamps[nextStamp++], i, q);
          }
        }

        String serialNumber = p.detectorID;
        p.detectorID = MetadataTools.createLSID("Detector", 0, i);

        for (int c = 0; c < p.channels.length; c++) {
          store.setDetectorSettingsBinning(getBinning(p.binning), i, c);
          store.setDetectorSettingsGain(new Double(p.gain), i, c);
          if (c < p.voltage.size()) {
            store.setDetectorSettingsVoltage(p.voltage.get(c), i, c);
          }
          store.setDetectorSettingsID(p.detectorID, i, c);
        }

        store.setDetectorID(p.detectorID, 0, i);
        if (p.detectorModel != null) {
          store.setDetectorModel(p.detectorModel, 0, i);
        }

        if (serialNumber != null) {
          store.setDetectorSerialNumber(serialNumber, 0, i);
        }

        if (p.detectorManufacturer != null) {
          store.setDetectorManufacturer(p.detectorManufacturer, 0, i);
        }

        if (p.cameraMode == null) p.cameraMode = "Other";
        store.setDetectorType(getDetectorType(p.cameraMode), 0, i);
        store.setImagingEnvironmentTemperature(p.temperature, i);
      }
    }
  }