示例#1
0
文件: EnviHeader.java 项目: pmar/nest
 private static void writedescription(PrintWriter out, RasterDataNode rasterDataNode) {
   assert rasterDataNode != null;
   String description = rasterDataNode.getDescription();
   String unit = rasterDataNode.getUnit();
   if (unit == null || unit.trim().length() == 0) {
     unit = "1";
   }
   if (rasterDataNode.isLog10Scaled()) {
     unit = "log(" + unit + ")";
   }
   unit = " - Unit: " + unit;
   String wavelength = "";
   //        String bandwidth = "";
   if (rasterDataNode instanceof Band) {
     Band band = (Band) rasterDataNode;
     if (band.getSpectralWavelength() != 0.0) {
       wavelength = " - Wavelength: " + band.getSpectralWavelength() + "nm";
       //                bandwidth = " - Bandwidth: " + band.getSpectralBandwidth() + "nm";
     }
   }
   if (description == null || description.trim().length() == 0) {
     description = rasterDataNode.getProduct().getDescription();
   }
   out.println(
       "description = {"
           + description
           + unit
           + wavelength
           //                    + bandwidth
           + "}");
 }
示例#2
0
 private void copyBandRasterDataSubSampling(
     Band sourceBand,
     int sourceOffsetX,
     int sourceOffsetY,
     int sourceWidth,
     int sourceHeight,
     int sourceStepX,
     int sourceStepY,
     ProductData destBuffer,
     int destWidth) {
   final int sourceMinY = sourceOffsetY;
   final int sourceMaxY = sourceOffsetY + sourceHeight - 1;
   int destPos = 0;
   for (int sourceY = sourceMinY; sourceY <= sourceMaxY; sourceY += sourceStepY) {
     // no subsampling in x-direction
     if (sourceStepX == 1) {
       copyData(
           sourceBand.getRasterData(),
           sourceY * sourceBand.getSceneRasterWidth() + sourceOffsetX,
           destBuffer,
           destPos,
           destWidth);
     } else {
       copyLine(
           sourceBand.getRasterData(),
           sourceY * sourceBand.getSceneRasterWidth() + sourceOffsetX,
           sourceWidth,
           sourceStepX,
           destBuffer,
           destPos);
     }
     destPos += destWidth;
   }
 }
示例#3
0
 @Override
 public Band addBand(String name, int dataType, double noDataValue) {
   Band band = addBand(name, dataType);
   band.setNoDataValue(noDataValue);
   band.setNoDataValueUsed(true);
   return band;
 }
  protected void addIndexCodingAndBitmasks(Band smBand) {
    final IndexCoding coding = new IndexCoding("SM_coding");
    final MetadataAttribute land =
        coding.addSample("LAND", 0, "Not cloud, shadow or edge AND land");
    final MetadataAttribute flooded =
        coding.addSample("FLOODED", 1, "Not land and not cloud, shadow or edge");
    final MetadataAttribute suspect = coding.addSample("SUSPECT", 2, "Cloud shadow or cloud edge");
    final MetadataAttribute cloud = coding.addSample("CLOUD", 3, "Cloud");
    final MetadataAttribute water = coding.addSample("WATER", 4, "Not land");
    final MetadataAttribute snow = coding.addSample("SNOW", 5, "Snow");
    final MetadataAttribute invalid = coding.addSample("INVALID", 6, "Invalid");
    final Product product = smBand.getProduct();
    product.getIndexCodingGroup().add(coding);
    smBand.setSampleCoding(coding);
    final ColorPaletteDef.Point[] points =
        new ColorPaletteDef.Point[] {
          new ColorPaletteDef.Point(0, Color.GREEN.darker(), "land"),
          new ColorPaletteDef.Point(1, Color.BLUE, "flooded"),
          new ColorPaletteDef.Point(2, Color.ORANGE, "suspect"),
          new ColorPaletteDef.Point(3, Color.GRAY, "cloud"),
          new ColorPaletteDef.Point(4, Color.BLUE.darker(), "water"),
          new ColorPaletteDef.Point(5, Color.LIGHT_GRAY, "snow"),
          new ColorPaletteDef.Point(6, Color.RED, "invalid")
        };
    smBand.setImageInfo(new ImageInfo(new ColorPaletteDef(points)));

    addMask(land, "SM == 0", Color.GREEN.darker(), product);
    addMask(flooded, "SM == 1", Color.BLUE, product);
    addMask(suspect, "SM == 2", Color.ORANGE, product);
    addMask(cloud, "SM == 3", Color.GRAY, product);
    addMask(water, "SM == 4", Color.BLUE.darker(), product);
    addMask(snow, "SM == 5", Color.LIGHT_GRAY, product);
    addMask(invalid, "SM == 6", Color.RED, product);
  }
