예제 #1
0
 private static ParamGroup createDefaultParamGroup(final InputProductValidator validator) {
   final ParamGroup paramGroup = new ParamGroup();
   final DefaultRequestElementFactory factory = DefaultRequestElementFactory.getInstance();
   final Parameter inputProductParameter = factory.createDefaultInputProductParameter();
   inputProductParameter.addParamChangeListener(
       new ParamChangeListener() {
         public void parameterValueChanged(final ParamChangeEvent event) {
           validateInputProduct(event.getParameter(), validator);
         }
       });
   paramGroup.addParameter(inputProductParameter);
   final Parameter outputProductParameter = factory.createDefaultOutputProductParameter();
   final Object defaultValue = outputProductParameter.getProperties().getDefaultValue();
   if (defaultValue instanceof File) {
     outputProductParameter
         .getProperties()
         .setDefaultValue(new File((File) defaultValue, _defaultOutputProductFileName));
   }
   paramGroup.addParameter(outputProductParameter);
   paramGroup.addParameter(factory.createOutputFormatParameter());
   paramGroup.addParameter(factory.createDefaultLogPatternParameter(_defaultLogPrefix));
   try {
     paramGroup.addParameter(factory.createLogToOutputParameter(_defaultLogToOutput));
   } catch (ParamValidateException e) {
     Debug.trace("Unable to validate parameter '" + LOG_TO_OUTPUT_PARAM_NAME + "'"); /*I18N*/
     Debug.trace(e);
   }
   return paramGroup;
 }
예제 #2
0
  /**
   * Activates the given <code>PageComponent</code>. Does nothing if it is already the active one.
   *
   * <p>Does nothing if this <code>ApplicationPage</code> doesn't contain the given <code>
   * PageComponent</code>.
   *
   * @param pageComponent the <code>PageComponent</code>
   */
  public void setActiveComponent(PageComponent pageComponent) {
    if (!pageComponentMap.containsValue(pageComponent)) {
      return;
    }

    Debug.trace("setActiveComponent: pageComponent = " + pageComponent);
    if (settingActiveComponent) {
      return;
    }

    // if pageComponent is already active, don't do anything
    if (this.activeComponent == pageComponent) {
      setActiveSelectionContext();
      return;
    }

    settingActiveComponent = true;

    if (this.activeComponent != null) {
      fireFocusLost(this.activeComponent);
    }
    giveFocusTo(pageComponent);
    this.activeComponent = pageComponent;
    fireFocusGained(this.activeComponent);

    setActiveSelectionContext();

    settingActiveComponent = false;
  }
예제 #3
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;
  }
예제 #4
0
 private void createScalarAttribute(
     int locationID, String name, int jh5DataType, int typeSize, Object value) throws IOException {
   Debug.trace(
       "Hdf5ProductWriter.createScalarAttribute("
           + "locationID="
           + locationID
           + ", name="
           + name
           + ", jh5DataType="
           + jh5DataType
           + ", typeSize="
           + typeSize
           + ", value="
           + value
           + ")");
   int attrTypeID = -1;
   int attrSpaceID = -1;
   int attributeID = -1;
   try {
     attrTypeID = H5.H5Tcopy(jh5DataType);
     if (typeSize > 0) {
       H5.H5Tset_size(attrTypeID, typeSize);
     }
     attrSpaceID = H5.H5Screate(HDF5Constants.H5S_SCALAR);
     attributeID =
         H5.H5Acreate(locationID, name, attrTypeID, attrSpaceID, HDF5Constants.H5P_DEFAULT);
     H5.H5Awrite(attributeID, attrTypeID, value);
   } catch (HDF5Exception e) {
     throw new ProductIOException(createErrorMessage(e));
   } finally {
     closeH5A(attributeID);
     closeH5S(attrSpaceID);
     closeH5T(attrTypeID);
   }
 }
