예제 #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;
  }
예제 #2
0
  private static void setSubsetSRGRCoefficients(
      final Product sourceProduct,
      final Product targetProduct,
      final ProductSubsetDef subsetDef,
      final MetadataElement absRoot,
      final boolean nearRangeOnLeft) {

    final MetadataElement SRGRCoefficientsElem = absRoot.getElement("SRGR_Coefficients");
    if (SRGRCoefficientsElem != null) {
      final double rangeSpacing = absRoot.getAttributeDouble("RANGE_SPACING", 0);
      final double colIndex = subsetDef.getRegion() == null ? 0 : subsetDef.getRegion().getX();

      for (MetadataElement srgrList : SRGRCoefficientsElem.getElements()) {
        final double grO = srgrList.getAttributeDouble("ground_range_origin", 0);
        double ground_range_origin_subset;
        if (nearRangeOnLeft) {
          ground_range_origin_subset = grO + colIndex * rangeSpacing;
        } else {
          final double colIndexFromRight =
              sourceProduct.getSceneRasterWidth() - colIndex - targetProduct.getSceneRasterWidth();
          ground_range_origin_subset = grO + colIndexFromRight * rangeSpacing;
        }
        srgrList.setAttributeDouble("ground_range_origin", ground_range_origin_subset);
      }
    }
  }
예제 #3
0
  public void testViewMode() {
    MaskTableModel maskTableModel = new MaskTableModel(false);
    assertEquals(false, maskTableModel.isInManagmentMode());
    assertEquals(4, maskTableModel.getColumnCount());
    assertEquals("Name", maskTableModel.getColumnName(0));
    assertEquals("Colour", maskTableModel.getColumnName(1));
    assertEquals("Transparency", maskTableModel.getColumnName(2));
    assertEquals("Description", maskTableModel.getColumnName(3));
    assertEquals(0, maskTableModel.getRowCount());

    Product product = MaskFormTest.createTestProduct();
    maskTableModel.setProduct(product, null);
    assertEquals(false, maskTableModel.isInManagmentMode());
    assertEquals(4, maskTableModel.getColumnCount());
    assertEquals("Name", maskTableModel.getColumnName(0));
    assertEquals("Colour", maskTableModel.getColumnName(1));
    assertEquals("Transparency", maskTableModel.getColumnName(2));
    assertEquals("Description", maskTableModel.getColumnName(3));
    assertEquals(10, maskTableModel.getRowCount());

    maskTableModel.setProduct(product, product.getBand("C"));
    assertEquals(false, maskTableModel.isInManagmentMode());
    assertEquals(5, maskTableModel.getColumnCount());
    assertEquals("Visibility", maskTableModel.getColumnName(0));
    assertEquals("Name", maskTableModel.getColumnName(1));
    assertEquals("Colour", maskTableModel.getColumnName(2));
    assertEquals("Transparency", maskTableModel.getColumnName(3));
    assertEquals("Description", maskTableModel.getColumnName(4));
    assertEquals(10, maskTableModel.getRowCount());
  }
예제 #4
0
  static void addBitmaskDefinitions(final Product product, final String flagsBandName) {
    for (final Flags flag : Flags.values()) {
      final String name =
          new StringBuilder(flagsBandName.split("flags")[0]).append(flag.name()).toString();

      final ProductNodeGroup<Mask> maskGroup = product.getMaskGroup();
      if (maskGroup.contains(name)) {
        continue;
      }

      final String expression =
          new StringBuilder(flagsBandName).append(".").append(flag.name()).toString();
      final int width = product.getSceneRasterWidth();
      final int height = product.getSceneRasterHeight();
      Mask mask =
          Mask.BandMathsType.create(
              name,
              flag.getDescription(),
              width,
              height,
              expression,
              flag.getColor(),
              flag.getTransparency());
      maskGroup.add(mask);
    }
  }
