Exemple #1
0
  // Loads the appropriate coefficient set for the band.
  private boolean loadBandCoefficients(Band band) {
    boolean bRet = false;
    URL url;
    SensorCoefficientFile coeff = new SensorCoefficientFile();
    boolean handleError = false;

    try {
      url = _coeffMgr.getCoefficientFile(_sensorType, band.getName(), _aerosolType);
      if (url == null) {
        handleError = true;
      } else {
        coeff.readFile(new File(url.toURI()).getAbsolutePath());
        _logger.info(SmacConstants.LOG_MSG_LOADED_COEFFICIENTS + url.getFile());
        _algorithm.setSensorCoefficients(coeff);
        bRet = true;
      }
    } catch (IOException e) {
      handleError = true;
      _logger.severe(e.getMessage());
    } catch (URISyntaxException e) {
      handleError = true;
      _logger.severe(e.getMessage());
    }

    if (handleError) {
      _logger.severe(SmacConstants.LOG_MSG_ERROR_COEFFICIENTS + band.getName());
      if (_editor != null) {
        _editor.showWarningDialog(SmacConstants.LOG_MSG_ERROR_COEFFICIENTS + band.getName());
      }
    }

    return bRet;
  }
  private void assertCreateRightGeneralFilterBand(Element xmlElement) {
    final Object object = _generalFilterBandPersistable.createObjectFromXml(xmlElement, _product);
    _product.addBand((Band) object);

    assertNotNull(object);
    assertTrue(object instanceof GeneralFilterBand);
    final GeneralFilterBand gfb = (GeneralFilterBand) object;
    assertEquals(1, _product.getBandIndex(gfb.getName()));
    assertEquals(-1, gfb.getSpectralBandIndex());
    assertEquals("filtered_coffee", gfb.getName());
    assertEquals("with milk & sugar", gfb.getDescription());
    assertEquals(_source.getGeophysicalDataType(), gfb.getDataType());
    assertEquals("l", gfb.getUnit());
    assertEquals(0.0, gfb.getSolarFlux(), EPS);
    assertEquals(0.0, gfb.getSpectralWavelength(), EPS);
    assertEquals(0.0, gfb.getSpectralBandwidth(), EPS);
    assertEquals(1.0, gfb.getScalingFactor(), EPS);
    assertEquals(0.0, gfb.getScalingOffset(), EPS);
    assertFalse(gfb.isLog10Scaled());
    assertEquals(gfb.getSource().getName(), _source.getName());
    assertEquals(5, gfb.getSubWindowSize());
    assertEquals(5, gfb.getSubWindowWidth());
    assertEquals(5, gfb.getSubWindowHeight());
    assertTrue(gfb.getOperator() instanceof GeneralFilterBand.Mean);
  }
Exemple #3
0
 @Override
 public void copyBands(ProductNodeFilter<Band> filter) {
   Band[] sourceBands = getSourceProduct().getBands();
   for (Band sourceBand : sourceBands) {
     if (filter.accept(sourceBand)) {
       copyBand(sourceBand.getName());
     }
   }
 }
  private boolean checkFlagDatasetIncluded() {
    final String[] nodeNames = productSubsetDef.getNodeNames();
    final List<String> flagDsNameList = new ArrayList<String>(10);
    boolean flagDsInSubset = false;
    for (int i = 0; i < product.getNumBands(); i++) {
      Band band = product.getBandAt(i);
      if (band.getFlagCoding() != null) {
        flagDsNameList.add(band.getName());
        if (StringUtils.contains(nodeNames, band.getName())) {
          flagDsInSubset = true;
        }
        break;
      }
    }

    final int numFlagDs = flagDsNameList.size();
    boolean ok = true;
    if (numFlagDs > 0 && !flagDsInSubset) {
      int status =
          JOptionPane.showConfirmDialog(
              getJDialog(),
              "No flag dataset selected.\n\n"
                  + "If you do not include a flag dataset in the subset,\n"
                  + "you will not be able to create bitmask overlays.\n\n"
                  + "Do you wish to include the available flag dataset(s)\n"
                  + "in the current subset?\n",
              "No Flag Dataset Selected",
              JOptionPane.YES_NO_CANCEL_OPTION);
      if (status == JOptionPane.YES_OPTION) {
        productSubsetDef.addNodeNames(flagDsNameList.toArray(new String[numFlagDs]));
        ok = true;
      } else if (status == JOptionPane.NO_OPTION) {
        /* OK, no flag datasets wanted */
        ok = true;
      } else if (status == JOptionPane.CANCEL_OPTION) {
        ok = false;
      }
    }

    return ok;
  }
