List<Band> getBands(Product product) { List<String> names = getBandNames(); List<Band> bands = new ArrayList<>(names.size()); for (String name : names) { Band band = product.getBand(name); if (band == null) { return null; } bands.add(band); } return bands; }
public static void main(String[] args) { try { Product product = ProductIO.readProduct(args[0]); Band band = product.getBand("radiance_13"); BufferedImage rgbImage = band.createRgbImage(ProgressMonitor.NULL); ImageIO.write(rgbImage, "PNG", new File(product.getName() + ".png")); } catch (IOException e) { System.err.println("Error: " + e.getMessage()); } } }
public void addGeocoding(final Product product) throws ProductIOException { final String longitude = "longitude"; final String latitude = "latitude"; Band latBand = product.getBand(latitude); Band lonBand = product.getBand(longitude); latBand.setNoDataValue(-999.); lonBand.setNoDataValue(-999.); latBand.setNoDataValueUsed(true); lonBand.setNoDataValueUsed(true); product.setGeoCoding(GeoCodingFactory.createPixelGeoCoding(latBand, lonBand, null, 5)); } }
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 computeTileStack(Map<Band, Tile> targetTiles, Rectangle targetRectangle, ProgressMonitor pm) throws OperatorException { for (Map.Entry<Band, Tile> entry : targetTiles.entrySet()) { checkForCancellation(); Band targetBand = entry.getKey(); Tile targetTile = entry.getValue(); Band sourceBand = tempCloudProduct.getBand(targetBand.getName()); Rectangle targetRect = targetTile.getRectangle(); ProductData rawSamples = getSourceTile(sourceBand, targetRect).getRawSamples(); targetTile.setRawSamples(rawSamples); } }
private void addSpectralInfo(Product product, String name, int index, float min, float max, float solFlux) { Band spectralBand = product.getBand(name); if (spectralBand != null) { spectralBand.setSpectralBandIndex(index); spectralBand.setSpectralWavelength(min + 0.5f * (max - min)); spectralBand.setSpectralBandwidth(max - min); spectralBand.setSolarFlux(solFlux); spectralBand.setDescription(MessageFormat.format("{0} spectral band", name)); } }
private void testThat(ProductReader reader) throws IOException { Product product = reader.readProductNodes(null, null); testThat(product.getBand("B1").getSourceImage(), product.getBand("B2").getSourceImage()); testThat(product.getBand("B1").getGeophysicalImage(), product.getBand("B2").getGeophysicalImage()); }
@Test public void testStoreRgbaExpressions() { final Product p1 = createTestProduct(); RGBImageProfile.storeRgbaExpressions(p1, new String[]{"U", "V", "W", "X"}); assertNotNull(p1.getBand(RGBImageProfile.RED_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.GREEN_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.BLUE_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.ALPHA_BAND_NAME)); }
@Test public void testStoreRgbaExpressionsWithoutAlpha() { final Product p1 = createTestProduct(); RGBImageProfile.storeRgbaExpressions(p1, new String[]{"U", "V", "W", ""}); assertNotNull(p1.getBand(RGBImageProfile.RED_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.GREEN_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.BLUE_BAND_NAME)); assertNull(p1.getBand(RGBImageProfile.ALPHA_BAND_NAME)); }
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); } }
@Test public void testNoDataIsReplaced_WithNaN() throws IOException { parameterMap.put("crs", UTM33N_CODE); final Band srcBand = sourceProduct.getBand(FLOAT_BAND_NAME); srcBand.setValidPixelExpression("fneq("+FLOAT_BAND_NAME + ",299)"); final Product targetPoduct = createReprojectedProduct(); assertNoDataValue(targetPoduct.getBand(FLOAT_BAND_NAME), new PixelPos(23.5f, 13.5f), Float.NaN, Float.NaN); }
@Test public void testNoDataParameter_Float() throws IOException { parameterMap.put("crs", UTM33N_CODE); parameterMap.put("noDataValue", 42.0); final Product targetPoduct = createReprojectedProduct(); assertNoDataValue(targetPoduct.getBand(FLOAT_BAND_NAME), new PixelPos(23.5f, 13.5f), 42.0, 299.0); }
private BufferedImage createQuickLook(final Product product) throws IOException { final ProductSubsetDef productSubsetDef = new ProductSubsetDef("subset"); int scaleFactor = product.getSceneRasterWidth() / maxWidth; if (scaleFactor < 1) { scaleFactor = 1; } productSubsetDef.setSubSampling(scaleFactor, scaleFactor); final Product productSubset = product.createSubset(productSubsetDef, null, null); final String quicklookBandName = ProductUtils.findSuitableQuicklookBandName(productSubset); return ProductUtils.createColorIndexedImage(productSubset.getBand(quicklookBandName), ProgressMonitor.NULL); }
@Test public void testNoDataIsPreservedFloat() throws IOException { parameterMap.put("crs", UTM33N_CODE); final Band srcBand = sourceProduct.getBand(FLOAT_BAND_NAME); srcBand.setNoDataValue(299); srcBand.setNoDataValueUsed(true); final Product targetPoduct = createReprojectedProduct(); assertNoDataValue(targetPoduct.getBand(FLOAT_BAND_NAME), new PixelPos(23.5f, 13.5f), 299.0, 299.0); }
@Test public void testStxHandling() throws IOException { final Product product2 = ProductSubsetBuilder.createProductSubset(product, null, "subset", ""); assertEquals(false, product2.getBand(INDEX_CODED_BAND_NAME).isStxSet()); product.getBand(INDEX_CODED_BAND_NAME).getStx(true, ProgressMonitor.NULL); final Product product3 = ProductSubsetBuilder.createProductSubset(product, null, "subset", ""); assertEquals(true, product3.getBand(INDEX_CODED_BAND_NAME).isStxSet()); }
@Test public void testWithWktFile() throws IOException { parameterMap.put("wktFile", wktFile); final Product targetPoduct = createReprojectedProduct(); assertNotNull(targetPoduct); assertPixelValue(targetPoduct.getBand(FLOAT_BAND_NAME), 23.5f, 13.5f, (double) 299, EPS); }
@Test public void testNoDataIsPreservedFloat_withExpression() throws IOException { parameterMap.put("crs", UTM33N_CODE); final Band srcBand = sourceProduct.getBand(FLOAT_BAND_NAME); srcBand.setNoDataValue(299); srcBand.setNoDataValueUsed(true); srcBand.setValidPixelExpression("fneq("+FLOAT_BAND_NAME + ",299)"); final Product targetPoduct = createReprojectedProduct(); assertNoDataValue(targetPoduct.getBand(FLOAT_BAND_NAME), new PixelPos(23.5f, 13.5f), 299.0, 299.0); }
protected void assertPixelValue(Band targetBand, float sourceX, float sourceY, double expectedPixelValue, double delta) 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); final double[] pixels = new double[1]; targetBand.readPixels((int) Math.floor(targetPP.x), (int) Math.floor(targetPP.y), 1, 1, pixels); assertEquals(expectedPixelValue, pixels[0], delta); }
private void doTestTransferGeoCoding() throws IOException { Product sourceProduct = createProduct(); GeoCoding newGeoCoding = new PixelGeoCoding(sourceProduct.getBand("latBand"), sourceProduct.getBand("lonBand"), null, 5, ProgressMonitor.NULL); sourceProduct.setGeoCoding(newGeoCoding); Product targetProduct = createProduct(); targetProduct.setGeoCoding(null); // remove geo-coding of target product sourceProduct.transferGeoCodingTo(targetProduct, null); PixelGeoCoding targetGC = (PixelGeoCoding) targetProduct.getGeoCoding(); assertNotNull(targetGC.getPixelPosEstimator()); }
@Override public void initialize() throws OperatorException { sourceBand = sourceProduct.getBand(bandName); targetProduct = new Product(sourceProduct.getName(), sourceProduct.getProductType(), sourceProduct.getSceneRasterWidth(), sourceProduct.getSceneRasterHeight()); targetBand = targetProduct.addBand(bandName, sourceBand.getDataType()); }