changeset 8596:b486812f4f14

(issue1755) Filter out NaN values before creating the interplation function
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 19 Mar 2015 15:15:55 +0100
parents cc1c644ed30f
children ba2a34a4e440
files artifacts/src/main/java/org/dive4elements/river/utils/DoubleUtil.java
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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());

http://dive4elements.wald.intevation.org