示例#5
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;
  }
示例#6
0
 @Override
 public void configureSourceSamples(
     SampleConfigurer sampleConfigurer, Product sourceProduct, String spectralBandPrefix) {
   for (int i = 0; i < MODIS_L1B_NUM_SPECTRAL_BANDS; i++) {
     if (sourceProduct.containsBand(MODIS_L1B_SPECTRAL_BAND_NAMES[i])) {
       sampleConfigurer.defineSample(i, MODIS_L1B_SPECTRAL_BAND_NAMES[i], sourceProduct);
     } else {
       sampleConfigurer.defineSample(
           i, MODIS_L1B_SPECTRAL_BAND_NAMES[i].replace(".", "_"), sourceProduct);
     }
   }
   for (int i = 0; i < MODIS_L1B_NUM_EMISSIVE_BANDS; i++) {
     if (sourceProduct.containsBand(MODIS_L1B_EMISSIVE_BAND_NAMES[i])) {
       sampleConfigurer.defineSample(
           OccciConstants.MODIS_SRC_RAD_OFFSET + i,
           MODIS_L1B_EMISSIVE_BAND_NAMES[i],
           sourceProduct);
     } else {
       final String newEmissiveBandName = MODIS_L1B_EMISSIVE_BAND_NAMES[i].replace(".", "_");
       final Band emissiveBand = sourceProduct.getBand(newEmissiveBandName);
       emissiveBand.setScalingFactor(
           1.0); // todo: we do this to come back to counts with SeaDAS reader,
       // as the NN was also trained with counts
       emissiveBand.setScalingOffset(0.0);
       sampleConfigurer.defineSample(
           OccciConstants.MODIS_SRC_RAD_OFFSET + i, newEmissiveBandName, sourceProduct);
     }
   }
 }
  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);
  }
示例#8
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);
 }
示例#9
0
 @Override
 public Band addBand(String name, String expression, double noDataValue) {
   Band band = addBand(name, expression);
   band.setNoDataValue(noDataValue);
   band.setNoDataValueUsed(true);
   return band;
 }
示例#10
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;
  }
示例#11
0
文件: EnviHeader.java 项目: pmar/nest
 /**
  * Writes the wavelength value to the out stream if the given rasterDataNode is an instance of
  * <code>BAND</code>
  *
  * @param out - the tream to write to
  * @param rasterDataNode the <code>RasterDataNode</code>
  */
 private static void writeWavelength(PrintWriter out, RasterDataNode rasterDataNode) {
   if (rasterDataNode instanceof Band) {
     final Band band = (Band) rasterDataNode;
     final float spectralWavelength = band.getSpectralWavelength();
     if (spectralWavelength != 0) {
       out.println("wavelength = {" + spectralWavelength + "}");
     }
   }
 }
示例#12
0
 @Override
 void setInvalidPixelExpression(Band band) {
   if (band.isFlagBand()) {
     band.setNoDataValueUsed(false);
   } else {
     band.setNoDataValueUsed(true);
     band.setNoDataValue(-2);
   }
 }
