Ejemplo n.º 1
0
  private static void readCalibrationLUT(
      final File file, final String lutName, final MetadataElement root, final boolean flipLUT)
      throws IOException {
    if (!file.exists()) return;
    final org.jdom.Document xmlDoc = XMLSupport.LoadXML(file.getAbsolutePath());
    final Element rootElement = xmlDoc.getRootElement();

    final Element offsetElem = rootElement.getChild("offset");
    final double offset = Double.parseDouble(offsetElem.getValue());

    final Element gainsElem = rootElement.getChild("gains");
    double[] gainsArray = StringUtils.toDoubleArray(gainsElem.getValue().trim(), " ");
    if (flipLUT) {
      double tmp;
      for (int i = 0; i < gainsArray.length / 2; i++) {
        tmp = gainsArray[i];
        gainsArray[i] = gainsArray[gainsArray.length - i - 1];
        gainsArray[gainsArray.length - i - 1] = tmp;
      }
    }

    final MetadataElement lut = new MetadataElement(lutName);
    root.addElement(lut);

    final MetadataAttribute offsetAttrib =
        new MetadataAttribute("offset", ProductData.TYPE_FLOAT64);
    offsetAttrib.getData().setElemDouble(offset);
    lut.addAttribute(offsetAttrib);

    final MetadataAttribute gainsAttrib =
        new MetadataAttribute("gains", ProductData.TYPE_FLOAT64, gainsArray.length);
    gainsAttrib.getData().setElems(gainsArray);
    lut.addAttribute(gainsAttrib);
  }
Ejemplo n.º 2
0
  private void handleMetadataGroup(Group group, MetadataElement metadataElement)
      throws ProductIOException {
    List<Variable> variables = group.getVariables();
    for (Variable variable : variables) {
      final String name = variable.getShortName();
      final int dataType = getProductDataType(variable);
      Array array;
      try {
        array = variable.read();
      } catch (IOException e) {
        throw new ProductIOException(e.getMessage());
      }
      final ProductData data = ProductData.createInstance(dataType, array.getStorage());
      final MetadataAttribute attribute = new MetadataAttribute("data", data, true);

      final MetadataElement sdsElement = new MetadataElement(name);
      sdsElement.addAttribute(attribute);
      metadataElement.addElement(sdsElement);

      final List<Attribute> list = variable.getAttributes();
      for (Attribute hdfAttribute : list) {
        final String attribName = hdfAttribute.getShortName();
        if ("units".equals(attribName)) {
          attribute.setUnit(hdfAttribute.getStringValue());
        } else if ("long_name".equals(attribName)) {
          attribute.setDescription(hdfAttribute.getStringValue());
        } else {
          addAttributeToElement(sdsElement, hdfAttribute);
        }
      }
    }
  }
Ejemplo n.º 3
0
  public void addBandMetadata(Product product) throws ProductIOException {
    Group group = ncFile.findGroup("Geophysical_Data");
    if (productReader.getProductType() == SeadasProductReader.ProductType.Level2_Aquarius) {
      group = ncFile.findGroup("Aquarius_Data");
    }
    if (productReader.getProductType() == SeadasProductReader.ProductType.Level1B_HICO) {
      group = ncFile.findGroup("products");
    }
    if (group != null) {
      final MetadataElement bandAttributes = new MetadataElement("Band_Attributes");
      List<Variable> variables = group.getVariables();
      for (Variable variable : variables) {
        final String name = variable.getShortName();
        final MetadataElement sdsElement = new MetadataElement(name + ".attributes");
        final int dataType = getProductDataType(variable);
        final MetadataAttribute prodtypeattr = new MetadataAttribute("data_type", dataType);

        sdsElement.addAttribute(prodtypeattr);
        bandAttributes.addElement(sdsElement);

        final List<Attribute> list = variable.getAttributes();
        for (Attribute varAttribute : list) {
          addAttributeToElement(sdsElement, varAttribute);
        }
      }
      final MetadataElement metadataRoot = product.getMetadataRoot();
      metadataRoot.addElement(bandAttributes);
    }
  }
Ejemplo n.º 4
0
  public void addInputParamMetadata(Product product) throws ProductIOException {

    Variable inputParams = ncFile.findVariable("Input_Parameters");
    if (inputParams != null) {
      final MetadataElement inputParamsMeta = new MetadataElement("Input_Parameters");
      Array array;
      try {
        array = inputParams.read();
      } catch (IOException e) {
        throw new ProductIOException(e.getMessage());
      }

      String[] lines = array.toString().split("\n");
      for (String line : lines) {
        String[] parts = line.split("=");
        if (parts.length == 2) {
          final String name = parts[0].trim();
          final String value = parts[1].trim();
          final ProductData data = ProductData.createInstance(ProductData.TYPE_ASCII, value);
          final MetadataAttribute attribute = new MetadataAttribute(name, data, true);
          inputParamsMeta.addAttribute(attribute);
        }
      }

      final MetadataElement metadataRoot = product.getMetadataRoot();
      metadataRoot.addElement(inputParamsMeta);
    }
  }
