/** This method creates the target product */
  private void createTargetProduct() {

    final String productType = synergyProduct.getProductType();
    final String productName = synergyProduct.getName();
    final int sceneWidth = synergyProduct.getSceneRasterWidth();
    final int sceneHeight = synergyProduct.getSceneRasterHeight();

    final int downscaledRasterWidth = (int) (Math.ceil((float) (sceneWidth / scalingFactor) - 0.5));
    final int downscaledRasterHeight =
        (int) (Math.ceil((float) (sceneHeight / scalingFactor) - 0.5));

    targetProduct =
        new Product(productName, productType, downscaledRasterWidth, downscaledRasterHeight);
    //        targetProduct.setPreferredTileSize(128, 128);

    ProductUtils.copyGeoCoding(synergyProduct, targetProduct);
    ProductUtils.copyMetadata(synergyProduct, targetProduct);
    AerosolHelpers.copyDownscaledTiePointGrids(synergyProduct, targetProduct, scalingFactor);
    AerosolHelpers.copyDownscaledFlagBands(synergyProduct, targetProduct, scalingFactor);

    //        AerosolHelpers.addAerosolFlagBand(targetProduct, downscaledRasterWidth,
    // downscaledRasterHeight);

    final BandMathsOp bandArithmeticOp =
        BandMathsOp.createBooleanExpressionBand(INVALID_EXPRESSION, synergyProduct);
    invalidBand = bandArithmeticOp.getTargetProduct().getBandAt(0);

    setTargetBands();
  }
示例#2
0
  private static FilterBand createFilterBand(Filter filter, String bandName, int iterationCount) {
    RasterDataNode sourceRaster = (RasterDataNode) VisatApp.getApp().getSelectedProductNode();

    FilterBand targetBand;
    Product product = sourceRaster.getProduct();

    if (filter.getOperation() == Filter.Operation.CONVOLVE) {
      targetBand =
          new ConvolutionFilterBand(bandName, sourceRaster, getKernel(filter), iterationCount);
      if (sourceRaster instanceof Band) {
        ProductUtils.copySpectralBandProperties((Band) sourceRaster, targetBand);
      }
    } else {
      GeneralFilterBand.OpType opType = getOpType(filter.getOperation());
      targetBand =
          new GeneralFilterBand(bandName, sourceRaster, opType, getKernel(filter), iterationCount);
      if (sourceRaster instanceof Band) {
        ProductUtils.copySpectralBandProperties((Band) sourceRaster, targetBand);
      }
    }

    targetBand.setDescription(
        String.format(
            "Filter '%s' (=%s) applied to '%s'",
            filter.getName(), filter.getOperation(), sourceRaster.getName()));
    if (sourceRaster instanceof Band) {
      ProductUtils.copySpectralBandProperties((Band) sourceRaster, targetBand);
    }
    product.addBand(targetBand);
    targetBand.fireProductNodeDataChanged();
    return targetBand;
  }
示例#3
0
 private void copyBand(String name) {
   Band sourceBand = getSourceProduct().getBand(name);
   Band targetBand = ProductUtils.copyBand(name, getSourceProduct(), getTargetProduct());
   targetBand.setSourceImage(sourceBand.getSourceImage());
   maybeCopyFlagCoding(sourceBand, targetBand);
   maybeCopyIndexCoding(sourceBand, targetBand);
 }
