Beispiel #1
0
  private Integer createBandH5D(Band band) throws IOException {

    final int w = band.getRasterWidth();
    final int h = band.getRasterHeight();
    long[] dims = new long[] {h, w};
    int datasetID = -1;
    int fileTypeID = -1;
    int fileSpaceID = -1;

    try {
      fileTypeID = createH5TypeID(band.getDataType());
      fileSpaceID = H5.H5Screate_simple(2, dims, null);
      datasetID =
          H5.H5Dcreate(
              _fileID,
              "/bands/" + band.getName(),
              fileTypeID,
              fileSpaceID,
              HDF5Constants.H5P_DEFAULT);

      try {
        // @todo 1 nf/tb - MEMOPT: add min, max here
        createScalarAttribute(datasetID, "raster_width", band.getRasterWidth());
        createScalarAttribute(datasetID, "raster_height", band.getRasterHeight());
        createScalarAttribute(datasetID, "scaling_factor", band.getScalingFactor());
        createScalarAttribute(datasetID, "scaling_offset", band.getScalingOffset());
        createScalarAttribute(datasetID, "log10_scaled", band.isLog10Scaled() ? "true" : "false");
        createScalarAttribute(datasetID, "unit", band.getUnit());
        createScalarAttribute(datasetID, "description", band.getDescription());
        if (band.getSpectralBandIndex() >= 0) {
          createScalarAttribute(datasetID, "spectral_band_index", band.getSpectralBandIndex() + 1);
          createScalarAttribute(datasetID, "solar_flux", band.getSolarFlux());
          createScalarAttribute(datasetID, "bandwidth", band.getSpectralBandwidth());
          createScalarAttribute(datasetID, "wavelength", band.getSpectralWavelength());
        }
        if (band.getFlagCoding() != null) {
          createScalarAttribute(datasetID, "flag_coding", band.getFlagCoding().getName());
        }
        createScalarAttribute(datasetID, "CLASS", "IMAGE");
        createScalarAttribute(datasetID, "IMAGE_VERSION", 1.2F);

        if (band.isStxSet()) {
          final Stx stx = band.getStx();
          createScalarAttribute(datasetID, "min_sample", stx.getMinimum());
          createScalarAttribute(datasetID, "max_sample", stx.getMaximum());
        }
        if (band.getImageInfo() != null) {
          final ColorPaletteDef paletteDef = band.getImageInfo().getColorPaletteDef();
          float[] minmax =
              new float[] {
                (float) paletteDef.getMinDisplaySample(), (float) paletteDef.getMaxDisplaySample()
              };
          createArrayAttribute(datasetID, "IMAGE_MINMAXRANGE", minmax);
        }
      } catch (IOException e) {
        /* ignore IOException because these attributes are not very essential... */
        Debug.trace("failed to create attribute: " + e.getMessage());
      }

    } catch (HDF5Exception e) {
      closeH5D(datasetID);
      throw new ProductIOException(createErrorMessage(e));
    } finally {
      closeH5S(fileSpaceID);
      closeH5T(fileTypeID);
    }

    return datasetID;
  }
