[PATCH] (issue1755) Filter out NaN values before creating the interplation function

Wald Commits scm-commit at wald.intevation.org
Thu Mar 19 15:16:00 CET 2015


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1426774555 -3600
# Node ID b486812f4f1428cab1be768fb12cc3b454a00e81
# Parent  cc1c644ed30fd012791e5ea25d6afb6134634625
(issue1755) Filter out NaN values before creating the interplation function

diff -r cc1c644ed30f -r b486812f4f14 artifacts/src/main/java/org/dive4elements/river/utils/DoubleUtil.java
--- a/artifacts/src/main/java/org/dive4elements/river/utils/DoubleUtil.java	Thu Mar 19 14:21:39 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/DoubleUtil.java	Thu Mar 19 15:15:55 2015 +0100
@@ -317,9 +317,18 @@
      * This is basically a static wrapper to for LinearInterpolator.interpolate
      * with error handling. Returns null on error.*/
     public static PolynomialSplineFunction getLinearInterpolator(double[] x, double[] y) {
+        /* We want copies here to remove NaNs but don't change the original data. */
+        TDoubleArrayList tX = new TDoubleArrayList();
+        TDoubleArrayList tY = new TDoubleArrayList();
+        for (int i = 0; i < x.length; i++) {
+            if (!Double.isNaN(y[i])) {
+                tX.add(x[i]);
+                tY.add(y[i]);
+            }
+        }
         LinearInterpolator lpol = new LinearInterpolator();
         try {
-            return lpol.interpolate(x, y);
+            return lpol.interpolate(tX.toNativeArray(), tY.toNativeArray());
         } catch (DimensionMismatchException e) {
             log.error("KMs and Result values have different sizes. Failed to interpolate: " +
                     e.getMessage());


More information about the Dive4Elements-commits mailing list