예제 #5
0
    private BufferedImage createThumbNailImage(Dimension imgSize, ProgressMonitor pm) {
      Assert.notNull(pm, "pm");

      String thumbNailBandName = getThumbnailBandName();
      Band thumbNailBand = product.getBand(thumbNailBandName);

      Debug.trace(
          "ProductSubsetDialog: Reading thumbnail data for band '" + thumbNailBandName + "'...");
      pm.beginTask("Creating thumbnail image", 5);
      BufferedImage image = null;
      try {
        MultiLevelSource multiLevelSource =
            BandImageMultiLevelSource.create(thumbNailBand, SubProgressMonitor.create(pm, 1));
        final ImageLayer imageLayer = new ImageLayer(multiLevelSource);
        final int imageWidth = imgSize.width;
        final int imageHeight = imgSize.height;
        final int imageType = BufferedImage.TYPE_3BYTE_BGR;
        image = new BufferedImage(imageWidth, imageHeight, imageType);
        Viewport snapshotVp = new DefaultViewport(isModelYAxisDown(imageLayer));
        final BufferedImageRendering imageRendering = new BufferedImageRendering(image, snapshotVp);

        final Graphics2D graphics = imageRendering.getGraphics();
        graphics.setColor(getBackground());
        graphics.fillRect(0, 0, imageWidth, imageHeight);

        snapshotVp.zoom(imageLayer.getModelBounds());
        snapshotVp.moveViewDelta(snapshotVp.getViewBounds().x, snapshotVp.getViewBounds().y);
        imageLayer.render(imageRendering);

        pm.worked(4);
      } finally {
        pm.done();
      }
      return image;
    }
예제 #6
0
 protected void fireClosed(PageComponent component) {
   Debug.trace("AbstractApplicationPage.fireClosed [" + component + "]");
   component.componentClosed();
   for (PageComponentListener listener : pageComponentListeners) {
     listener.componentClosed(component);
   }
 }
예제 #7
0
 protected void fireFocusLost(PageComponent component) {
   Debug.trace("AbstractApplicationPage.fireFocusLost [" + component + "]");
   component.componentFocusLost();
   for (PageComponentListener listener : pageComponentListeners) {
     listener.componentFocusLost(component);
   }
 }
예제 #8
0
  /**
   * Creates a parameter editor instance for the given parameter.
   *
   * @param parameter the parameter
   * @return the parameter editor, never null
   */
  public static ParamEditor createParamEditor(Parameter parameter) {
    Guardian.assertNotNull("parameter", parameter);
    ParamProperties paramProps = parameter.getProperties();
    Debug.assertNotNull(paramProps);

    ParamEditor editor = null;

    // Step 1: Try to create an editor from the 'editorClass' property
    //
    Class editorClass = paramProps.getEditorClass();
    if (editorClass != null) {
      Constructor editorConstructor = null;
      try {
        editorConstructor = editorClass.getConstructor(Parameter.class);
      } catch (NoSuchMethodException e) {
        Debug.trace(e);
      } catch (SecurityException e) {
        Debug.trace(e);
      }
      if (editorConstructor != null) {
        try {
          editor = (ParamEditor) editorConstructor.newInstance(parameter);
        } catch (InstantiationException e) {
          Debug.trace(e);
        } catch (IllegalAccessException e) {
          Debug.trace(e);
        } catch (IllegalArgumentException e) {
          Debug.trace(e);
        } catch (InvocationTargetException e) {
          Debug.trace(e);
        }
      }
    }
    if (editor != null) {
      return editor;
    }

    // Step 2: Create a default editor based on the parameter's type info
    //
    if (parameter.isTypeOf(Boolean.class)) {
      editor = new BooleanEditor(parameter);
    } else if (parameter.isTypeOf(Color.class)) {
      editor = new ColorEditor(parameter);
    } else if (parameter.isTypeOf(File.class)) {
      editor = new FileEditor(parameter);
    } else if (paramProps.getValueSet() != null && paramProps.getValueSet().length > 0) {
      if (parameter.isTypeOf(String[].class)) {
        editor = new ListEditor(parameter);
      } else {
        editor = new ComboBoxEditor(parameter);
      }
    }

    // The last choice works always: a text field!
    if (editor == null) {
      editor = new TextFieldEditor(parameter);
    }

    return editor;
  }