Beispiel #2
0
  // Processes a single band MERIS data using the MERIS ADS.
  private void processMerisBandWithADS(Band band, ProgressMonitor pm) throws IOException {
    // load appropriate Sensor coefficientFile and init algorithm
    // ----------------------------------------------------------
    if (!loadBandCoefficients(band)) {
      _logger.severe(
          SmacConstants.LOG_MSG_COEFF_NOT_FOUND_1
              + band.getName()
              + SmacConstants.LOG_MSG_COEFF_NOT_FOUND_2); /*I18N*/
      setCurrentStatus(ProcessorConstants.STATUS_FAILED);
      return;
    }

    _logger.info(
        SmacConstants.LOG_MSG_GENERATING_PIXEL_1
            + band.getName()
            + SmacConstants.LOG_MSG_GENERATING_PIXEL_2); /*I18N*/

    // initialize vectors and other data
    // ---------------------------------
    int width = band.getSceneRasterWidth();
    int height = band.getSceneRasterHeight();
    Band outBand = _outputProduct.getBand(convertMerisBandName(band));
    float[] sza = new float[width];
    float[] saa = new float[width];
    float[] vza = new float[width];
    float[] vaa = new float[width];
    float[] taup550 = new float[width];
    float[] uh2o = new float[width];
    float[] uo3 = new float[width];
    float[] press = new float[width];
    float[] elev = new float[width];
    boolean[] process = new boolean[width];
    float[] toa = new float[width];
    float[] toa_corr = new float[width];

    // set up vector - this parameter is constant for the request
    for (int x = 0; x < width; x++) {
      taup550[x] = _tau_aero_550;
      process[x] = true;
    }

    // progress bar init
    // -----------------
    pm.beginTask(
        SmacConstants.LOG_MSG_GENERATING_PIXEL_1
            + band.getName()
            + SmacConstants.LOG_MSG_GENERATING_PIXEL_2,
        height * 10);
    try {
      // loop over all scanlines
      // -----------------------
      for (int y = 0; y < height; y++) {
        // read scanline
        // -------------
        band.readPixels(0, y, width, 1, toa, SubProgressMonitor.create(pm, 1));
        _szaBand.readPixels(0, y, width, 1, sza, SubProgressMonitor.create(pm, 1));
        _saaBand.readPixels(0, y, width, 1, saa, SubProgressMonitor.create(pm, 1));
        _vzaBand.readPixels(0, y, width, 1, vza, SubProgressMonitor.create(pm, 1));
        _vaaBand.readPixels(0, y, width, 1, vaa, SubProgressMonitor.create(pm, 1));
        _wvBand.readPixels(0, y, width, 1, uh2o, SubProgressMonitor.create(pm, 1));
        _o3Band.readPixels(0, y, width, 1, uo3, SubProgressMonitor.create(pm, 1));
        _pressBand.readPixels(0, y, width, 1, press, SubProgressMonitor.create(pm, 1));
        _elevBand.readPixels(0, y, width, 1, elev, SubProgressMonitor.create(pm, 1));

        // scale radiance to reflectance
        // -------------------------------
        toa = RsMathUtils.radianceToReflectance(toa, sza, band.getSolarFlux(), toa);

        // correct pressure due to elevation
        // ---------------------------------
        press = RsMathUtils.simpleBarometric(press, elev, press);

        // scale DU to cm * atm
        // ----------------------
        uo3 = dobsonToCmAtm(uo3);

        // scale relative humidity to g/cm^2
        // -----------------------------------
        uh2o = relativeHumidityTogcm2(uh2o);

        // forEachPixel bitmask
        // ----------------
        if (_bitMaskTerm != null) {
          _inputProduct.readBitmask(0, y, width, 1, _bitMaskTerm, process, ProgressMonitor.NULL);
        }

        // process scanline
        // ----------------
        toa_corr =
            _algorithm.run(
                sza,
                saa,
                vza,
                vaa,
                taup550,
                uh2o,
                uo3,
                press,
                process,
                _invalidPixel,
                toa,
                toa_corr);

        // write scanline
        // --------------
        outBand.writePixels(0, y, width, 1, toa_corr, ProgressMonitor.NULL);

        // update progressbar
        // ------------------
        pm.worked(1);
        if (pm.isCanceled()) {
          _logger.warning(ProcessorConstants.LOG_MSG_PROC_CANCELED);
          setCurrentStatus(ProcessorConstants.STATUS_ABORTED);
          return;
        }
      }
    } finally {
      pm.done();
    }

    _logger.info(ProcessorConstants.LOG_MSG_PROC_SUCCESS);
  }
  protected void addBandsToProduct(Product product) {
    Debug.assertNotNull(getSourceProduct());
    Debug.assertNotNull(product);
    for (int i = 0; i < getSourceProduct().getNumBands(); i++) {
      Band sourceBand = getSourceProduct().getBandAt(i);
      String bandName = sourceBand.getName();
      if (isNodeAccepted(bandName)) {
        Band destBand;
        boolean treatVirtualBandsAsRealBands = false;
        if (getSubsetDef() != null && getSubsetDef().getTreatVirtualBandsAsRealBands()) {
          treatVirtualBandsAsRealBands = true;
        }

        // @todo 1 se/se - extract copy of a band or virtual band to create deep clone of band and
        // virtual band
        if (!treatVirtualBandsAsRealBands && sourceBand instanceof VirtualBand) {
          VirtualBand virtualSource = (VirtualBand) sourceBand;
          destBand =
              new VirtualBand(
                  bandName,
                  sourceBand.getDataType(),
                  getSceneRasterWidth(),
                  getSceneRasterHeight(),
                  virtualSource.getExpression());
        } else {
          destBand =
              new Band(
                  bandName,
                  sourceBand.getDataType(),
                  getSceneRasterWidth(),
                  getSceneRasterHeight());
        }
        if (sourceBand.getUnit() != null) {
          destBand.setUnit(sourceBand.getUnit());
        }
        if (sourceBand.getDescription() != null) {
          destBand.setDescription(sourceBand.getDescription());
        }
        destBand.setScalingFactor(sourceBand.getScalingFactor());
        destBand.setScalingOffset(sourceBand.getScalingOffset());
        destBand.setLog10Scaled(sourceBand.isLog10Scaled());
        destBand.setSpectralBandIndex(sourceBand.getSpectralBandIndex());
        destBand.setSpectralWavelength(sourceBand.getSpectralWavelength());
        destBand.setSpectralBandwidth(sourceBand.getSpectralBandwidth());
        destBand.setSolarFlux(sourceBand.getSolarFlux());
        if (sourceBand.isNoDataValueSet()) {
          destBand.setNoDataValue(sourceBand.getNoDataValue());
        }
        destBand.setNoDataValueUsed(sourceBand.isNoDataValueUsed());
        destBand.setValidPixelExpression(sourceBand.getValidPixelExpression());
        FlagCoding sourceFlagCoding = sourceBand.getFlagCoding();
        IndexCoding sourceIndexCoding = sourceBand.getIndexCoding();
        if (sourceFlagCoding != null) {
          String flagCodingName = sourceFlagCoding.getName();
          FlagCoding destFlagCoding = product.getFlagCodingGroup().get(flagCodingName);
          Debug.assertNotNull(
              destFlagCoding); // should not happen because flag codings should be already in
                               // product
          destBand.setSampleCoding(destFlagCoding);
        } else if (sourceIndexCoding != null) {
          String indexCodingName = sourceIndexCoding.getName();
          IndexCoding destIndexCoding = product.getIndexCodingGroup().get(indexCodingName);
          Debug.assertNotNull(
              destIndexCoding); // should not happen because index codings should be already in
                                // product
          destBand.setSampleCoding(destIndexCoding);
        } else {
          destBand.setSampleCoding(null);
        }
        if (isFullScene(getSubsetDef()) && sourceBand.isStxSet()) {
          copyStx(sourceBand, destBand);
        }
        product.addBand(destBand);
        bandMap.put(destBand, sourceBand);
      }
    }
    for (final Map.Entry<Band, RasterDataNode> entry : bandMap.entrySet()) {
      copyImageInfo(entry.getValue(), entry.getKey());
    }
  }
