NdviOp extends Operator { static String findBand(float minWavelength, float maxWavelength, Product product) { String bestBand = null; float bestBandLowerDelta = Float.MAX_VALUE; for (Band band : product.getBands()) { float bandWavelength = band.getSpectralWavelength(); if (bandWavelength != 0.0F) { float lowerDelta = bandWavelength - minWavelength; if (lowerDelta < bestBandLowerDelta && bandWavelength <= maxWavelength && bandWavelength >= minWavelength) { bestBand = band.getName(); bestBandLowerDelta = lowerDelta; } } } return bestBand; }  @Override void initialize(); @Override void computeTileStack(Map<Band, Tile> targetTiles, Rectangle rectangle, ProgressMonitor pm); static final String NDVI_BAND_NAME; static final String NDVI_FLAGS_BAND_NAME; static final String NDVI_ARITHMETIC_FLAG_NAME; static final String NDVI_LOW_FLAG_NAME; static final String NDVI_HIGH_FLAG_NAME; static final int NDVI_ARITHMETIC_FLAG_VALUE; static final int NDVI_LOW_FLAG_VALUE; static final int NDVI_HIGH_FLAG_VALUE; }
@Test public void testFindBand() throws Exception { Product product = new Product("dummy", "dummy", 10, 10); addBand(product, "a", 500); addBand(product, "b", 600); addBand(product, "c", 620); addBand(product, "d", 700); addBand(product, "e", 712); addBand(product, "f", 715); addBand(product, "g", 799); addBand(product, "h", 800); addBand(product, "i", 801); addBand(product, "j", 899); addBand(product, "k", 900); addBand(product, "l", 16000); assertEquals("b", NdviOp.findBand(600, 650, product)); assertEquals("h", NdviOp.findBand(800, 900, product)); }
@Test public void testFindBand_nothingFound() throws Exception { Product product = new Product("dummy", "dummy", 10, 10); addBand(product, "a", 500); addBand(product, "b", 600); addBand(product, "c", 620); addBand(product, "d", 700); addBand(product, "e", 712); addBand(product, "f", 715); addBand(product, "g", 799); addBand(product, "h", 800); addBand(product, "i", 801); addBand(product, "j", 899); addBand(product, "k", 900); assertNull(NdviOp.findBand(400, 499, product)); assertNull(NdviOp.findBand(701, 711, product)); assertNull(NdviOp.findBand(901, 12000, product)); }
@Test public void testFindBand_nothingFound_2() throws Exception { Product product = new Product("dummy", "dummy", 10, 10); addBand(product, "a"); addBand(product, "b"); addBand(product, "c"); addBand(product, "d"); addBand(product, "e"); addBand(product, "f"); addBand(product, "g"); addBand(product, "h"); addBand(product, "i"); addBand(product, "j"); addBand(product, "k"); addBand(product, "l"); assertNull(NdviOp.findBand(600, 650, product)); }