예제 #9
0
 private void closeH5S(int spaceID) {
   if (spaceID != -1) {
     try {
       H5.H5Sclose(spaceID);
     } catch (HDF5LibraryException e) {
       Debug.trace(e);
       /*...*/
     }
   }
 }
예제 #10
0
 private void closeH5D(int datasetID) {
   if (datasetID != -1) {
     try {
       H5.H5Dclose(datasetID);
     } catch (HDF5LibraryException e) {
       Debug.trace(e);
       /*...*/
     }
   }
 }
예제 #11
0
 private void closeH5A(int attributeID) {
   if (attributeID != -1) {
     try {
       H5.H5Aclose(attributeID);
     } catch (HDF5LibraryException e) {
       Debug.trace(e);
       /*...*/
     }
   }
 }
예제 #12
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;
  }
예제 #13
0
 private void closeH5T(int typeID) {
   if (typeID != -1) {
     try {
       H5.H5Tclose(typeID);
     } catch (HDF5LibraryException e) {
       Debug.trace(e);
       /*...*/
     }
   }
 }
예제 #14
0
 private void closeH5G(int groupID) {
   if (groupID != -1) {
     try {
       H5.H5Gclose(groupID);
     } catch (HDF5LibraryException e) {
       Debug.trace(e);
       /*...*/
     }
   }
 }
예제 #15
0
  private void writeTiePointGrid(TiePointGrid grid, String path) throws IOException {
    final int w = grid.getRasterWidth();
    final int h = grid.getRasterHeight();
    long[] dims = new long[] {h, w};
    int dataTypeID = -1;
    int dataSpaceID = -1;
    int datasetID = -1;
    try {
      dataTypeID = createH5TypeID(grid.getDataType());
      dataSpaceID = H5.H5Screate_simple(2, dims, null);
      datasetID =
          H5.H5Dcreate(
              _fileID,
              path + "/" + grid.getName(),
              dataTypeID,
              dataSpaceID,
              HDF5Constants.H5P_DEFAULT);

      // Very important attributes
      createScalarAttribute(datasetID, "scene_raster_width", grid.getSceneRasterWidth());
      createScalarAttribute(datasetID, "scene_raster_height", grid.getSceneRasterHeight());
      createScalarAttribute(datasetID, "offset_x", grid.getOffsetX());
      createScalarAttribute(datasetID, "offset_y", grid.getOffsetY());
      createScalarAttribute(datasetID, "sub_sampling_x", grid.getSubSamplingX());
      createScalarAttribute(datasetID, "sub_sampling_y", grid.getSubSamplingY());

      // Less important attributes
      try {
        createScalarAttribute(datasetID, "raster_width", grid.getRasterWidth());
        createScalarAttribute(datasetID, "raster_height", grid.getRasterHeight());
        createScalarAttribute(datasetID, "unit", grid.getUnit());
        createScalarAttribute(datasetID, "description", grid.getDescription());
        createScalarAttribute(datasetID, "CLASS", "IMAGE");
        createScalarAttribute(datasetID, "IMAGE_VERSION", 1.0F);
      } catch (IOException e) {
        /* ignore IOException because these attributes are not very essential... */
        Debug.trace("failed to create attribute: " + e.getMessage());
      }

      H5.H5Dwrite(
          datasetID,
          dataTypeID,
          HDF5Constants.H5S_ALL,
          HDF5Constants.H5S_ALL,
          HDF5Constants.H5P_DEFAULT,
          grid.getData().getElems());

    } catch (HDF5Exception e) {
      throw new ProductIOException(createErrorMessage(e));
    } finally {
      closeH5D(datasetID);
      closeH5S(dataSpaceID);
      closeH5T(dataTypeID);
    }
  }
