public Map<Band, Variable> addBands( Product product, Variable idxVariable, List<Variable> l3ProdVars) { final Structure binListStruc = (Structure) idxVariable; final Map<Band, Variable> bandToVariableMap = new HashMap<Band, Variable>(); // bandToVariableMap.put(addBand(product, "bin_num", ProductData.TYPE_UINT32), // binListStruc.select("bin_num").findVariable("bin_num")); bandToVariableMap.put( addBand(product, "weights", ProductData.TYPE_FLOAT32), binListStruc.select("weights").findVariable("weights")); bandToVariableMap.put( addBand(product, "nobs", ProductData.TYPE_UINT16), binListStruc.select("nobs").findVariable("nobs")); bandToVariableMap.put( addBand(product, "nscenes", ProductData.TYPE_UINT16), binListStruc.select("nscenes").findVariable("nscenes")); // ncFile.getRootGroup().findGroup("Level-3 Binned Data").findVariable("BinList"); if (ncFile.getRootGroup().findGroup("Level-3_Binned_Data").findVariable("qual_l3") != null) { bandToVariableMap.put( addBand(product, "qual_l3", ProductData.TYPE_UINT8), ncFile.getRootGroup().findGroup("Level-3_Binned_Data").findVariable("qual_l3")); } String groupnames = ""; for (Variable l3Var : l3ProdVars) { String varName = l3Var.getShortName(); final int dataType = ProductData.TYPE_FLOAT32; if (!varName.contains("Bin") && (!varName.startsWith("qual")) && (!varName.equalsIgnoreCase("SEAGrid")) && (!varName.equalsIgnoreCase("Input_Files"))) { final Structure binStruc = (Structure) l3Var; if (groupnames.length() == 0) { groupnames = varName; } else { groupnames = groupnames + ":" + varName; } List<String> vnames = binStruc.getVariableNames(); for (String bandvar : vnames) { bandToVariableMap.put( addBand(product, bandvar, dataType), binStruc.select(bandvar).findVariable(bandvar)); } // Add virtual band for product mean StringBuilder prodname = new StringBuilder(varName); prodname.append("_mean"); String calcmean = ComputeBinMeans(varName); Band varmean = new VirtualBand( prodname.toString(), ProductData.TYPE_FLOAT32, product.getSceneRasterWidth(), product.getSceneRasterHeight(), calcmean); varmean.setNoDataValue(Double.NaN); varmean.setNoDataValueUsed(true); product.addBand(varmean); // Add virtual band for product stdev int underscore = prodname.indexOf("_mean"); prodname.delete(underscore, underscore + 5); prodname.append("_stdev"); String calcstdev = ComputeBinVariances(varName); Band varstdev = new VirtualBand( prodname.toString(), ProductData.TYPE_FLOAT32, product.getSceneRasterWidth(), product.getSceneRasterHeight(), calcstdev); varstdev.setNoDataValue(Double.NaN); varstdev.setNoDataValueUsed(true); product.addBand(varstdev); } } product.setAutoGrouping(groupnames); return bandToVariableMap; }
@Override void setInvalidPixelExpression(Band band) { if (band.isFlagBand()) { band.setNoDataValueUsed(false); } else { band.setNoDataValueUsed(true); band.setNoDataValue(-2); } }
@Override public Band addBand(String name, String expression, double noDataValue) { Band band = addBand(name, expression); band.setNoDataValue(noDataValue); band.setNoDataValueUsed(true); return band; }
@Override public Band addBand(String name, int dataType, double noDataValue) { Band band = addBand(name, dataType); band.setNoDataValue(noDataValue); band.setNoDataValueUsed(true); return band; }
private void setTargetBands() { Band aot550Band = targetProduct.addBand(SynergyConstants.OUTPUT_AOT_BAND_NAME, ProductData.TYPE_FLOAT32); aot550Band.setNoDataValue(SynergyConstants.OUTPUT_AOT_BAND_NODATAVALUE); aot550Band.setNoDataValueUsed(SynergyConstants.OUTPUT_AOT_BAND_NODATAVALUE_USED); aot550Band.setUnit("dl"); Band aot550ErrBand = targetProduct.addBand(SynergyConstants.OUTPUT_AOTERR_BAND_NAME, ProductData.TYPE_FLOAT32); aot550ErrBand.setNoDataValue(SynergyConstants.OUTPUT_AOT_BAND_NODATAVALUE); aot550ErrBand.setNoDataValueUsed(SynergyConstants.OUTPUT_AOT_BAND_NODATAVALUE_USED); aot550ErrBand.setUnit("dl"); if (!computeLand) { // write more bands specific for ocean retrieval Band angBand = targetProduct.addBand(SynergyConstants.OUTPUT_ANG_BAND_NAME, ProductData.TYPE_FLOAT32); angBand.setNoDataValue(SynergyConstants.OUTPUT_ANG_BAND_NODATAVALUE); angBand.setNoDataValueUsed(SynergyConstants.OUTPUT_ANG_BAND_NODATAVALUE_USED); Band angErrBand = targetProduct.addBand(SynergyConstants.OUTPUT_ANGERR_BAND_NAME, ProductData.TYPE_FLOAT32); angErrBand.setNoDataValue(SynergyConstants.OUTPUT_ANG_BAND_NODATAVALUE); angErrBand.setNoDataValueUsed(SynergyConstants.OUTPUT_ANG_BAND_NODATAVALUE_USED); } }
private Band addBand(Product product, String varName, int productType) { Band band = new Band( varName, productType, product.getSceneRasterWidth(), product.getSceneRasterHeight()); band.setScalingOffset(0.0); band.setScalingFactor(1.0); band.setLog10Scaled(false); if (productType == ProductData.TYPE_FLOAT32) { band.setNoDataValue(Double.NaN); } else { band.setNoDataValue(-999); } band.setNoDataValueUsed(true); product.addBand(band); return band; }
protected Band addNewBand(Product product, Variable variable) { final int sceneRasterWidth = product.getSceneRasterWidth(); final int sceneRasterHeight = product.getSceneRasterHeight(); Band band = null; int variableRank = variable.getRank(); if (variableRank == 2) { final int[] dimensions = variable.getShape(); final int height = dimensions[0] - leadLineSkip - tailLineSkip; final int width = dimensions[1]; if (height == sceneRasterHeight && width == sceneRasterWidth) { final String name = variable.getShortName(); final int dataType = getProductDataType(variable); band = new Band(name, dataType, width, height); final String validExpression = bandInfoMap.get(name); if (validExpression != null && !validExpression.equals("")) { band.setValidPixelExpression(validExpression); } product.addBand(band); try { band.setNoDataValue( (double) variable.findAttribute("bad_value_scaled").getNumericValue().floatValue()); band.setNoDataValueUsed(true); } catch (Exception ignored) { } final List<Attribute> list = variable.getAttributes(); for (Attribute hdfAttribute : list) { final String attribName = hdfAttribute.getShortName(); if ("units".equals(attribName)) { band.setUnit(hdfAttribute.getStringValue()); } else if ("long_name".equals(attribName)) { band.setDescription(hdfAttribute.getStringValue()); } else if ("slope".equals(attribName)) { band.setScalingFactor(hdfAttribute.getNumericValue(0).doubleValue()); } else if ("intercept".equals(attribName)) { band.setScalingOffset(hdfAttribute.getNumericValue(0).doubleValue()); } } } } return band; }
protected void addBands(Product product, GCTileFile gcTileFile) { final List<BandDescriptor> bandDescriptorList = gcTileFile.getBandDescriptorList(); for (BandDescriptor descriptor : bandDescriptorList) { final Band band = new Band( descriptor.getName(), descriptor.getDataType(), product.getSceneRasterWidth(), product.getSceneRasterHeight()); band.setScalingFactor(descriptor.getScaleFactor()); band.setScalingOffset(descriptor.getOffsetValue()); band.setDescription(descriptor.getDescription()); band.setUnit(descriptor.getUnit()); band.setNoDataValueUsed(descriptor.isFillValueUsed()); band.setNoDataValue(descriptor.getFillValue()); product.addBand(band); band.setSourceImage(getMultiLevelImage(band)); } }
protected Map<Band, Variable> addSmiBands(Product product, List<Variable> variables) { final int sceneRasterWidth = product.getSceneRasterWidth(); final int sceneRasterHeight = product.getSceneRasterHeight(); Map<Band, Variable> bandToVariableMap = new HashMap<Band, Variable>(); for (Variable variable : variables) { int variableRank = variable.getRank(); if (variableRank == 2) { final int[] dimensions = variable.getShape(); final int height = dimensions[0]; final int width = dimensions[1]; if (height == sceneRasterHeight && width == sceneRasterWidth) { String name = variable.getShortName(); if (name.equals("l3m_data")) { try { name = getStringAttribute("Parameter") + " " + getStringAttribute("Measure"); } catch (Exception e) { e.printStackTrace(); } } final int dataType = getProductDataType(variable); final Band band = new Band(name, dataType, width, height); // band = new Band(name, dataType, width, height); product.addBand(band); try { Attribute fillvalue = variable.findAttribute("_FillValue"); if (fillvalue == null) { fillvalue = variable.findAttribute("Fill"); } if (fillvalue != null) { band.setNoDataValue((double) fillvalue.getNumericValue().floatValue()); band.setNoDataValueUsed(true); } } catch (Exception ignored) { } bandToVariableMap.put(band, variable); // Set units, if defined try { band.setUnit(getStringAttribute("Units")); } catch (Exception ignored) { } final List<Attribute> list = variable.getAttributes(); double[] validMinMax = {0.0, 0.0}; for (Attribute hdfAttribute : list) { final String attribName = hdfAttribute.getShortName(); if ("units".equals(attribName)) { band.setUnit(hdfAttribute.getStringValue()); } else if ("long_name".equalsIgnoreCase(attribName)) { band.setDescription(hdfAttribute.getStringValue()); } else if ("slope".equalsIgnoreCase(attribName)) { band.setScalingFactor(hdfAttribute.getNumericValue(0).doubleValue()); } else if ("intercept".equalsIgnoreCase(attribName)) { band.setScalingOffset(hdfAttribute.getNumericValue(0).doubleValue()); } else if ("scale_factor".equals(attribName)) { band.setScalingFactor(hdfAttribute.getNumericValue(0).doubleValue()); } else if ("add_offset".equals(attribName)) { band.setScalingOffset(hdfAttribute.getNumericValue(0).doubleValue()); } else if (attribName.startsWith("valid_")) { if ("valid_min".equals(attribName)) { validMinMax[0] = hdfAttribute.getNumericValue(0).doubleValue(); } else if ("valid_max".equals(attribName)) { validMinMax[1] = hdfAttribute.getNumericValue(0).doubleValue(); } else if ("valid_range".equals(attribName)) { validMinMax[0] = hdfAttribute.getNumericValue(0).doubleValue(); validMinMax[1] = hdfAttribute.getNumericValue(1).doubleValue(); } } } if (validMinMax[0] != validMinMax[1]) { double[] minmax = {0.0, 0.0}; minmax[0] = validMinMax[0]; minmax[1] = validMinMax[1]; if (band.getScalingFactor() != 1.0) { minmax[0] *= band.getScalingFactor(); minmax[1] *= band.getScalingFactor(); } if (band.getScalingOffset() != 0.0) { minmax[0] += band.getScalingOffset(); minmax[1] += band.getScalingOffset(); } String validExp = format("%s >= %.2f && %s <= %.2f", name, minmax[0], name, minmax[1]); band.setValidPixelExpression( validExp); // .format(name, validMinMax[0], name, validMinMax[1])); } } } else if (variableRank == 4) { final int[] dimensions = variable.getShape(); final int height = dimensions[2]; final int width = dimensions[3]; if (height == sceneRasterHeight && width == sceneRasterWidth) { String name = variable.getShortName(); final int dataType = getProductDataType(variable); final Band band = new Band(name, dataType, width, height); // band = new Band(name, dataType, width, height); Variable sliced = null; try { sliced = variable.slice(0, 0).slice(0, 0); } catch (InvalidRangeException e) { e.printStackTrace(); // Todo change body of catch statement. } bandToVariableMap.put(band, sliced); product.addBand(band); try { Attribute fillvalue = variable.findAttribute("_FillValue"); if (fillvalue != null) { band.setNoDataValue((double) fillvalue.getNumericValue().floatValue()); band.setNoDataValueUsed(true); } } catch (Exception ignored) { } // Set units, if defined try { band.setUnit(getStringAttribute("units")); } catch (Exception ignored) { } final List<Attribute> list = variable.getAttributes(); for (Attribute hdfAttribute : list) { final String attribName = hdfAttribute.getShortName(); if ("scale_factor".equals(attribName)) { band.setScalingFactor(hdfAttribute.getNumericValue(0).doubleValue()); } else if ("add_offset".equals(attribName)) { band.setScalingOffset(hdfAttribute.getNumericValue(0).doubleValue()); } } } } } return bandToVariableMap; }
protected void addBandsToProduct(Product product) { Debug.assertNotNull(getSourceProduct()); Debug.assertNotNull(product); for (int i = 0; i < getSourceProduct().getNumBands(); i++) { Band sourceBand = getSourceProduct().getBandAt(i); String bandName = sourceBand.getName(); if (isNodeAccepted(bandName)) { Band destBand; boolean treatVirtualBandsAsRealBands = false; if (getSubsetDef() != null && getSubsetDef().getTreatVirtualBandsAsRealBands()) { treatVirtualBandsAsRealBands = true; } // @todo 1 se/se - extract copy of a band or virtual band to create deep clone of band and // virtual band if (!treatVirtualBandsAsRealBands && sourceBand instanceof VirtualBand) { VirtualBand virtualSource = (VirtualBand) sourceBand; destBand = new VirtualBand( bandName, sourceBand.getDataType(), getSceneRasterWidth(), getSceneRasterHeight(), virtualSource.getExpression()); } else { destBand = new Band( bandName, sourceBand.getDataType(), getSceneRasterWidth(), getSceneRasterHeight()); } if (sourceBand.getUnit() != null) { destBand.setUnit(sourceBand.getUnit()); } if (sourceBand.getDescription() != null) { destBand.setDescription(sourceBand.getDescription()); } destBand.setScalingFactor(sourceBand.getScalingFactor()); destBand.setScalingOffset(sourceBand.getScalingOffset()); destBand.setLog10Scaled(sourceBand.isLog10Scaled()); destBand.setSpectralBandIndex(sourceBand.getSpectralBandIndex()); destBand.setSpectralWavelength(sourceBand.getSpectralWavelength()); destBand.setSpectralBandwidth(sourceBand.getSpectralBandwidth()); destBand.setSolarFlux(sourceBand.getSolarFlux()); if (sourceBand.isNoDataValueSet()) { destBand.setNoDataValue(sourceBand.getNoDataValue()); } destBand.setNoDataValueUsed(sourceBand.isNoDataValueUsed()); destBand.setValidPixelExpression(sourceBand.getValidPixelExpression()); FlagCoding sourceFlagCoding = sourceBand.getFlagCoding(); IndexCoding sourceIndexCoding = sourceBand.getIndexCoding(); if (sourceFlagCoding != null) { String flagCodingName = sourceFlagCoding.getName(); FlagCoding destFlagCoding = product.getFlagCodingGroup().get(flagCodingName); Debug.assertNotNull( destFlagCoding); // should not happen because flag codings should be already in // product destBand.setSampleCoding(destFlagCoding); } else if (sourceIndexCoding != null) { String indexCodingName = sourceIndexCoding.getName(); IndexCoding destIndexCoding = product.getIndexCodingGroup().get(indexCodingName); Debug.assertNotNull( destIndexCoding); // should not happen because index codings should be already in // product destBand.setSampleCoding(destIndexCoding); } else { destBand.setSampleCoding(null); } if (isFullScene(getSubsetDef()) && sourceBand.isStxSet()) { copyStx(sourceBand, destBand); } product.addBand(destBand); bandMap.put(destBand, sourceBand); } } for (final Map.Entry<Band, RasterDataNode> entry : bandMap.entrySet()) { copyImageInfo(entry.getValue(), entry.getKey()); } }
@Override public void initialize() throws OperatorException { if (category == DataCategory.NDVI_MAXCOMPOSIT_NEW) { Arrays.sort(sourceProducts, new ProductNameComparator()); sortedDataSourceProducts = sourceProducts; } else { final String sourceDataProductFilter = "_data"; final String sourceFlagProductFilter = "_flag"; sortedDataSourceProducts = DiversityAuxdataUtils.sortProductsByMonth(sourceProducts, sourceDataProductFilter, 2, 7); sortedFlagSourceProducts = DiversityAuxdataUtils.sortProductsByMonth(sourceProducts, sourceFlagProductFilter, 2, 7); } final Product yearlyNdviProduct = createYearlyProduct(); if (writeFlags) { final FlagCoding ndviFlagCoding = DiversityAuxdataUtils.createNdviFlagCoding(); yearlyNdviProduct.getFlagCodingGroup().add(ndviFlagCoding); TARGET_BAND_PREFIX += "flag_"; DiversityAuxdataUtils.addPatternToAutoGrouping(yearlyNdviProduct, "ndvi_max_flag"); } else { DiversityAuxdataUtils.addPatternToAutoGrouping(yearlyNdviProduct, "ndvi_max"); } halfmonthlyDataProductsMap = new HashMap<String, List<Product>>(); halfmonthlyFlagProductsMap = new HashMap<String, List<Product>>(); for (int i = 0; i < Constants.MONTHS.length; i++) { final String month = Constants.MONTHS[i]; List<Product> thisMonthDataProducts = new ArrayList<Product>(); List<Product> thisMonthFlagProducts = new ArrayList<Product>(); for (Product product : sortedDataSourceProducts) { if (category == DataCategory.NDVI_MAXCOMPOSIT_NEW) { if (product.getName().contains(String.format("_%02d_", i + 1))) { thisMonthDataProducts.add(product); } } else { if (product.getName().contains(month)) { thisMonthDataProducts.add(product); } } } if (category == DataCategory.NDVI_MAXCOMPOSIT) { for (Product product : sortedFlagSourceProducts) { if (product.getName().contains(month)) { thisMonthFlagProducts.add(product); } } } if (thisMonthDataProducts.size() == 2 && (thisMonthFlagProducts.size() == 2 || category == DataCategory.NDVI_MAXCOMPOSIT_NEW)) { // the normal case halfmonthlyDataProductsMap.put(month, thisMonthDataProducts); halfmonthlyFlagProductsMap.put(month, thisMonthFlagProducts); Band targetBand = new Band(TARGET_BAND_PREFIX + month, ProductData.TYPE_FLOAT32, width, height); targetBand.setNoDataValue(Constants.NDVI_INVALID_VALUE); targetBand.setNoDataValueUsed(true); yearlyNdviProduct.addBand(targetBand); } else { System.err.println( "Warning: NDVI products for '" + month + "' missing or incomplete - skipping."); } } setTargetProduct(yearlyNdviProduct); }