示例#13
0
 /**
  * The template method which is called by the <code>readBandRasterDataSubSampling</code> method
  * after an optional spatial subset has been applied to the input parameters.
  *
  * <p>
  *
  * <p>The destination band, buffer and region parameters are exactly the ones passed to the
  * original <code>readBandRasterDataSubSampling</code> call. Since the <code>destOffsetX</code>
  * and <code>destOffsetY</code> parameters are already taken into acount in the <code>
  * sourceOffsetX</code> and <code>sourceOffsetY</code> parameters, an implementor of this method
  * is free to ignore them.
  *
  * @param sourceOffsetX the absolute X-offset in source raster co-ordinates
  * @param sourceOffsetY the absolute Y-offset in source raster co-ordinates
  * @param sourceWidth the width of region providing samples to be read given in source raster
  *     co-ordinates
  * @param sourceHeight the height of region providing samples to be read given in source raster
  *     co-ordinates
  * @param sourceStepX the sub-sampling in X direction within the region providing samples to be
  *     read
  * @param sourceStepY the sub-sampling in Y direction within the region providing samples to be
  *     read
  * @param destBand the destination band which identifies the data source from which to read the
  *     sample values
  * @param destBuffer the destination buffer which receives the sample values to be read
  * @param destOffsetX the X-offset in the band's raster co-ordinates
  * @param destOffsetY the Y-offset in the band's raster co-ordinates
  * @param destWidth the width of region to be read given in the band's raster co-ordinates
  * @param destHeight the height of region to be read given in the band's raster co-ordinates
  * @throws IOException if an I/O error occurs
  * @see #getSubsetDef
  */
 @Override
 protected void readBandRasterDataImpl(
     int sourceOffsetX,
     int sourceOffsetY,
     int sourceWidth,
     int sourceHeight,
     int sourceStepX,
     int sourceStepY,
     Band destBand,
     int destOffsetX,
     int destOffsetY,
     int destWidth,
     int destHeight,
     ProductData destBuffer,
     ProgressMonitor pm)
     throws IOException {
   Band sourceBand = (Band) bandMap.get(destBand);
   // if the band already has an internal raster
   if (sourceBand.getRasterData() != null) {
     // if the destination region equals the entire raster
     if (sourceBand.getSceneRasterWidth() == destWidth
         && sourceBand.getSceneRasterHeight() == destHeight) {
       copyBandRasterDataFully(sourceBand, destBuffer, destWidth, destHeight);
       // else if the destination region is smaller than the entire raster
     } else {
       copyBandRasterDataSubSampling(
           sourceBand,
           sourceOffsetX,
           sourceOffsetY,
           sourceWidth,
           sourceHeight,
           sourceStepX,
           sourceStepY,
           destBuffer,
           destWidth);
     }
   } else {
     // if the desired destination region equals the source raster
     if (sourceWidth == destWidth && sourceHeight == destHeight) {
       readBandRasterDataRegion(
           sourceBand, sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, destBuffer, pm);
       // else if the desired destination region is smaller than the source raster
     } else {
       readBandRasterDataSubSampling(
           sourceBand,
           sourceOffsetX,
           sourceOffsetY,
           sourceWidth,
           sourceHeight,
           sourceStepX,
           sourceStepY,
           destBuffer,
           destWidth,
           pm);
     }
   }
 }
示例#14
0
 @Override
 public void copyBands(ProductNodeFilter<Band> filter) {
   Band[] sourceBands = getSourceProduct().getBands();
   for (Band sourceBand : sourceBands) {
     if (filter.accept(sourceBand)) {
       copyBand(sourceBand.getName());
     }
   }
 }
示例#15
0
  public synchronized void readBandData(
      Band destBand,
      int sourceOffsetX,
      int sourceOffsetY,
      int sourceWidth,
      int sourceHeight,
      int sourceStepX,
      int sourceStepY,
      ProductData destBuffer,
      ProgressMonitor pm)
      throws IOException, InvalidRangeException {

    if (mustFlipY) {
      sourceOffsetY = destBand.getSceneRasterHeight() - (sourceOffsetY + sourceHeight);
    }
    if (mustFlipX) {
      sourceOffsetX = destBand.getSceneRasterWidth() - (sourceOffsetX + sourceWidth);
    }
    sourceOffsetY += leadLineSkip;
    start[0] = sourceOffsetY;
    start[1] = sourceOffsetX;
    stride[0] = sourceStepY;
    stride[1] = sourceStepX;
    count[0] = sourceHeight;
    count[1] = sourceWidth;
    Object buffer = destBuffer.getElems();
    Variable variable = variableMap.get(destBand);

    pm.beginTask("Reading band '" + variable.getShortName() + "'...", sourceHeight);
    try {
      Section section = new Section(start, count, stride);

      Array array;
      int[] newshape = {sourceHeight, sourceWidth};

      array = variable.read(section);
      if (array.getRank() == 3) {
        array = array.reshapeNoCopy(newshape);
      }
      Object storage;

      if (mustFlipX && !mustFlipY) {
        storage = array.flip(1).copyTo1DJavaArray();
      } else if (!mustFlipX && mustFlipY) {
        storage = array.flip(0).copyTo1DJavaArray();
      } else if (mustFlipX && mustFlipY) {
        storage = array.flip(0).flip(1).copyTo1DJavaArray();
      } else {
        storage = array.copyTo1DJavaArray();
      }

      arraycopy(storage, 0, buffer, 0, destBuffer.getNumElems());
    } finally {
      pm.done();
    }
  }