예제 #16
0
  /**
   * Writes the in-memory representation of a data product. This method was called by <code>
   * writeProductNodes(product,
   * output)</code> of the AbstractProductWriter.
   *
   * @throws IllegalArgumentException if <code>output</code> type is not one of the supported output
   *     sources.
   * @throws IOException if an I/O error occurs
   */
  @Override
  protected void writeProductNodesImpl() throws IOException {

    if (!_hdf5LibInit) {
      try {
        H5.H5open();
        _hdf5LibInit = true;
      } catch (HDF5LibraryException e) {
        throw new ProductIOException(createErrorMessage(e));
      }
    }

    if (getOutput() instanceof String) {
      _outputFile = new File((String) getOutput());
    } else if (getOutput() instanceof File) {
      _outputFile = (File) getOutput();
    }
    Debug.assertNotNull(_outputFile); // super.writeProductNodes should have checked this already

    _outputFile =
        FileUtils.ensureExtension(_outputFile, Hdf5ProductWriterPlugIn.HDF5_FILE_EXTENSION);

    try {
      Debug.trace("creating HDF5 file " + _outputFile.getPath());
      _fileID =
          H5.H5Fcreate(
              _outputFile.getPath(),
              HDF5Constants.H5F_ACC_TRUNC,
              HDF5Constants.H5P_DEFAULT,
              HDF5Constants.H5P_DEFAULT);
    } catch (HDF5LibraryException e) {
      throw new ProductIOException(createErrorMessage(e));
    }

    writeTiePointGrids();
    writeGeoCoding();
    writeFlagCodings();
    writeMetadata();
  }
예제 #17
0
 public static String getDefaultOFileNameFromIFile(String ifileName, String programName) {
   debug("Program name is " + programName);
   Debug.assertNotNull(ifileName);
   ProcessorTypeInfo.ProcessorID processorID = ProcessorTypeInfo.getProcessorID(programName);
   String ofileName = ifileName + "_" + programName + ".out";
   switch (processorID) {
     case EXTRACTOR:
       ofileName = ifileName + ".sub";
       break;
     case MODIS_L1A_PY:
       // FileUtils.exchangeExtension(ifileName, "GEO") ;
       break;
     case MODIS_GEO_PY:
       ofileName = ifileName.replaceAll("L1A_LAC", "GEO");
       break;
     case L1BGEN:
       ofileName = ifileName.replaceAll("L1A", "L1B");
       break;
     case MODIS_L1B_PY:
       ofileName = ifileName.replaceAll("L1A", "L1B");
       break;
     case L1BRSGEN:
       ofileName = ifileName + ".BRS";
       break;
     case L2BRSGEN:
       ofileName = ifileName + ".BRS";
       break;
     case L1MAPGEN:
       ofileName = ifileName + "_" + programName + ".out";
       break;
     case L2MAPGEN:
       ofileName = ifileName + "_" + programName + ".out";
       break;
     case L2BIN:
       ofileName = ifileName.replaceAll("L2_.{3,}", "L3b_DAY");
       break;
     case L3BIN:
       ofileName = ifileName.replaceAll("L2_.{3,}", "L3b_DAY");
       break;
     case SMIGEN:
       ofileName = ifileName.replaceAll("L3B", "L3m");
       ofileName = ofileName.replaceAll("L3b", "L3m");
       ofileName = ofileName.replaceAll(".main", "");
       break;
     case SMITOPPM:
       ofileName = ifileName.trim().length() > 0 ? ifileName + ".ppm" : "";
       break;
   }
   return ofileName;
 }
