private Band createTestBand(int type, int w, int h) { final double mean = (w * h - 1.0) / 2.0; return createTestBand(type, w, h, mean); }
@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); }
@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); }