changeset 4630:63368dcc3f94

Moved MovingAverage into math package
author Sascha L. Teichmann <teichmann@intevation.de>
date Mon, 03 Dec 2012 18:44:48 +0100
parents e29f368c09ba
children d35d316049e8
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/MovingAverage.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FlowVelocityFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MovingAverage.java
diffstat 3 files changed, 61 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/MovingAverage.java	Mon Dec 03 18:44:48 2012 +0100
@@ -0,0 +1,59 @@
+package de.intevation.flys.artifacts.math;
+
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+
+public class MovingAverage
+{
+
+    public static double[][] simple(double[][] values, double radius) {
+        TreeMap<Double, Double> map = toMap(values);
+        double[][] result = new double[values.length][values[0].length];
+        int ndx = 0;
+        for (double x: map.keySet()) {
+            SortedMap<Double, Double> range =
+                map.subMap(x-radius, true, x+radius, true);
+            double avg = 0d;
+            for (Double v: range.values()) {
+                avg += v;
+            }
+            avg /= range.size();
+            result[0][ndx] = x;
+            result[1][ndx] = avg;
+            ndx++;
+        }
+        return result;
+    }
+
+    public static double[][] weighted(double[][] values, double radius) {
+        TreeMap<Double, Double> map = toMap(values);
+        double[][] result = new double[values.length][values[0].length];
+        int ndx = 0;
+        for (double x: map.keySet()) {
+            double avg = 0d;
+            double weights = 0d;
+            for (Map.Entry<Double, Double> e:
+                map.subMap(x-radius, false, x+radius, false).entrySet()
+            ) {
+                double weight = 1d - Math.abs(x - e.getKey())/radius;
+                avg += weight*e.getValue();
+                weights += weight;
+            }
+            avg /= weights;
+            result[0][ndx] = x;
+            result[1][ndx] = avg;
+            ndx++;
+        }
+        return result;
+    }
+
+    private static TreeMap<Double, Double> toMap(double[][] values) {
+        TreeMap<Double, Double> map = new TreeMap<Double, Double>();
+        for(int i = 0; i < values[0].length; i++) {
+            map.put(values[0][i], values[1][i]);
+        }
+        return map;
+    }
+}
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FlowVelocityFacet.java	Mon Dec 03 17:55:04 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FlowVelocityFacet.java	Mon Dec 03 18:44:48 2012 +0100
@@ -9,11 +9,12 @@
 
 import de.intevation.flys.artifacts.access.RiverAccess;
 import de.intevation.flys.artifacts.context.FLYSContext;
+
+import de.intevation.flys.artifacts.math.MovingAverage;
 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
 
 import org.apache.log4j.Logger;
 
-
 /**
  * Facet of a FlowVelocity curve.
  */
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MovingAverage.java	Mon Dec 03 17:55:04 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-package de.intevation.flys.artifacts.model;
-
-import java.util.Map;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-
-public class MovingAverage
-{
-
-    public static double[][] simple(double[][] values, double radius) {
-        TreeMap<Double, Double> map = toMap(values);
-        double[][] result = new double[values.length][values[0].length];
-        int ndx = 0;
-        for (double x: map.keySet()) {
-            SortedMap<Double, Double> range =
-                map.subMap(x-radius, true, x+radius, true);
-            double avg = 0d;
-            for (Double v: range.values()) {
-                avg += v;
-            }
-            avg /= range.size();
-            result[0][ndx] = x;
-            result[1][ndx] = avg;
-            ndx++;
-        }
-        return result;
-    }
-
-    public static double[][] weighted(double[][] values, double radius) {
-        TreeMap<Double, Double> map = toMap(values);
-        double[][] result = new double[values.length][values[0].length];
-        int ndx = 0;
-        for (double x: map.keySet()) {
-            double avg = 0d;
-            double weights = 0d;
-            for (Map.Entry<Double, Double> e:
-                map.subMap(x-radius, false, x+radius, false).entrySet()
-            ) {
-                double weight = 1d - Math.abs(x - e.getKey())/radius;
-                avg += weight*e.getValue();
-                weights += weight;
-            }
-            avg /= weights;
-            result[0][ndx] = x;
-            result[1][ndx] = avg;
-            ndx++;
-        }
-        return result;
-    }
-
-    private static TreeMap<Double, Double> toMap(double[][] values) {
-        TreeMap<Double, Double> map = new TreeMap<Double, Double>();
-        for(int i = 0; i < values[0].length; i++) {
-            map.put(values[0][i], values[1][i]);
-        }
-        return map;
-    }
-}

http://dive4elements.wald.intevation.org