Exemple #5
0
  // Helper Routine. Converts a given MERIS L1b band name (radiance_x) to the band name needed in
  // the output product
  // (reflectance_x).
  private static String convertMerisBandName(Band band) {
    String inBandName;
    String outBandName;
    inBandName = band.getName();

    outBandName = _merisBandPrefix;
    int blankIndex = inBandName.indexOf('_');
    if (blankIndex > 0) {
      outBandName += inBandName.substring(blankIndex, inBandName.length());
    }
    return outBandName;
  }
Exemple #6
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);
    }
  }
Exemple #7
0
  /**
   * Checks if the given band is an AATSR forward band.
   *
   * @param band the <code>Band</code> to be checked.
   * @return true when the band is a forward band
   */
  private static boolean checkForAATSRForwardBand(Band band) {
    boolean bRet = false;
    int bandIndex;

    for (int _aatsrMDSIndice : _aatsrMDSIndices) {
      bandIndex = _aatsrMDSIndice;
      if (ObjectUtils.equalObjects(
          band.getName(), EnvisatConstants.AATSR_L1B_BAND_NAMES[bandIndex])) {
        bRet = true;
        break;
      }
    }

    return bRet;
  }
  /**
   * This method provides a real tie point grid from a 'tie point band'.
   *
   * @param band - the 'tie point band'
   * @return TiePointGrid
   */
  public static TiePointGrid getTpgFromBand(Band band) {
    final DataBuffer dataBuffer = band.getSourceImage().getData().getDataBuffer();
    float[] tpgData = new float[dataBuffer.getSize()];
    for (int i = 0; i < dataBuffer.getSize(); i++) {
      tpgData[i] = dataBuffer.getElemFloat(i);
    }

    return new TiePointGrid(
        band.getName(),
        band.getSceneRasterWidth(),
        band.getSceneRasterHeight(),
        0.0f,
        0.0f,
        1.0f,
        1.0f,
        tpgData);
  }
  /**
   * This method downscales a band by a given factor
   *
   * @param inputBand - the input band
   * @param scalingFactor - the scaling factor
   * @return Band - the downscaled band
   */
  public static Band downscaleBand(Band inputBand, float scalingFactor) {
    final RenderedImage sourceImage = inputBand.getSourceImage();
    final RenderedOp downscaledImage =
        ScaleDescriptor.create(
            sourceImage,
            1.0f / scalingFactor,
            1.0f / scalingFactor,
            0.0f,
            0.0f,
            Interpolation.getInstance(Interpolation.INTERP_NEAREST),
            null);
    Band downscaledBand =
        new Band(
            inputBand.getName(), inputBand.getDataType(),
            downscaledImage.getWidth(), downscaledImage.getHeight());

    downscaledBand.setSourceImage(downscaledImage);
    return downscaledBand;
  }
 /**
  * This method provides a rescaled tie point grid from a 'tie point band'.
  *
  * @param band - the 'tie point band'
  * @param rescaledWidth - width of the rescaled TPG
  * @param rescaledHeight - height of the rescaled TPG
  * @return TiePointGrid
  */
 public static TiePointGrid getRescaledTpgFromBand(
     Band band, int rescaledWidth, int rescaledHeight) {
   final DataBuffer dataBuffer = band.getSourceImage().getData().getDataBuffer();
   float[] tpgData = new float[rescaledWidth * rescaledHeight];
   if (rescaledWidth * rescaledHeight > band.getSceneRasterWidth() * band.getSceneRasterHeight()) {
     throw new OperatorException("Cannot create TPG - width*height too large.");
   }
   int tpgIndex = 0;
   for (int j = 0; j < rescaledHeight; j++) {
     for (int i = 0; i < rescaledWidth; i++) {
       tpgData[rescaledWidth * j + i] = dataBuffer.getElemFloat(tpgIndex);
       tpgIndex++;
     }
     for (int i = rescaledWidth; i < band.getSceneRasterWidth(); i++) {
       tpgIndex++;
     }
   }
   return new TiePointGrid(
       band.getName(), rescaledWidth, rescaledHeight, 0.0f, 0.0f, 1.0f, 1.0f, tpgData);
 }