예제 #5
0
 @Override
 public boolean accept(Product sourceProduct) {
   final ProductData.UTC productStartTime = sourceProduct.getStartTime();
   final ProductData.UTC productEndTime = sourceProduct.getEndTime();
   final boolean hasStartTime = productStartTime != null;
   final boolean hasEndTime = productEndTime != null;
   final GeoCoding geoCoding = sourceProduct.getGeoCoding();
   if (geoCoding == null || !geoCoding.canGetGeoPos()) {
     return false;
   } else if (startTime != null
       && hasStartTime
       && productStartTime.getAsDate().after(startTime.getAsDate())
       && endTime != null
       && hasEndTime
       && productEndTime.getAsDate().before(endTime.getAsDate())) {
     return true;
   } else if (!hasStartTime && !hasEndTime) {
     return true;
   } else if (startTime != null
       && hasStartTime
       && productStartTime.getAsDate().after(startTime.getAsDate())
       && !hasEndTime) {
     return true;
   } else if (!hasStartTime
       && endTime != null
       && productEndTime.getAsDate().before(endTime.getAsDate())) {
     return true;
   } else {
     return false;
   }
 }
예제 #6
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;
  }
  private float getAvePixel(Tile inputTile, int iTarX, int iTarY) {

    double value = 0;
    double noDataValue = 0;
    int n = 0;

    final int minX = Math.max(0, iTarX - aveBlock);
    final int minY = Math.max(0, iTarY - aveBlock);
    final int maxX = Math.min(synergyProduct.getSceneRasterWidth() - 1, iTarX + aveBlock);
    final int maxY = Math.min(synergyProduct.getSceneRasterHeight() - 1, iTarY + aveBlock);

    for (int iy = minY; iy <= maxY; iy++) {
      for (int ix = minX; ix <= maxX; ix++) {
        final double val = inputTile.getSampleDouble(ix, iy);
        noDataValue = inputTile.getRasterDataNode().getNoDataValue();
        final boolean valid = (Double.compare(val, noDataValue) != 0);
        if (valid) {
          n++;
          value += val;
        }
      }
    }
    if (!(n < minNAve)) {
      value /= n;
    } else {
      value = noDataValue;
    }

    return (float) value;
  }
  @Override
  protected void onApply() {
    if (!canApply()) {
      return;
    }

    String productDir = targetProductSelector.getModel().getProductDir().getAbsolutePath();
    appContext
        .getPreferences()
        .setPropertyString(BasicApp.PROPERTY_KEY_APP_LAST_SAVE_DIR, productDir);

    Product targetProduct = null;
    try {
      targetProduct = createTargetProduct();
      if (targetProduct == null) {
        // throw new NullPointerException("Target product is null.");
      }
    } catch (Throwable t) {
      handleInitialisationError(t);
    }
    if (targetProduct == null) {
      return;
    }

    targetProduct.setName(targetProductSelector.getModel().getProductName());
    if (targetProductSelector.getModel().isSaveToFileSelected()) {
      targetProduct.setFileLocation(targetProductSelector.getModel().getProductFile());
      final ProgressMonitorSwingWorker worker = new ProductWriterWorker(targetProduct);
      // worker.executeWithBlocking();
      worker.execute();
    } else if (targetProductSelector.getModel().isOpenInAppSelected()) {
      appContext.getProductManager().addProduct(targetProduct);
      showOpenInAppInfo();
    }
  }