示例#4
0
  public void createData(final RepositoryEntry entry, final Repository repository)
      throws IOException {
    final Product product = entry.getProduct();
    final PropertyMap propertyMap = repository.getPropertyMap();
    final String productName = entry.getProductFile().getName();

    if (product.getGeoCoding() != null) {
      final String boundaryPathString = createPathsString(product);
      propertyMap.setPropertyString(productName + KEY_BOUNDARY_PATH, boundaryPathString);
      final GeoPos centerGeoPos = ProductUtils.getCenterGeoPos(product);
      propertyMap.setPropertyDouble(productName + KEY_PRODUCT_CENTER_LAT, centerGeoPos.lat);
      propertyMap.setPropertyDouble(productName + KEY_PRODUCT_CENTER_LON, centerGeoPos.lon);
    } else {
      propertyMap.setPropertyString(productName + KEY_BOUNDARY_PATH, "");
      propertyMap.setPropertyDouble(productName + KEY_PRODUCT_CENTER_LAT, null);
      propertyMap.setPropertyDouble(productName + KEY_PRODUCT_CENTER_LON, null);
    }

    if (createWorldMapFile) {
      final File worldMapImageFile =
          getWorldMapImageFile(repository.getStorageDir(), entry.getProductFile().getName());
      final BufferedImage worldMapImage = createWorldMapImage(product);
      writeImage(worldMapImage, worldMapImageFile);
    }
  }
示例#5
0
 private void addSubsetInfoMetadata(Product product) {
   if (getSubsetDef() != null) {
     ProductSubsetDef subsetDef = getSubsetDef();
     Product sourceProduct = getSourceProduct();
     String nameSubsetinfo = "SubsetInfo";
     MetadataElement subsetElem = new MetadataElement(nameSubsetinfo);
     addAttribString("SourceProduct.name", sourceProduct.getName(), subsetElem);
     subsetElem.setAttributeInt("SubSampling.x", subsetDef.getSubSamplingX());
     subsetElem.setAttributeInt("SubSampling.y", subsetDef.getSubSamplingY());
     if (subsetDef.getRegion() != null) {
       Rectangle region = subsetDef.getRegion();
       subsetElem.setAttributeInt("SubRegion.x", region.x);
       subsetElem.setAttributeInt("SubRegion.y", region.y);
       subsetElem.setAttributeInt("SubRegion.width", region.width);
       subsetElem.setAttributeInt("SubRegion.height", region.height);
     }
     String[] nodeNames = subsetDef.getNodeNames();
     if (nodeNames != null) {
       for (int i = 0; i < nodeNames.length; i++) {
         addAttribString("ProductNodeName." + (i + 1), nodeNames[i], subsetElem);
       }
     }
     ProductUtils.addElementToHistory(product, subsetElem);
   }
 }
示例#6
0
  private static void addFlagCoding(Product product, FlagCoding flagCoding) {
    final FlagCoding targetFlagCoding = new FlagCoding(flagCoding.getName());

    targetFlagCoding.setDescription(flagCoding.getDescription());
    ProductUtils.copyMetadata(flagCoding, targetFlagCoding);
    product.getFlagCodingGroup().add(targetFlagCoding);
  }
示例#7
0
 @Override
 public void copyTiePointGrids(String... names) {
   if (names.length == 0) {
     names = getSourceProduct().getTiePointGridNames();
   }
   for (String name : names) {
     ProductUtils.copyTiePointGrid(name, getSourceProduct(), getTargetProduct());
   }
 }
  private Product createYearlyProduct() {
    width = sortedDataSourceProducts[0].getSceneRasterWidth();
    height = sortedDataSourceProducts[0].getSceneRasterHeight();

    Product yearlyProduct = new Product("DIVERSITY_NDVI_MAX", "DIVERSITY_NDVI_MAX", width, height);
    ProductUtils.copyGeoCoding(sortedDataSourceProducts[0], yearlyProduct);

    return yearlyProduct;
  }
示例#9
0
  private static BufferedImage createWorldMapImage(final Product product) {
    final GeneralPath[] geoBoundaryPaths = ProductUtils.createGeoBoundaryPaths(product);
    final Image wmImage = WorldMapImageLoader.getWorldMapImage(false);
    final WorldMapPainter worldMapPainter =
        new WorldMapPainter(
            wmImage.getScaledInstance(wmImage.getHeight(null) / 2, -1, Image.SCALE_SMOOTH));

    return worldMapPainter.createWorldMapImage(geoBoundaryPaths);
  }
 @Override
 public boolean validatePage() {
   try {
     crsSelectionPanel.getCrs(
         ProductUtils.getCenterGeoPos(getContext().getAppContext().getSelectedProduct()));
   } catch (FactoryException ignored) {
     return false;
   }
   return true;
 }
