changeset 649:44175d4720f8

Fix crashes in back jump correction. flys-artifacts/trunk@2038 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 01 Jun 2011 09:57:22 +0000
parents d4c4fefb095b
children 6695e03e9b82
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java
diffstat 5 files changed, 87 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Jun 01 09:18:00 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Jun 01 09:57:22 2011 +0000
@@ -1,3 +1,19 @@
+2011-06-01	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java:
+	  Changed interpolation methods to interpolate to an arbitrary position
+	  in a given double result array as a preparation for segment independent
+	  calculation.
+
+	* src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java:
+	  Removed superfluous import.
+
+	* src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java:
+	  Fixed cause for crashing: Run back too far in some siutations.
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
+	  Refactored range code a bit. Needs more work.
+
 2011-06-01  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/InfoGeneratorHelper.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Jun 01 09:18:00 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Jun 01 09:57:22 2011 +0000
@@ -535,6 +535,38 @@
 
     }
 
+    protected static double [] extractBoundsKm(River river, double [][] segments) {
+
+        if (segments.length == 2) {
+            return getBounds(segments);
+        }
+
+        TDoubleArrayList bounds = new TDoubleArrayList();
+
+        bounds.add(Math.min(segments[0][0], segments[0][1]));
+
+        for (int i = 1; i < segments.length-1; ++i) {
+            double [] segment = segments[i];
+
+            Gauge gauge = river.determineGauge(segment[0], segment[1]);
+
+            if (gauge == null) {
+                logger.warn("no gauge found between " + 
+                    segment[0] + " and " + segment[1]);
+                bounds.add(0.5*(segment[0] + segment[1]));
+            }
+            else {
+                bounds.add(gauge.getStation().doubleValue());
+            }
+        }
+
+        bounds.add(Math.max(
+            segments[segments.length-1][0],
+            segments[segments.length-1][1]));
+
+        return bounds.toNativeArray();
+    }
+
     /**
      * Returns the data computed by the discharge longitudinal section
      * computation.
@@ -594,37 +626,8 @@
 
         // more than one segment
 
-        double [] boundKms;
-
-        if (segments.length == 2) {
-            boundKms = getBounds(segments);
-        }
-        else {
-            TDoubleArrayList bounds = new TDoubleArrayList();
-
-            bounds.add(Math.min(segments[0][0], segments[0][1]));
-
-            for (int i = 1; i < segments.length-1; ++i) {
-                double [] segment = segments[i];
-
-                Gauge gauge = river.determineGauge(segment[0], segment[1]);
+        double [] boundKms = extractBoundsKm(river, segments);
 
-                if (gauge == null) {
-                    logger.warn("no gauge found between " + 
-                        segment[0] + " and " + segment[1]);
-                    bounds.add(0.5*(segment[0] + segment[1]));
-                }
-                else {
-                    bounds.add(gauge.getStation().doubleValue());
-                }
-            }
-
-            bounds.add(Math.max(
-                segments[segments.length-1][0],
-                segments[segments.length-1][1]));
-
-            boundKms = bounds.toNativeArray();
-        }
 
         if (logger.isDebugEnabled()) {
             logger.debug("bound kms: " + joinDoubles(boundKms));
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java	Wed Jun 01 09:18:00 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java	Wed Jun 01 09:57:22 2011 +0000
@@ -11,6 +11,8 @@
 
 import org.apache.commons.math.ArgumentOutsideDomainException;
 
+import org.apache.commons.math.exception.MathIllegalArgumentException;
+
 import org.apache.log4j.Logger;
 
 public class BackJumpCorrector
@@ -125,7 +127,7 @@
                 break;
             }
 
-            if (back < 0) {
+            if (back <= 0) {
                 //log.debug("run over left border");
                 // fill with same as ws[i]
                 for (int j = 0; j < i; ++j) {
@@ -193,7 +195,15 @@
                 }
             }
 
-            PolynomialSplineFunction spline = interpolator.interpolate(x, y);
+            PolynomialSplineFunction spline;
+            
+            try {
+                spline = interpolator.interpolate(x, y);
+            }
+            catch (MathIllegalArgumentException miae) {
+                log.error(miae);
+                continue;
+            }
 
             try {
                 if (log.isDebugEnabled()) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Wed Jun 01 09:18:00 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Wed Jun 01 09:57:22 2011 +0000
@@ -345,13 +345,25 @@
         QPosition   qPosition,
         LinearRemap remap
     ) {
+        interpolate(kms, ws, qs, qPosition, remap, 0, kms.length);
+    }
+
+    public void interpolate(
+        double []   kms,
+        double []   ws,
+        double []   qs,
+        QPosition   qPosition,
+        LinearRemap remap,
+        int         startIndex,
+        int         length
+    ) {
         int R1 = rows.size()-1;
 
         Row kmKey = new Row();
 
         QPosition nPosition = new QPosition();
 
-        for (int i = 0; i < kms.length; ++i) {
+        for (int i = startIndex, end = startIndex+length; i < end; ++i) {
             kmKey.km = kms[i];
 
             qs[i] = remap.eval(kms[i], getQ(qPosition, kms[i]));
@@ -389,6 +401,18 @@
         double [] ws,
         double [] qs
     ) {
+        return interpolate(q, referenceKm, kms, ws, qs, 0, kms.length);
+    }
+
+    public QPosition interpolate(
+        double    q,
+        double    referenceKm,
+        double [] kms,
+        double [] ws,
+        double [] qs,
+        int       startIndex,
+        int       length
+    ) {
         QPosition qPosition = getQPosition(referenceKm, q);
 
         if (qPosition == null) {
@@ -400,7 +424,7 @@
 
         int R1 = rows.size()-1;
 
-        for (int i = 0; i < kms.length; ++i) {
+        for (int i = startIndex, end = startIndex+length; i < end; ++i) {
             kmKey.km = kms[i];
 
             int rowIndex = Collections.binarySearch(rows, kmKey);
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Wed Jun 01 09:18:00 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Wed Jun 01 09:57:22 2011 +0000
@@ -7,7 +7,6 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Vector;
 
 import javax.xml.xpath.XPathConstants;
 

http://dive4elements.wald.intevation.org