changeset 4355:d095b4267772

Added missing percentage cut off in extreme calculation.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 02 Nov 2012 12:01:32 +0100
parents e0add97c432b
children 375550eb45b7
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/ExtremeCalculation.java
diffstat 1 files changed, 34 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/ExtremeCalculation.java	Fri Nov 02 11:02:15 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/ExtremeCalculation.java	Fri Nov 02 12:01:32 2012 +0100
@@ -11,6 +11,7 @@
 
 import de.intevation.flys.artifacts.access.ExtremeAccess;
 
+import de.intevation.flys.artifacts.math.Linear;
 import de.intevation.flys.artifacts.math.Utils;
 
 import de.intevation.flys.artifacts.math.fitting.Function;
@@ -254,7 +255,7 @@
         return new CalculationResult(result, this);
     }
 
-    protected static double [] doFitting(
+    protected double [] doFitting(
         Function    function,
         double [][] wqs,
         double []   chiSqr
@@ -295,7 +296,7 @@
         return coeffs;
     }
 
-    protected static double [][] extractPointsToFit(double [][] wqs) {
+    protected double [][] extractPointsToFit(double [][] wqs) {
         TDoubleArrayList ows = new TDoubleArrayList();
         TDoubleArrayList oqs = new TDoubleArrayList();
 
@@ -346,14 +347,42 @@
             w1 = cw;
         }
 
-        // XXX: Not really needed for fitting.
-        // oqs.reverse();
-        // ows.reverse();
+        oqs.reverse();
+        ows.reverse();
+        cutPercent(ows, oqs);
 
         return new double [][] {
             ows.toNativeArray(),
             oqs.toNativeArray()
         };
     }
+
+    protected void cutPercent(TDoubleArrayList ws, TDoubleArrayList qs) {
+        int N = qs.size();
+        if (percent <= 0d || N == 0) {
+            return;
+        }
+
+        double minQ = qs.getQuick(0);
+        double maxQ = qs.getQuick(N-1);
+        double factor = Math.min(Math.max(0d, percent/100d), 1d);
+        double cutQ = Linear.weight(factor, minQ, maxQ);
+        int cutIndex = 0;
+        for (; cutIndex < N; ++cutIndex) {
+            double q = qs.getQuick(cutIndex);
+            if (minQ < maxQ) {
+                if (q > cutQ) {
+                    break;
+                }
+            }
+            else {
+                if (q < cutQ) {
+                    break;
+                }
+            }
+        }
+        ws.remove(0, cutIndex);
+        qs.remove(0, cutIndex);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org