private Band createTestBand(int type, int w, int h) { final double mean = (w * h - 1.0) / 2.0; return createTestBand(type, w, h, mean); }
private Band createTestBand(int type, int w, int h, double offset) { final Product product = createTestProduct(w, h); final Band band = new VirtualBand("V", type, w, h, "(Y-0.5) * " + w + " + (X-0.5) - " + offset); product.addBand(band); return band; }
@Test public void testThatAccumulateWithSummaryStxOpGetsTheRightMinMax() { //preparation final Band testBand = createFloatTestBand(10, 10, 20, 60); final SummaryStxOp stxOp = new SummaryStxOp(); //execution StxFactory.accumulate(testBand, 0, null, null, stxOp, ProgressMonitor.NULL); //verification assertEquals(20, stxOp.getMinimum(), 1e-44); assertEquals(60, stxOp.getMaximum(), 1e-44); assertEquals(40, stxOp.getMean(), 1e-7); final double variance = 137.4009443244; assertEquals(variance, stxOp.getVariance(), 1e-7); assertEquals(Math.sqrt(variance), stxOp.getStandardDeviation(), 1e-7); }
@Test public void testFloatBandStatisticsWithGapsInHistogram() throws Exception { final Band band = createTestBand(ProductData.TYPE_FLOAT32, 10, 12); Stx stx = new StxFactory().create(band, ProgressMonitor.NULL); assertEquals(0.0, stx.getMedian(), 0.0); assertEquals(0.0, stx.getMean(), 0.0); assertEquals(34.8, stx.getStandardDeviation(), 1.0e-1); }
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; }
@Test public void testSignedByteBandStatistics() throws Exception { final Band band = createTestBand(ProductData.TYPE_INT8, 11, 13); final Stx stx = new StxFactory().create(band, ProgressMonitor.NULL); assertEquals(0.0, stx.getMedian(), 1.0e-1); assertEquals(0.0, stx.getMean(), 0.0); assertEquals(41.4, stx.getStandardDeviation(), 1.0e-1); }
@Test public void testFloatBandStatistics() throws Exception { final Band band = createTestBand(ProductData.TYPE_FLOAT32, 100, 120); final Stx stx = new StxFactory().create(band, ProgressMonitor.NULL); assertEquals(0.0, stx.getMedian(), 0.0); assertEquals(0.0, stx.getMean(), 0.0); assertEquals(3464.2, stx.getStandardDeviation(), 1.0e-1); }
@Test public void testCreateStxForMultipleBands() throws Exception { final Band testBand1 = createTestBand(ProductData.TYPE_FLOAT64, 10, 10, -100); final Band testBand2 = createTestBand(ProductData.TYPE_FLOAT64, 10, 10, -200); Stx stx = new StxFactory().withHistogramBinCount(2097152).create(null, new RasterDataNode[]{testBand1, testBand2}, ProgressMonitor.NULL); assertEquals(100, stx.getMinimum(), 1E-3); assertEquals(299, stx.getMaximum(), 1E-3); assertEquals(199.5, stx.getMean(), 1E-3); assertEquals(199.5, stx.getMedian(), 1E-3); assertEquals(279, stx.getHistogram().getPTileThreshold(0.9)[0], 1E-3); assertEquals(199, stx.getHistogram().getPTileThreshold(0.5)[0], 1E-3); assertEquals(119, stx.getHistogram().getPTileThreshold(0.1)[0], 1E-3); }
@Test public void testCreateStxForMultipleBandsAndRoiMask() throws Exception { final Band testBand1 = createTestBand(ProductData.TYPE_FLOAT64, 10, 10, -100); final Band testBand2 = createTestBand(ProductData.TYPE_FLOAT64, 10, 10, -200); final Mask roiMask = testBand1.getProduct().addMask("validMask", "X < 5", "testValidMask", Color.gray, Double.NaN); final Mask roiMask2 = testBand2.getProduct().addMask("validMask", "X < 5", "testValidMask", Color.gray, Double.NaN); Stx stx = new StxFactory() .withHistogramBinCount(2097152) .create(new Mask[]{roiMask, roiMask2}, new RasterDataNode[]{testBand1, testBand2}, ProgressMonitor.NULL); assertEquals(100, stx.getMinimum(), 1E-3); assertEquals(294, stx.getMaximum(), 1E-3); assertEquals(197, stx.getMean(), 1E-3); assertEquals(274, stx.getHistogram().getPTileThreshold(0.9)[0], 1E-3); assertEquals(194, stx.getHistogram().getPTileThreshold(0.5)[0], 1E-3); assertEquals(114, stx.getHistogram().getPTileThreshold(0.1)[0], 1E-3); }
@Test public void testCreateStxForNullBands() throws Exception { final Band testBand1 = createTestBand(ProductData.TYPE_FLOAT64, 10, 10, -100); final Band testBand2 = null; Stx stx = new StxFactory().withHistogramBinCount(524288).create(null, new RasterDataNode[]{testBand1, testBand2}, ProgressMonitor.NULL); assertEquals(100, stx.getMinimum(), 1E-3); assertEquals(199, stx.getMaximum(), 1E-3); assertEquals(149.5, stx.getMean(), 1E-3); assertEquals(149.5, stx.getMedian(), 1E-3); assertEquals(189, stx.getHistogram().getPTileThreshold(0.9)[0], 1E-3); assertEquals(149, stx.getHistogram().getPTileThreshold(0.5)[0], 1E-3); assertEquals(109, stx.getHistogram().getPTileThreshold(0.1)[0], 1E-3); }
@Test public void testFloatBandStatisticsWithNoDataValueSet() throws Exception { final Band band = createTestBand(ProductData.TYPE_FLOAT32, 100, 120); band.setNoDataValueUsed(true); band.setNoDataValue(-0.5); Stx stx = new StxFactory().withRoiImage(band.getValidMaskImage()).create(band, ProgressMonitor.NULL); assertEquals(5.0e-1, stx.getMedian(), 0.1e-1); assertEquals(4.1e-5, stx.getMean(), 0.1e-5); assertEquals(3464.4, stx.getStandardDeviation(), 1.0e-1); band.setNoDataValue(0.5); stx = new StxFactory().withRoiImage(band.getValidMaskImage()).create(band, ProgressMonitor.NULL); assertEquals(-5.0e-1, stx.getMedian(), 0.1e-1); assertEquals(-4.1e-5, stx.getMean(), 0.1e-5); assertEquals(3464.4, stx.getStandardDeviation(), 1.0e-1); }