Exemple #11
0
  @Override
  public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm)
      throws OperatorException {
    try {

      final Rectangle rect = targetTile.getRectangle();
      //            System.out.println("Original: x0 = " + rect.x + ", y = " + rect.y + ", w = " +
      // rect.width + ", h = " + rect.height);
      final int x0 = rect.x;
      final int y0 = rect.y;
      final int w = rect.width;
      final int h = rect.height;

      Window tileWindow = new Window(y0, y0 + h - 1, x0, x0 + w - 1);

      for (String absPhaseKey : targetMap.keySet()) {

        final ProductContainer product = targetMap.get(absPhaseKey);

        if (targetBand.getName().equals(product.targetBandName_I)) {

          // check out from source
          Tile tileRealMaster = getSourceTile(product.sourceMaster.realBand, rect);
          final DoubleMatrix dataMaster =
              TileUtilsDoris.pullDoubleMatrix(tileRealMaster); // check out from source

          // get class for this slave from the map
          Slant2Height slant2Height = slant2HeightMap.get(product.sourceSlave.date);
          slant2Height.applySchwabisch(tileWindow, dataMaster);

          TileUtilsDoris.pushDoubleMatrix(dataMaster, targetTile, targetTile.getRectangle());
        }
      }

    } catch (Exception e) {
      throw new OperatorException(e);
    }
  }
  @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();
    }
  }
  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());
    }
  }
  @Override
  public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm)
      throws OperatorException {

    final Rectangle targetRectangle = targetTile.getRectangle();

    final String name = targetBand.getName();
    final String currentMonth = name.substring(TARGET_BAND_PREFIX.length(), name.length());

    final List<Product> currentMonthDataProducts = halfmonthlyDataProductsMap.get(currentMonth);
    List<Product> currentMonthFlagProducts;

    if (currentMonthDataProducts.size() != 2) {
      return;
    }

    final Band firstNdviBand = currentMonthDataProducts.get(0).getBand("band_1");
    final Tile firstNdviTile = getSourceTile(firstNdviBand, targetRectangle);
    final Band secondNdviBand = currentMonthDataProducts.get(1).getBand("band_1");
    final Tile secondNdviTile = getSourceTile(secondNdviBand, targetRectangle);

    Band firstNdviFlagBand;
    Tile firstNdviFlagTile = null;
    Band secondNdviFlagBand;
    Tile secondNdviFlagTile = null;
    if (writeFlags) {
      currentMonthFlagProducts = halfmonthlyFlagProductsMap.get(currentMonth);
      if (currentMonthFlagProducts.size() != 2) {
        return;
      }
      firstNdviFlagBand = currentMonthFlagProducts.get(0).getBand("band_1");
      firstNdviFlagTile = getSourceTile(firstNdviFlagBand, targetRectangle);
      secondNdviFlagBand = currentMonthFlagProducts.get(1).getBand("band_1");
      secondNdviFlagTile = getSourceTile(secondNdviFlagBand, targetRectangle);
    }

    for (int y = targetRectangle.y; y < targetRectangle.y + targetRectangle.height; y++) {
      checkForCancellation();
      for (int x = targetRectangle.x; x < targetRectangle.x + targetRectangle.width; x++) {
        final boolean isSampleInvalid = isSampleInvalid(firstNdviBand, secondNdviBand, x, y);
        final boolean isSampleMissing = isSampleMissing(firstNdviTile, secondNdviTile, x, y);

        if (!isSampleInvalid && !isSampleMissing) {
          final int firstNdvi = firstNdviTile.getSampleInt(x, y);
          final int secondNdvi = secondNdviTile.getSampleInt(x, y);
          if (firstNdviBand.isPixelValid(x, y) && secondNdviBand.isPixelValid(x, y)) {
            final int maxNdvi = Math.max(firstNdvi, secondNdvi);
            if (writeFlags) {
              if (firstNdvi >= secondNdvi) {
                final int firstNdviFlag = firstNdviFlagTile.getSampleInt(x, y);
                targetTile.setSample(x, y, firstNdviFlag);
              } else {
                final int secondNdviFlag = secondNdviFlagTile.getSampleInt(x, y);
                targetTile.setSample(x, y, secondNdviFlag);
              }
            } else {
              targetTile.setSample(x, y, maxNdvi);
            }
          } else if (!firstNdviBand.isPixelValid(x, y)) {
            if (writeFlags) {
              final int firstNdviFlag = firstNdviFlagTile.getSampleInt(x, y);
              targetTile.setSample(x, y, firstNdviFlag);
            } else {
              targetTile.setSample(x, y, firstNdvi);
            }
          } else if (!secondNdviBand.isPixelValid(x, y)) {
            if (writeFlags) {
              final int secondNdviFlag = secondNdviFlagTile.getSampleInt(x, y);
              targetTile.setSample(x, y, secondNdviFlag);
            } else {
              targetTile.setSample(x, y, secondNdvi);
            }
          }
        } else {
          targetTile.setSample(x, y, Constants.NDVI_INVALID_VALUE);
        }
      }
    }
  }
