private static void replaceAbstractedMetadataField(final MetadataElement abstractedMetadata, final String attrName, final String newValue) { final ProductData productData = abstractedMetadata.getAttribute(attrName).getData(); productData.setElems(newValue); }
private static void addAttrib(final MetadataElement elem, final String tag, final double value) { final MetadataAttribute attrib = new MetadataAttribute(tag, ProductData.TYPE_FLOAT64); attrib.getData().setElemDouble(value); elem.addAttribute(attrib); }
protected void validateMetadata(final Product trgProduct) throws Exception { final MetadataElement absRoot = AbstractMetadata.getAbstractedMetadata(trgProduct); final MetadataAttribute[] attribs = absRoot.getAttributes(); for(MetadataAttribute attrib : attribs) { System.out.println(attrib.getName() +"= "+ attrib.getData().toString()); } } }
public MetadataTableLeaf(MetadataAttribute attribute) { this(attribute.getName(), attribute.getDataType(), attribute.getData(), attribute.getUnit(), attribute.getDescription()); }
public static MetadataAttribute addAttribute(final MetadataElement dest, final String tag, final int dataType, final String unit, final String desc) { final MetadataAttribute attribute = new MetadataAttribute(tag, dataType, 1); attribute.setUnit(unit); attribute.setDescription(desc); attribute.setReadOnly(true); dest.addAttribute(attribute); return attribute; }
private void addFlagDescriptor(String name, int value, String description) { MetadataAttribute attribute = new MetadataAttribute(name, ProductData.TYPE_INT32); attribute.getData().setElemInt(value); attribute.setDescription(description); flagCoding.addAttribute(attribute); }
productData = ProductData.createInstance(ProductData.TYPE_UINT32, 1); productData.setElemUInt(d.getLength()); final MetadataAttribute metadataAttribute = new MetadataAttribute(d.getFullName(), productData, true); dimElem.addAttribute(metadataAttribute); if (metadataAttribute.getName().equals("owiRaSize")) { sceneWidth = metadataAttribute.getData().getElemInt(); // width = #columns } else if (metadataAttribute.getName().equals("owiAzSize")) { sceneHeight = metadataAttribute.getData().getElemInt(); // height = #rows
final String name = attrib.getName(); boolean lastDupe = true; for (int j = i + 1; j < elem.getNumAttributes(); j++) { final MetadataAttribute dupeAtrib = elem.getAttributeAt(j); if (dupeAtrib.getName().equals(name)) { Integer cnt = dupeCntAtrib.get(name); if (cnt == null) if (lastDupe) ++cnt; attrib.setName(attrib.getName() + "." + cnt); final int dataType = attrib.getDataType(); if (dataType == ProductData.TYPE_FLOAT32 || dataType == ProductData.TYPE_FLOAT64) { newGroup.addAttribute(new Attribute(attrib.getName(), elem.getAttributeDouble(attrib.getName(), 0))); } else if (dataType == ProductData.TYPE_UTC || attrib.getData() instanceof ProductData.UTC) { newGroup.addAttribute(new Attribute(attrib.getName(), NetcdfConstants.UTC_TYPE + elem.getAttributeString(attrib.getName(), " "))); } else if (dataType > ProductData.TYPE_INT8 && dataType < ProductData.TYPE_FLOAT32) { newGroup.addAttribute(new Attribute(attrib.getName(), elem.getAttributeInt(attrib.getName(), 0))); } else { newGroup.addAttribute(new Attribute(attrib.getName(), elem.getAttributeString(attrib.getName(), " ")));
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 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); } }
public MetadataElement toMetadataElement() { MetadataElement element = new MetadataElement("Component"); element.addAttribute(new MetadataAttribute("dx", ProductData.ASCII.createInstance(String.valueOf(dx)), false)); element.addAttribute(new MetadataAttribute("dy", ProductData.ASCII.createInstance(String.valueOf(dy)), false)); element.addAttribute(new MetadataAttribute("precision", ProductData.ASCII.createInstance(String.valueOf(precision)), false)); element.addAttribute(new MetadataAttribute("signed", ProductData.ASCII.createInstance(String.valueOf(isSigned)), false)); return element; } }
private static MetadataTableElement[] getChildrenElementsFromElement(MetadataElement metadataElement) { MetadataElement[] elements = metadataElement.getElements(); MetadataAttribute[] attributes = metadataElement.getAttributes(); List<MetadataTableElement> metadataTableElementList = new ArrayList<>(); for (MetadataElement element : elements) { metadataTableElementList.add(new MetadataTableInnerElement(element)); } for (MetadataAttribute attribute : attributes) { final long dataElemSize = attribute.getNumDataElems(); if (dataElemSize > 1) { final int dataType = attribute.getDataType(); ProductData data = attribute.getData(); if ((ProductData.isFloatingPointType(dataType) || ProductData.isIntType(dataType)) && !(data instanceof ProductData.UTC)) { addMetadataAttributes(attribute, data, metadataTableElementList); } else { metadataTableElementList.add(new MetadataTableLeaf(attribute)); } } else { metadataTableElementList.add(new MetadataTableLeaf(attribute)); } } return metadataTableElementList.toArray(new MetadataTableElement[metadataTableElementList.size()]); }
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); } } } }
private static void addMetadataAttributes(MetadataAttribute attribute, ProductData data, List<MetadataTableElement> metadataTableElementList) { final String name = attribute.getName(); final String unit = attribute.getUnit(); final String description = attribute.getDescription(); for (int j = 0; j < data.getNumElems(); j++) { String elemName = String.format("%s.%d", name, j + 1); metadataTableElementList.add(new MetadataTableArrayElemLeaf(elemName, unit, description, data, j)); } } }
void indexAttribute(String parentElementPath, MetadataAttribute attribute) { String key = (parentElementPath + "@" + attribute.getName()).toLowerCase(); if (!this.attributeMap.containsKey(key)) { this.attributeMap.put(key, new ArrayList<>()); } this.attributeMap.get(key).add(attribute); }
private void configureRangeAxis(int index, MetadataElement metadataElement, String yAttributeName, String[] recordElementNames, String refRecordName, double[] recordIndices) { double[] yAxisData = new double[recordIndices.length]; Arrays.setAll(yAxisData, i -> getDataAsDouble(metadataElement.getElement(recordElementNames[i]).getAttribute(yAttributeName).getData())); DefaultXYDataset dataset2 = new DefaultXYDataset(); dataset2.addSeries(yAttributeName, new double[][]{recordIndices, yAxisData}); xyPlot.setDataset(index, dataset2); xyPlot.mapDatasetToRangeAxis(index, index); int yDataType = getAttributeType(metadataElement.getElement(refRecordName).getAttribute(yAttributeName)); ValueAxis yAxis = configureRangeIndex(index, yDataType); String yUnit = metadataElement.getElement(refRecordName).getAttribute(yAttributeName).getUnit(); yAxis.setLabel(getYAxisLabel(yAttributeName, yUnit)); xyPlot.setRenderer(index, creatItemRenderer(index, yDataType)); }
final MetadataAttribute slaveBandsAttr = new MetadataAttribute("Slave_bands", ProductData.TYPE_ASCII); slaveProduct.addAttribute(slaveBandsAttr); slaveProduct.setAttributeString(slaveBandsAttr.getName(), slaveBands);
protected List<Mask> createMasksFromFlagCodding(Product product, FlagCoding flagCoding) { String flagCodingName = flagCoding.getName(); ArrayList<Mask> masks = new ArrayList<>(); final int width = product.getSceneRasterWidth(); final int height = product.getSceneRasterHeight(); for (String flagName : flagCoding.getFlagNames()) { MetadataAttribute flag = flagCoding.getFlag(flagName); masks.add(Mask.BandMathsType.create(flagName, flag.getDescription(), width, height, flagCodingName + "." + flagName, ColorIterator.next(), 0.5)); } return masks; }
public static void createFlagMasks(Product targetProduct) { Guardian.assertNotNull("targetProduct", targetProduct); int w = targetProduct.getSceneRasterWidth(); int h = targetProduct.getSceneRasterHeight(); MyMaskColor mColor = new MyMaskColor(); ProductNodeGroup<Mask> tarMG = targetProduct.getMaskGroup(); ProductNodeGroup<FlagCoding> tarFCG = targetProduct.getFlagCodingGroup(); for (int node=0; node<tarFCG.getNodeCount(); node++){ FlagCoding fc = tarFCG.get(node); for (int i=0; i<fc.getNumAttributes(); i++){ MetadataAttribute f = fc.getAttributeAt(i); String expr = fc.getName() + "." + f.getName(); Mask m = Mask.BandMathsType.create(f.getName(), f.getDescription(), w, h, expr, mColor.next(), 0.5); tarMG.add(m); } } }
private static void searchMetadata(final MetadataElement resultElem, final MetadataElement elem, final String tag) { final MetadataElement[] elemList = elem.getElements(); for (MetadataElement e : elemList) { searchMetadata(resultElem, e, tag); } final MetadataAttribute[] attribList = elem.getAttributes(); for (MetadataAttribute attrib : attribList) { if (attrib.getName().toUpperCase().contains(tag)) { final MetadataAttribute newAttrib = attrib.createDeepClone(); newAttrib.setDescription(getAttributePath(attrib)); resultElem.addAttribute(newAttrib); } } }