@Test @Category(UnitTest.class) public void testFloat() { float[] values = {0.21f, 0.32f, 0.43f, 0.54f}; float nodata = -9999.0f; float result; Aggregator agg = new MinAvgPairAggregator(); result = agg.aggregate(values, nodata); assertEquals(0.265, result, epsilon); values[0] = nodata; result = agg.aggregate(values, nodata); assertEquals(0.375, result, epsilon); values[1] = nodata; result = agg.aggregate(values, nodata); assertEquals(0.485, result, epsilon); values[2] = nodata; result = agg.aggregate(values, nodata); assertEquals(nodata, result, epsilon); values[3] = nodata; result = agg.aggregate(values, nodata); assertEquals(nodata, result, epsilon); }
@Override public double aggregate(double[] values, double nodata) { boolean data0 = FloatUtils.isNotNodata(values[0], nodata); boolean data1 = FloatUtils.isNotNodata(values[1], nodata); boolean data2 = FloatUtils.isNotNodata(values[2], nodata); boolean data3 = FloatUtils.isNotNodata(values[3], nodata); Collection<Double> averages = new ArrayList<>(); if (data0 && data1) { averages.add((values[0] + values[1]) / 2); } if (data0 && data2) { averages.add((values[0] + values[2]) / 2); } if (data0 && data3) { averages.add((values[0] + values[3]) / 2); } if (data1 && data2) { averages.add((values[1] + values[2]) / 2); } if (data1 && data3) { averages.add((values[1] + values[3]) / 2); } if (data2 && data3) { averages.add((values[2] + values[3]) / 2); } return (averages.isEmpty()) ? nodata : Collections.min(averages); }
MinAvgPairAggregator implements Aggregator { @Override public double aggregate(double[] values, double nodata) { boolean data0 = FloatUtils.isNotNodata(values[0], nodata); boolean data1 = FloatUtils.isNotNodata(values[1], nodata); boolean data2 = FloatUtils.isNotNodata(values[2], nodata); boolean data3 = FloatUtils.isNotNodata(values[3], nodata); Collection<Double> averages = new ArrayList<>(); if (data0 && data1) { averages.add((values[0] + values[1]) / 2); } if (data0 && data2) { averages.add((values[0] + values[2]) / 2); } if (data0 && data3) { averages.add((values[0] + values[3]) / 2); } if (data1 && data2) { averages.add((values[1] + values[2]) / 2); } if (data1 && data3) { averages.add((values[1] + values[3]) / 2); } if (data2 && data3) { averages.add((values[2] + values[3]) / 2); } return (averages.isEmpty()) ? nodata : Collections.min(averages); } }
MinAvgPairAggregator implements Aggregator { @Override public double aggregate(double[] values, double nodata) { boolean data0 = FloatUtils.isNotNodata(values[0], nodata); boolean data1 = FloatUtils.isNotNodata(values[1], nodata); boolean data2 = FloatUtils.isNotNodata(values[2], nodata); boolean data3 = FloatUtils.isNotNodata(values[3], nodata); Collection<Double> averages = new ArrayList<>(); if (data0 && data1) { averages.add((values[0] + values[1]) / 2); } if (data0 && data2) { averages.add((values[0] + values[2]) / 2); } if (data0 && data3) { averages.add((values[0] + values[3]) / 2); } if (data1 && data2) { averages.add((values[1] + values[2]) / 2); } if (data1 && data3) { averages.add((values[1] + values[3]) / 2); } if (data2 && data3) { averages.add((values[2] + values[3]) / 2); } return (averages.isEmpty()) ? nodata : Collections.min(averages); }  }
MinAvgPairAggregator implements Aggregator { @Override public double aggregate(double[] values, double nodata) { boolean data0 = FloatUtils.isNotNodata(values[0], nodata); boolean data1 = FloatUtils.isNotNodata(values[1], nodata); boolean data2 = FloatUtils.isNotNodata(values[2], nodata); boolean data3 = FloatUtils.isNotNodata(values[3], nodata); Collection<Double> averages = new ArrayList<>(); if (data0 && data1) { averages.add((values[0] + values[1]) / 2); } if (data0 && data2) { averages.add((values[0] + values[2]) / 2); } if (data0 && data3) { averages.add((values[0] + values[3]) / 2); } if (data1 && data2) { averages.add((values[1] + values[2]) / 2); } if (data1 && data3) { averages.add((values[1] + values[3]) / 2); } if (data2 && data3) { averages.add((values[2] + values[3]) / 2); } return (averages.isEmpty()) ? nodata : Collections.min(averages); }  @Override double aggregate(double[] values, double nodata); @Override float aggregate(float[] values, float nodata); @Override int aggregate(int[] values, int nodata); @Override short aggregate(short[] values, short nodata); @Override byte aggregate(byte[] values, byte nodata); @Override double aggregate(double[][] values, double weightx, double weighty, double nodata); @Override float aggregate(float[][] values, double weightx, double weighty, float nodata); @Override byte aggregate(byte[][] values, double weightx, double weighty, byte nodata); @Override short aggregate(short[][] values, double weightx, double weighty, short nodata); @Override int aggregate(int[][] values, double weightx, double weighty, int nodata); }
MinAvgPairAggregator implements Aggregator { @Override public double aggregate(double[] values, double nodata) { boolean data0 = FloatUtils.isNotNodata(values[0], nodata); boolean data1 = FloatUtils.isNotNodata(values[1], nodata); boolean data2 = FloatUtils.isNotNodata(values[2], nodata); boolean data3 = FloatUtils.isNotNodata(values[3], nodata); Collection<Double> averages = new ArrayList<>(); if (data0 && data1) { averages.add((values[0] + values[1]) / 2); } if (data0 && data2) { averages.add((values[0] + values[2]) / 2); } if (data0 && data3) { averages.add((values[0] + values[3]) / 2); } if (data1 && data2) { averages.add((values[1] + values[2]) / 2); } if (data1 && data3) { averages.add((values[1] + values[3]) / 2); } if (data2 && data3) { averages.add((values[2] + values[3]) / 2); } return (averages.isEmpty()) ? nodata : Collections.min(averages); }  @Override double aggregate(double[] values, double nodata); @Override float aggregate(float[] values, float nodata); @Override int aggregate(int[] values, int nodata); @Override short aggregate(short[] values, short nodata); @Override byte aggregate(byte[] values, byte nodata); @Override double aggregate(double[][] values, double weightx, double weighty, double nodata); @Override float aggregate(float[][] values, double weightx, double weighty, float nodata); @Override byte aggregate(byte[][] values, double weightx, double weighty, byte nodata); @Override short aggregate(short[][] values, double weightx, double weighty, short nodata); @Override int aggregate(int[][] values, double weightx, double weighty, int nodata);  }