@Override public boolean isEoVariableSelected(String variableName) { final MetadataElement[] variables = getVariableMetadataElements(); for (MetadataElement elem : variables) { if (elem.getAttributeString(VARIABLE_NAME).equals(variableName)) { return Boolean.parseBoolean(elem.getAttributeString(VARIABLE_SELECTION)); } } return false; }
boolean isLandsatETM_Plus() { final MetadataElement productMetadata = getProductMetadata(); return "ETM+".equals(productMetadata.getAttributeString(SENSOR_ID)); }
@Override public List<String> getEoVariables() { MetadataElement[] variableElems = getVariableMetadataElements(); List<String> variables = new ArrayList<String>(); for (MetadataElement varElem : variableElems) { variables.add(varElem.getAttributeString(VARIABLE_NAME)); } return variables; }
boolean isLandsatTM() { final MetadataElement productMetadata = getProductMetadata(); return "TM".equals(productMetadata.getAttributeString(SENSOR_ID)); }
protected ProductData.UTC getCenterTime(String acquisitionDateKey, String sceneCenterScanTimeKey) { MetadataElement metadata = getProductMetadata(); String dateString = metadata.getAttributeString(acquisitionDateKey); String timeString = metadata.getAttributeString(sceneCenterScanTimeKey); try { if (dateString != null && timeString != null) { timeString = timeString.substring(0, 12); final DateFormat dateFormat = ProductData.UTC.createDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); final Date date = dateFormat.parse(dateString + " " + timeString); String milliSeconds = timeString.substring(timeString.length() - 3); return ProductData.UTC.create(date, Long.parseLong(milliSeconds) * 1000); } } catch (ParseException ignored) { // ignore } return null; }
private void removeAttributeWithValue(String attributeName, String value, MetadataElement parentElement) { final MetadataElement[] childElements = parentElement.getElements(); for (MetadataElement elem : childElements) { if (elem.getAttributeString(attributeName).equals(value)) { parentElement.removeElement(elem); return; } } }
private void initProductLocations() { MetadataElement tsElem = tsProduct.getMetadataRoot().getElement(TIME_SERIES_ROOT_NAME); MetadataElement productListElem = tsElem.getElement(PRODUCT_LOCATIONS); MetadataElement[] productElems = productListElem.getElements(); productLocationList = new ArrayList<ProductLocation>(productElems.length); final File fileLocation = tsProduct.getProduct().getFileLocation(); for (MetadataElement productElem : productElems) { String path = productElem.getAttributeString(PL_PATH); File productFile; if (fileLocation != null) { final URI resolvedUri = fileLocation.toURI().resolve(path); productFile = new File(resolvedUri); } else { productFile = new File(path); } String type = productElem.getAttributeString(PL_TYPE); productLocationList.add(new ProductLocation(ProductLocationType.valueOf(type), productFile.getAbsolutePath())); } }
public static ReprocessingVersion autoDetect(Product product) { final MetadataElement dsdElement = product.getMetadataRoot().getElement(ELEM_NAME_DSD); if (dsdElement != null) { MetadataElement[] dsdElements = dsdElement.getElements(); for (MetadataElement element : dsdElements) { String datasetName = element.getAttributeString("DATASET_NAME", "").toLowerCase(); if (datasetName.startsWith("radiometric") && datasetName.contains("calibration")) { final String calibrationFileName = element.getAttributeString(ATTRIBUTE_FILE_NAME); if (StringUtils.isNotNullAndNotEmpty(calibrationFileName)) { final boolean reduced = product.getProductType().startsWith(REDUCED_RESOLUTION_PREFIX); final ReprocessingVersion version = detectReprocessingVersion(calibrationFileName, reduced); if (!ReprocessingVersion.AUTO_DETECT.equals(version)) { return version; } } } } } return ReprocessingVersion.AUTO_DETECT; }
@Override public boolean isAutoAdjustingTimeCoding() { final MetadataElement tsRootElement = tsProduct.getMetadataRoot().getElement(TIME_SERIES_ROOT_NAME); if (!tsRootElement.containsAttribute(AUTO_ADJUSTING_TIME_CODING)) { setAutoAdjustingTimeCoding(true); } final String autoAdjustString = tsRootElement.getAttributeString(AUTO_ADJUSTING_TIME_CODING); return Boolean.parseBoolean(autoAdjustString); }
private static void initParameter(MetadataElement parentElement, Field field, Map<String, Object> parameters) throws OperatorException { Parameter annotation = field.getAnnotation(Parameter.class); String name = annotation.alias(); if (name.isEmpty()) { name = field.getName(); } try { if (parentElement.containsAttribute(name)) { final Converter converter = getConverter(field.getType(), annotation); final String parameterText = parentElement.getAttributeString(name); final Object value = converter.parse(parameterText); parameters.put(name, value); } else { final MetadataElement element = parentElement.getElement(name); if (element != null) { final Object obj = field.getType().newInstance(); final HashMap<String, Object> objParams = new HashMap<String, Object>(); collectParameters(obj.getClass(), element, objParams); initObject(objParams, obj); parameters.put(name, obj); } } } catch (Exception e) { throw new OperatorException(String.format("Cannot initialise operator parameter '%s'", name), e); } }
public static Map<String, Object> getOperatorParameters(Product product) throws OperatorException { final MetadataElement graphElement = product.getMetadataRoot().getElement("Processing_Graph"); if (graphElement == null) { throw new OperatorException("Product has no metadata element named 'Processing_Graph'"); } final String operatorAlias = "Mosaic"; final Map<String, Object> parameters = new HashMap<String, Object>(); boolean operatorFound = false; for (MetadataElement nodeElement : graphElement.getElements()) { if (operatorAlias.equals(nodeElement.getAttributeString("operator"))) { operatorFound = true; collectParameters(MosaicOp.class, nodeElement.getElement("parameters"), parameters); } } if (!operatorFound) { throw new OperatorException("No metadata found for operator '" + operatorAlias + "'"); } return parameters; }
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); } }
@Override public void setEoVariableSelected(String variableName, boolean selected) { // set in metadata final MetadataElement[] variables = getVariableMetadataElements(); for (MetadataElement elem : variables) { if (elem.getAttributeString(VARIABLE_NAME).equals(variableName)) { elem.setAttributeString(VARIABLE_SELECTION, String.valueOf(selected)); } } // set in product if (selected) { for (Product product : getAllProducts(ProgressMonitor.NULL)) { addSpecifiedBandOfGivenProduct(variableName, product); } } else { final Band[] bands = tsProduct.getBands(); for (Band band : bands) { if (variableName.equals(rasterToVariableName(band.getName()))) { tsProduct.removeBand(band); } } } fireChangeEvent(new TimeSeriesChangeEvent(TimeSeriesChangeEvent.PROPERTY_EO_VARIABLE_SELECTION, null, this)); }
private void updateMetadata(Product product) { final MetadataElement graphElement = product.getMetadataRoot().getElement("Processing_Graph"); for (MetadataElement nodeElement : graphElement.getElements()) { if (getSpi().getOperatorAlias().equals(nodeElement.getAttributeString("operator"))) { final MetadataElement sourcesElement = nodeElement.getElement("sources"); for (int i = 0; i < sourceProducts.length; i++) { final String oldIndex = String.valueOf(i + 1); final String newIndex = String.valueOf(sourcesElement.getNumAttributes() + i + 1); final Product sourceProduct = sourceProducts[i]; final String attributeName = getSourceProductId(sourceProduct).replaceFirst(oldIndex, newIndex); final File location = sourceProduct.getFileLocation(); final ProductData attributeValue; if (location == null) { attributeValue = ProductData.createInstance(product.toString()); } else { attributeValue = ProductData.createInstance(location.getPath()); } final MetadataAttribute attribute = new MetadataAttribute(attributeName, attributeValue, true); sourcesElement.addAttribute(attribute); } } } }
private MetadataElement getSourcesElement(MosaicOp mosaicUpdateOp, MetadataElement mosaicMetadata) { for (MetadataElement element : mosaicMetadata.getElements()) { if (mosaicUpdateOp.getSpi().getOperatorAlias().equals(element.getAttributeString("operator"))) { return element.getElement("sources"); } } return null; }
private String getPathString(final String tsMetadataName, int idx) { return testProduct.getMetadataRoot() .getElement(AbstractTimeSeries.TIME_SERIES_ROOT_NAME) .getElement(tsMetadataName) .getElement(tsMetadataName + "." + idx) .getAttributeString(AbstractTimeSeries.PL_PATH); }
addAbstractedAttribute("PRODUCT", mph.getAttributeString("PRODUCT", ""), absRoot, "Product name"); addAbstractedAttribute("PRODUCT_TYPE", _productType, absRoot, "Product type"); addAbstractedAttribute("SPH_DESCRIPTOR", sph.getAttributeString("SPH_DESCRIPTOR", ""), absRoot, "Description"); addAbstractedAttribute("MISSION", getMission(_productType, _file), absRoot, "Satellite mission"); addAbstractedAttribute("BEAMS", " ", absRoot, "Beams used"); if (waveProduct) { addAbstractedAttribute("SWATH", sph.getAttributeString("SWATH_1", ""), absRoot, "Swath name"); } else { addAbstractedAttribute("SWATH", sph.getAttributeString("SWATH", ""), absRoot, "Swath Name"); addAbstractedAttribute("Processing_system_identifier", mph.getAttributeString("SOFTWARE_VER", ""), absRoot, "Processing system identifier"); addAbstractedAttribute(mph, "CYCLE", absRoot, "Cycle"); addAbstractedAttribute("STATE_VECTOR_TIME", mph.getAttributeUTC("STATE_VECTOR_TIME", new ProductData.UTC(0)), absRoot, "Time of orbit state vector"); addAbstractedAttribute("VECTOR_SOURCE", mph.getAttributeString("VECTOR_SOURCE", ""), absRoot, "State vector source"); String mds1_tx_rx_polar = sph.getAttributeString("tx_rx_polar", ""); mds1_tx_rx_polar = mds1_tx_rx_polar.replace("/", ""); addAbstractedAttribute("mds1_tx_rx_polar", mds1_tx_rx_polar, absRoot, "Polarization"); addAbstractedAttribute("PASS", sph.getAttributeString("PASS", ""), absRoot, "ASCENDING or DESCENDING"); addAbstractedAttribute("SAMPLE_TYPE", sph.getAttributeString("SAMPLE_TYPE").trim(), absRoot, "DETECTED or COMPLEX"); String mds1_tx_rx_polar = sph.getAttributeString("mds1_tx_rx_polar", ""); mds1_tx_rx_polar = mds1_tx_rx_polar.replace("/", "");
@Test public void testProcessingGraphInMetadata() { // using the SubsetOp here, because when using a TestOperator the module.xml is not found OperatorSpiRegistry operatorSpiRegistry = GPF.getDefaultInstance().getOperatorSpiRegistry(); if (operatorSpiRegistry.getOperatorSpi("Subset") == null) { operatorSpiRegistry.addOperatorSpi(new SubsetOp.Spi()); } final Operator testOp = operatorSpiRegistry.getOperatorSpi("Subset").createOperator(); testOp.setSourceProduct(new Product("dummy", "T", 10, 10)); Product targetProduct = testOp.getTargetProduct(); MetadataElement metadataRoot = targetProduct.getMetadataRoot(); MetadataElement elementPG = metadataRoot.getElement(OperatorContext.PROCESSING_GRAPH_ELEMENT_NAME); assertNotNull(elementPG); MetadataElement node0Element = elementPG.getElement("node.0"); assertNotNull(node0Element); assertEquals(9, node0Element.getNumAttributes()); assertNotNull(node0Element.getAttribute("id")); assertNotNull(node0Element.getAttribute("operator")); assertNotNull(node0Element.getAttribute("moduleName")); assertEquals("beam-gpf", node0Element.getAttributeString("moduleName")); assertNotNull(node0Element.getAttribute("moduleVersion")); assertNotNull(node0Element.getAttribute("processingTime")); }