Beispiel #1
0
  @Override
  public Product createProduct() throws IOException {

    sceneHeight =
        ncFile.getRootGroup().findGroup("Level-3_Binned_Data").findVariable("BinIndex").getShape(0);
    sceneWidth = sceneHeight * 2;

    grid = new ISINGrid(sceneHeight);

    String productName = getStringAttribute("Product_Name");

    Product product =
        new Product(productName, "NASA-OBPG-L3", sceneWidth, sceneHeight, productReader);
    product.setFileLocation(productReader.getInputFile());
    product.setProductReader(productReader);

    addGlobalMetadata(product);

    final Variable idxVariable =
        ncFile.getRootGroup().findGroup("Level-3_Binned_Data").findVariable("BinList");
    List<Variable> l3ProdVars = ncFile.getVariables();
    variableMap = addBands(product, idxVariable, l3ProdVars);
    //        try {
    //            addBandsBinMap(product);
    //        } catch (InvalidRangeException e) {
    //            e.printStackTrace();
    //        }
    if (product.getNumBands() == 0) {
      throw new ProductIOException("No bands found.");
    }

    initGeoCoding(product);

    return product;
  }
Beispiel #2
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 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);
        }
      }
    }
  }