Exemple #15
0
  // Processes a single AATSR band.
  private void processAatsrBand(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);
      setCurrentStatus(ProcessorConstants.STATUS_FAILED);
      return;
    }

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

    // initialize vectors and other data
    // ---------------------------------
    int width = band.getSceneRasterWidth();
    int height = band.getSceneRasterHeight();
    Band outBand = _outputProduct.getBand(band.getName());
    boolean isForwardBand = checkForAATSRForwardBand(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];
    boolean[] process = new boolean[width];
    float[] toa = new float[width];
    float[] toa_corr = new float[width];

    TiePointGrid szaBand;
    TiePointGrid saaBand;
    TiePointGrid vzaBand;
    TiePointGrid vaaBand;
    Term bitMask;

    // set the tie point bands according to input band view
    // ----------------------------------------------------
    if (isForwardBand) {
      szaBand = _szaFwdBand;
      saaBand = _saaFwdBand;
      vzaBand = _vzaFwdBand;
      vaaBand = _vaaFwdBand;
      bitMask = _bitMaskTermForward;
    } else {
      szaBand = _szaBand;
      saaBand = _saaBand;
      vzaBand = _vzaBand;
      vaaBand = _vaaBand;
      bitMask = _bitMaskTerm;
    }

    // initialize vectors
    // ------------------
    for (int x = 0; x < width; x++) {
      taup550[x] = _tau_aero_550;
      uh2o[x] = _u_h2o;
      uo3[x] = _u_o3;
      press[x] = _surf_press;
      process[x] = true;
    }

    // progress init
    pm.beginTask(
        SmacConstants.LOG_MSG_GENERATING_PIXEL_1
            + band.getName()
            + SmacConstants.LOG_MSG_GENERATING_PIXEL_2,
        height * 6);
    try {
      // loop over all scanlines
      for (int y = 0; y < band.getSceneRasterHeight(); 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));

        // scale sun and view elevation to zenith angles
        sza = RsMathUtils.elevationToZenith(sza, sza);
        vza = RsMathUtils.elevationToZenith(vza, sza);

        // forEachPixel bitmask
        if (bitMask != null) {
          _inputProduct.readBitmask(0, y, width, 1, bitMask, 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 progress
        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);
  }
Exemple #16
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);
  }
Exemple #17
0
  /** {@inheritDoc} */
  public void writeBandRasterData(
      Band sourceBand,
      int sourceOffsetX,
      int sourceOffsetY,
      int sourceWidth,
      int sourceHeight,
      ProductData sourceBuffer,
      ProgressMonitor pm)
      throws IOException {
    checkBufferSize(sourceWidth, sourceHeight, sourceBuffer);
    final int sourceBandWidth = sourceBand.getSceneRasterWidth();
    final int sourceBandHeight = sourceBand.getSceneRasterHeight();
    checkSourceRegionInsideBandRegion(
        sourceWidth, sourceBandWidth, sourceHeight, sourceBandHeight, sourceOffsetX, sourceOffsetY);

    int memTypeID = -1;
    int memSpaceID = -1;

    pm.beginTask("Writing band '" + sourceBand.getName() + "'...", 1);
    try {
      final int datasetID = getOrCreateBandH5D(sourceBand);
      final int fileSpaceID = H5.H5Dget_space(datasetID);
      final long[] memDims = new long[] {sourceHeight, sourceWidth};
      final long[] memStart = new long[2];
      final long[] memCount = new long[2];
      final long[] fileStart = new long[2];
      final long[] fileCount = new long[2];

      memTypeID = createH5TypeID(sourceBuffer.getType());
      memSpaceID = H5.H5Screate_simple(2, memDims, null);

      memStart[0] = 0;
      memStart[1] = 0;
      memCount[0] = sourceHeight;
      memCount[1] = sourceWidth;
      H5.H5Sselect_hyperslab(
          memSpaceID, HDF5Constants.H5S_SELECT_SET, memStart, null, memCount, null);

      fileStart[0] = sourceOffsetY;
      fileStart[1] = sourceOffsetX;
      fileCount[0] = sourceHeight;
      fileCount[1] = sourceWidth;
      H5.H5Sselect_hyperslab(
          fileSpaceID, HDF5Constants.H5S_SELECT_SET, fileStart, null, fileCount, null);

      H5.H5Dwrite(
          datasetID,
          memTypeID,
          memSpaceID,
          fileSpaceID,
          HDF5Constants.H5P_DEFAULT,
          sourceBuffer.getElems());

      pm.worked(1);
    } catch (IOException e) {
      throw e;
    } catch (HDF5Exception e) {
      throw new ProductIOException(createErrorMessage(e));
    } finally {
      closeH5S(memSpaceID);
      closeH5T(memTypeID);
      pm.done();
    }
  }