示例#11
0
  private Product createProduct() {
    Product sourceProduct = getSourceProduct();
    Debug.assertNotNull(sourceProduct);
    Debug.assertTrue(getSceneRasterWidth() > 0);
    Debug.assertTrue(getSceneRasterHeight() > 0);
    final String newProductName;
    if (this.newProductName == null || this.newProductName.length() == 0) {
      newProductName = sourceProduct.getName();
    } else {
      newProductName = this.newProductName;
    }
    final Product product =
        new Product(
            newProductName,
            sourceProduct.getProductType(),
            getSceneRasterWidth(),
            getSceneRasterHeight(),
            this);
    product.setPointingFactory(sourceProduct.getPointingFactory());
    if (newProductDesc == null || newProductDesc.length() == 0) {
      product.setDescription(sourceProduct.getDescription());
    } else {
      product.setDescription(newProductDesc);
    }
    if (!isMetadataIgnored()) {
      ProductUtils.copyMetadata(sourceProduct, product);
      addTiePointGridsToProduct(product);
      addFlagCodingsToProduct(product);
      addIndexCodingsToProduct(product);
    }
    addBandsToProduct(product);
    if (!isMetadataIgnored()) {
      addGeoCodingToProduct(product);
    }
    ProductUtils.copyVectorData(sourceProduct, product);
    ProductUtils.copyMasks(sourceProduct, product);
    ProductUtils.copyOverlayMasks(sourceProduct, product);
    ProductUtils.copyPreferredTileSize(sourceProduct, product);
    setSceneRasterStartAndStopTime(product);
    addSubsetInfoMetadata(product);

    return product;
  }
示例#12
0
 private void maybeCopyIndexCoding(Band sourceBand, Band targetBand) {
   IndexCoding sourceCoding = sourceBand.getIndexCoding();
   if (sourceCoding != null) {
     IndexCoding targetCoding =
         getTargetProduct().getIndexCodingGroup().get(sourceCoding.getName());
     if (targetCoding == null) {
       targetCoding = ProductUtils.copyIndexCoding(sourceCoding, getTargetProduct());
     }
     targetBand.setSampleCoding(targetCoding);
   }
 }
示例#13
0
 static Band createSubset(Band sourceBand, Scene targetScene, ProductSubsetDef subsetDef) {
   final Band targetBand =
       new Band(
           sourceBand.getName(),
           sourceBand.getDataType(),
           targetScene.getRasterWidth(),
           targetScene.getRasterHeight());
   ProductUtils.copyRasterDataNodeProperties(sourceBand, targetBand);
   targetBand.setSourceImage(getSourceImage(subsetDef, sourceBand));
   return targetBand;
 }
示例#14
0
 private void scrollToCenterPath(final GeneralPath geoBoundaryPath, final JViewport viewport) {
   final GeneralPath pixelPath =
       ProductUtils.convertToPixelPath(geoBoundaryPath, wmPainter.getGeoCoding());
   final Rectangle viewRect = viewport.getViewRect();
   final Rectangle pathBounds = pixelPath.getBounds();
   setCenter(viewRect, new Point((int) pathBounds.getCenterX(), (int) pathBounds.getCenterY()));
   final Dimension bounds =
       new Dimension(scaledImage.getWidth(null), scaledImage.getHeight(null));
   ensureRectIsInBounds(viewRect, bounds);
   viewport.scrollRectToVisible(viewRect);
 }
  /**
   * This method copies all bands which contain a flagcoding from the source product to the target
   * product.
   *
   * @param sourceProduct the source product
   * @param targetProduct the target product
   */
  public static void copyDownscaledFlagBands(
      Product sourceProduct, Product targetProduct, float scalingFactor) {
    Guardian.assertNotNull("source", sourceProduct);
    Guardian.assertNotNull("target", targetProduct);
    if (sourceProduct.getFlagCodingGroup().getNodeCount() > 0) {

      ProductUtils.copyFlagCodings(sourceProduct, targetProduct);
      ProductUtils.copyMasks(sourceProduct, targetProduct);

      // loop over bands and check if they have a flags coding attached
      for (int i = 0; i < sourceProduct.getNumBands(); i++) {
        Band sourceBand = sourceProduct.getBandAt(i);
        FlagCoding coding = sourceBand.getFlagCoding();
        if (coding != null) {
          Band targetBand = AerosolHelpers.downscaleBand(sourceBand, scalingFactor);
          targetBand.setSampleCoding(coding);
          targetProduct.addBand(targetBand);
        }
      }
    }
  }
