boolean isLegacyFormat() { MetadataElement metadata = getProductMetadata(); return metadata.getAttribute("BAND1_FILE_NAME") != null; }
/** * Returns the string value of the attribute with the given name. <p>An Exception is thrown if an * attribute with the given name could not be found in this node. * * @param name the attribute name * * @return the attribute value as integer. * * @throws IllegalArgumentException if an attribute with the given name could not be found */ public String getAttributeString(String name) { final MetadataAttribute attribute = getAttribute(name); if (attribute == null) { throw new IllegalArgumentException(getAttributeNotFoundMessage(name)); } return attribute.getData().getElemString(); }
@Override public double getScalingOffset(String bandId) { final String spectralInput = getSpectralInputString(); String attributeKey = String.format("%s_ADD_BAND_%s", spectralInput, bandId); MetadataElement radiometricRescalingElement = getMetaDataElementRoot().getElement("RADIOMETRIC_RESCALING"); if (radiometricRescalingElement.getAttribute(attributeKey) == null) { return DEFAULT_OFFSET; } final double scalingOffset = radiometricRescalingElement.getAttributeDouble(attributeKey); final double sunAngleCorrectionFactor = getSunAngleCorrectionFactor(spectralInput); return scalingOffset / sunAngleCorrectionFactor; }
private static void replaceWithRelativePaths(MetadataElement[] elements, File outputDir) { for (MetadataElement element : elements) { final String pathName = element.getAttributeString(AbstractTimeSeries.PL_PATH); final URI relativeUri = FileUtils.getRelativeUri(outputDir.toURI(), new File(pathName)); final MetadataAttribute pathAttr = element.getAttribute(AbstractTimeSeries.PL_PATH); final MetadataAttribute typeAttr = element.getAttribute(AbstractTimeSeries.PL_TYPE); element.removeAttribute(pathAttr); element.removeAttribute(typeAttr); pathAttr.dispose(); final MetadataAttribute newPathAttr = new MetadataAttribute(AbstractTimeSeries.PL_PATH, ProductData.createInstance(relativeUri.toString()), true); element.addAttribute(newPathAttr); element.addAttribute(typeAttr); } }
protected String getProductType(String productTypeKey) { final MetadataAttribute product_type = getProductMetadata().getAttribute(productTypeKey); final MetadataAttribute spacecraft_id = getProductMetadata().getAttribute("SPACECRAFT_ID"); final MetadataAttribute sensor_id = getProductMetadata().getAttribute("SENSOR_ID"); final StringBuilder result = new StringBuilder(); result.append(spacecraft_id.getData().getElemString()); result.append("_"); result.append(sensor_id.getData().getElemString()); result.append("_"); result.append(product_type.getData().getElemString()); return result.toString(); }
@Override public double getScalingFactor(String bandId) { final String spectralInput = getSpectralInputString(); String attributeKey = String.format("%s_MULT_BAND_%s", spectralInput, bandId); MetadataElement radiometricRescalingElement = getMetaDataElementRoot().getElement("RADIOMETRIC_RESCALING"); if (radiometricRescalingElement.getAttribute(attributeKey) == null) { return DEFAULT_SCALE_FACTOR; } final double scalingFactor = radiometricRescalingElement.getAttributeDouble(attributeKey); final double sunAngleCorrectionFactor = getSunAngleCorrectionFactor(spectralInput); return scalingFactor / sunAngleCorrectionFactor; }
private MetadataAttribute getAndMaybeCreateAttribute(final String name, final int type, final int numElems) { MetadataAttribute attribute = getAttribute(name); if (attribute == null) { attribute = new MetadataAttribute(name, type, numElems); addAttribute(attribute); } return attribute; }
protected Dimension getDimension(String widthAttributeName, String heightAttributeName) { MetadataElement metadata = getProductMetadata(); MetadataAttribute widthAttribute = metadata.getAttribute(widthAttributeName); MetadataAttribute heightAttribute = metadata.getAttribute(heightAttributeName); if (widthAttribute != null && heightAttribute != null) { int width = widthAttribute.getData().getElemInt(); int height = heightAttribute.getData().getElemInt(); return new Dimension(width, height); } else { return null; } }
/** * Returns the string value of the attribute with the given name. <p>The given default value is returned if an * attribute with the given name could not be found in this node. * * @param name the attribute name * @param defaultValue the default value * * @return the attribute value as integer. */ public String getAttributeString(String name, String defaultValue) { final MetadataAttribute attribute = getAttribute(name); if (attribute == null) { return defaultValue; } return attribute.getData().getElemString(); }
private static float[] getSolarFlux(Product product) { MetadataElement metadataRoot = product.getMetadataRoot(); MetadataElement gadsElem = metadataRoot.getElement("Scaling_Factor_GADS"); MetadataAttribute solarFluxAtt = gadsElem.getAttribute("sun_spec_flux"); return (float[]) solarFluxAtt.getDataElems(); } }
private static void addIDNode(final MetadataElement absRoot, final MetadataElement identNode, final String title, final String tag) { final MetadataAttribute attrib = absRoot.getAttribute(tag); if (attrib == null) return; final String value = title + ": " + attrib.getData().getElemString(); final MetadataElement newAttrib = new MetadataElement(value); identNode.addElement(newAttrib); }
private static float getSolarFluxFromMetadata(MetadataElement metadataRoot, int bandIndex) { if (metadataRoot != null) { MetadataElement scalingFactorGads = metadataRoot.getElement("Scaling_Factor_GADS"); if (scalingFactorGads != null) { MetadataAttribute sunSpecFlux = scalingFactorGads.getAttribute("sun_spec_flux"); ProductData data = sunSpecFlux.getData(); if (data.getNumElems() > bandIndex) { return data.getElemFloatAt(bandIndex); } } } return 0.0f; }
static String extractProductName(MetadataElement processingGraphElement) { if (processingGraphElement != null) { final MetadataElement nodeElement = processingGraphElement.getElement("node.0"); if (nodeElement != null) { final MetadataElement sourcesElement = nodeElement.getElement("sources"); if (sourcesElement != null) { final MetadataAttribute sourceProductAttribute = sourcesElement.getAttribute("sourceProduct"); if (sourceProductAttribute != null) { return sourceProductAttribute.getData().getElemString(); } } } } return null; } }
/** * Adds an attribute from src to dest * * @param src the source element * @param tag the name of the attribute * @param dest the destination element * @param desc the description */ private static void addAbstractedAttribute(MetadataElement src, String tag, MetadataElement dest, String desc) { final MetadataAttribute attrib = src.getAttribute(tag); if (attrib != null) { MetadataAttribute copiedAttrib = attrib.createDeepClone(); copiedAttrib.setReadOnly(false); copiedAttrib.setDescription(desc); dest.addAttribute(copiedAttrib); } }
public LandsatReprocessedMetadata(FileReader fileReader) throws IOException { super(fileReader); landsatLegacyMetadataDelegate = new LandsatLegacyMetadata(getMetaDataElementRoot()); landsat8MetadataDelegate = new Landsat8Metadata(getMetaDataElementRoot()); sensorId = getMetaDataElementRoot().getElement("PRODUCT_METADATA").getAttribute("SENSOR_ID").getData().getElemString(); }
static void assertInputElementAt(int index, String inputName, MetadataElement metadataElement) { final MetadataElement productElement = metadataElement.getElementAt(index); assertEquals("source." + Integer.toString(index), productElement.getName()); final MetadataAttribute nameAttribute = productElement.getAttribute("name"); assertNotNull(nameAttribute); assertEquals(inputName, nameAttribute.getData().getElemString()); }
public static void assertStringAttribute(MetadataElement elem, String attibuteName, String expectedValue) { final MetadataAttribute attribute = elem.getAttribute(attibuteName); assertNotNull(attribute); assertEquals(ProductData.TYPESTRING_ASCII, attribute.getData().getTypeString()); assertEquals(expectedValue, attribute.getData().getElemString()); }
public static void assertIntAttribute(MetadataElement elem, String attributeName, int expectedValue) { final MetadataAttribute attribute = elem.getAttribute(attributeName); assertNotNull(attribute); assertEquals(ProductData.TYPE_INT32, attribute.getDataType()); assertEquals(1, attribute.getNumDataElems()); assertEquals(expectedValue, attribute.getData().getElemInt()); }
@Test public void testAggregateOneInput_withGraph_withoutValidProductName() { final Product product = TestHelper.createProductWithProcessingGraph(1, "inputProduct"); final MetadataElement node_0 = product.getMetadataRoot().getElement("Processing_Graph").getElement("node.0"); final MetadataElement sourcesElement = node_0.getElement("sources"); final MetadataAttribute sourceProductAttribute = sourcesElement.getAttribute("sourceProduct"); sourcesElement.removeAttribute(sourceProductAttribute); aggregator.aggregateMetadata(product); final MetadataElement metadataElement = aggregator.getMetadata(); TestHelper.assertCorrectNameAndNoAttributes(metadataElement); assertEquals(1, metadataElement.getNumElements()); TestHelper.assertInputElementAt(0, "product_1", metadataElement); }
@Test public void testAsMetadataElement() throws ParseException { final BinningOp binningOp = createBinningOp(); final GlobalMetadata globalMetadata = GlobalMetadata.create(binningOp); final MetadataElement processingGraphElement = globalMetadata.asMetadataElement(); assertNotNull(processingGraphElement); assertEquals("Processing_Graph", processingGraphElement.getName()); final MetadataElement node_0_Element = processingGraphElement.getElement("node.0"); assertNotNull(node_0_Element); final MetadataElement parameterElement = node_0_Element.getElement("parameters"); assertEquals(11, parameterElement.getNumAttributes()); // @todo 2 tb/tb check for other meta elements 2014-10-10 final MetadataAttribute software_qualified_name = parameterElement.getAttribute("software_qualified_name"); assertNotNull(software_qualified_name); assertEquals("org.esa.beam.binning.operator.BinningOp", software_qualified_name.getData().getElemString()); }