示例#1
0
  private void sortOutSourceProducts() {

    // check whether there are absolute phases bands in the product
    Band tempBand = null;
    for (Band band : sourceProduct.getBands()) {
      if (band.getUnit().equals(Unit.ABS_PHASE)) {
        tempBand = band;
      }
    }
    if (tempBand == null) {
      throw new OperatorException("Slant2HeightOp requires minimum one 'unwrapped' phase band");
    }
  }
示例#2
0
  /**
   * Adds requested bands to the output product.
   *
   * @param description a description template for the new bands to be created
   * @param bConvertMerisName it set to true, the MERIS l1b band name is converted from
   *     <i>radiance_n</i> to <i>reflectance_n</i>
   */
  private void addBandsToOutput(String description, boolean bConvertMerisName) {

    for (Band inBand : _inputBandList) {
      String newBandName;
      String bandUnit;
      if (bConvertMerisName) {
        newBandName = convertMerisBandName(inBand);
        bandUnit = "dl";
      } else {
        newBandName = inBand.getName();
        bandUnit = inBand.getUnit();
      }
      Band outBand =
          new Band(
              newBandName,
              inBand.getGeophysicalDataType(),
              inBand.getSceneRasterWidth(),
              inBand.getSceneRasterHeight());
      outBand.setUnit(bandUnit);
      ProductUtils.copySpectralBandProperties(inBand, outBand);
      outBand.setDescription(description + inBand.getName());
      _outputProduct.addBand(outBand);
    }
  }
