private void fillBandWithData(final Band band, final int start) { final ProductData data = band.createCompatibleRasterData(); for (int i = 0; i < WIDTH * HEIGHT; i++) { data.setElemIntAt(i, start + i); } band.setData(data); }
private Band createDataBand(int min, int max, String bandName) { final Band band = new Band(bandName, ProductData.TYPE_INT8, PRODUCT_WIDTH, PRODUCT_HEIGHT); final byte[] array = new byte[PRODUCT_WIDTH * PRODUCT_HEIGHT]; fillArray(array, max, min); band.setData(new ProductData.Byte(array)); return band; }
private Band createFloatTestBand(int w, int h, float min, float max) { final Product product = createTestProduct(w, h); final Band band = product.addBand("float", ProductData.TYPE_FLOAT32); final float[] values = new float[w * h]; for (int i = 0; i < values.length; i++) { values[i] = min + i * (max - min) / (values.length - 1); } band.setData(new ProductData.Float(values)); return band; }
/** * Creates an in-memory product with given width and height and adds a band to the product. * * @return the created in-memory product. */ public static Product createInMemoryProduct() { // define the product size in pixels int width = 200; int height = 200; // allocate data for the band to be added float[] bandData = new float[width * height]; // create the product. Name and type of the product identify the product. // The constructor accepts four parameters: // name - String - the name of the product // type - String - the product type description // width - int - the width of the scene data raster of the product // height - int - the height of the scene data raster of the product Product product = new Product("productName", "productType", width, height); // Create a band of type float. The width and height of the band must match the // product width and height where the band shall be added to. Band aBand = new Band("bandName", ProductData.TYPE_FLOAT32, width, height); // Attach the data array to the band. aBand.setData(ProductData.createInstance(bandData)); // Add the band to the product product.addBand(aBand); product.setModified(false); return product; }
private static void fillBandWithData(Band band) { final ProductData productData = band.createCompatibleRasterData(); final int n = productData.getNumElems(); for (int i = 0; i < n; i++) { productData.setElemDoubleAt(i, i * 2.4); } band.setData(productData); } }
private static ProductData createProductDataForBand(final Band band, final int start) { final ProductData data = band.createCompatibleRasterData(); for (int i = 0; i < band.getSceneRasterWidth() * band.getSceneRasterHeight(); i++) { data.setElemIntAt(i, start + i); } band.setData(data); return data; }
private static ProductData createProductDataForBand(final Band band, final double start) { final ProductData data = band.createCompatibleRasterData(); for (int i = 0; i < band.getSceneRasterWidth() * band.getSceneRasterHeight(); i++) { data.setElemDoubleAt(i, start + i); } band.setData(data); return data; }
private void fillBandWithData(final Band band, final int start) { final ProductData data = band.createCompatibleRasterData(); for (int i = 0; i < band.getSceneRasterWidth() * band.getSceneRasterHeight(); i++) { data.setElemIntAt(i, start + i); } band.setData(data); } }
private static Product createTestProduct(int w, int h) throws ParseException { Product testProduct = new Product("p", "t", w, h); Band band1 = testProduct.addBand("band1", ProductData.TYPE_INT32); int[] intValues = new int[w * h]; Arrays.fill(intValues, 1); band1.setData(ProductData.createInstance(intValues)); Band band2 = testProduct.addBand("band2", ProductData.TYPE_FLOAT32); float[] floatValues = new float[w * h]; Arrays.fill(floatValues, 2.5f); band2.setData(ProductData.createInstance(floatValues)); Band band3 = testProduct.addBand("band3", ProductData.TYPE_INT16); band3.setScalingFactor(0.5); short[] shortValues = new short[w * h]; Arrays.fill(shortValues, (short) 6); band3.setData(ProductData.createInstance(shortValues)); testProduct.setStartTime(ProductData.UTC.parse("01-APR-2011 11:22:33")); testProduct.setEndTime(ProductData.UTC.parse("02-APR-2011 11:22:33")); return testProduct; }
private static ProductData createProductDataForBand(final Band band, final float start) { final ProductData data = band.createCompatibleRasterData(); for (int i = 0; i < band.getSceneRasterWidth() * band.getSceneRasterHeight(); i++) { data.setElemFloatAt(i, start + i); } band.setData(data); return data; }
@Test public void testModifiedFlagAfterBandHasBeenModified() { Band band = new Band("band1", ProductData.TYPE_FLOAT32, _sceneWidth, _sceneHeight); product.addBand(band); product.setModified(false); band.setData(ProductData.createInstance(new float[_sceneWidth * _sceneHeight])); assertEquals("data initialized, modified flag should not be set", false, product.isModified()); band.setData(ProductData.createInstance(new float[_sceneWidth * _sceneHeight])); assertEquals("data modified, modified flag should be set", true, product.isModified()); band.setModified(false); product.setModified(false); band.setData(null); assertEquals("data set to null, modified flag should be set", true, product.isModified()); }
@Test public void testCreateTransectProfileText_Float() throws IOException { final Product product = new Product("X", "Y", 2, 1); Band node = product.addBand("name", ProductData.TYPE_FLOAT32); node.setSynthetic(true); final float[] data = new float[product.getSceneRasterWidth() * product.getSceneRasterHeight()]; Arrays.fill(data, 1.0f); data[0] = Float.NaN; // no data node.setData(ProductData.createInstance(data)); final Line2D.Float shape = new Line2D.Float(0.5f, 0.5f, 1.5f, 0.5f); final TransectProfileData profileData = node.createTransectProfileData(shape); final String profileDataString = StatisticsUtils.TransectProfile.createTransectProfileText(node, profileData); assertTrue(profileDataString.contains("NaN")); assertFalse(profileDataString.toLowerCase().contains("no data")); } }
private void fillBandDataInt(Band band, int startValue) { final ProductData data = band.createCompatibleProductData(product.getSceneRasterWidth() * product.getSceneRasterHeight()); int value = startValue; int dataIndex = 0; for(int i = 0; i < product.getSceneRasterWidth(); i++) { for(int j = 0; j < product.getSceneRasterHeight(); j++) { data.setElemIntAt(dataIndex++, value++); } } band.setData(data); }
private void fillBandDataFloat(Band band, int startValue) { final ProductData data = band.createCompatibleProductData(product.getSceneRasterWidth() * product.getSceneRasterHeight()); int value = startValue; int dataIndex = 0; for(int i = 0; i < product.getSceneRasterWidth(); i++) { for(int j = 0; j < product.getSceneRasterHeight(); j++) { data.setElemFloatAt(dataIndex++, value++); } } band.setData(data); } }
@Test public void testCreateTransectProfileText_Byte() throws IOException { final Product product = new Product("X", "Y", 2, 1); Band node = product.addBand("name", ProductData.TYPE_INT8); node.setSynthetic(true); node.setNoDataValue(0); node.setNoDataValueUsed(true); final byte[] data = new byte[product.getSceneRasterWidth() * product.getSceneRasterHeight()]; Arrays.fill(data, (byte) 1); data[0] = 0; // no data node.setData(ProductData.createInstance(data)); final Line2D.Float shape = new Line2D.Float(0.5f, 0.5f, 1.5f, 0.5f); final TransectProfileData profileData = node.createTransectProfileData(shape); final String profileDataString = StatisticsUtils.TransectProfile.createTransectProfileText(node, profileData); assertTrue(profileDataString.contains("NaN")); assertFalse(profileDataString.toLowerCase().contains("no data")); }
@Test public void testGetPixelString_Float() { final Product product = new Product("X", "Y", 2, 1); Band node = product.addBand("name", ProductData.TYPE_FLOAT32); node.setSynthetic(true); final float[] data = new float[product.getSceneRasterWidth() * product.getSceneRasterHeight()]; Arrays.fill(data, 1.0f); data[0] = Float.NaN; // no data node.setData(ProductData.createInstance(data)); assertEquals("NaN", node.getPixelString(0, 0)); assertEquals("1.0", node.getPixelString(1, 0)); }
int[] intValues = new int[w * h]; Arrays.fill(intValues, 1); band1.setData(ProductData.createInstance(intValues)); band2.setData(ProductData.createInstance(floatValues)); short[] shortValues = new short[w * h]; Arrays.fill(shortValues, (short) 6); band3.setData(ProductData.createInstance(shortValues));
@Test public void testGetPixelString_Byte() { final Product product = new Product("X", "Y", 2, 1); Band node = product.addBand("name", ProductData.TYPE_INT8); node.setSynthetic(true); node.setNoDataValue(0); node.setNoDataValueUsed(true); final byte[] data = new byte[product.getSceneRasterWidth() * product.getSceneRasterHeight()]; Arrays.fill(data, (byte) 1); data[0] = 0; // no data node.setData(ProductData.createInstance(data)); assertEquals("NaN", node.getPixelString(0, 0)); assertEquals("1", node.getPixelString(1, 0)); }
private void testDataType(int productDataType, double v1, double v2, String validMask) { Product p = new Product("p", "t", 1, 2); Band b = p.addBand("b", productDataType); ProductData pData = ProductData.createInstance(productDataType, 2); pData.setElemDoubleAt(0, v1); pData.setElemDoubleAt(1, v2); b.setData(pData); b.setNoDataValue(v2); b.setNoDataValueUsed(true); assertTrue(b.isPixelValid(0, 0)); assertFalse(b.isPixelValid(0, 1)); assertEquals(validMask, b.getValidMaskExpression()); }