public Object createObject(int index) throws Exception { _dem.updateCache(GETASSE30ElevationTile.this); return band.readPixels(0, index, width, 1, new float[width], ProgressMonitor.NULL); } };
static double[] getSpectrum(List<Band> bands, int pixelX, int pixelY) throws IOException { final double[] pixel = new double[1]; final double[] spectrum = new double[bands.size()]; for (int i = 0; i < bands.size(); i++) { final Band band = bands.get(i); band.readPixels(pixelX, pixelY, 1, 1, pixel, com.bc.ceres.core.ProgressMonitor.NULL); final double value; if (band.isPixelValid(pixelX, pixelY)) { value = pixel[0]; } else { value = Double.NaN; } spectrum[i] = value; } return spectrum; }
/** * Checks whether or not the longitudes of this geo-coding cross the +/- 180 degree meridian. * * @return <code>true</code>, if so */ @Override public boolean isCrossingMeridianAt180() { if (crossingMeridianAt180 == null) { crossingMeridianAt180 = false; final PixelPos[] pixelPoses = ProductUtils.createPixelBoundary(lonBand, null, 1); try { float[] firstLonValue = new float[1]; lonBand.readPixels(0, 0, 1, 1, firstLonValue); float[] secondLonValue = new float[1]; for (int i = 1; i < pixelPoses.length; i++) { final PixelPos pixelPos = pixelPoses[i]; lonBand.readPixels((int) pixelPos.x, (int) pixelPos.y, 1, 1, secondLonValue); if (Math.abs(firstLonValue[0] - secondLonValue[0]) > 180) { crossingMeridianAt180 = true; break; } firstLonValue[0] = secondLonValue[0]; } } catch (IOException e) { throw new IllegalStateException("raster data is not readable", e); } } return crossingMeridianAt180; }
if (band.isPixelValid(x, y)) { if (band.isFloatingPointType()) { band.readPixels(x, y, 1, 1, floatPixel, ProgressMonitor.NULL); out.print(floatPixel[0]); } else { band.readPixels(x, y, 1, 1, intPixel, ProgressMonitor.NULL); out.print(intPixel[0]);
public static void main(String[] args) { try { Product product = ProductIO.readProduct("C:/Projects/BEAM/data/MER_RR__1P_A.N1"); int width = product.getSceneRasterWidth(); int height = product.getSceneRasterHeight(); Band band = product.getBand("radiance_13"); float[] scan = new float[width]; for (int y = 0; y < height; y += 100) { band.readPixels(0, y, width, 1, scan, ProgressMonitor.NULL); for (int x = 0; x < width; x += 100) { float value = scan[x]; System.out.println(value + " "); } } System.out.println(); product.dispose(); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use Options | File Templates. } } }
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); } }
float[] latData = latitudeBand.readPixels(0, 0, rasterWidth, rasterHeight, (float[]) null); TiePointGrid tpLat = new TiePointGrid("latitude", rasterWidth, rasterHeight, 0.5f, 0.5f, 1f, 1f, latData); product.addTiePointGrid(tpLat); float[] lonData = longitudeBand.readPixels(0, 0, rasterWidth, rasterHeight, (float[]) null); TiePointGrid tpLon = new TiePointGrid("longitude", rasterWidth, rasterHeight, 0.5f, 0.5f, 1f, 1f, lonData); product.addTiePointGrid(tpLon);
@Test public void testTwoSourceProductsWithNames() throws Exception { HashMap<String, Product> productMap = new HashMap<String, Product>(); productMap.put("numberOne", createTestProduct(4, 4)); productMap.put("numberTwo", createTestProduct(4, 4)); Map<String, Object> parameters = new HashMap<String, Object>(); BandMathsOp.BandDescriptor[] bandDescriptors = new BandMathsOp.BandDescriptor[1]; bandDescriptors[0] = createBandDescription("aBandName", "$numberOne.band1 + $numberTwo.band2", ProductData.TYPESTRING_FLOAT32, "milliUnit"); parameters.put("targetBands", bandDescriptors); Product targetProduct = GPF.createProduct("BandMaths", parameters, productMap); Band band = targetProduct.getBand("aBandName"); float[] actualValues = new float[16]; band.readPixels(0, 0, 4, 4, actualValues, ProgressMonitor.NULL); float[] expectedValues = new float[16]; Arrays.fill(expectedValues, 3.5f); assertTrue(Arrays.equals(expectedValues, actualValues)); }
@Test public void testTwoSourceBandsOneTargetBand() throws Exception { Product sourceProduct = createTestProduct(4, 4); Map<String, Object> parameters = new HashMap<>(); BandMathsOp.BandDescriptor[] bandDescriptors = new BandMathsOp.BandDescriptor[1]; bandDescriptors[0] = createBandDescription("aBandName", "band1 + band2", ProductData.TYPESTRING_FLOAT32, ""); parameters.put("targetBands", bandDescriptors); Product targetProduct = GPF.createProduct("BandMaths", parameters, sourceProduct); Band band = targetProduct.getBand("aBandName"); float[] actualValues = new float[16]; band.readPixels(0, 0, 4, 4, actualValues, ProgressMonitor.NULL); float[] expectedValues = new float[16]; Arrays.fill(expectedValues, 3.5f); assertTrue(Arrays.equals(expectedValues, actualValues)); }
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); }
band1.readPixels(0, y, width, 1, band1Samples); band2.readPixels(0, y, width, 1, band2Samples); band3.readPixels(0, y, width, 1, band3Samples); for (int x = 0; x < width; x++) { float L1 = band1Samples[x];
@Test public void testTwoSourceProductsOneTargetBand() throws Exception { Product sourceProduct1 = createTestProduct(4, 4); Product sourceProduct2 = createTestProduct(4, 4); Map<String, Object> parameters = new HashMap<String, Object>(); BandMathsOp.BandDescriptor[] bandDescriptors = new BandMathsOp.BandDescriptor[1]; bandDescriptors[0] = createBandDescription("aBandName", "$sourceProduct.1.band1 + $sourceProduct.2.band2", ProductData.TYPESTRING_FLOAT32, "milliUnit"); parameters.put("targetBands", bandDescriptors); Product targetProduct = GPF.createProduct("BandMaths", parameters, sourceProduct1, sourceProduct2); Band band = targetProduct.getBand("aBandName"); float[] actualValues = new float[16]; band.readPixels(0, 0, 4, 4, actualValues, ProgressMonitor.NULL); float[] expectedValues = new float[16]; Arrays.fill(expectedValues, 3.5f); assertTrue(Arrays.equals(expectedValues, actualValues)); }
private void computeClusters(ProgressMonitor pm) throws IOException { int width = sourceProduct.getSceneRasterWidth(); int height = sourceProduct.getSceneRasterHeight(); double[] scanLine = new double[width]; double[][] dsVectors = new double[width][featureBands.length]; // todo - handle valid expression! DataSet ds = new DataSet(width * height, featureBands.length); for (int y = 0; y < height; y++) { for (int i = 0; i < featureBands.length; i++) { Band featureBand = featureBands[i]; featureBand.readPixels(0, y, width, 1, scanLine, ProgressMonitor.NULL); // todo - handle no-data! for (int x = 0; x < width; x++) { dsVectors[x][i] = scanLine[x]; } } for (int x = 0; x < width; x++) { ds.add(dsVectors[x]); } checkForCancellation(); } clucov = new Clucov(ds); //clucov. clucov.initialize(30); clucov.run(); }
@Test public void testScaledInputBand() throws Exception { Map<String, Object> parameters = new HashMap<>(); BandMathsOp.BandDescriptor[] bandDescriptors = new BandMathsOp.BandDescriptor[2]; bandDescriptors[0] = createBandDescription("aBandName", "band3", ProductData.TYPESTRING_FLOAT32, "milliUnits"); bandDescriptors[1] = createBandDescription("bBandName", "band3.raw & 64", ProductData.TYPESTRING_INT32, "noUnits"); parameters.put("targetBands", bandDescriptors); Product sourceProduct = createTestProduct(4, 4); Product targetProduct = GPF.createProduct("BandMaths", parameters, sourceProduct); assertNotNull(targetProduct); Band band = targetProduct.getBand("aBandName"); assertNotNull(band); assertEquals("aDescription", band.getDescription()); assertEquals("milliUnits", band.getUnit()); assertEquals(ProductData.TYPE_FLOAT32, band.getDataType()); float[] floatValues = new float[16]; band.readPixels(0, 0, 4, 4, floatValues, ProgressMonitor.NULL); float[] expectedValues = new float[16]; Arrays.fill(expectedValues, 3.0f); assertTrue(Arrays.equals(expectedValues, floatValues)); Band bband = targetProduct.getBand("bBandName"); int[] intValues = new int[16]; bband.readPixels(0, 0, 4, 4, intValues, ProgressMonitor.NULL); int[] expectedIntValues = new int[16]; Arrays.fill(expectedValues, (3 & 64)); assertTrue(Arrays.equals(expectedIntValues, intValues)); }
@Test public void testDivisionByZero() throws Exception { Map<String, Object> parameters = new HashMap<String, Object>(); BandMathsOp.BandDescriptor[] bandDescriptors = new BandMathsOp.BandDescriptor[1]; bandDescriptors[0] = createBandDescription("aBandName", "band1/0.0", ProductData.TYPESTRING_FLOAT32, "bigUnits"); parameters.put("targetBands", bandDescriptors); Product sourceProduct = createTestProduct(4, 4); Product targetProduct = GPF.createProduct("BandMaths", parameters, sourceProduct); assertNotNull(targetProduct); Band band = targetProduct.getBand("aBandName"); assertNotNull(band); assertEquals("aDescription", band.getDescription()); assertEquals("bigUnits", band.getUnit()); assertEquals(ProductData.TYPE_FLOAT32, band.getDataType()); float[] floatValues = new float[16]; band.readPixels(0, 0, 4, 4, floatValues, ProgressMonitor.NULL); float[] expectedValues = new float[16]; Arrays.fill(expectedValues, Float.NaN); assertTrue(Arrays.equals(expectedValues, floatValues)); }
int[] expectedObsLine = new int[region.width]; for (int y = 0; y < region.height; y++) { numObs.readPixels(0, y, region.width, 1, actualObsLine); Arrays.fill(expectedObsLine, y); if (y == 3) { int[] expectedPassesLine = new int[region.width]; for (int y = 0; y < region.height; y++) { numPasses.readPixels(0, y, region.width, 1, actualPassesLine); Arrays.fill(expectedPassesLine, y+1); if (y == 3) {
@Test public void testSimplestCaseWithFactoryMethod() throws Exception { Product sourceProduct = createTestProduct(4, 4); BandMathsOp bandMathsOp = createBooleanExpressionBand(sourceProduct, "band1 > 0"); assertNotNull(bandMathsOp); Product targetProduct = bandMathsOp.getTargetProduct(); assertNotNull(targetProduct); Band band = targetProduct.getBandAt(0); assertNotNull(band); assertEquals(ProductData.TYPE_INT8, band.getDataType()); int[] intValues = new int[16]; band.readPixels(0, 0, 4, 4, intValues, ProgressMonitor.NULL); int[] expectedValues = new int[16]; Arrays.fill(expectedValues, 1); assertTrue(Arrays.equals(expectedValues, intValues)); }
int[] expectedObsLine = new int[region.width]; for (int y = 0; y < region.height; y++) { numObs.readPixels(0, y, region.width, 1, actualObsLine); Arrays.fill(expectedObsLine, y); if (y == 3) { Arrays.fill(expectedConst3Line, 3); for (int y = 0; y < region.height; y++) { const3.readPixels(0, y, region.width, 1, actualConst3Line); assertArrayEquals(expectedConst3Line, actualConst3Line);
@Test public void testScaledOutputBand() throws Exception { Map<String, Object> parameters = new HashMap<>(); BandMathsOp.BandDescriptor[] bandDescriptors = new BandMathsOp.BandDescriptor[1]; bandDescriptors[0] = createBandDescription("aBandName", "band1", ProductData.TYPESTRING_FLOAT32, "milliUnits", 0.1, 5.0); parameters.put("targetBands", bandDescriptors); Product sourceProduct = createTestProduct(4, 4); Product targetProduct = GPF.createProduct("BandMaths", parameters, sourceProduct); assertNotNull(targetProduct); Band band = targetProduct.getBand("aBandName"); assertNotNull(band); assertEquals("aDescription", band.getDescription()); assertEquals("milliUnits", band.getUnit()); assertEquals(ProductData.TYPE_FLOAT32, band.getDataType()); assertEquals(0.1, band.getScalingFactor(), 1E-6); assertEquals(5.0, band.getScalingOffset(), 1E-6); float[] floatValues = new float[16]; band.readPixels(0, 0, 4, 4, floatValues, ProgressMonitor.NULL); float[] expectedValues = new float[16]; Arrays.fill(expectedValues, 1.0F); assertTrue(Arrays.equals(expectedValues, floatValues)); }
@Test public void testSimplestCase() throws Exception { Map<String, Object> parameters = new HashMap<String, Object>(); BandMathsOp.BandDescriptor[] bandDescriptors = new BandMathsOp.BandDescriptor[1]; bandDescriptors[0] = createBandDescription("aBandName", "1.0", ProductData.TYPESTRING_FLOAT32, "bigUnits"); parameters.put("targetBands", bandDescriptors); Product sourceProduct = createTestProduct(4, 4); Product targetProduct = GPF.createProduct("BandMaths", parameters, sourceProduct); assertNotNull(targetProduct); Band band = targetProduct.getBand("aBandName"); assertNotNull(band); assertEquals("aDescription", band.getDescription()); assertEquals("bigUnits", band.getUnit()); assertEquals(ProductData.TYPE_FLOAT32, band.getDataType()); float[] floatValues = new float[16]; band.readPixels(0, 0, 4, 4, floatValues, ProgressMonitor.NULL); float[] expectedValues = new float[16]; Arrays.fill(expectedValues, 1.0f); assertTrue(Arrays.equals(expectedValues, floatValues)); assertNotNull(targetProduct.getStartTime()); assertEquals(sourceProduct.getStartTime(), targetProduct.getStartTime()); assertNotNull(targetProduct.getEndTime()); assertEquals(sourceProduct.getEndTime(), targetProduct.getEndTime()); }