private static void addBandNameRefs(Product product, String namePrefix, List<String> list) { for (int j = 0; j < product.getNumBands(); j++) { Band band = product.getBandAt(j); list.add(namePrefix + band.getName()); } }
@Override public boolean matches(Object argument) { return bandName.equals(((Band) argument).getName()); } }
@Override public List<Band> getBandsForVariable(String variableName) { final List<Band> bands = new ArrayList<Band>(); for (Band band : tsProduct.getBands()) { if (variableName.equals(rasterToVariableName(band.getName()))) { bands.add(band); } } sortBands(bands); return bands; }
private float getWavelength(String bandName) { final Band band = sourceProduct.getBand(bandName); final float wavelength = band.getSpectralWavelength(); if (wavelength == 0.0f) { throw new OperatorException( "The band '" + band.getName() + "' is not a spectral band.\nPlease select a spectral band for processing."); } return wavelength; }
@Override public void visit(final Band band) { if (band.getRasterData() != null && !band.isReadOnly()) { getLogger().info("Unloading raster data of '" + band.getName() + "'..."); band.unloadRasterData(); getLogger().info("Raster data unloaded."); } } }
@Override public void computeTile(Band band, Tile targetTile, ProgressMonitor pm) { if (!band.getName().equals("OperatorBand")) { throw new OperatorException("operator called for wrong band: "+ band.getName()); } // Fill the tile with the constant sample value 42 // for (Tile.Pos pos : targetTile) { targetTile.setSample(pos.x, pos.y, 42); } }
@Override public void copyBands(ProductNodeFilter<Band> filter) { Band[] sourceBands = getSourceProduct().getBands(); for (Band sourceBand : sourceBands) { if (filter.accept(sourceBand)) { copyBand(sourceBand.getName()); } } }
private static PixelGrid create(final Band b, ProgressMonitor pm) throws IOException { final int w = b.getRasterWidth(); final int h = b.getRasterHeight(); final float[] pixels = new float[w * h]; b.readPixels(0, 0, w, h, pixels, pm); return new PixelGrid(b.getProduct(), b.getName(), w, h, 0.5f, 0.5f, 1.0f, 1.0f, pixels); } }
private static void ensureBand(Scene destScene, Band sourceBand, ProductSubsetDef subsetDef) { Band band = destScene.getProduct().getBand(sourceBand.getName()); if (band == null) { Band newBand = createSubset(sourceBand, destScene, subsetDef); destScene.getProduct().addBand(newBand); } }
private void resetBandTableModel() { bandModel.clear(); if (currentRaster != null) { final int numBands = currentProduct.getNumBands(); for (int i = 0; i < numBands; i++) { final Band band = currentProduct.getBandAt(i); if (shouldDisplayBand(band)) { bandModel.addRow(band.getName(), "", band.getUnit()); } } } }
private static void registerBandSymbols(WritableNamespace namespace, Product product, String namePrefix) { for (int i = 0; i < product.getNumBands(); i++) { final Band band = product.getBandAt(i); final String symbolName = namePrefix + band.getName(); namespace.registerSymbol(new RasterDataSymbol(symbolName, band, RasterDataSymbol.GEOPHYSICAL)); namespace.registerSymbol(new RasterDataSymbol(symbolName + ".raw", band, RasterDataSymbol.RAW)); } }
static Band createSubset(Band sourceBand, Scene targetScene, ProductSubsetDef subsetDef) { final Band targetBand = new Band(sourceBand.getName(), sourceBand.getDataType(), targetScene.getRasterWidth(), targetScene.getRasterHeight()); ProductUtils.copyRasterDataNodeProperties(sourceBand, targetBand); targetBand.setSourceImage(getSourceImage(subsetDef, sourceBand)); return targetBand; }
private Band addBand(Product product, BandReader bandReader, int channelIndex) { final Band band = product.addBand(bandReader.getBandName(), bandReader.getDataType()); band.setScalingFactor(bandReader.getScalingFactor()); band.setUnit(bandReader.getBandUnit()); band.setDescription(bandReader.getBandDescription()); band.setSpectralBandIndex(channelIndex + 1); band.setValidPixelExpression(band.getName() + " != NaN"); bandReaderMap.put(band, bandReader); return band; }
protected void assertPixelValidState(Band targetBand, float sourceX, float sourceY, boolean expectedValid) throws IOException { final Band sourceBand = sourceProduct.getBand(targetBand.getName()); final PixelPos sourcePP = new PixelPos(sourceX, sourceY); final GeoPos geoPos = sourceBand.getGeoCoding().getGeoPos(sourcePP, null); final PixelPos targetPP = targetBand.getGeoCoding().getPixelPos(geoPos, null); boolean pixelValid = targetBand.isPixelValid((int) Math.floor(targetPP.x), (int) Math.floor(targetPP.y)); assertEquals(expectedValid, pixelValid); }
private void testBands(Product product) { final Band[] bands = product.getBands(); assertEquals(4, bands.length); assertEquals("lat", bands[0].getName()); assertEquals("lon", bands[1].getName()); assertEquals("radiance_1", bands[2].getName()); assertEquals("radiance_2", bands[3].getName()); assertEquals(ProductData.TYPE_FLOAT32, bands[0].getDataType()); assertEquals(ProductData.TYPE_FLOAT32, bands[1].getDataType()); assertEquals(ProductData.TYPE_FLOAT32, bands[2].getDataType()); assertEquals(ProductData.TYPE_FLOAT32, bands[3].getDataType()); }
@Override public void computeTile(Band band, Tile targetTile, ProgressMonitor pm) throws OperatorException { Band sourceBand = sourceProduct.getBand(band.getName()); Tile sourceTile = getSourceTile(sourceBand, targetTile.getRectangle()); for (int y = 0; y < targetTile.getHeight(); y++) { for (int x = 0; x < targetTile.getWidth(); x++) { targetTile.setSample(x, y, sourceTile.getSampleDouble(x, y) * factor); } } } }
@Override public void initialize() throws OperatorException { Product targetProduct = new Product("target", "target", 100, 100); for (Band srcBand : source.getBands()) { Band band = targetProduct.addBand(srcBand.getName(), srcBand.getDataType()); band.setSourceImage(srcBand.getSourceImage()); } setTargetProduct(targetProduct); }
private void copyBandTo(Product destP, Band sourceBand) { final Band destBand = new Band(sourceBand.getName(), sourceBand.getDataType(), sourceBand.getRasterWidth(), sourceBand.getRasterHeight()); destBand.setRasterData(sourceBand.getData().createDeepClone()); destP.addBand(destBand); }
@Override public void initialize() throws OperatorException { targetProduct = new Product(sourceProduct1.getName() + "_Add", sourceProduct1.getProductType(), sourceProduct1.getSceneRasterWidth(), sourceProduct1.getSceneRasterHeight()); Band[] bands = sourceProduct1.getBands(); for (Band sourceBand : bands) { targetProduct.addBand(sourceBand.getName(), sourceBand.getDataType()); } }
@Override public void initialize() { int width = sourceProduct.getSceneRasterWidth(); int height = sourceProduct.getSceneRasterHeight(); PlanarImage constImage = ConstantDescriptor.create((float) width, (float) height, new Float[]{66.6f}, null); targetProduct = new Product("name", "desc", width, height); targetProduct.addBand("OperatorBand", ProductData.TYPE_INT8); targetProduct.addBand("ConstantBand", ProductData.TYPE_FLOAT32).setSourceImage(constImage); targetProduct.addBand(new VirtualBand("VirtualBand", ProductData.TYPE_FLOAT32, width, height, "OperatorBand + ConstantBand")); ProductUtils.copyBand(sourceProduct.getBandAt(0).getName(), sourceProduct, targetProduct, true); }