示例#16
0
  // Creates the appropriate <code>Product</code> for the current request and assembles a list of
  // <code>RsBands</code>
  // to be processed. This method does NOT load the tie point ADS because these are product
  // specific.
  private void loadInputProduct() throws IOException, ProcessorException {
    Request request = getRequest();
    Band band;
    Parameter bandParam;
    String[] bandNames;

    // clear vector of bands
    // ---------------------
    _inputBandList.clear();

    // only the first product - there might be more but these will be ignored
    // ----------------------------------------------------------------------
    _inputProduct = loadInputProduct(0);

    // check what product type the input is and load the appropriate tie point ADS
    // ---------------------------------------------------------------------------
    _sensorType = SmacUtils.getSensorType(_inputProduct.getProductType());
    if (ObjectUtils.equalObjects(_sensorType, SensorCoefficientManager.MERIS_NAME)) {
      loadMerisBitmaskExpression();
      loadMERIS_ADS(_inputProduct);
    } else if (ObjectUtils.equalObjects(_sensorType, SensorCoefficientManager.AATSR_NAME)) {
      loadAatsrBitmaskExpression();
      loadAATSR_ADS(_inputProduct);
      _useMerisADS = false; // then we must set this to false anyway
    } else {
      throw new ProcessorException(SmacConstants.LOG_MSG_UNSUPPORTED_SENSOR);
    }

    // set up the bands we need for this request
    // -----------------------------------------
    bandParam = request.getParameter(SmacConstants.BANDS_PARAM_NAME);
    checkParamNotNull(bandParam, "bands");
    bandNames = (String[]) bandParam.getValue();

    if ((bandNames == null) || (bandNames.length < 1)) {
      throw new ProcessorException(SmacConstants.LOG_MSG_NO_INPUT_BANDS);
    }

    for (String bandName : bandNames) {
      band = _inputProduct.getBand(bandName);
      if (band == null) {
        _logger.warning(
            "The requested band '" + bandName + "' is not contained in the input product!");
      } else {
        if (band.getSpectralBandIndex() != -1) {
          _inputBandList.add(band);
        } else {
          _logger.warning(
              "The requested band '"
                  + bandName
                  + "' is not a spectral band! It is excluded from processing");
        }
      }
    }
  }
示例#17
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);
   }
 }
示例#18
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");
    }
  }
  public static Product createDummySourceProduct(int width, int height) {
    Product product = new Product("dummy", "dummy", width, height);
    Band b = product.addBand("b1", ProductData.TYPE_FLOAT32);

    float[] bData = new float[width * height];
    for (int i = 0; i < width; i++) {
      for (int j = 0; j < height; j++) {
        bData[i * width + j] = 1.0f;
      }
    }
    b.setDataElems(bData);

    product.setPreferredTileSize(product.getSceneRasterWidth(), 45);

    return product;
  }
示例#20
0
 private void readBandRasterDataSubSampling(
     Band sourceBand,
     int sourceOffsetX,
     int sourceOffsetY,
     int sourceWidth,
     int sourceHeight,
     int sourceStepX,
     int sourceStepY,
     ProductData destBuffer,
     int destWidth,
     ProgressMonitor pm)
     throws IOException {
   final int sourceMinY = sourceOffsetY;
   final int sourceMaxY = sourceOffsetY + sourceHeight - 1;
   ProductData lineBuffer = ProductData.createInstance(destBuffer.getType(), sourceWidth);
   int destPos = 0;
   try {
     pm.beginTask("Reading sub sampled raster data...", 2 * (sourceMaxY - sourceMinY));
     for (int sourceY = sourceMinY; sourceY <= sourceMaxY; sourceY += sourceStepY) {
       sourceBand.readRasterData(
           sourceOffsetX, sourceY, sourceWidth, 1, lineBuffer, SubProgressMonitor.create(pm, 1));
       if (sourceStepX == 1) {
         copyData(lineBuffer, 0, destBuffer, destPos, destWidth);
       } else {
         copyLine(lineBuffer, 0, sourceWidth, sourceStepX, destBuffer, destPos);
       }
       pm.worked(1);
       destPos += destWidth;
     }
   } finally {
     pm.done();
   }
 }