Ejemplo n.º 5
0
  /** Creates Metadata nodes for all the necessary information. */
  protected MetadataElement[] getMetadata() {
    MetadataElement[] metadata = new MetadataElement[2];

    MetadataElement fileList = new MetadataElement("Input_Products");
    final String[] productList = context.getProcessedProducts();
    String keyString;

    for (int n = 0; n < productList.length; n++) {
      keyString = "Product." + n;
      fileList.addAttribute(
          new MetadataAttribute(keyString, ProductData.createInstance(productList[n]), true));
    }
    metadata[0] = fileList;

    MetadataElement binParams = new MetadataElement("Binning_Parameter");
    binParams.addAttribute(
        new MetadataAttribute(
            "Resampling_Type", ProductData.createInstance(context.getResamplingType()), true));
    final String cellSizeName;
    if (L3Constants.RESAMPLING_TYPE_VALUE_BINNING.equals(context.getResamplingType())) {
      cellSizeName = "Bin_Size_In_Km";
    } else {
      cellSizeName = "Bins_Per_Degree";
    }
    binParams.addAttribute(
        new MetadataAttribute(
            cellSizeName,
            ProductData.createInstance(new float[] {context.getGridCellSize()}),
            true));
    final L3Context.BandDefinition[] bandDefs = context.getBandDefinitions();
    for (int bandIndex = 0; bandIndex < bandDefs.length; bandIndex++) {
      final L3Context.BandDefinition bandDef = bandDefs[bandIndex];
      binParams.addAttribute(
          new MetadataAttribute(
              "Geophysical_Parameter_" + bandIndex,
              ProductData.createInstance(bandDef.getBandName()),
              true));
      binParams.addAttribute(
          new MetadataAttribute(
              "Bitmask_" + bandIndex, ProductData.createInstance(bandDef.getBitmaskExp()), true));
      binParams.addAttribute(
          new MetadataAttribute(
              "Algorithm_" + bandIndex,
              ProductData.createInstance(bandDef.getAlgorithm().getTypeString()),
              true));
    }
    metadata[1] = binParams;

    return metadata;
  }
Ejemplo n.º 6
0
  public void addSmiMetadata(final Product product) {
    //        Variable l3mvar = ncFile.findVariable("l3m_data");
    final MetadataElement bandAttributes = new MetadataElement("Band_Attributes");
    List<Variable> variables = ncFile.getVariables();
    for (Variable variable : variables) {
      final String name = variable.getShortName();
      final MetadataElement sdsElement = new MetadataElement(name);
      final int dataType = getProductDataType(variable);
      final MetadataAttribute prodtypeattr = new MetadataAttribute("data_type", dataType);

      sdsElement.addAttribute(prodtypeattr);
      bandAttributes.addElement(sdsElement);

      final List<Attribute> list = variable.getAttributes();
      for (Attribute varAttribute : list) {
        addAttributeToElement(sdsElement, varAttribute);
      }
    }
    final MetadataElement metadataRoot = product.getMetadataRoot();
    metadataRoot.addElement(bandAttributes);
  }
Ejemplo n.º 7
0
 public MetadataElement getAsMetadataElement(CompoundData compoundData) throws IOException {
   CompoundType type = compoundData.getType();
   final int memberCount = type.getMemberCount();
   MetadataElement metadataElement = new MetadataElement(type.getName());
   for (int i = 0; i < memberCount; i++) {
     String typeName = type.getMemberName(i);
     CompoundMember member = type.getMember(i);
     FormatMetadata formatMetadata = (FormatMetadata) member.getMetadata();
     if (typeName.equals("fill")) {
       // ignore
     } else if (formatMetadata != null && formatMetadata.getType().equals("string")) {
       String stringValue = getAsString(compoundData.getSequence(i));
       Map<Object, String> map = getMetaData(member).getItemMap();
       if (map != null) {
         stringValue = map.get(stringValue);
       }
       ProductData data = ProductData.createInstance(stringValue);
       MetadataAttribute attribute = new MetadataAttribute(typeName, data, true);
       attribute.setDescription(getDescription(member));
       attribute.setUnit(getUnits(member));
       metadataElement.addAttribute(attribute);
     } else if (member.getType().getName().equals("DATE")) {
       CompoundData dateCompound = compoundData.getCompound(i);
       ProductData data = createDate(dateCompound);
       MetadataAttribute attribute = new MetadataAttribute(typeName, data, true);
       attribute.setDescription(getDescription(member));
       attribute.setUnit(getUnits(member));
       metadataElement.addAttribute(attribute);
     } else if (member.getType().isSequenceType()) {
       SequenceData sequence = compoundData.getSequence(i);
       for (int j = 0; j < sequence.getType().getElementCount(); j++) {
         CompoundData compound = sequence.getCompound(j);
         metadataElement.addElement(getAsMetadataElement(compound));
       }
     } else if (member.getType().isCompoundType()) {
       metadataElement.addElement(getAsMetadataElement(compoundData.getCompound(i)));
     } else if (member.getType().isSimpleType()) {
       int intValue = compoundData.getInt(i);
       Map<Object, String> map = getMetaData(member).getItemMap();
       ProductData data;
       if (map != null) {
         String stringValue = map.get(intValue);
         data = ProductData.createInstance(stringValue);
       } else {
         double scalingFactor = getMetaData(member).getScalingFactor();
         if (scalingFactor == 1.0) {
           data = ProductData.createInstance(new int[] {intValue});
         } else {
           data = ProductData.createInstance(new double[] {intValue * scalingFactor});
         }
       }
       MetadataAttribute attribute = new MetadataAttribute(typeName, data, true);
       attribute.setDescription(getDescription(member));
       attribute.setUnit(getUnits(member));
       metadataElement.addAttribute(attribute);
     } else {
       System.out.println("not handled: name=" + typeName);
       System.out.println("member = " + member.getType());
     }
   }
   return metadataElement;
 }
Ejemplo n.º 8
0
 protected void addAttributeToElement(final MetadataElement element, final Attribute attribute) {
   final MetadataAttribute metadataAttribute = attributeToMetadata(attribute);
   element.addAttribute(metadataAttribute);
 }