changeset 2198:672a41efe222

"Bezugslinienverfahren": Replaced normalized curve generation with a better and needed solution. flys-artifacts/trunk@3814 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 28 Jan 2012 12:50:03 +0000
parents 5781847433d8
children 7bac5afb9892
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/Sub.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/NormalizedReferenceCurveFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ReferenceCurveFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/W.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WW.java
diffstat 6 files changed, 101 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Jan 27 17:59:24 2012 +0000
+++ b/flys-artifacts/ChangeLog	Sat Jan 28 12:50:03 2012 +0000
@@ -1,3 +1,29 @@
+2012-01-28	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/WW.java:
+	  Removed the createNormalized() method because it did not
+	  solve all problems with the transformation of the W~W data we have.
+
+	  - We need to shift the values to be based in (0, 0).
+	  - We need to linear transform the values if they are at gauges.
+	  - Copying the data is memory expensive.
+
+	  Therefore there is now a new inner class ApplyFunctionIterator
+	  that is able to transform the values in an iterator like manner.
+	  The transform functions default to the identity.
+
+	* src/main/java/de/intevation/flys/artifacts/math/Sub.java: New.
+	  Simple function that subtract a scalar from the parameter.
+
+	* src/main/java/de/intevation/flys/artifacts/model/W.java: Added
+	  method minWs() to calulate the minimal W of the data.
+
+	* src/main/java/de/intevation/flys/artifacts/model/NormalizedReferenceCurveFacet.java:
+	  getData() returns a WW.ApplyFunctionIterator with identity transform.
+
+	* src/main/java/de/intevation/flys/artifacts/model/ReferenceCurveFacet.java:
+	  getData() returns a WW.ApplyFunctionIterator with a base shift to (0, 0).
+
 2012-01-27	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/WW.java:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/Sub.java	Sat Jan 28 12:50:03 2012 +0000
@@ -0,0 +1,17 @@
+package de.intevation.flys.artifacts.math;
+
+public final class Sub
+implements         Function
+{
+    private double s;
+
+    public Sub(double s) {
+        this.s = s;
+    }
+
+    @Override
+    public double value(double x) {
+        return x - s;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/NormalizedReferenceCurveFacet.java	Fri Jan 27 17:59:24 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/NormalizedReferenceCurveFacet.java	Sat Jan 28 12:50:03 2012 +0000
@@ -4,6 +4,8 @@
 
 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
 
+import de.intevation.flys.artifacts.math.Sub;
+
 public class NormalizedReferenceCurveFacet
 extends      ReferenceCurveFacet
 {
@@ -31,8 +33,12 @@
 
     @Override
     protected Object getInternalData(WW [] wws) {
-        // TODO: On-the-fly generation of normalized WW.
-        return wws[index].createNormalized();
+        return new WW.ApplyFunctionIterator(wws[index]) {
+            {
+                function1 = new Sub(ww.minWs());
+                function2 = new Sub(ww.minWs2());
+            }
+        };
     }
 
     /** Copy deeply. */
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ReferenceCurveFacet.java	Fri Jan 27 17:59:24 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ReferenceCurveFacet.java	Sat Jan 28 12:50:03 2012 +0000
@@ -51,7 +51,8 @@
 
     /** To be overwritten by normalized reference curve. */
     protected Object getInternalData(WW [] wws) {
-        return wws[index];
+        // Using the ApplyFunctionIterator to unify data processing.
+        return new WW.ApplyFunctionIterator(wws[index]);
     }
 
     @Override
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/W.java	Fri Jan 27 17:59:24 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/W.java	Sat Jan 28 12:50:03 2012 +0000
@@ -54,6 +54,10 @@
         return dst;
     }
 
+    public double minWs() {
+        return ws.min();
+    }
+
     public static void removeNaNs(TDoubleArrayList [] arrays) {
 
         int dest = 0;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WW.java	Fri Jan 27 17:59:24 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WW.java	Sat Jan 28 12:50:03 2012 +0000
@@ -1,10 +1,52 @@
 package de.intevation.flys.artifacts.model;
 
+import de.intevation.flys.artifacts.math.Function;
+import de.intevation.flys.artifacts.math.Identity;
+
 import gnu.trove.TDoubleArrayList;
 
 public class WW
 extends      W
 {
+    public static class ApplyFunctionIterator
+    {
+        protected Function function1;
+        protected Function function2;
+        protected int      pos;
+        protected WW       ww;
+
+        public ApplyFunctionIterator(WW ww) {
+            this.ww        = ww;
+            this.function1 = Identity.IDENTITY;
+            this.function2 = Identity.IDENTITY;
+        }
+
+        public boolean hasNext() {
+            return pos < ww.size();
+        }
+
+        public int size() {
+            return ww.size();
+        }
+
+        public void reset() {
+            pos = 0;
+        }
+
+        public WW getWW() {
+            return ww;
+        }
+
+        public void get(int idx, double [] wwPair) {
+            wwPair[0] = function1.value(ww.getW(idx));
+            wwPair[1] = function2.value(ww.getW2(idx));
+        }
+
+        public void next(double [] wwPair) {
+            get(pos++, wwPair);
+        }
+    } // class FunctionIterator
+
     protected TDoubleArrayList ws2;
 
     public WW() {
@@ -65,22 +107,8 @@
         removeNaNs(new TDoubleArrayList [] { ws, ws2 });
     }
 
-    public WW createNormalized() {
-
-        double minW1 = ws. min();
-        double minW2 = ws2.min(); 
-
-        int N = size();
-
-        TDoubleArrayList ws1c = new TDoubleArrayList(N);
-        TDoubleArrayList ws2c = new TDoubleArrayList(N);
-
-        for (int i = 0; i < N; ++i) {
-            ws1c.add(ws. getQuick(i) - minW1);
-            ws2c.add(ws2.getQuick(i) - minW2);
-        }
-
-        return new WW(getName(), ws1c, ws2c);
+    public double minWs2() {
+        return ws2.min();
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org