Beispiel #4
0
  // Processes a single spectralBand of MERIS data.
  private void processMerisBand(Band spectralBand, ProgressMonitor pm) throws IOException {
    // load appropriate Sensor coefficientFile and init algorithm
    // ----------------------------------------------------------
    if (!loadBandCoefficients(spectralBand)) {
      _logger.severe(
          SmacConstants.LOG_MSG_COEFF_NOT_FOUND_1
              + spectralBand.getName()
              + SmacConstants.LOG_MSG_COEFF_NOT_FOUND_2);
      setCurrentStatus(ProcessorConstants.STATUS_FAILED);
      return;
    }

    _logger.info(
        SmacConstants.LOG_MSG_GENERATING_PIXEL_1
            + spectralBand.getName()
            + SmacConstants.LOG_MSG_GENERATING_PIXEL_2); /*I18N*/

    // initialize vectors and other data
    int n;
    int width = spectralBand.getSceneRasterWidth();
    int height = spectralBand.getSceneRasterHeight();
    Band outBand = _outputProduct.getBand(convertMerisBandName(spectralBand));
    float[] sza = new float[width];
    float[] saa = new float[width];
    float[] vza = new float[width];
    float[] vaa = new float[width];
    float[] taup550 = new float[width];
    float[] uh2o = new float[width];
    float[] uo3 = new float[width];
    float[] press = new float[width];
    boolean[] process = new boolean[width];
    float[] toa = new float[width];
    float[] toa_corr = new float[width];

    for (n = 0; n < width; n++) {
      taup550[n] = _tau_aero_550;
      uh2o[n] = _u_h2o;
      uo3[n] = _u_o3;
      press[n] = _surf_press;
      process[n] = true;
    }

    // progress init
    pm.beginTask(
        SmacConstants.LOG_MSG_GENERATING_PIXEL_1
            + spectralBand.getName()
            + SmacConstants.LOG_MSG_GENERATING_PIXEL_2,
        height * 6);
    try {
      // loop over all scanlines
      for (int y = 0; y < spectralBand.getSceneRasterHeight(); y++) {
        // read scanline
        spectralBand.readPixels(0, y, width, 1, toa, SubProgressMonitor.create(pm, 1));
        _szaBand.readPixels(0, y, width, 1, sza, SubProgressMonitor.create(pm, 1));
        _saaBand.readPixels(0, y, width, 1, saa, SubProgressMonitor.create(pm, 1));
        _vzaBand.readPixels(0, y, width, 1, vza, SubProgressMonitor.create(pm, 1));
        _vaaBand.readPixels(0, y, width, 1, vaa, SubProgressMonitor.create(pm, 1));

        // scale radiances to reflectances
        toa = RsMathUtils.radianceToReflectance(toa, sza, spectralBand.getSolarFlux(), toa);

        // forEachPixel bitmask
        if (_bitMaskTerm != null) {
          _inputProduct.readBitmask(0, y, width, 1, _bitMaskTerm, process, ProgressMonitor.NULL);
        }

        // process scanline
        toa_corr =
            _algorithm.run(
                sza,
                saa,
                vza,
                vaa,
                taup550,
                uh2o,
                uo3,
                press,
                process,
                _invalidPixel,
                toa,
                toa_corr);

        // write scanline
        outBand.writePixels(0, y, width, 1, toa_corr, ProgressMonitor.NULL);

        // update progressbar
        pm.worked(1);
        if (pm.isCanceled()) {
          _logger.warning(ProcessorConstants.LOG_MSG_PROC_CANCELED);
          setCurrentStatus(ProcessorConstants.STATUS_ABORTED);
          return;
        }
      }
    } finally {
      pm.done();
    }

    _logger.info(ProcessorConstants.LOG_MSG_PROC_SUCCESS);
  }