示例#16
0
 private static String createPathsString(final Product product) {
   final GeneralPath[] geoBoundaryPaths = ProductUtils.createGeoBoundaryPaths(product);
   final StringWriter pathWriter = new StringWriter();
   for (int i = 0; i < geoBoundaryPaths.length; i++) {
     final GeneralPath geoBoundaryPath = geoBoundaryPaths[i];
     if (i > 0) {
       pathWriter.write(",");
     }
     write(geoBoundaryPath, pathWriter);
   }
   return pathWriter.toString();
 }
示例#17
0
 static Geometry computeProductGeometry(Product product) {
   final GeneralPath[] paths = ProductUtils.createGeoBoundaryPaths(product);
   final Polygon[] polygons = new Polygon[paths.length];
   final GeometryFactory factory = new GeometryFactory();
   for (int i = 0; i < paths.length; i++) {
     polygons[i] = convertAwtPathToJtsPolygon(paths[i], factory);
   }
   final DouglasPeuckerSimplifier peuckerSimplifier =
       new DouglasPeuckerSimplifier(
           polygons.length == 1 ? polygons[0] : factory.createMultiPolygon(polygons));
   return peuckerSimplifier.getResultGeometry();
 }
 @Override
 public AbstractLayerSourceAssistantPage getNextPage() {
   final LayerSourcePageContext context = getContext();
   try {
     final Product product = context.getAppContext().getSelectedProduct();
     final GeoPos referencePos = ProductUtils.getCenterGeoPos(product);
     final CoordinateReferenceSystem crs = crsSelectionPanel.getCrs(referencePos);
     context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FEATURE_COLLECTION_CRS, crs);
     return new ShapefileAssistantPage3();
   } catch (FactoryException e) {
     e.printStackTrace();
     context.showErrorDialog("Could not create CRS:\n" + e.getMessage());
   }
   return null;
 }
  /**
   * Initializes this operator and sets the one and only target product.
   *
   * <p>The target product can be either defined by a field of type {@link
   * org.esa.beam.framework.datamodel.Product} annotated with the {@link
   * org.esa.beam.framework.gpf.annotations.TargetProduct TargetProduct} annotation or by calling
   * {@link #setTargetProduct} method.
   *
   * <p>The framework calls this method after it has created this operator. Any client code that
   * must be performed before computation of tile data should be placed here.
   *
   * @throws org.esa.beam.framework.gpf.OperatorException If an error occurs during operator
   *     initialisation.
   * @see #getTargetProduct()
   */
  @Override
  public void initialize() throws OperatorException {

    productName = sourceProduct.getName() + "_vgtComp";

    targetProduct =
        new Product(
            productName,
            "VGT_COMP",
            sourceProduct.getSceneRasterWidth(),
            sourceProduct.getSceneRasterHeight());
    // Some target products may require more aid from ProductUtils methods...
    ProductUtils.copyGeoCoding(sourceProduct, targetProduct);

    sourceBandS1_B0 = sourceProduct.getBand(sourceBandNameS1_B0);
    sourceBandS1_B2 = sourceProduct.getBand(sourceBandNameS1_B2);
    sourceBandS1_B3 = sourceProduct.getBand(sourceBandNameS1_B3);
    sourceBandS1_MIR = sourceProduct.getBand(sourceBandNameS1_MIR);
    sourceBandS1_SM = sourceProduct.getBand(sourceBandNameS1_SM);

    sourceBandP_B0 = sourceProduct.getBand(sourceBandNameP_B0);
    sourceBandP_B2 = sourceProduct.getBand(sourceBandNameP_B2);
    sourceBandP_B3 = sourceProduct.getBand(sourceBandNameP_B3);
    sourceBandP_MIR = sourceProduct.getBand(sourceBandNameP_MIR);
    sourceBandP_SM = sourceProduct.getBand(sourceBandNameP_SM);

    sourceBandP_Idepix = sourceProduct.getBand(sourceBandNameP_Idepix);

    targetDifferenceBandB0 =
        targetProduct.addBand(targetDifferenceBandNameB0, ProductData.TYPE_FLOAT32);
    targetDifferenceBandB2 =
        targetProduct.addBand(targetDifferenceBandNameB2, ProductData.TYPE_FLOAT32);
    targetDifferenceBandB3 =
        targetProduct.addBand(targetDifferenceBandNameB3, ProductData.TYPE_FLOAT32);
    targetDifferenceBandMIR =
        targetProduct.addBand(targetDifferenceBandNameMIR, ProductData.TYPE_FLOAT32);

    targetProduct.setPreferredTileSize(
        new Dimension(targetProduct.getSceneRasterWidth(), targetProduct.getSceneRasterHeight()));
  }
