Пример #1
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;
  }
Пример #2
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;
 }
Пример #3
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;
  }
Пример #4
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;
  }
Пример #5
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();
  }
Пример #6
0
  /**
   * 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");
    }
  }
Пример #7
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;
  }
Пример #8
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);
    }
  }
Пример #9
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());
    }
  }