/** * Creates an {@code Stx} instance. * * @return The statistics. */ public Stx create() { return create(null, ProgressMonitor.NULL); }
/** * Computes statistics for the given raster data node. * * @param raster The raster data node. * @param pm A progress monitor. * @return The statistics. */ public Stx create(RasterDataNode raster, ProgressMonitor pm) { if (roiMask != null) { return create(new Mask[]{roiMask}, new RasterDataNode[]{raster}, pm); } return create(null, new RasterDataNode[]{raster}, pm); }
/** * Computes the statistics. May be overridden. * This method belongs to preliminary API and may be removed or changed in the future. * * @param level The resolution level. * @param pm A progress monitor. * @return The statistics. * @since BEAM 4.5 */ protected Stx computeStxImpl(int level, ProgressMonitor pm) { return new StxFactory().withResolutionLevel(level).create(this, pm); }
private static double computeStxOnce(Band band) { final long t0 = System.nanoTime(); new StxFactory().create(band, ProgressMonitor.NULL); final long t1 = System.nanoTime(); return (t1 - t0) / 1e6; } }
private void setRange(int varIndex, RasterDataNode raster, Mask mask, ProgressMonitor pm) throws IOException { final AxisRangeControl axisRangeControl = axisRangeControls[varIndex]; if (axisRangeControl.isAutoMinMax()) { Stx stx; if (mask == null) { stx = raster.getStx(false, pm); } else { stx = new StxFactory().withRoiMask(mask).create(raster, pm); } axisRangeControl.adjustComponents(stx.getMinimum(), stx.getMaximum(), NUM_DECIMALS); } }
private Stx createStx() { return new StxFactory() .withMinimum(-0.2) .withMaximum(3) .withMean(5.5) .withStandardDeviation(3.67) .withHistogramBins(new int[]{4, 5, 4, 7, 5, 8}) .create(); }
@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); }
private static Stx createStx(Band band, Element bandStatisticsElem) { final Double minSample = getElemDouble(bandStatisticsElem, DimapProductConstants.TAG_STX_MIN); final Double maxSample = getElemDouble(bandStatisticsElem, DimapProductConstants.TAG_STX_MAX); final Double mean = getElemDouble(bandStatisticsElem, DimapProductConstants.TAG_STX_MEAN); final Double stdDev = getElemDouble(bandStatisticsElem, DimapProductConstants.TAG_STX_STDDEV); final Integer level = getElemInt(bandStatisticsElem, DimapProductConstants.TAG_STX_LEVEL); final int[] bins = getHistogramBins(bandStatisticsElem); boolean intHistogram = !ProductData.isFloatingPointType(band.getGeophysicalDataType()); if (minSample != null && maxSample != null) { return new StxFactory() .withMinimum(minSample) .withMaximum(maxSample) .withMean(mean) .withStandardDeviation(stdDev) .withIntHistogram(intHistogram) .withHistogramBins(bins == null ? new int[0] : bins) .withResolutionLevel(level).create(); } return null; }
private void setLogarithmicDisplay(final RasterDataNode raster, final boolean logarithmicDisplay) { final ImageInfoEditorModel model = imageInfoEditor.getModel(); if (logarithmicDisplay) { final StxFactory stxFactory = new StxFactory(); final Stx stx = stxFactory .withHistogramBinCount(raster.getStx().getHistogramBinCount()) .withLogHistogram(logarithmicDisplay) .withResolutionLevel(raster.getSourceImage().getModel().getLevelCount() - 1) .create(raster, ProgressMonitor.NULL); model.setDisplayProperties(raster.getName(), raster.getUnit(), stx, POW10_SCALING); } else { model.setDisplayProperties(raster.getName(), raster.getUnit(), raster.getStx(), Scaling.IDENTITY); } model.getImageInfo().setLogScaled(logarithmicDisplay); }
@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); }
@Test public void testMinMaxBinsLogHistogram() throws Exception { StxFactory factory = new StxFactory(); factory .withMinimum(0.1) .withMaximum(10) .withLogHistogram(true) .withHistogramBins(new int[]{1, 2, 3, 6, 6, 3, 2, 1}); Stx stx = factory.create(); assertNotNull(stx.getHistogram()); assertEquals(1, stx.getHistogram().getNumBands()); assertEquals(8, stx.getHistogram().getNumBins()[0]); assertEquals(0.1, stx.getMinimum(), 1e-10); assertEquals(10, stx.getMaximum(), 1e-10); assertEquals(Math.pow(10.0, stx.getHistogram().getMean()[0]), stx.getMean(), 1e-3); assertEquals(Math.pow(10.0, 0), stx.getMedian(), 1e-3); assertEquals(-1.0, stx.getHistogram().getLowValue(0), 1e-10); assertEquals(1.0, stx.getHistogram().getHighValue(0), 1e-10); assertArrayEquals(new int[]{1, 2, 3, 6, 6, 3, 2, 1}, stx.getHistogramBins()); }
@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 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 testMinMaxBins() throws Exception { StxFactory factory = new StxFactory(); factory .withMinimum(-1.0) .withMaximum(1.0) .withHistogramBins(new int[]{1, 2, 3, 6, 6, 3, 2, 1}); Stx stx = factory.create(); assertEquals(-1.0, stx.getMinimum(), 1e-10); assertEquals(1.0, stx.getMaximum(), 1e-10); assertEquals(-0.125, stx.getMean(), 1e-10); assertEquals(0.0, stx.getMedian(), 1e-10); assertNotNull(stx.getHistogram()); assertEquals(1, stx.getHistogram().getNumBands()); assertEquals(8, stx.getHistogram().getNumBins()[0]); assertEquals(-1.0, stx.getHistogram().getLowValue(0), 1e-10); assertEquals(1.0, stx.getHistogram().getHighValue(0), 1e-10); assertArrayEquals(new int[]{1, 2, 3, 6, 6, 3, 2, 1}, stx.getHistogramBins()); }
@Test public void testMinMaxBinsLogHistogramWithNegativeMinimum() throws Exception { StxFactory factory = new StxFactory(); factory .withMinimum(-10) .withMaximum(+10) .withLogHistogram(true) .withHistogramBins(new int[]{1, 2, 3, 6, 6, 3, 2, 1}); Stx stx = factory.create(); assertEquals(-10, stx.getMinimum(), 1e-10); assertEquals(+10, stx.getMaximum(), 1e-10); assertEquals(0.0, stx.getMean(), 1e-3); assertEquals(0.0, stx.getMedian(), 1e-3); assertNotNull(stx.getHistogram()); assertEquals(1, stx.getHistogram().getNumBands()); assertEquals(8, stx.getHistogram().getNumBins()[0]); assertEquals(-9.0, stx.getHistogram().getLowValue(0), 1e-10); // 1E-9 is the max value we handle assertEquals(1.0, stx.getHistogram().getHighValue(0), 1e-10); assertArrayEquals(new int[]{1, 2, 3, 6, 6, 3, 2, 1}, stx.getHistogramBins()); }
@Test public void testMinMaxBinsIntHistogram() throws Exception { StxFactory factory = new StxFactory(); factory .withMinimum(1) .withMaximum(100) .withIntHistogram(true) .withHistogramBins(new int[]{1, 2, 3, 6, 6, 3, 2, 1}); Stx stx = factory.create(); assertEquals(1, stx.getMinimum(), 1e-10); assertEquals(100, stx.getMaximum(), 1e-10); assertEquals(44.75, stx.getMean(), 1e-10); assertEquals(51.0, stx.getMedian(), 1e-10); assertNotNull(stx.getHistogram()); assertEquals(1, stx.getHistogram().getNumBands()); assertEquals(8, stx.getHistogram().getNumBins()[0]); assertEquals(1, stx.getHistogram().getLowValue(0), 1e-10); assertEquals(101, stx.getHistogram().getHighValue(0), 1e-10); assertArrayEquals(new int[]{1, 2, 3, 6, 6, 3, 2, 1}, stx.getHistogramBins()); }
@Test public void testMinIsMax() throws Exception { StxFactory factory = new StxFactory(); factory .withMinimum(0) .withMaximum(0) .withHistogramBins(new int[]{1000, 0, 0, 0, 0, 0, 0, 0}); Stx stx = factory.create(); assertEquals(0, stx.getMinimum(), 1e-10); assertEquals(0, stx.getMaximum(), 1e-10); assertEquals(0, stx.getMean(), 1e-10); assertEquals(0, stx.getMedian(), 1e-10); assertNotNull(stx.getHistogram()); assertEquals(1, stx.getHistogram().getNumBands()); assertEquals(8, stx.getHistogram().getNumBins()[0]); assertEquals(0, stx.getHistogram().getLowValue(0), 1E-10); assertEquals(1.0E-10, stx.getHistogram().getHighValue(0), 1E-10); assertTrue(stx.getHistogram().getLowValue(0) < stx.getHistogram().getHighValue(0)); assertArrayEquals(new int[]{1000, 0, 0, 0, 0, 0, 0, 0}, stx.getHistogramBins()); }