示例#21
0
  /** Calls the given handler for all frames of the product the operator executor product. */
  public Object execute(Handler handler) throws Exception {
    int parallelism = Runtime.getRuntime().availableProcessors();
    System.out.println("parallelism = " + parallelism);
    JAI.getDefaultInstance().getTileScheduler().setParallelism(parallelism);
    Dimension frameSize = getFrameSize();
    int numXFrames = 1 + (product.getSceneRasterWidth() - 1) / frameSize.width;
    int numYFrames = 1 + (product.getSceneRasterHeight() - 1) / frameSize.height;

    Rectangle sceneRegion =
        new Rectangle(product.getSceneRasterWidth(), product.getSceneRasterHeight());

    for (int frameY = 0; frameY < numYFrames; frameY++) {
      for (int frameX = 0; frameX < numXFrames; frameX++) {

        Rectangle frameRegion =
            new Rectangle(
                    frameX * frameSize.width,
                    frameY * frameSize.height,
                    frameSize.width,
                    frameSize.height)
                .intersection(sceneRegion);

        int numBands = product.getNumBands();
        Band[] bandArray = new Band[numBands];
        ProductData[] dataArray = new ProductData[numBands];
        for (int b = 0; b < numBands; b++) {
          Band band = product.getBandAt(b);
          PlanarImage planarImage = band.getSourceImage();
          Point[] indices = planarImage.getTileIndices(null);
          System.out.println("indices = " + indices.length);
          TileRequest tileRequest = planarImage.queueTiles(indices);
          Raster raster = planarImage.getData();
          System.out.println("raster = " + raster);
          ProductData data = band.createCompatibleRasterData(frameRegion.width, frameRegion.height);
          band.readRasterData(
              frameRegion.x, frameRegion.y, frameRegion.width, frameRegion.height, data);
          bandArray[b] = band;
          dataArray[b] = data;
        }

        MyFrame frame = new MyFrame(frameRegion, bandArray, dataArray);
        handler.frameComputed(frame);
      }
    }

    return new Object();
  }
  private Element createXmlElement(final String version) {
    final List<Element> contentList = new ArrayList<Element>(16);
    contentList.add(createElement(DimapProductConstants.TAG_BAND_INDEX, "1"));
    contentList.add(createElement(DimapProductConstants.TAG_BAND_NAME, "filtered_coffee"));
    contentList.add(createElement(DimapProductConstants.TAG_BAND_DESCRIPTION, "with milk & sugar"));
    final String typeString = ProductData.getTypeString(_source.getGeophysicalDataType());
    contentList.add(createElement(DimapProductConstants.TAG_DATA_TYPE, typeString));
    contentList.add(createElement(DimapProductConstants.TAG_PHYSICAL_UNIT, "l"));
    contentList.add(createElement(DimapProductConstants.TAG_SOLAR_FLUX, "0.0"));
    contentList.add(createElement(DimapProductConstants.TAG_BAND_WAVELEN, "0.0"));
    contentList.add(createElement(DimapProductConstants.TAG_BANDWIDTH, "0.0"));
    contentList.add(createElement(DimapProductConstants.TAG_SCALING_FACTOR, "1.0"));
    contentList.add(createElement(DimapProductConstants.TAG_SCALING_OFFSET, "0.0"));
    contentList.add(createElement(DimapProductConstants.TAG_SCALING_LOG_10, "false"));
    contentList.add(createElement(DimapProductConstants.TAG_NO_DATA_VALUE_USED, "true"));
    contentList.add(
        createElement(
            DimapProductConstants.TAG_NO_DATA_VALUE,
            String.valueOf(_source.getGeophysicalNoDataValue())));
    final List<Element> filterBandInfoList = new ArrayList<Element>(5);
    filterBandInfoList.add(createElement(DimapProductConstants.TAG_FILTER_SOURCE, "anyBand"));
    filterBandInfoList.add(
        createElement(
            DimapProductConstants.TAG_FILTER_OPERATOR_CLASS_NAME,
            "org.esa.beam.framework.datamodel.GeneralFilterBand$Mean"));
    final Element filterBandInfo = new Element(DimapProductConstants.TAG_FILTER_BAND_INFO);
    filterBandInfo.setAttribute(
        GeneralFilterBandPersistable.ATTRIBUTE_BAND_TYPE,
        GeneralFilterBandPersistable.GENERAL_FILTER_BAND_TYPE);
    if (GeneralFilterBandPersistable.VERSION_1_1.equals(version)) {
      filterBandInfoList.add(createElement(DimapProductConstants.TAG_FILTER_SUB_WINDOW_SIZE, "5"));
      filterBandInfo.setAttribute(
          GeneralFilterBandPersistable.ATTRIBUTE_VERSION, GeneralFilterBandPersistable.VERSION_1_1);
    } else {
      // Version 1.0
      filterBandInfoList.add(createElement(DimapProductConstants.TAG_FILTER_SUB_WINDOW_WIDTH, "5"));
      filterBandInfoList.add(
          createElement(DimapProductConstants.TAG_FILTER_SUB_WINDOW_HEIGHT, "2"));
    }
    filterBandInfo.addContent(filterBandInfoList);
    contentList.add(filterBandInfo);

    final Element root = new Element(DimapProductConstants.TAG_SPECTRAL_BAND_INFO);
    root.setContent(contentList);
    return root;
  }
  /**
   * 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);
  }
示例#24
0
 protected void setSpectralBand(Product product) {
   int spectralBandIndex = 0;
   for (String name : product.getBandNames()) {
     Band band = product.getBandAt(product.getBandIndex(name));
     if (name.matches("\\w+_\\d{3,}")) {
       String[] parts = name.split("_");
       String wvlstr = parts[parts.length - 1].trim();
       // Some bands have the wvl portion in the middle...
       if (!wvlstr.matches("^\\d{3,}")) {
         wvlstr = parts[parts.length - 2].trim();
       }
       final float wavelength = Float.parseFloat(wvlstr);
       band.setSpectralWavelength(wavelength);
       band.setSpectralBandIndex(spectralBandIndex++);
     }
   }
 }
示例#25
0
  private Product createClostProduct(RenderedOp blueAerosolPanCirrusImage) {

    Product product =
        new Product(
            sourceProduct.getName() + "_clost",
            sourceProduct.getProductType() + " (clost)",
            sourceProduct.getSceneRasterWidth(),
            sourceProduct.getSceneRasterHeight());

    product.setGeoCoding(sourceProduct.getGeoCoding());
    product.setDescription("Product holding Clost Image");

    Band band = product.addBand(CLOST_BAND_NAME, ProductData.TYPE_FLOAT32);
    band.setSourceImage(blueAerosolPanCirrusImage);
    band.setUnit("dl");
    band.setDescription("CLOST Image: aerosol * blue * pan * cirrus ");

    return product;
  }
示例#26
0
 @Override
 public void decode(ProfileReadContext ctx, Product p) throws IOException {
   RasterDigest rasterDigest = ctx.getRasterDigest();
   final Variable[] variables = rasterDigest.getRasterVariables();
   for (Variable variable : variables) {
     final int rasterDataType = DataTypeUtils.getRasterDataType(variable);
     final Band band = p.addBand(variable.getShortName(), rasterDataType);
     CfBandPart.readCfBandAttributes(variable, band);
     band.setSourceImage(new NetcdfMultiLevelImage(band, variable, ctx));
   }
   ScaledVariable[] scaledVariables = rasterDigest.getScaledVariables();
   for (ScaledVariable scaledVariable : scaledVariables) {
     Variable variable = scaledVariable.getVariable();
     final int rasterDataType = DataTypeUtils.getRasterDataType(variable);
     final Band band = p.addBand(variable.getShortName(), rasterDataType);
     CfBandPart.readCfBandAttributes(variable, band);
     band.setSourceImage(new ScaledMultiLevelImage(band, scaledVariable, ctx));
   }
 }
  /**
   * 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);
 }
示例#29
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;
  }
示例#30
0
 private void readBandRasterDataRegion(
     Band sourceBand,
     int sourceOffsetX,
     int sourceOffsetY,
     int sourceWidth,
     int sourceHeight,
     ProductData destBuffer,
     ProgressMonitor pm)
     throws IOException {
   sourceBand.readRasterData(
       sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, destBuffer, pm);
 }