示例#3
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;
  }
  @Override
  public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm)
      throws OperatorException {

    if (targetBand.isFlagBand()) {
      // no computations
      return;
    }

    final Rectangle rectangle = targetTile.getRectangle();
    final int bigWidth = (int) (scalingFactor * rectangle.getWidth());
    final int bigHeight = (int) (scalingFactor * rectangle.getHeight());
    final int bigX = (int) (scalingFactor * rectangle.getX());
    final int bigY = (int) (scalingFactor * rectangle.getY());
    final Rectangle big = new Rectangle(bigX, bigY, bigWidth, bigHeight);

    pm.beginTask("Processing frame...", rectangle.height);

    try {
      // todo: clean up the tiles which are not finally needed  (depends on how many channels are
      // used)
      final Tile szMerisTile = getSourceTile(synergyProduct.getTiePointGrid("sun_zenith"), big);
      final Tile vzMerisTile = getSourceTile(synergyProduct.getTiePointGrid("view_zenith"), big);
      final Tile saMerisTile = getSourceTile(synergyProduct.getTiePointGrid("sun_azimuth"), big);
      final Tile pressureTile = getSourceTile(synergyProduct.getTiePointGrid("atm_press"), big);

      final Tile seAatsrNadirTile =
          getSourceTile(
              synergyProduct.getBand(
                  "sun_elev_nadir" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + ""),
              big);
      final Tile veAatsrNadirTile =
          getSourceTile(
              synergyProduct.getBand(
                  "view_elev_nadir" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + ""),
              big);
      final Tile saAatsrNadirTile =
          getSourceTile(
              synergyProduct.getBand(
                  "sun_azimuth_nadir" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + ""),
              big);
      final Tile seAatsrFwardTile =
          getSourceTile(
              synergyProduct.getBand(
                  "sun_elev_fward" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + ""),
              big);
      final Tile veAatsrFwardTile =
          getSourceTile(
              synergyProduct.getBand(
                  "view_elev_fward" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + ""),
              big);
      final Tile saAatsrFwardTile =
          getSourceTile(
              synergyProduct.getBand(
                  "sun_azimuth_fward" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + ""),
              big);
      final Tile vaAatsrFwardTile =
          getSourceTile(
              synergyProduct.getBand(
                  "view_azimuth_fward" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + ""),
              big);
      final Tile merisRad13Tile =
          getSourceTile(
              synergyProduct.getBand(
                  "radiance_13" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_MERIS + ""),
              big);
      final Tile merisRad14Tile =
          getSourceTile(
              synergyProduct.getBand(
                  "radiance_14" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_MERIS + ""),
              big);

      final Band reflecNadir16Band =
          synergyProduct.getBand(
              "reflec_nadir_1600" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + "");
      final Tile aatsrReflNadir1600Tile = getSourceTile(reflecNadir16Band, big);
      final Band reflecNadir87Band =
          synergyProduct.getBand(
              "reflec_nadir_0870" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + "");
      final Tile aatsrReflNadir0870Tile = getSourceTile(reflecNadir87Band, big);
      final Band reflecFward16Band =
          synergyProduct.getBand(
              "reflec_fward_1600" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + "");
      final Tile aatsrReflFward1600Tile = getSourceTile(reflecFward16Band, big);
      final Band reflecFward87Band =
          synergyProduct.getBand(
              "reflec_fward_0870" + "_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR + "");
      final Tile aatsrReflFward0870Tile = getSourceTile(reflecFward87Band, big);

      final Tile wsTile =
          getSourceTile(glintProduct.getBand(GlintAveOp.RESULT_WINDSPEED_NAME), rectangle);

      // Flags tiles

      final Tile isInvalid = getSourceTile(invalidBand, rectangle);

      for (int iY = rectangle.y; iY < rectangle.y + rectangle.height; iY++) {
        for (int iX = rectangle.x; iX < rectangle.x + rectangle.width; iX++) {

          final int iTarX = (int) (scalingFactor * iX + aveBlock);
          final int iTarY = (int) (scalingFactor * iY + aveBlock);
          checkForCancellation();

          final float aatsrViewElevationNadir = getAvePixel(veAatsrNadirTile, iTarX, iTarY);
          final float aatsrSunElevationNadir = getAvePixel(seAatsrNadirTile, iTarX, iTarY);
          final float aatsrViewElevationFward = getAvePixel(veAatsrFwardTile, iTarX, iTarY);
          final float aatsrSunElevationFward = getAvePixel(seAatsrFwardTile, iTarX, iTarY);

          // just use one windspeed (the 'closer to ECMWF' one from Glint retrieval)
          final float ws = wsTile.getSampleFloat(iX, iY);

          if (isInvalid.getSampleBoolean(iX, iY)
              || ws == SynergyConstants.OUTPUT_WS_BAND_NODATAVALUE) {
            targetTile.setSample(iX, iY, noDataVal);
          } else if (targetBand.getName().equals(SynergyConstants.OUTPUT_AOT_BAND_NAME)
              && (aot550Result[iX][iY] > 0.0
                  || aot550Result[iX][iY] == SynergyConstants.OUTPUT_AOT_BAND_NODATAVALUE)) {
            targetTile.setSample(iX, iY, aot550Result[iX][iY]);
          } else if (targetBand.getName().equals(SynergyConstants.OUTPUT_ANG_BAND_NAME)
              && (angResult[iX][iY] > 0.0
                  || angResult[iX][iY] == SynergyConstants.OUTPUT_ANG_BAND_NODATAVALUE)) {
            targetTile.setSample(iX, iY, angResult[iX][iY]);
          } else if (targetBand.getName().equals(SynergyConstants.OUTPUT_AOTERR_BAND_NAME)
              && (aot550ErrorResult[iX][iY] > 0.0
                  || aot550ErrorResult[iX][iY]
                      == SynergyConstants.OUTPUT_AOTERR_BAND_NODATAVALUE)) {
            targetTile.setSample(iX, iY, aot550ErrorResult[iX][iY]);
          } else if (targetBand.getName().equals(SynergyConstants.OUTPUT_ANGERR_BAND_NAME)
              && (angErrorResult[iX][iY] > 0.0
                  || angErrorResult[iX][iY] == SynergyConstants.OUTPUT_ANGERR_BAND_NODATAVALUE)) {
            targetTile.setSample(iX, iY, aot550ErrorResult[iX][iY]);
          } else if (targetBand.getName().equals(SynergyConstants.OUTPUT_GLINT_BAND_NAME)
              && (glintResult[iX][iY] > 0.0
                  || glintResult[iX][iY] == SynergyConstants.OUTPUT_GLINT_BAND_NODATAVALUE)) {
            targetTile.setSample(iX, iY, glintResult[iX][iY]);
          } else if (targetBand.getName().equals(SynergyConstants.OUTPUT_WS_BAND_NAME)
              && (wsResult[iX][iY] > 0.0
                  || wsResult[iX][iY] == SynergyConstants.OUTPUT_WS_BAND_NODATAVALUE)) {
            targetTile.setSample(iX, iY, wsResult[iX][iY]);
          } else {
            final float merisViewAzimuth = getAvePixel(vaMerisTileComplete, iTarX, iTarY);
            final float merisSunAzimuth = getAvePixel(saMerisTile, iTarX, iTarY);
            final float merisAzimuthDifference =
                GlintPreparation.removeAzimuthDifferenceAmbiguity(
                    merisViewAzimuth, merisSunAzimuth);
            final float merisViewZenith = getAvePixel(vzMerisTile, iTarX, iTarY);
            final float merisSunZenith = getAvePixel(szMerisTile, iTarX, iTarY);
            final float merisRad13 =
                getAvePixel(merisRad13Tile, iTarX, iTarY) / SynergyConstants.MERIS_13_SOLAR_FLUX;
            final float merisRad14 =
                getAvePixel(merisRad14Tile, iTarX, iTarY) / SynergyConstants.MERIS_14_SOLAR_FLUX;
            final double aatsrSeNadir = getAvePixel(seAatsrNadirTile, iTarX, iTarY);
            final double aatsrSeFward = getAvePixel(seAatsrFwardTile, iTarX, iTarY);

            // for RP test data (unit '%'), we need to divide AATSR reflectances by 100.
            // however, the correct AATSR units should be 'dl', as for the Synergy products created
            // in the Synergy module
            float aatsrUnitCorrFactor = 1.0f;
            if (reflecNadir87Band.getUnit().equals("%")) {
              // check for one band should be enough
              aatsrUnitCorrFactor = 100.0f;
            }
            final float aatsrReflNadir87 =
                (float)
                    (getAvePixel(aatsrReflNadir0870Tile, iTarX, iTarY)
                        / (Math.PI
                            * Math.cos(MathUtils.DTOR * (90.0 - aatsrSeNadir))
                            * aatsrUnitCorrFactor));
            final float aatsrReflNadir16 =
                (float)
                    (getAvePixel(aatsrReflNadir1600Tile, iTarX, iTarY)
                        / (Math.PI
                            * Math.cos(MathUtils.DTOR * (90.0 - aatsrSeNadir))
                            * aatsrUnitCorrFactor));
            final float aatsrReflFward87 =
                (float)
                    (getAvePixel(aatsrReflFward0870Tile, iTarX, iTarY)
                        / (Math.PI
                            * Math.cos(MathUtils.DTOR * (90.0 - aatsrSeFward))
                            * aatsrUnitCorrFactor));
            final float aatsrReflFward16 =
                (float)
                    (getAvePixel(aatsrReflFward1600Tile, iTarX, iTarY)
                        / (Math.PI
                            * Math.cos(MathUtils.DTOR * (90.0 - aatsrSeFward))
                            * aatsrUnitCorrFactor));

            final float aatsrViewAzimuthNadir = getAvePixel(vaAatsrNadirTileComplete, iTarX, iTarY);
            final float aatsrSunAzimuthNadir = getAvePixel(saAatsrNadirTile, iTarX, iTarY);
            final float aatsrViewAzimuthFward = vaAatsrFwardTile.getSampleFloat(iTarX, iTarY);
            final float aatsrSunAzimuthFward = saAatsrFwardTile.getSampleFloat(iTarX, iTarY);

            final float aatsrAzimuthDifferenceNadir =
                GlintPreparation.removeAzimuthDifferenceAmbiguity(
                    aatsrViewAzimuthNadir, aatsrSunAzimuthNadir);
            final float aatsrAzimuthDifferenceFward = aatsrViewAzimuthFward - aatsrSunAzimuthFward;
            // negative pressures were stored in LUT to ensure ascending sequence
            final float surfacePressure = -1.0f * getAvePixel(pressureTile, iTarX, iTarY);

            // breadboard begin STEP 1
            final float[] glintArray =
                doSynAOStep1(
                    aatsrViewElevationNadir,
                    aatsrViewElevationFward,
                    aatsrSunElevationNadir,
                    aatsrSunElevationFward,
                    aatsrAzimuthDifferenceNadir,
                    aatsrAzimuthDifferenceFward,
                    merisViewZenith,
                    merisSunZenith,
                    merisAzimuthDifference,
                    surfacePressure,
                    ws);
            glintResult[iX][iY] = glintArray[0];
            wsResult[iX][iY] = ws;
            // breadboard end STEP 1

            // breadboard begin STEP 2
            doSynAOStep2();
            // breadboard end STEP 2

            // breadboard begin STEP 3
            doSynAOStep3(
                iY,
                iX,
                merisRad13,
                merisRad14,
                aatsrReflNadir16,
                aatsrReflNadir87,
                aatsrReflFward16,
                aatsrReflFward87);

            // breadboard end STEP 3

            if (targetBand.getName().equals(SynergyConstants.OUTPUT_AOT_BAND_NAME)) {
              targetTile.setSample(iX, iY, aot550Result[iX][iY]);
            }
            if (targetBand.getName().equals(SynergyConstants.OUTPUT_ANG_BAND_NAME)) {
              targetTile.setSample(iX, iY, angResult[iX][iY]);
            }
            if (targetBand.getName().equals(SynergyConstants.OUTPUT_AOTERR_BAND_NAME)) {
              targetTile.setSample(iX, iY, aot550ErrorResult[iX][iY]);
            }
            if (targetBand.getName().equals(SynergyConstants.OUTPUT_ANGERR_BAND_NAME)) {
              targetTile.setSample(iX, iY, angErrorResult[iX][iY]);
            }
            if (targetBand.getName().equals(SynergyConstants.OUTPUT_GLINT_BAND_NAME)) {
              targetTile.setSample(iX, iY, glintResult[iX][iY]);
            }
            if (targetBand.getName().equals(SynergyConstants.OUTPUT_WS_BAND_NAME)) {
              targetTile.setSample(iX, iY, wsResult[iX][iY]);
            }
          }
          pm.worked(1);
        }
      }
    } catch (Exception e) {
      throw new OperatorException(
          "Failed to process ocean aerosol algorithm:\n" + e.getMessage(), e);
    } finally {
      pm.done();
    }
  }
示例#5
0
  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());
    }
  }