Exemple #18
0
  @Override
  public void initialize() throws OperatorException {
    if (computeErrorBands) {
      deactivateComputeTileMethod();
    }

    if (endmemberFile != null) {
      loadEndmemberFile();
    }

    if (sourceBandNames == null || sourceBandNames.length == 0) {
      Band[] bands = sourceProduct.getBands();
      ArrayList<String> bandNameList = new ArrayList<String>();
      for (Band band : bands) {
        if (band.getSpectralWavelength() > 0) {
          bandNameList.add(band.getName());
        }
      }
      sourceBandNames = bandNameList.toArray(new String[bandNameList.size()]);
    }

    validateParameters();

    sourceBands = new Band[sourceBandNames.length];
    for (int i = 0; i < sourceBandNames.length; i++) {
      String sourceBandName = sourceBandNames[i];
      Band sourceBand = sourceProduct.getBand(sourceBandName);
      if (sourceBand == null) {
        throw new OperatorException("Source band not found: " + sourceBandName);
      }
      if (sourceBand.getSpectralWavelength() <= 0) {
        throw new OperatorException("Source band without spectral wavelength: " + sourceBandName);
      }
      sourceBands[i] = sourceBand;
    }

    int numSourceBands = sourceBands.length;
    int numEndmembers = endmembers.length;

    if (numSourceBands < numEndmembers) {
      throw new OperatorException("Number of source bands must be >= number of endmembers.");
    }

    double[][] lsuMatrixElements = new double[numSourceBands][numEndmembers];
    for (int j = 0; j < numEndmembers; j++) {
      Endmember endmember = endmembers[j];
      double[] wavelengths = endmember.getWavelengths();
      double[] radiations = endmember.getRadiations();
      for (int i = 0; i < numSourceBands; i++) {
        Band sourceBand = sourceBands[i];
        float wavelength = sourceBand.getSpectralWavelength();
        float bandwidth = sourceBand.getSpectralBandwidth();
        int k =
            findEndmemberSpectralIndex(wavelengths, wavelength, Math.max(bandwidth, minBandwidth));
        if (k == -1) {
          throw new OperatorException(
              String.format(
                  "Band %s: No matching endmember wavelength found (%f nm)",
                  sourceBand.getName(), wavelength));
        }
        lsuMatrixElements[i][j] = radiations[k];
      }
    }

    if (UC_LSU.equals(unmixingModelName)) {
      spectralUnmixing = new UnconstrainedLSU(lsuMatrixElements);
    } else if (C_LSU.equals(unmixingModelName)) {
      spectralUnmixing = new ConstrainedLSU(lsuMatrixElements);
    } else if (FC_LSU.equals(unmixingModelName)) {
      spectralUnmixing = new FullyConstrainedLSU(lsuMatrixElements);
    } else if (unmixingModelName == null) {
      spectralUnmixing = new UnconstrainedLSU(lsuMatrixElements);
    }

    int width = sourceProduct.getSceneRasterWidth();
    int height = sourceProduct.getSceneRasterHeight();

    targetProduct =
        new Product(sourceProduct.getName() + "_unmixed", "SpectralUnmixing", width, height);

    abundanceBands = new Band[numEndmembers];
    for (int i = 0; i < numEndmembers; i++) {
      abundanceBands[i] =
          targetProduct.addBand(
              endmembers[i].getName() + abundanceBandNameSuffix, ProductData.TYPE_FLOAT32);
    }

    if (computeErrorBands) {
      errorBands = new Band[numSourceBands];
      for (int i = 0; i < errorBands.length; i++) {
        final String erroBandName = sourceBands[i].getName() + errorBandNameSuffix;
        errorBands[i] = targetProduct.addBand(erroBandName, ProductData.TYPE_FLOAT32);
        ProductUtils.copySpectralBandProperties(sourceBands[i], errorBands[i]);
      }
      summaryErrorBand = targetProduct.addBand("summary_error", ProductData.TYPE_FLOAT32);
      summaryErrorBand.setDescription("Root mean square error");
    }

    ProductUtils.copyMetadata(sourceProduct, targetProduct);
    ProductUtils.copyTiePointGrids(sourceProduct, targetProduct);
    ProductUtils.copyGeoCoding(sourceProduct, targetProduct);
  }
Exemple #19
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;
  }
Exemple #20
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);
  }