@Test public void loadLoaderFactory() throws Exception { IDataHolder dataHolder = LoaderFactory.getData(testFileFolder + file, null); IDataset data = dataHolder.getDataset("Portable Grey Map"); // Check the first data point assertEquals(data.getDouble(0, 0), 0.0, 0.0); // Check the middle data point assertEquals(data.getDouble(512, 511), 15104.0, 0.0); // Check the last data point assertEquals(data.getDouble(1023, 1023), 0.0, 0.0); }
@Test public void lazyLoadLoaderFactory() throws Exception { IDataHolder dataHolder = LoaderFactory.getData(testFileFolder + file, true, true, true, null); ILazyDataset lazy = dataHolder.getLazyDataset("Portable Grey Map"); assertArrayEquals(new int[] {1024, 1024}, lazy.getShape()); IDataset data = lazy.getSlice(); // Check the first data point assertEquals(data.getDouble(0, 0), 0.0, 0.0); // Check the middle data point assertEquals(data.getDouble(512, 511), 15104.0, 0.0); // Check the last data point assertEquals(data.getDouble(1023, 1023), 0.0, 0.0); }
public static IDataset interpolate(IDataset oldx, IDataset oldy, IDataset newx) { // TODO more sanity checks on inputs DoubleDataset dx = (DoubleDataset) DatasetUtils.cast(oldx, Dataset.FLOAT64); DoubleDataset dy = (DoubleDataset) DatasetUtils.cast(oldy, Dataset.FLOAT64); boolean sorted = true; double maxtest = oldx.getDouble(0); for (int i = 1; i < ((Dataset) oldx).count(); i++) { if (maxtest > oldx.getDouble(i)) { sorted = false; break; } maxtest = dx.getDouble(i); } double[] sortedx = null; double[] sortedy = null; if (!sorted) { IntegerDataset sIdx = getIndiciesOfSorted(dx); sortedx = new double[dx.getData().length]; sortedy = new double[dy.getData().length]; for (int i = 0; i < sIdx.getSize(); i++) { sortedx[i] = dx.getDouble(sIdx.get(i)); sortedy[i] = dy.getDouble(sIdx.get(i)); } } else { sortedx = dx.getData(); sortedy = dy.getData(); } SplineInterpolator si = new SplineInterpolator(); PolynomialSplineFunction poly = si.interpolate(sortedx, sortedy); IDataset newy = newx.clone(); newy.setName(oldy.getName() + "_interpolated"); for (int i = 0; i < ((Dataset) newx).count(); i++) { newy.set(poly.value(newx.getDouble(i)), i); } return newy; }
@Override public double calculateSignificance(int position, int windowSize, IDataset yData) { double posVal = yData.getDouble(position); // Calculate the averages of the the left & right windows. // N.B. left & right diffs are in opposite directions. Double leftAvg = 0.0; Double rightAvg = 0.0; for (int i = 0; i < windowSize; i++) { leftAvg = leftAvg + yData.getDouble(position - i - 1); rightAvg = rightAvg + yData.getDouble(position + i + 1); } leftAvg = leftAvg / windowSize; rightAvg = rightAvg / windowSize; // Calculate the average of difference of the point and the averages (i.e. significance) double sig = ((posVal - leftAvg) + (posVal - rightAvg)) / 2; return sig; }