예제 #9
0
  @Override
  protected void addCustomMetadata(Product product) throws IOException {
    // add bitmasks for ATSR active fires, see http://dup.esrin.esa.it/ionia/wfa/algorithm.asp
    final String nadirBand = EnvisatConstants.AATSR_L1B_BTEMP_NADIR_0370_BAND_NAME;
    final String fwardBand = EnvisatConstants.AATSR_L1B_BTEMP_FWARD_0370_BAND_NAME;

    ProductNodeGroup<Mask> maskGroup = product.getMaskGroup();
    if (product.containsBand(nadirBand)) {
      maskGroup.add(
          mask(
              "fire_nadir_1", "ATSR active fire (ALGO1)", nadirBand + " > 312.0", Color.RED, 0.5f));
      maskGroup.add(
          mask(
              "fire_nadir_2",
              "ATSR active fire (ALGO2)",
              nadirBand + " > 308.0",
              Color.RED.darker(),
              0.5f));
    }
    if (product.containsBand(fwardBand)) {
      maskGroup.add(
          mask(
              "fire_fward_1", "ATSR active fire (ALGO1)", fwardBand + " > 312.0", Color.RED, 0.5f));
      maskGroup.add(
          mask(
              "fire_fward_2",
              "ATSR active fire (ALGO2)",
              fwardBand + " > 308.0",
              Color.RED.darker(),
              0.5f));
    }
  }
  /** 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();
  }
예제 #11
0
  /**
   * Provides an implementation of the <code>readProductNodes</code> interface method. Clients
   * implementing this method can be sure that the input object and eventually the subset
   * information has already been set.
   *
   * <p>
   *
   * <p>This method is called as a last step in the <code>readProductNodes(input, subsetInfo)</code>
   * method.
   *
   * @throws java.io.IOException if an I/O error occurs
   */
  @Override
  protected Product readProductNodesImpl() throws IOException {

    Product product;
    try {
      final File fileFromInput = ReaderUtils.getFileFromInput(getInput());
      dataDir = createDirectory(fileFromInput);
      dataDir.readProductDirectory();
      product = dataDir.createProduct();
      addCalibrationLUT(product, fileFromInput.getParentFile());
      product.getGcpGroup();
      product.setFileLocation(fileFromInput);
      product.setProductReader(this);
      product.setModified(false);

      final MetadataElement absRoot = AbstractMetadata.getAbstractedMetadata(product);
      isAscending = absRoot.getAttributeString(AbstractMetadata.PASS).equals("ASCENDING");
      isAntennaPointingRight =
          absRoot.getAttributeString(AbstractMetadata.antenna_pointing).equals("right");
    } catch (Exception e) {
      Debug.trace(e.toString());
      final IOException ioException = new IOException(e.getMessage());
      ioException.initCause(e);
      throw ioException;
    }

    return product;
  }
예제 #12
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);
   }
 }
  /**
   * @param inputProduct
   * @param instr
   * @param bandList
   */
  public static void getGeometryBandList(
      Product inputProduct, String instr, ArrayList<RasterDataNode> bandList) {
    final String[] viewArr = {"nadir", "fward"};
    int nView = viewArr.length;
    final String[] bodyArr = {"sun", "view"};
    final String[] angArr = {"elev", "azimuth"};
    String bandName;

    if (instr.equals("MERIS")) {
      angArr[0] = "zenith";
      nView = 1;
    }
    for (int iView = 0; iView < nView; iView++) {
      for (String body : bodyArr) {
        for (String ang : angArr) {
          if (instr.equals("AATSR")) {
            bandName =
                body
                    + "_"
                    + ang
                    + "_"
                    + viewArr[iView]
                    + "_"
                    + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR;
            bandList.add(inputProduct.getBand(bandName));
          } else {
            bandName = body + "_" + ang;
            bandList.add(inputProduct.getRasterDataNode(bandName));
          }
        }
      }
    }
  }
예제 #14
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);
    }
  }
  /**
   * This method copies selected tie point grids to a rescaled target product
   *
   * @param sourceProduct - the source product
   * @param targetProduct - the target product
   * @param xScalingFactor - scaling factor in x-direction
   * @param yScalingFactor - scaling factor in y-direction
   */
  public static void copyRescaledTiePointGrids(
      Product sourceProduct, Product targetProduct, int xScalingFactor, int yScalingFactor) {
    // Add tie point grids for sun/view zenith/azimuths. Get data from AATSR bands.
    final Band szaBand =
        sourceProduct.getBand("sun_elev_nadir_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR);
    final Band saaBand =
        sourceProduct.getBand("sun_azimuth_nadir_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR);
    final Band latitudeBand =
        sourceProduct.getBand("latitude_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR);
    final Band longitudeBand =
        sourceProduct.getBand("longitude_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR);
    final Band altitudeBand =
        sourceProduct.getBand("altitude_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR);

    final TiePointGrid szaTpg = getRescaledTpgFromBand(szaBand, xScalingFactor, yScalingFactor);
    targetProduct.addTiePointGrid(szaTpg);
    final TiePointGrid saaTpg = getRescaledTpgFromBand(saaBand, xScalingFactor, yScalingFactor);
    targetProduct.addTiePointGrid(saaTpg);
    final TiePointGrid latTpg =
        getRescaledTpgFromBand(latitudeBand, xScalingFactor, yScalingFactor);
    targetProduct.addTiePointGrid(latTpg);
    final TiePointGrid lonTpg =
        getRescaledTpgFromBand(longitudeBand, xScalingFactor, yScalingFactor);
    targetProduct.addTiePointGrid(lonTpg);
    final TiePointGrid altTpg =
        getRescaledTpgFromBand(altitudeBand, xScalingFactor, yScalingFactor);
    targetProduct.addTiePointGrid(altTpg);
  }
예제 #16
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);
  }
예제 #18
0
 private ProductNodeSubsetPane createBandSubsetPane() {
   Band[] bands = product.getBands();
   if (bands.length == 0) {
     return null;
   }
   return new ProductNodeSubsetPane(product.getBands(), true);
 }
예제 #19
0
  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);
  }
예제 #20
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;
  }
