Exemplo n.º 1
0
  static boolean setFlagCodingsAndBitmaskDefs(final Product product) {
    final FlagCoding flagCoding = new FlagCoding("GLOBCOLOUR");

    for (Flags flag : Flags.values()) {
      flagCoding.addFlag(flag.name(), flag.getMask(), flag.getDescription());
    }

    boolean codingAdded = false;

    for (final String name : product.getBandNames()) {
      if (name.endsWith("flags")) {
        final Band band = product.getBand(name);

        if (band == null || band.isFloatingPointType() || band.getFlagCoding() != null) {
          continue;
        }
        if (!product.getFlagCodingGroup().contains(flagCoding.getName())) {
          product.getFlagCodingGroup().add(flagCoding);
        }

        band.setSampleCoding(flagCoding);
        addBitmaskDefinitions(product, name);

        codingAdded = true;
      }
    }

    return codingAdded;
  }
Exemplo n.º 2
0
 private void maybeCopyFlagCoding(Band sourceBand, Band targetBand) {
   FlagCoding sourceCoding = sourceBand.getFlagCoding();
   if (sourceCoding != null) {
     FlagCoding targetCoding =
         getTargetProduct().getFlagCodingGroup().get(sourceCoding.getName());
     if (targetCoding == null) {
       targetCoding = ProductUtils.copyFlagCoding(sourceCoding, getTargetProduct());
     }
     targetBand.setSampleCoding(targetCoding);
   }
 }
Exemplo n.º 3
0
  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;
  }
  /**
   * 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);
        }
      }
    }
  }
Exemplo n.º 5
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;
  }
Exemplo n.º 6
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());
    }
  }