示例#20
0
  // Creates the output product for the given request.
  private void createOutputProduct(ProgressMonitor pm) throws IOException, ProcessorException {

    // take only the first output product. There might be more but we will ignore
    // these in SMAC.
    ProductRef prod = getRequest().getOutputProductAt(0);
    checkParamNotNull(prod, "output product");

    String productType = _inputProduct.getProductType() + "_SMAC";
    String productName = getOutputProductNameSafe();
    int sceneWidth = _inputProduct.getSceneRasterWidth();
    int sceneHeight = _inputProduct.getSceneRasterHeight();
    _outputProduct = new Product(productName, productType, sceneWidth, sceneHeight);

    ProductWriter writer = ProcessorUtils.createProductWriter(prod);
    _outputProduct.setProductWriter(writer);

    // loop over bands and create them
    // -------------------------------
    if (ObjectUtils.equalObjects(_sensorType, SensorCoefficientManager.MERIS_NAME)) {
      addBandsToOutput("Atmosphere corrected MERIS band ", true);
    } else {
      addBandsToOutput("Atmosphere corrected band ");
    }
    ProductUtils.copyTiePointGrids(_inputProduct, _outputProduct);
    copyRequestMetaData(_outputProduct);
    copyFlagBands(_inputProduct, _outputProduct);

    // for MERIS FSG / FRG products
    copyBand(
        EnvisatConstants.MERIS_AMORGOS_L1B_CORR_LATITUDE_BAND_NAME, _inputProduct, _outputProduct);
    copyBand(
        EnvisatConstants.MERIS_AMORGOS_L1B_CORR_LONGITUDE_BAND_NAME, _inputProduct, _outputProduct);
    copyBand(EnvisatConstants.MERIS_AMORGOS_L1B_ALTIUDE_BAND_NAME, _inputProduct, _outputProduct);

    copyGeoCoding(_inputProduct, _outputProduct);

    // and initialize the disk represenation
    writer.writeProductNodes(_outputProduct, new File(prod.getFilePath()));
    copyBandData(getBandNamesToCopy(), _inputProduct, _outputProduct, pm);
  }
  /**
   * This method copies the flag bands from the synergy product to the target product
   *
   * @param synergyProduct - the Synergy product
   * @param targetProduct - the target product
   */
  public static void copySynergyFlagBands(Product synergyProduct, Product targetProduct) {
    final Band aatsrConfidFlagNadirBand =
        targetProduct.addBand(SynergyConstants.CONFID_NADIR_FLAGS_AATSR, ProductData.TYPE_INT16);
    final Band aatsrConfidFlagFwardBand =
        targetProduct.addBand(SynergyConstants.CONFID_FWARD_FLAGS_AATSR, ProductData.TYPE_INT16);
    final Band aatsrCloudFlagNadirBand =
        targetProduct.addBand(SynergyConstants.CLOUD_NADIR_FLAGS_AATSR, ProductData.TYPE_INT16);
    final Band aatsrCloudFlagFwardBand =
        targetProduct.addBand(SynergyConstants.CLOUD_FWARD_FLAGS_AATSR, ProductData.TYPE_INT16);
    final Band merisL1FlagsBand =
        targetProduct.addBand(SynergyConstants.L1_FLAGS_MERIS, ProductData.TYPE_INT16);
    final Band merisCloudFlagBand =
        targetProduct.addBand(SynergyConstants.CLOUD_FLAG_MERIS, ProductData.TYPE_INT16);

    final FlagCoding aatsrConfidNadirFlagCoding =
        synergyProduct.getFlagCodingGroup().get(SynergyConstants.CONFID_NADIR_FLAGS_AATSR);
    ProductUtils.copyFlagCoding(aatsrConfidNadirFlagCoding, targetProduct);
    aatsrConfidFlagNadirBand.setSampleCoding(aatsrConfidNadirFlagCoding);

    final FlagCoding aatsrConfidFwardFlagCoding =
        synergyProduct.getFlagCodingGroup().get(SynergyConstants.CONFID_FWARD_FLAGS_AATSR);
    ProductUtils.copyFlagCoding(aatsrConfidFwardFlagCoding, targetProduct);
    aatsrConfidFlagFwardBand.setSampleCoding(aatsrConfidFwardFlagCoding);

    final FlagCoding aatsrCloudNadirFlagCoding =
        synergyProduct.getFlagCodingGroup().get(SynergyConstants.CLOUD_NADIR_FLAGS_AATSR);
    ProductUtils.copyFlagCoding(aatsrCloudNadirFlagCoding, targetProduct);
    aatsrCloudFlagNadirBand.setSampleCoding(aatsrCloudNadirFlagCoding);

    final FlagCoding aatsrCloudFwardFlagCoding =
        synergyProduct.getFlagCodingGroup().get(SynergyConstants.CLOUD_FWARD_FLAGS_AATSR);
    ProductUtils.copyFlagCoding(aatsrCloudFwardFlagCoding, targetProduct);
    aatsrCloudFlagFwardBand.setSampleCoding(aatsrCloudFwardFlagCoding);

    final FlagCoding merisL1FlagsCoding =
        synergyProduct.getFlagCodingGroup().get(SynergyConstants.L1_FLAGS_MERIS);
    ProductUtils.copyFlagCoding(merisL1FlagsCoding, targetProduct);
    merisL1FlagsBand.setSampleCoding(merisL1FlagsCoding);

    final FlagCoding merisCloudFlagCoding =
        synergyProduct.getFlagCodingGroup().get(SynergyConstants.CLOUD_FLAG_MERIS);
    ProductUtils.copyFlagCoding(merisCloudFlagCoding, targetProduct);
    merisCloudFlagBand.setSampleCoding(merisCloudFlagCoding);
  }
示例#22
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);
    }
  }
示例#23
0
 @Override
 public void copyMasks() {
   ProductUtils.copyMasks(getSourceProduct(), getTargetProduct());
 }
示例#24
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);
  }
示例#25
0
 @Override
 public void copyGeoCoding() {
   ProductUtils.copyGeoCoding(getSourceProduct(), getTargetProduct());
 }
示例#26
0
 @Override
 public void copyVectorData() {
   ProductUtils.copyVectorData(getSourceProduct(), getTargetProduct());
 }
示例#27
0
 private String getThumbnailBandName() {
   return ProductUtils.findSuitableQuicklookBandName(product);
 }