예제 #21
0
 /**
  * Creates the target product instance. Called by {@link #initialize()}.
  *
  * <p>The default implementation creates a target product instance given the raster size of the
  * (first) source product.
  *
  * @return A new target product instance.
  * @throws OperatorException If the target product cannot be created.
  */
 protected Product createTargetProduct() throws OperatorException {
   Product sourceProduct = getSourceProduct();
   return new Product(
       getId(),
       getClass().getName(),
       sourceProduct.getSceneRasterWidth(),
       sourceProduct.getSceneRasterHeight());
 }
 /**
  * Adds a land mask sample definition to a configurator used in a point operator
  *
  * @param configurator - the configurator
  * @param index - the sample index
  * @param sourceProduct - the source product
  */
 public static void setSeaiceMaskSourceSample(
     SampleConfigurer configurator, int index, Product sourceProduct) {
   BandMathsOp seaiceOp =
       BandMathsOp.createBooleanExpressionBand(
           AlbedoInversionConstants.seaiceMaskExpression, sourceProduct);
   Product seaiceProduct = seaiceOp.getTargetProduct();
   configurator.defineSample(index, seaiceProduct.getBandAt(0).getName(), seaiceProduct);
 }
예제 #23
0
 private static String getProductLocation(Product product) {
   final File fileLocation = product.getFileLocation();
   if (fileLocation != null) {
     return fileLocation.getAbsolutePath();
   } else {
     return String.format("Not saved to disk [%s]", product.getName());
   }
 }
예제 #24
0
 private void writeGeoCoding() throws IOException {
   final Product product = getSourceProduct();
   if (product.getGeoCoding() instanceof TiePointGeoCoding) {
     writeGeoCoding((TiePointGeoCoding) product.getGeoCoding());
   } else if (product.getGeoCoding() instanceof MapGeoCoding) {
     writeGeoCoding((MapGeoCoding) product.getGeoCoding());
   }
 }
예제 #25
0
 @Override
 public void decode(Modis35ProfileReadContext ctx, Product p) throws IOException {
   NetcdfFile ncFile = ctx.getNetcdfFile();
   p.setStartTime(
       TimeUtils.getSceneRasterTime(
           ncFile, Modis35Constants.START_DATE_ATT_NAME, Modis35Constants.START_TIME_ATT_NAME));
   p.setEndTime(
       TimeUtils.getSceneRasterTime(
           ncFile, Modis35Constants.STOP_DATE_ATT_NAME, Modis35Constants.STOP_TIME_ATT_NAME));
 }
