@Override public String getValue() throws IllegalAccessException, InvocationTargetException { return leaf.getData().getElemString(); } }
public String[] getAttributeValues(String attributePath) { String[] values = null; if (attributePath != null) { attributePath = ensureAttributeTagPresent(attributePath); List<MetadataAttribute> attributes; if (attributeMap.containsKey(attributePath) && (attributes = attributeMap.get(attributePath)) != null && attributes.size() > 0) { values = new String[attributes.size()]; for (int i = 0; i < attributes.size(); i++) { values[i] = attributes.get(i).getData().getElemString(); if (values[i] == null) { warn(MISSING_ELEMENT_WARNING, attributes.get(i).getName()); } } } else { warn(NO_SUCH_PATH_WARNING, attributePath); } } return values; }
private void writeAttributes(PrintWriter out, MetadataElement element) { final MetadataAttribute[] attributes = element.getAttributes(); for (MetadataAttribute attribute : attributes) { out.print(createAttributeName(attribute) + "\t"); out.print(attribute.getData().getElemString() + "\t"); out.print(attribute.getUnit() + "\t"); out.print(attribute.getDescription() + "\t\n"); } final MetadataElement[] subElements = element.getElements(); for (MetadataElement subElement : subElements) { writeAttributes(out, subElement); } }
default MetadataElement getMetadataObject(final MetadataElement origProdRoot, final String metadataObjectName) { final MetadataElement metadataSection = origProdRoot.getElement("XFDU").getElement("metadataSection"); final MetadataElement[] metadataObjects = metadataSection.getElements(); for (MetadataElement elem : metadataObjects) { if (elem.getAttribute("ID").getData().getElemString().equals(metadataObjectName)) { return elem; } } return null; } }
private static double[] getDoubleArray(final MetadataElement elem, final String tag) { final MetadataAttribute attribute = elem.getAttribute(tag); if (attribute == null) { throw new OperatorException(tag + " attribute not found"); } double[] array = null; if (attribute.getData() instanceof ProductData.ASCII) { final String dataStr = attribute.getData().getElemString(); final String[] items = dataStr.split(" "); array = new double[items.length]; for (int i = 0; i < items.length; i++) { try { array[i] = Double.parseDouble(items[i]); } catch (NumberFormatException e) { throw new OperatorException("Failed in getting" + tag + " array"); } } } return array; }
public ArrayList<String> getBandNames() { ArrayList<String> bands = new ArrayList<>(17); MetadataElement bandGlobalListElement = getRootElement().getElement("Product_Characteristics").getElement("Band_Global_List"); for (int j = 0; j < bandGlobalListElement.getNumAttributes(); j++) { if (bandGlobalListElement.getAttributeAt(j).getName().equals("BAND_ID")) { bands.add(bandGlobalListElement.getAttributeAt(j).getData().getElemString()); } } return bands; }
/** * Find the quantification value (U) stored in the Sentinel product metadata. * * @param product the input product * @return the quantification value (U) stored in the Sentinel product metadata */ public static float extractUFromSentinelProduct(Product product) { float u = 0.0f; MetadataElement metadataRoot = product.getMetadataRoot(); String[] reflectanceConversionPath = {"Level-1C_User_Product", "General_Info", "Product_Image_Characteristics", "Reflectance_Conversion"}; MetadataElement reflectanceConversionElement = findTreeElement(metadataRoot, reflectanceConversionPath); if (reflectanceConversionElement != null) { MetadataAttribute metadataAttribute = reflectanceConversionElement.getAttribute("U"); ProductData data = metadataAttribute.getData(); u = Float.parseFloat(data.getElemString()); } return u; }
private static int[] getIntArray(final MetadataElement elem, final String tag) { final MetadataAttribute attribute = elem.getAttribute(tag); if (attribute == null) { throw new OperatorException(tag + " attribute not found"); } int[] array = null; if (attribute.getDataType() == ProductData.TYPE_ASCII) { final String dataStr = attribute.getData().getElemString(); final String[] items = dataStr.split(" "); array = new int[items.length]; for (int i = 0; i < items.length; i++) { try { array[i] = Integer.parseInt(items[i]); } catch (NumberFormatException e) { throw new OperatorException("Failed in getting" + tag + " array"); } } } return array; }
private static int[] getIntArray(final MetadataElement elem, final String tag) { final MetadataAttribute attribute = elem.getAttribute(tag); if (attribute == null) { throw new OperatorException(tag + " attribute not found"); } int[] array = null; if (attribute.getDataType() == ProductData.TYPE_ASCII) { final String dataStr = attribute.getData().getElemString(); final String[] items = dataStr.split(" "); array = new int[items.length]; for (int i = 0; i < items.length; i++) { try { array[i] = Integer.parseInt(items[i]); } catch (NumberFormatException e) { throw new OperatorException("Failed in getting" + tag + " array"); } } } return array; }
/** * Get antenna pattern gain array from metadata. */ private void getLUT() { final MetadataElement calibrationElem = origMetadataRoot.getElement("calibration"); final MetadataElement[] elements = calibrationElem.getElements(); for (MetadataElement elem : elements) { final String elemName = elem.getName(); if (elemName.contains("lutSigma")) { final int pixelFirstLutValue = Integer.parseInt(elem.getAttributeString("pixelFirstLutValue")); final int stepSize = Integer.parseInt(elem.getAttributeString("stepSize")); final int numberOfValues = Integer.parseInt(elem.getAttributeString("numberOfValues")); final int offset = Integer.parseInt(elem.getAttributeString("offset")); final MetadataAttribute attribute = elem.getAttribute("gains"); final String gainsStr = attribute.getData().getElemString(); final double[] gainLUT = new double[numberOfValues]; addToArray(gainLUT, 0, gainsStr, " "); final CalibrationLUT lut = new CalibrationLUT(pixelFirstLutValue, stepSize, numberOfValues, offset, gainLUT); final String pol = elemName.substring(elemName.lastIndexOf("_") + 1); gainsMap.put(pol, lut); } } }
public ArrayList<String> getBandNames(String resolutionId) { ArrayList<String> bands = new ArrayList<>(13); MetadataElement bandGroupListElement = getRootElement().getElement("Product_Characteristics").getElement("Band_Group_List"); for (int i = 0; i < bandGroupListElement.getNumElements(); i++) { MetadataElement element = bandGroupListElement.getElementAt(i); if (element.getAttribute("group_id").getData().getElemString().equals(resolutionId)) { MetadataElement bandListElement = element.getElement("Band_List"); for (int j = 0; j < bandListElement.getNumAttributes(); j++) { if (bandListElement.getAttributeAt(j).getName().equals("BAND_ID")) { bands.add(bandListElement.getAttributeAt(j).getData().getElemString()); } } } } return bands; }
private static void searchMetadataValue(final MetadataElement resultElem, final MetadataElement elem, final String value) { final MetadataElement[] elemList = elem.getElements(); for (MetadataElement e : elemList) { searchMetadataValue(resultElem, e, value); } final MetadataAttribute[] attribList = elem.getAttributes(); for (MetadataAttribute attrib : attribList) { if (attrib.getData().getElemString().toUpperCase().contains(value)) { final MetadataAttribute newAttrib = attrib.createDeepClone(); newAttrib.setDescription(SearchMetadataAction.getAttributePath(attrib)); resultElem.addAttribute(newAttrib); } } } }
public synchronized ArrayList<MuscateImage> getImages() { if (images == null) { images = new ArrayList<>(13); MetadataElement imageListElement = getRootElement().getElement("Product_Organisation").getElement("Muscate_Product").getElement("Image_List"); for (int i = 0; i < imageListElement.getNumElements(); i++) { MuscateImage muscateImage = new MuscateImage(); MetadataElement imageElement = imageListElement.getElementAt(i); MetadataElement propertiesElement = imageElement.getElement("Image_Properties"); muscateImage.nature = propertiesElement.getAttribute("NATURE").getData().getElemString(); muscateImage.compression = propertiesElement.getAttribute("COMPRESSION").getData().getElemString(); muscateImage.encoding = propertiesElement.getAttribute("ENCODING").getData().getElemString(); muscateImage.endianness = propertiesElement.getAttribute("ENDIANNESS").getData().getElemString(); muscateImage.format = propertiesElement.getAttribute("FORMAT").getData().getElemString(); MetadataElement fileListElement = imageElement.getElement("Image_File_List"); int numImages = fileListElement.getNumAttributes(); for (int j = 0; j < numImages; j++) { String path = fileListElement.getAttributeAt(j).getData().getElemString(); muscateImage.addMuscateImageFile(path); } images.add(muscateImage); } } return images; }
/** * Get thermal noise correction flag from the original product metadata. */ private void getThermalNoiseCorrectionFlag() { final MetadataElement annotationElem = origMetadataRoot.getElement("annotation"); final MetadataElement[] annotationDataSetListElem = annotationElem.getElements(); final MetadataElement productElem = annotationDataSetListElem[0].getElement("product"); final MetadataElement imageAnnotationElem = productElem.getElement("imageAnnotation"); final MetadataElement processingInformationElem = imageAnnotationElem.getElement("processingInformation"); thermalNoiseCorrectionPerformed = Boolean.parseBoolean( processingInformationElem.getAttribute("thermalNoiseCorrectionPerformed").getData().getElemString()); }
/** * Get the processing facility identifier. */ private void getProcessingFacilityIDFromENVISAT() { MetadataElement mph = origMetadataRoot.getElement("MPH"); if (mph == null) { throw new OperatorException("MPH not found"); } MetadataAttribute attr = mph.getAttribute("proc_center"); if (attr == null) { throw new OperatorException("proc_center not found"); } pafID = attr.getData().getElemString(); /* if (!pafID.contains(ESRIN) && !pafID.contains(D_PAF) && !pafID.contains(I_PAF) && !pafID.contains(UK_PAF)) { throw new OperatorException("Invalid processing facility identifier: " + pafID); } */ //System.out.println("Processing facility identifier is " + pafID); }
/** * Get the processing version identifier. */ private void getProcessingVersionID() { // Field 83 in PRI Data Set Summary Record final MetadataElement facility = origMetadataRoot.getElement("Leader").getElement("Scene Parameters"); if (facility == null) { throw new OperatorException("Scene Parameters not found"); } final MetadataAttribute attr = facility.getAttribute("Processing version identifier"); if (attr == null) { throw new OperatorException("Processing version identifier not found"); } pvID = attr.getData().getElemString(); //System.out.println("Processing version identifier is " + pvID); }
/** * Get thermal noise correction flag from the original product metadata. */ private void getThermalNoiseCorrectionFlag() { final MetadataElement annotationElem = origMetadataRoot.getElement("annotation"); final MetadataElement[] annotationDataSetListElem = annotationElem.getElements(); final MetadataElement productElem = annotationDataSetListElem[0].getElement("product"); final MetadataElement imageAnnotationElem = productElem.getElement("imageAnnotation"); final MetadataElement processingInformationElem = imageAnnotationElem.getElement("processingInformation"); thermalNoiseCorrectionPerformed = Boolean.parseBoolean( processingInformationElem.getAttribute("thermalNoiseCorrectionPerformed").getData().getElemString()); if (removeThermalNoise && thermalNoiseCorrectionPerformed) { throw new OperatorException("Thermal noise correction has already been performed for the product"); } if (reIntroduceThermalNoise && !thermalNoiseCorrectionPerformed) { throw new OperatorException("Thermal noise correction has never been performed for the product"); } }
/** * Get the zero doppler azimuth time of the first azimuth pixel (in second). * * @return The zero doppler time. */ private double getZeroDopplerAzimuthTimeOfFirstAzimuthPixel() { // Field 126/5 in PRI Data Set Summary Record (in UTC) final MetadataElement facility = origMetadataRoot.getElement("Leader").getElement("Scene Parameters"); if (facility == null) { throw new OperatorException("Scene Parameters not found"); } final MetadataAttribute attr = facility.getAttribute("Zero-doppler azimuth time of first azimuth pixel"); if (attr == null) { throw new OperatorException("Zero-doppler azimuth time of first azimuth pixel not found"); } return convertUTCTimes(attr.getData().getElemString()); // in s }
/** * Get the zero doppler azimuth time of the centre azimuth pixel (in second). * * @return The zero doppler time. */ private double getZeroDopplerAzimuthTimeOfCentreAzimuthPixel() { // Field 126/5 in PRI Data Set Summary Record (in UTC) final MetadataElement facility = origMetadataRoot.getElement("Leader").getElement("Scene Parameters"); if (facility == null) { throw new OperatorException("Scene Parameters not found"); } final MetadataAttribute attr = facility.getAttribute("Zero-doppler azimuth time of centre azimuth pixel"); if (attr == null) { throw new OperatorException("Zero-doppler azimuth time of centre azimuth pixel not found"); } return convertUTCTimes(attr.getData().getElemString()); // in s }
private void updateMetadata() { final MetadataElement abstractedMetadata = AbstractMetadata.getAbstractedMetadata(targetProduct); if(abstractedMetadata != null) { abstractedMetadata.setAttributeInt("collocated_stack", 1); } final MetadataElement inputElem = ProductInformation.getInputProducts(targetProduct); getBaselines(sourceProduct, targetProduct); for (Product srcProduct : sourceProduct) { if (srcProduct == masterProduct) continue; final MetadataElement slvInputElem = ProductInformation.getInputProducts(srcProduct); final MetadataAttribute[] slvInputProductAttrbList = slvInputElem.getAttributes(); for (MetadataAttribute attrib : slvInputProductAttrbList) { final MetadataAttribute inputAttrb = AbstractMetadata.addAbstractedAttribute(inputElem, "InputProduct", ProductData.TYPE_ASCII, "", ""); inputAttrb.getData().setElems(attrib.getData().getElemString()); } } }