예제 #18
0
 private static void copyLine(
     ProductData sourceBuffer,
     int sourceOffsetPos,
     int sourceWidth,
     int sourceStepX,
     ProductData destBuffer,
     int destOffsetPos) {
   final int sourceMinX = sourceOffsetPos;
   final int sourceMaxX = sourceOffsetPos + sourceWidth - 1;
   if (destBuffer.getElems() instanceof byte[]) {
     byte[] destArray = (byte[]) destBuffer.getElems();
     byte[] sourceArray = (byte[]) sourceBuffer.getElems();
     for (int sourceX = sourceMinX; sourceX <= sourceMaxX; sourceX += sourceStepX) {
       destArray[destOffsetPos] = sourceArray[sourceX];
       destOffsetPos++;
     }
   } else if (destBuffer.getElems() instanceof short[]) {
     short[] destArray = (short[]) destBuffer.getElems();
     short[] sourceArray = (short[]) sourceBuffer.getElems();
     for (int sourceX = sourceMinX; sourceX <= sourceMaxX; sourceX += sourceStepX) {
       destArray[destOffsetPos] = sourceArray[sourceX];
       destOffsetPos++;
     }
   } else if (destBuffer.getElems() instanceof int[]) {
     int[] destArray = (int[]) destBuffer.getElems();
     int[] sourceArray = (int[]) sourceBuffer.getElems();
     for (int sourceX = sourceMinX; sourceX <= sourceMaxX; sourceX += sourceStepX) {
       destArray[destOffsetPos] = sourceArray[sourceX];
       destOffsetPos++;
     }
   } else if (destBuffer.getElems() instanceof float[]) {
     float[] destArray = (float[]) destBuffer.getElems();
     float[] sourceArray = (float[]) sourceBuffer.getElems();
     for (int sourceX = sourceMinX; sourceX <= sourceMaxX; sourceX += sourceStepX) {
       destArray[destOffsetPos] = sourceArray[sourceX];
       destOffsetPos++;
     }
   } else if (destBuffer.getElems() instanceof double[]) {
     double[] destArray = (double[]) destBuffer.getElems();
     double[] sourceArray = (double[]) sourceBuffer.getElems();
     for (int sourceX = sourceMinX; sourceX <= sourceMaxX; sourceX += sourceStepX) {
       destArray[destOffsetPos] = sourceArray[sourceX];
       destOffsetPos++;
     }
   } else {
     Debug.assertTrue(false, "illegal product data type");
     throw new IllegalStateException("illegal product data type");
   }
 }
예제 #19
0
  private static RasterDataNode[] getReferencedNodes(final RasterDataNode node) {
    final Product product = node.getProduct();
    if (product != null) {
      final List<String> expressions = new ArrayList<String>(10);
      if (node.getValidPixelExpression() != null) {
        expressions.add(node.getValidPixelExpression());
      }
      final ProductNodeGroup<Mask> overlayMaskGroup = node.getOverlayMaskGroup();
      if (overlayMaskGroup.getNodeCount() > 0) {
        final Mask[] overlayMasks =
            overlayMaskGroup.toArray(new Mask[overlayMaskGroup.getNodeCount()]);
        for (final Mask overlayMask : overlayMasks) {
          final String expression;
          if (overlayMask.getImageType() == Mask.BandMathsType.INSTANCE) {
            expression = Mask.BandMathsType.getExpression(overlayMask);
          } else if (overlayMask.getImageType() == Mask.RangeType.INSTANCE) {
            expression = Mask.RangeType.getExpression(overlayMask);
          } else {
            expression = null;
          }
          if (expression != null) {
            expressions.add(expression);
          }
        }
      }
      if (node instanceof VirtualBand) {
        final VirtualBand virtualBand = (VirtualBand) node;
        expressions.add(virtualBand.getExpression());
      }

      final ArrayList<Term> termList = new ArrayList<Term>(10);
      for (final String expression : expressions) {
        try {
          final Term term = product.parseExpression(expression);
          if (term != null) {
            termList.add(term);
          }
        } catch (ParseException e) {
          // @todo se handle parse exception
          Debug.trace(e);
        }
      }

      final Term[] terms = termList.toArray(new Term[termList.size()]);
      final RasterDataSymbol[] refRasterDataSymbols = BandArithmetic.getRefRasterDataSymbols(terms);
      return BandArithmetic.getRefRasters(refRasterDataSymbols);
    }
    return new RasterDataNode[0];
  }