예제 #26
0
 private ProductNodeSubsetPane createTiePointGridSubsetPane() {
   TiePointGrid[] tiePointGrids = product.getTiePointGrids();
   if (tiePointGrids.length == 0) {
     return null;
   }
   return new ProductNodeSubsetPane(
       product.getTiePointGrids(),
       new String[] {BeamConstants.LAT_DS_NAME, BeamConstants.LON_DS_NAME},
       true);
 }
    @Override
    protected Product doInBackground(com.bc.ceres.core.ProgressMonitor pm) throws Exception {
      final TargetProductSelectorModel model = getTargetProductSelector().getModel();
      pm.beginTask("Writing...", model.isOpenInAppSelected() ? 100 : 95);
      ProgressMonitorList.instance().add(pm); // NESTMOD
      saveTime = 0L;
      Product product = null;
      try {
        // free cache	// NESTMOD
        JAI.getDefaultInstance().getTileCache().flush();
        System.gc();

        executeStartTime = Calendar.getInstance().getTime();
        long t0 = System.currentTimeMillis();
        Operator operator = null;
        if (targetProduct.getProductReader() instanceof OperatorProductReader) {
          final OperatorProductReader opReader =
              (OperatorProductReader) targetProduct.getProductReader();
          if (opReader.getOperatorContext().getOperator() instanceof Output) {
            operator = opReader.getOperatorContext().getOperator();
          }
        }
        if (operator == null) {
          WriteOp writeOp =
              new WriteOp(targetProduct, model.getProductFile(), model.getFormatName());
          writeOp.setDeleteOutputOnFailure(true);
          writeOp.setWriteEntireTileRows(true);
          writeOp.setClearCacheAfterRowWrite(false);
          operator = writeOp;
        }
        final OperatorExecutor executor = OperatorExecutor.create(operator);
        executor.execute(SubProgressMonitor.create(pm, 95));

        saveTime = System.currentTimeMillis() - t0;
        File targetFile = model.getProductFile();
        if (model.isOpenInAppSelected() && targetFile.exists()) {
          product = ProductIO.readProduct(targetFile);
          if (product == null) {
            product = targetProduct; // todo - check - this cannot be ok!!! (nf)
          }
          pm.worked(5);
        }
      } finally {
        // free cache
        JAI.getDefaultInstance().getTileCache().flush();
        System.gc();

        pm.done();
        ProgressMonitorList.instance().remove(pm); // NESTMOD
        if (product != targetProduct) {
          targetProduct.dispose();
        }
      }
      return product;
    }
  /**
   * This method copies selected tie point grids to a downscaled target product
   *
   * @param sourceProduct - the source product
   * @param targetProduct - the target product
   * @param scalingFactor - factor of downscaling
   */
  public static void copyDownscaledTiePointGrids(
      Product sourceProduct, Product targetProduct, float scalingFactor) {
    // Add tie point grids for sun/view zenith/azimuths. Get data from AATSR bands.
    final Band szaBand =
        sourceProduct.getBand("sun_elev_nadir_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR);
    final Band saaBand =
        sourceProduct.getBand("sun_azimuth_nadir_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR);
    final Band latitudeBand =
        sourceProduct.getBand("latitude_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR);
    final Band longitudeBand =
        sourceProduct.getBand("longitude_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR);
    final Band altitudeBand =
        sourceProduct.getBand("altitude_" + SynergyConstants.INPUT_BANDS_SUFFIX_AATSR);

    final Band szaDownscaledBand = downscaleBand(szaBand, scalingFactor);
    final Band saaDownscaledBand = downscaleBand(saaBand, scalingFactor);
    final Band latitudeDownscaledBand = downscaleBand(latitudeBand, scalingFactor);
    final Band longitudeDownscaledBand = downscaleBand(longitudeBand, scalingFactor);
    final Band altitudeDownscaledBand = downscaleBand(altitudeBand, scalingFactor);

    addTpg(targetProduct, szaDownscaledBand, "sun_zenith");
    addTpg(targetProduct, saaDownscaledBand, "sun_azimuth");
    // unscaled latitude/longitude TPGs were added by 'copyGeoCoding', we have to remove them before
    // downscaling
    targetProduct.removeTiePointGrid(targetProduct.getTiePointGrid("latitude"));
    targetProduct.removeTiePointGrid(targetProduct.getTiePointGrid("longitude"));
    addTpg(targetProduct, latitudeDownscaledBand, "latitude");
    addTpg(targetProduct, longitudeDownscaledBand, "longitude");
    addTpg(targetProduct, altitudeDownscaledBand, "altitude");
  }
예제 #29
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");
        }
      }
    }
  }
예제 #30
0
 private MetadataElement getMetadataElementSave(Product product, String name) {
   final MetadataElement metadataElement = product.getMetadataRoot().getElement(name);
   final MetadataElement namedElem;
   if (metadataElement == null) {
     namedElem = new MetadataElement(name);
     product.getMetadataRoot().addElement(namedElem);
   } else {
     namedElem = metadataElement;
   }
   return namedElem;
 }