changeset 458:523a256451cd

Use unsharp km lookup (epsilon = 0.0001). flys-artifacts/trunk@1957 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 19 May 2011 14:38:15 +0000
parents 52532b300483
children fadf797bf123
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java
diffstat 3 files changed, 20 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu May 19 12:39:41 2011 +0000
+++ b/flys-artifacts/ChangeLog	Thu May 19 14:38:15 2011 +0000
@@ -1,3 +1,12 @@
+2011-05-19	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java:
+	  Sort by rows (should not be necessary).
+
+	* src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java:
+	  Use unsharp km lookup (epsilon = 0.0001). This fixes the problem
+	  that some kms were not found.
+
 2011-05-19  Ingo Weinzierl <ingo@intevation.de>
 
 	  flys/issue66
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Thu May 19 12:39:41 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Thu May 19 14:38:15 2011 +0000
@@ -117,14 +117,6 @@
             return (1.0-factor)*a + factor*b;
         }
 
-        public double getWForKM(Row other, int index, double km) {
-            double w1  = ws[index];
-            double w2  = other.ws[index];
-            double km1 = this.km;
-            double km2 = other.km;
-            return linear(km, km1, km2, w1, w2);
-        }
-
         public void interpolateW(
             Row       other,
             double    km,
@@ -194,17 +186,11 @@
 
         public int compareTo(Row other) {
             double d = km - other.km;
-            if (d < 0.0) return -1;
-            if (d > 0.0) return +1;
+            if (d < -0.0001) return -1;
+            if (d >  0.0001) return +1;
             return 0;
         }
 
-        public double [][] cloneWQs() {
-            return new double [][] {
-                (double [])ws.clone(),
-                (double [])qs.clone() };
-        }
-
         public double [][] interpolateWQ(Row other, double km, int steps) {
 
             int W = Math.min(ws.length, other.ws.length);
@@ -296,37 +282,6 @@
             return new double [][] { outWs, outQs };
         }
 
-        public int ascendingWs() {
-            if (ws.length < 2) {
-                return ws.length;
-            }
-
-            int idx = 1;
-
-            for (; idx < ws.length; ++idx) {
-                if (Double.isNaN(ws[idx]) || ws[idx] < ws[idx-1]) {
-                    return idx;
-                }
-            }
-
-            return idx;
-        }
-
-        public double [][] weightWQs(Row other, double km) {
-            int W = Math.min(ws.length, other.ws.length);
-            double factor = factor(km, this.km, other.km);
-
-            double [] outWs = new double[W];
-            double [] outQs = new double[W];
-
-            for (int i = 0; i < W; ++i) {
-                outWs[i] = weight(factor, ws[i], other.ws[i]);
-                outQs[i] = weight(factor, qs[i], other.qs[i]);
-            }
-
-            return new double [][] { outWs, outQs };
-        }
-
         public QPosition getQPosition(double q) {
             int qIndex = getQIndex(q);
 
@@ -488,6 +443,11 @@
         this.columns = columns;
     }
 
+    public void sortRows() {
+        Collections.sort(rows);
+    }
+
+
     public double [] interpolateW(double km, double [] qs) {
         return interpolateW(km, qs, new double[qs.length]);
     }
@@ -619,6 +579,7 @@
 
         for (int i = 0; i < kms.length; ++i) {
             kmKey.km = kms[i];
+
             rowIndex = Collections.binarySearch(rows, kmKey);
 
             if (rowIndex >= 0) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java	Thu May 19 12:39:41 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java	Thu May 19 14:38:15 2011 +0000
@@ -187,6 +187,9 @@
             valueTable.rows.add(row);
         }
 
+        // XXX: should not be necessary
+        valueTable.sortRows();
+
         return valueTable;
     }
 }

http://dive4elements.wald.intevation.org