changeset 7299:cde863b2dae3

(issue1529) Only interpolate within a step limit in WQ diagram Created together with Sascha Teichmann
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 11 Oct 2013 17:11:15 +0200
parents 5b2126d21c2e
children 83bb52fa0c32
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/Parameters.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixWQCurveFacet.java
diffstat 2 files changed, 64 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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));
     }
--- 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;
         }
 

http://dive4elements.wald.intevation.org