/** * Returns the value as an <code>float</code>. <p>The method assumes that this value is a scalar and therefore * simply returns <code>getElemFloatAt(0)</code>. * * @see #getElemFloatAt(int index) */ public float getElemFloat() { return getElemFloatAt(0); }
/** * Gets the field element with the given index as an <code>float</code>. * * @param index the field index, must be <code>>=0</code> and <code><getNumDataElems()</code> * * @throws java.lang.IndexOutOfBoundsException * if the index is out of bounds */ public float getElemFloat(int index) { return getData().getElemFloatAt(index); }
@Override public boolean matches(Object argument) { float actualValue = ((ProductData) argument).getElemFloatAt(atIndex); return Float.compare(expectedValue, actualValue) == 0; } }
/** * Gets the <code>float</code> value of the parameter with the given key. The method performs a case-insensitive * search. * * @param key the parameter key * * @return the parameter value * * @throws HeaderEntryNotFoundException if an entry with the given key could not be found in the header */ public float getParamFloat(String key, int elemIndex) throws HeaderEntryNotFoundException { return getParamImpl(key).getData().getElemFloatAt(elemIndex); }
private static float getSolarFluxFromMetadata(MetadataElement metadataRoot, int bandIndex) { if (metadataRoot != null) { MetadataElement scalingFactorGads = metadataRoot.getElement("Scaling_Factor_GADS"); if (scalingFactorGads != null) { MetadataAttribute sunSpecFlux = scalingFactorGads.getAttribute("sun_spec_flux"); ProductData data = sunSpecFlux.getData(); if (data.getNumElems() > bandIndex) { return data.getElemFloatAt(bandIndex); } } } return 0.0f; }
private void getGeoPosInternal(int pixelX, int pixelY, GeoPos geoPos) { if (useTiling) { final int x = latLonImage.getMinX() + pixelX; final int y = latLonImage.getMinY() + pixelY; Raster data = latLonImage.getData(new Rectangle(x, y, 1, 1)); float lat = data.getSampleFloat(x, y, 0); float lon = data.getSampleFloat(x, y, 1); geoPos.setLocation(lat, lon); } else { int i = rasterWidth * pixelY + pixelX; final float lat = latGrid.getRasterData().getElemFloatAt(i); final float lon = lonGrid.getRasterData().getElemFloatAt(i); geoPos.setLocation(lat, lon); } }
@Override public float getSampleFloat(int x, int y) { float sample = dataBuffer.getElemFloatAt(index(x, y)); // handle unsigned data types, see also [BEAM-1147] (nf - 20100527) if (signedByte) { //noinspection SillyAssignment sample = (byte) sample; } if (scaled) { sample = toGeoPhysical(sample); } return sample; }
if (scaled) { for (int i = 0; i < size; i++) { samples[i] = toGeoPhysical(data.getElemFloatAt(i)); samples[i] = data.getElemFloatAt(i);
/** * Gets the sample for the pixel located at (x,y) as a float value. * * @param x The X co-ordinate of the pixel location * @param y The Y co-ordinate of the pixel location * @throws NullPointerException if this band has no raster data * @throws java.lang.ArrayIndexOutOfBoundsException * if the co-ordinates are not in bounds */ @Override public float getPixelFloat(int x, int y) { if (isScalingApplied()) { return (float) scale(getRasterData().getElemDoubleAt(getRasterWidth() * y + x)); } else { return getRasterData().getElemFloatAt(getRasterWidth() * y + x); } }
public void testDirect() { Operator op = new MyOp(); Product sourceProduct = new Product("N", "T", W, H); sourceProduct.addBand("a", ProductData.TYPE_FLOAT32).setSourceImage(ConstantDescriptor.create((float) W, (float) H, new Float[]{valueA}, null)); sourceProduct.addBand("b", ProductData.TYPE_FLOAT32).setSourceImage(ConstantDescriptor.create((float) W, (float) H, new Float[]{valueB}, null)); op.setSourceProduct(sourceProduct); Product targetProduct = op.getTargetProduct(); Band bandC = targetProduct.getBand("c"); ProductData data = bandC.createCompatibleRasterData(W, 1); DirectTile row1 = new DirectTile(bandC, data, new Rectangle(0, 0, W, 1)); op.computeTile(bandC, row1, ProgressMonitor.NULL); assertEquals(valueA + valueB, data.getElemFloatAt(0)); assertEquals(valueA + valueB, data.getElemFloatAt(1)); assertEquals(valueA + valueB, data.getElemFloatAt(2)); assertEquals(valueA + valueB, data.getElemFloatAt(3)); }
@Test public void testData() throws Exception { SimpleOp op = new SimpleOp(); Product s = new Product("S", "S", 10, 10); s.setPreferredTileSize(10, 2); op.setSourceProduct(s); Product t = op.getTargetProduct(); OperatorExecutor2 ex = new OperatorExecutor2(t); TracingHandler2 handler = new TracingHandler2(); Object metrics = ex.execute(handler); assertEquals(5, handler.trace.size()); OperatorExecutor2.Frame frame0 = handler.trace.get(0); assertNotNull(frame0.getData(0)); assertEquals(0.1f, frame0.getData(0).getElemFloatAt(0), 0.0f); assertEquals(0.3f, frame0.getData(3).getElemFloatAt(0), 0.0f); assertEquals(0.1f - 0.3f, frame0.getData(6).getElemFloatAt(0), 0.0f); assertEquals(0.1f, frame0.getData(0).getElemFloatAt(7), 0.0f); assertEquals(0.3f, frame0.getData(3).getElemFloatAt(7), 0.0f); assertEquals(0.1f - 0.3f, frame0.getData(6).getElemFloatAt(7), 0.0f); OperatorExecutor2.Frame frame3 = handler.trace.get(3); assertEquals(0.1f, frame3.getData(0).getElemFloatAt(0), 0.0f); assertEquals(0.3f, frame3.getData(3).getElemFloatAt(0), 0.0f); assertEquals(0.1f - 0.3f, frame3.getData(6).getElemFloatAt(0), 0.0f); assertEquals(0.1f, frame3.getData(0).getElemFloatAt(7), 0.0f); assertEquals(0.3f, frame3.getData(3).getElemFloatAt(7), 0.0f); assertEquals(0.1f - 0.3f, frame3.getData(6).getElemFloatAt(7), 0.0f); assertNotNull(metrics); }
if (scaled) { for (int i = 0; i < size; i++) { samples[i] = toGeoPhysical(data.getElemFloatAt(i)); samples[i] = data.getElemFloatAt(i);
@Test public void testOperatorApi() throws IOException, OperatorException, URISyntaxException { String filePath = GPFFacadeTest.class.getResource("test-product.dim").toURI().getPath(); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("file", new File(filePath)); Product p1 = GPF.createProduct("Read", parameters); assertNotNull(p1); assertNotNull(p1.getBand("forrest_abundance")); assertNotNull(p1.getBand("ocean_abundance")); assertNotNull(p1.getBand("cloud_abundance")); assertNotNull(p1.getBand("cropland_abundance")); assertNotNull(p1.getFileLocation()); assertEquals("test-product.dim", p1.getFileLocation().getName()); Product p2 = GPF.createProduct("Foo", GPF.NO_PARAMS, p1); assertNotNull(p2); assertNotNull(p2.getBand("forrest_abundance")); assertNotNull(p2.getBand("ocean_abundance")); assertNotNull(p2.getBand("cloud_abundance")); assertNotNull(p2.getBand("cropland_abundance")); Band band = p2.getBand("ocean_abundance"); band.readRasterDataFully(ProgressMonitor.NULL); ProductData rasterData = band.getRasterData(); for (int i = 0; i < rasterData.getNumElems(); i++) { assertTrue(rasterData.getElemFloatAt(i) >= 0); assertTrue(rasterData.getElemFloatAt(i) <= 1); } }
/** * {@inheritDoc} * <p/> * <p>The default implementation throws a runtime exception with the message "not implemented"</p>. */ @Override public void computeTile(Band band, Tile targetTile, ProgressMonitor pm) throws OperatorException { Tile sourceTile = getSourceTile(sourceProduct.getBand(band.getName()), targetTile.getRectangle()); ProductData rawTarget = targetTile.getRawSamples(); ProductData rawSource = sourceTile.getRawSamples(); int n = rawTarget.getNumElems(); for (int i = 0; i < n; i++) { float v = rawSource.getElemFloatAt(i); if (v < 0) { v = 0; } if (v > 1) { v = 1; } rawTarget.setElemFloatAt(i, v); } targetTile.setRawSamples(rawTarget); } }
protected void testFloat32RawSampleIO(TileImpl tile, int x, int y) { ProductData samplesGeneric = tile.getDataBuffer(); assertNotNull(samplesGeneric); float[] samplesFloat = tile.getDataBufferFloat(); assertNotNull(samplesFloat); assertSame(samplesFloat, samplesGeneric.getElems()); int lineOffset = tile.getScanlineOffset(); int lineStride = tile.getScanlineStride(); int index = lineOffset + (y - tile.getMinY()) * lineStride + (x - tile.getMinX()); assertTrue(index >= 0); assertTrue(index < samplesFloat.length); assertTrue(index < samplesGeneric.getNumElems()); assertEquals(index, tile.getDataBufferIndex(x, y)); samplesFloat[index] = 1234.56f; assertEquals(1234.56f, samplesFloat[index], 1e-5f); assertEquals(1234.56f, samplesGeneric.getElemFloatAt(index), 1e-5f); assertEquals(1234.56f, tile.getSampleFloat(x, y), 1e-5f); samplesGeneric.setElemFloatAt(index, 213.536f); assertEquals(213.536f, samplesFloat[index], 1e-5f); assertEquals(213.536f, samplesGeneric.getElemFloatAt(index), 1e-5f); assertEquals(213.536f, tile.getSampleFloat(x, y), 1e-5f); samplesGeneric.setElemIntAt(index, 707); assertEquals(707.0f, samplesFloat[index], 1e-5f); assertEquals(707.0f, samplesGeneric.getElemFloatAt(index), 1e-5f); assertEquals(707.0f, tile.getSampleFloat(x, y), 1e-5f); }
assertEquals(32767L, instance.getElemUIntAt(1)); assertEquals(-32768L, instance.getElemUIntAt(2)); assertEquals(-1.0F, instance.getElemFloatAt(0), 0.0e-12F); assertEquals(32767.0F, instance.getElemFloatAt(1), 0.0e-12F); assertEquals(-32768.0F, instance.getElemFloatAt(2), 0.0e-12F); assertEquals(-1.0D, instance.getElemDoubleAt(0), 0.0e-12D); assertEquals(32767.0D, instance.getElemDoubleAt(1), 0.0e-12D);
assertEquals(65L, instance.getElemUIntAt(1)); assertEquals(101L, instance.getElemUIntAt(2)); assertEquals(97F, instance.getElemFloatAt(0), 0.0e-12F); assertEquals(65.0F, instance.getElemFloatAt(1), 0.0e-12F); assertEquals(101.0F, instance.getElemFloatAt(2), 0.0e-12F); assertEquals(97.0D, instance.getElemDoubleAt(0), 0.0e-12D); assertEquals(65.0D, instance.getElemDoubleAt(1), 0.0e-12D);
assertEquals(2147483647L, instance.getElemUIntAt(1)); assertEquals(2147483648L, instance.getElemUIntAt(2)); assertEquals(4294967295.0F, instance.getElemFloatAt(0), 0.0e-12F); assertEquals(2147483647.0F, instance.getElemFloatAt(1), 0.0e-12F); assertEquals(2147483648.0F, instance.getElemFloatAt(2), 0.0e-12F); assertEquals(4294967295.0D, instance.getElemDoubleAt(0), 0.0e-12D); assertEquals(2147483647.0D, instance.getElemDoubleAt(1), 0.0e-12D);
assertEquals(127L, instance.getElemUIntAt(1)); assertEquals(128L, instance.getElemUIntAt(2)); assertEquals(255.0F, instance.getElemFloatAt(0), 0.0e-12F); assertEquals(127.0F, instance.getElemFloatAt(1), 0.0e-12F); assertEquals(128.0F, instance.getElemFloatAt(2), 0.0e-12F); assertEquals(255.0D, instance.getElemDoubleAt(0), 0.0e-12D); assertEquals(127.0D, instance.getElemDoubleAt(1), 0.0e-12D);
assertEquals(127L, instance.getElemUIntAt(1)); assertEquals(-128L, instance.getElemUIntAt(2)); assertEquals(-1.0F, instance.getElemFloatAt(0), 0.0e-12F); assertEquals(127.0F, instance.getElemFloatAt(1), 0.0e-12F); assertEquals(-128.0F, instance.getElemFloatAt(2), 0.0e-12F); assertEquals(-1.0D, instance.getElemDoubleAt(0), 0.0e-12D); assertEquals(127.0D, instance.getElemDoubleAt(1), 0.0e-12D);