예제 #20
0
 private static void validateInputProduct(
     final Parameter parameter, final InputProductValidator validator) {
   final File file = (File) parameter.getValue();
   if (file == null || "".equals(file.getPath().trim())) {
     return;
   }
   String msg = null;
   if (file.exists()) {
     Product product = null;
     try {
       product = ProductIO.readProduct(file);
       if (product != null) {
         if (validator != null) {
           final boolean valid = validator.validate(product);
           if (!valid) {
             msg = validator.getErrorMessage();
             if (msg == null) {
               msg = "Unknown error.";
             }
           }
         }
       } else {
         msg = "Unknown product file format.";
       }
     } catch (IOException e) {
       msg = e.getMessage();
     } finally {
       if (product != null) {
         product.dispose();
       }
     }
   } else {
     msg = "File '" + file.getPath() + "' does not exists.";
   }
   if (msg != null) {
     JOptionPane.showMessageDialog(
         parameter.getEditor().getEditorComponent(),
         "Invalid input product file:\n" + msg,
         "Invalid Input Product",
         JOptionPane.ERROR_MESSAGE);
     Debug.trace(msg);
   }
 }
예제 #21
0
  /**
   * Reads a data product and returns a in-memory representation of it. This method was called by
   * <code>readProductNodes(input, subsetInfo)</code> of the abstract superclass.
   *
   * @throws IllegalArgumentException if <code>input</code> type is not one of the supported input
   *     sources.
   * @throws IOException if an I/O error occurs
   */
  @Override
  protected Product readProductNodesImpl() throws IOException {
    if (getInput() instanceof Product) {
      sourceProduct = (Product) getInput();
    } else {
      throw new IllegalArgumentException("unsupported input source: " + getInput());
    }
    Debug.assertNotNull(sourceProduct);
    sceneRasterWidth = sourceProduct.getSceneRasterWidth();
    sceneRasterHeight = sourceProduct.getSceneRasterHeight();
    if (getSubsetDef() != null) {
      Dimension s = getSubsetDef().getSceneRasterSize(sceneRasterWidth, sceneRasterHeight);
      sceneRasterWidth = s.width;
      sceneRasterHeight = s.height;
    }
    final Product targetProduct = createProduct();
    updateMetadata(sourceProduct, targetProduct, getSubsetDef());

    return targetProduct;
  }
예제 #22
0
파일: DataNode.java 프로젝트: TonioF/beam
  /**
   * Checks if the data that should be used to access the data is compatible with the data this node
   * can hold.
   *
   * @param data the data to be checked for compatibility
   * @throws IllegalArgumentException if data is invalid.
   */
  protected void checkDataCompatibility(ProductData data) throws IllegalArgumentException {

    Debug.assertNotNull(data);

    if (data.getType() != getDataType()) {
      throw new IllegalArgumentException(
          "illegal data for data node '"
              + getName()
              + "', type "
              + ProductData.getTypeString(getDataType())
              + " expected");
    }

    if (data.getNumElems() != getNumDataElems()) {
      throw new IllegalArgumentException(
          "illegal number of data elements for data node '"
              + getName()
              + "', "
              + getNumDataElems()
              + " elements expected");
    }
  }
