[PATCH 1 of 2] (issue1529) Only interpolate within a step limit in WQ diagram

Wald Commits scm-commit at wald.intevation.org
Fri Oct 11 18:40:36 CEST 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1381504275 -7200
# Node ID cde863b2dae37626d3dfd91e62e3822f34d23a0d
# Parent  5b2126d21c2e07ab914d835f259e38560ac3b341
(issue1529) Only interpolate within a step limit in WQ diagram

    Created together with Sascha Teichmann

diff -r 5b2126d21c2e -r cde863b2dae3 artifacts/src/main/java/org/dive4elements/river/artifacts/model/Parameters.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Parameters.java	Fri Oct 11 15:35:25 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Parameters.java	Fri Oct 11 17:11:15 2013 +0200
@@ -314,6 +314,67 @@
         return values;
     }
 
+    public double [] interpolateWithLimit(
+        String    keyName,
+        double    key,
+        String [] columnNames,
+        double    limit
+    ) {
+        int keyIndex = columnIndex(keyName);
+        return keyIndex < 0
+            ? null
+            : interpolateWithLimit(keyIndex, key, columnNames, limit);
+    }
+
+    /* Only interpolate if the difference between the two key's
+     * is less then limit */
+    public double [] interpolateWithLimit(
+        int       keyIndex,
+        double    key,
+        String [] columnNames,
+        double    limit
+    ) {
+        int row = binarySearch(keyIndex, key, EPSILON);
+
+        if (row >= 0) { // direct match
+            double [] values = new double[columnNames.length];
+            for (int i = 0; i < values.length; ++i) {
+                int ci = columnIndex(columnNames[i]);
+                values[i] = ci < 0
+                    ? Double.NaN
+                    : columns[ci].getQuick(row);
+            }
+            return values;
+        }
+
+        row = -row - 1;
+        if (row < 1 || row >= size()) {
+            log.debug("interpolate: row is out of bounds");
+            return null;
+        }
+
+        double v1 = columns[keyIndex].getQuick(row-1);
+        double v2 = columns[keyIndex].getQuick(row);
+        if (Math.abs(v1-v2) > limit) {
+            return null;
+        }
+        double factor = Linear.factor(key, v1, v2);
+
+        double [] values = new double[columnNames.length];
+
+        for (int i = 0; i < values.length; ++i) {
+            int ci = columnIndex(columnNames[i]);
+            values[i] = ci < 0
+                ? Double.NaN
+                : Linear.weight(
+                    factor,
+                    columns[ci].getQuick(row-1),
+                    columns[ci].getQuick(row));
+        }
+
+        return values;
+    }
+
     public boolean isSorted(String columnName) {
         return isSorted(columnIndex(columnName));
     }
diff -r 5b2126d21c2e -r cde863b2dae3 artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixWQCurveFacet.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixWQCurveFacet.java	Fri Oct 11 15:35:25 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixWQCurveFacet.java	Fri Oct 11 17:11:15 2013 +0200
@@ -97,10 +97,11 @@
         Parameters params = result.getParameters();
         String[] paramNames = ff.getParameterNames();
 
-        double [] coeffs = params.interpolate("km", currentKm, paramNames);
+        double [] coeffs = params.interpolateWithLimit(
+            "km", currentKm, paramNames, access.getStep() / 1000 + 1E-3);
 
         if (coeffs == null) {
-            logger.warn("getData: coeffs == null");
+            logger.warn("getData: coeffs not in interpolation limits");
             return null;
         }
 


More information about the Dive4elements-commits mailing list