예제 #23
0
 /**
  * Writes all data in memory to disk. After a flush operation, the writer can be closed safely
  *
  * @throws IOException on failure
  */
 public void flush() throws IOException {
   if (_fileID == -1) {
     return;
   }
   if (_bandIDs != null) {
     Iterator it = _bandIDs.values().iterator();
     while (it.hasNext()) {
       int datasetID = (Integer) it.next();
       if (datasetID != -1) {
         try {
           H5.H5Fflush(datasetID, HDF5Constants.H5F_SCOPE_LOCAL);
         } catch (HDF5LibraryException e) {
           Debug.trace(e);
           /*...*/
         }
       }
     }
   }
   try {
     H5.H5Fflush(_fileID, HDF5Constants.H5F_SCOPE_LOCAL);
   } catch (HDF5LibraryException e) {
     throw new ProductIOException(createErrorMessage(e));
   }
 }
예제 #24
0
  public static String findNextLevelFileName(
      String ifileName, String programName, String[] additionalOptions) {

    if (ifileName == null || programName == null) {
      return null;
    }
    if (programName.equals("l3bindump")) {
      return ifileName + ".xml";
    }
    debug("Program name is " + programName);
    Debug.assertNotNull(ifileName);

    String[] cmdArray =
        (String[])
            ArrayUtils.addAll(
                getCmdArrayForNextLevelNameFinder(ifileName, programName), additionalOptions);

    String ifileDir =
        ifileName.substring(0, ifileName.lastIndexOf(System.getProperty("file.separator")));

    String ofileName;

    if (RuntimeContext.getConfig()
        .getContextProperty(OCSSW.OCSSW_LOCATION_PROPERTY)
        .equals(OCSSW.SEADAS_OCSSW_LOCATION_LOCAL)) {
      ofileName = retrieveOFileNameLocal(cmdArray, ifileDir);
    } else {

      ofileName = retrieveOFileNameRemote(cmdArray);
    }

    if (ofileName == null) {
      ofileName = "output";
    }
    return ofileName;
  }
예제 #25
0
  public static String findNextLevelFileName(String ifileName, String programName, String suite) {
    if (ifileName == null || programName == null) {
      return null;
    }
    if (programName.equals("l3bindump")) {
      return ifileName + ".xml";
    }
    debug("Program name is " + programName);
    Debug.assertNotNull(ifileName);
    // todo Add suite, also check calling program the make sure ProcessorModel call is right

    String[] cmdArray = new String[6];
    cmdArray[0] = OCSSW.getOcsswScriptPath();
    cmdArray[1] = "--ocsswroot";
    cmdArray[2] = OCSSW.getOcsswEnv();
    cmdArray[3] = NEXT_LEVEL_NAME_FINDER_PROGRAM_NAME;
    cmdArray[4] =
        RuntimeContext.getConfig()
                .getContextProperty(OCSSW.OCSSW_LOCATION_PROPERTY)
                .equals(OCSSW.SEADAS_OCSSW_LOCATION_LOCAL)
            ? ifileName
            : getIfileNameforRemoteServer(ifileName);
    cmdArray[5] = programName;
    // cmdArray[6] = "--suite="+suite;

    String ifileDir =
        ifileName.substring(0, ifileName.lastIndexOf(System.getProperty("file.separator")));

    if (RuntimeContext.getConfig()
        .getContextProperty(OCSSW.OCSSW_LOCATION_PROPERTY)
        .equals(OCSSW.SEADAS_OCSSW_LOCATION_LOCAL)) {
      return retrieveOFileNameLocal(cmdArray, ifileDir);
    } else {
      return retrieveOFileNameRemote(cmdArray);
    }
  }
예제 #26
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;
  }
예제 #27
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());
    }
  }
예제 #28
0
 protected void fireHidden(PageComponent component) {
   Debug.trace("AbstractApplicationPage.fireHidden [" + component + "]");
   for (PageComponentListener listener : pageComponentListeners) {
     listener.componentHidden(component);
   }
 }
예제 #29
0
  protected void addGeoCodingToProduct(final Product product) {

    if (!getSourceProduct().transferGeoCodingTo(product, getSubsetDef())) {
      Debug.trace("GeoCoding could not be transferred.");
    }
  }