changeset 3096:d7b0f52d6d04

FixA: Calculate Delta W(t) for reference points, too. flys-artifacts/trunk@4695 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 18 Jun 2012 16:00:19 +0000
parents 6ea299c208cd
children c041944a7f74
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/Fitting.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixFacetUtils.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixResult.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/QWD.java
diffstat 7 files changed, 64 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Jun 18 14:37:10 2012 +0000
+++ b/flys-artifacts/ChangeLog	Mon Jun 18 16:00:19 2012 +0000
@@ -1,3 +1,20 @@
+2012-06-18	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/Fitting.java:
+	  The reference points are now wrapped in QWDs. This enables the
+	  plotting of Delta W(t) data for the reference points.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/QWD.java:
+	  Added convenience constructor.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixResult.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java:
+	  Adjusted.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixFacetUtils.java:
+	  Cosmetics.
+
 2012-06-18	Christian Lins <christian.lins@intevation.de>
 
 	* doc/conf/artifacts/fixanalysis.xml:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/Fitting.java	Mon Jun 18 14:37:10 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/Fitting.java	Mon Jun 18 16:00:19 2012 +0000
@@ -25,26 +25,26 @@
     private static Logger log = Logger.getLogger(Fitting.class);
 
     /** Use instance of this factory to find meta infos for outliers. */
-    public interface QWFactory {
+    public interface QWDFactory {
 
-        QW create(double q, double w);
+        QWD create(double q, double w);
 
     } // interface QWFactory
 
-    public static final QWFactory QW_FACTORY = new QWFactory() {
+    public static final QWDFactory QWD_FACTORY = new QWDFactory() {
         @Override
-        public QW create(double q, double w) {
-            return new QW(q, w);
+        public QWD create(double q, double w) {
+            return new QWD(q, w);
         }
     };
 
     protected boolean       checkOutliers;
     protected Function      function;
-    protected QWFactory     qwFactory;
+    protected QWDFactory    qwdFactory;
     protected double        chiSqr;
     protected double []     parameters;
     protected ArrayList<QW> removed;
-    protected QW []         referenced;
+    protected QWD []        referenced;
 
 
     public Fitting() {
@@ -52,21 +52,21 @@
     }
 
     public Fitting(Function function) {
-        this(function, QW_FACTORY);
+        this(function, QWD_FACTORY);
     }
 
-    public Fitting(Function function, QWFactory qwFactory) {
-        this(function, qwFactory, false);
+    public Fitting(Function function, QWDFactory qwdFactory) {
+        this(function, qwdFactory, false);
     }
 
     public Fitting(
-        Function  function,
-        QWFactory qwFactory,
-        boolean   checkOutliers
+        Function   function,
+        QWDFactory qwdFactory,
+        boolean    checkOutliers
     ) {
         this();
         this.function      = function;
-        this.qwFactory     = qwFactory;
+        this.qwdFactory    = qwdFactory;
         this.checkOutliers = checkOutliers;
     }
 
@@ -109,8 +109,8 @@
         return removed.toArray(new QW[removed.size()]);
     }
 
-    public QW [] referencedToArray() {
-        return referenced != null ? (QW [])referenced.clone() : null;
+    public QWD [] referencedToArray() {
+        return referenced != null ? (QWD [])referenced.clone() : null;
     }
 
     public double getMaxQ() {
@@ -153,6 +153,8 @@
 
         List<IndexedValue> inputs = new ArrayList<IndexedValue>(xs.size());
 
+        de.intevation.flys.artifacts.math.Function instance = null;
+
         for (;;) {
             CurveFitter cf = new CurveFitter(lmo);
 
@@ -175,8 +177,7 @@
             inputs.clear();
 
             // This is the paraterized function for a given km.
-            de.intevation.flys.artifacts.math.Function instance =
-                function.instantiate(parameters);
+            instance = function.instantiate(parameters);
 
             for (int i = 0, N = xs.size(); i < N; ++i) {
                 double y = instance.value(xs.getQuick(i));
@@ -197,22 +198,24 @@
             for (int i = rem.size()-1; i >= 0; --i) {
                 int idx = rem.get(i).getIndex();
                 removed.add(
-                    qwFactory.create(
+                    qwdFactory.create(
                         xs.getQuick(idx), ys.getQuick(idx)));
                 xs.remove(idx);
                 ys.remove(idx);
             }
         }
 
-        referenced = new QW[xs.size()];
+        referenced = new QWD[xs.size()];
         for (int i = 0; i < referenced.length; ++i) {
-            QW qw = qwFactory.create(xs.getQuick(i), ys.getQuick(i));
+            QWD qwd = qwdFactory.create(xs.getQuick(i), ys.getQuick(i));
 
-            if (qw == null) {
+            if (qwd == null) {
                 log.warn("QW creation failed!");
             }
             else {
-                referenced[i] = qw;
+                referenced[i] = qwd;
+                double dw = (qwd.getW() - instance.value(qwd.getQ()))*100.0;
+                qwd.setDeltaW(dw);
             }
         }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java	Mon Jun 18 14:37:10 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java	Mon Jun 18 16:00:19 2012 +0000
@@ -169,27 +169,28 @@
         final double [] qs = new double[eventColumns.size()];
         final double [] ws = new double[qs.length];
 
-        Fitting.QWFactory qwFactory = new Fitting.QWFactory() {
+        Fitting.QWDFactory qwdFactory = new Fitting.QWDFactory() {
             @Override
-            public QW create(double q, double w) {
+            public QWD create(double q, double w) {
                 // Check all the event columns for close match
                 // and take the description and the date from meta.
                 for (int i = 0; i < qs.length; ++i) {
                     if (Math.abs(qs[i]-q) < EPSILON
                     &&  Math.abs(ws[i]-w) < EPSILON) {
                         Column column = eventColumns.get(i);
-                        return new QW(
+                        return new QWD(
                             q, w,
                             column.getDescription(),
-                            column.getDate());
+                            column.getDate(),
+                            0d);
                     }
                 }
                 log.warn("cannot find column for (" + q + ", " + w + ")");
-                return new QW(q, w);
+                return new QWD(q, w);
             }
         };
 
-        Fitting fitting = new Fitting(func, qwFactory, preprocessing);
+        Fitting fitting = new Fitting(func, qwdFactory, preprocessing);
 
         String [] parameterNames = func.getParameterNames();
 
@@ -202,8 +203,8 @@
             log.debug("number of kms: " + kms.length);
         }
 
-        KMIndex<QW []> outliers   = new KMIndex<QW []>();
-        KMIndex<QW []> referenced = new KMIndex<QW []>(kms.length);
+        KMIndex<QW []>  outliers   = new KMIndex<QW []>();
+        KMIndex<QWD []> referenced = new KMIndex<QWD []>(kms.length);
 
         int kmIndex             = results.columnIndex("km");
         int chiSqrIndex         = results.columnIndex("chi_sqr");
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixFacetUtils.java	Mon Jun 18 14:37:10 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixFacetUtils.java	Mon Jun 18 16:00:19 2012 +0000
@@ -7,9 +7,9 @@
     public static double getMaxQ(Parameters params, double km) {
         double [] maxQ = params.interpolate("km", km, new String[] { "max_q" });
         if (maxQ == null) {
-            return 1000;
+            return 1000d;
         }
-        double mQ = Math.min(10000, Math.abs(maxQ[0]));
+        double mQ = Math.min(10000d, Math.abs(maxQ[0]));
         return mQ + 0.05*mQ;
     }
 }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java	Mon Jun 18 14:37:10 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java	Mon Jun 18 16:00:19 2012 +0000
@@ -72,8 +72,8 @@
             double currentKm =
                 ((Double)context.getContextValue("currentKm")).doubleValue();
 
-            KMIndex<QW []> kmQWs = result.getReferenced();
-            KMIndex.Entry<QW []> kmQWsEntry = kmQWs.binarySearch(currentKm);
+            KMIndex<QWD []> kmQWs = result.getReferenced();
+            KMIndex.Entry<QWD []> kmQWsEntry = kmQWs.binarySearch(currentKm);
             QW[] qws = null;
             if (kmQWsEntry != null) {
                 qws = kmQWsEntry.getValue();
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixResult.java	Mon Jun 18 14:37:10 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixResult.java	Mon Jun 18 16:00:19 2012 +0000
@@ -10,7 +10,7 @@
 implements   Serializable
 {
     protected Parameters                 parameters;
-    protected KMIndex<QW []>             referenced;
+    protected KMIndex<QWD []>            referenced;
     protected KMIndex<QW []>             outliers;
     protected KMIndex<AnalysisPeriod []> analysisPeriods;
 
@@ -19,7 +19,7 @@
 
     public FixResult(
         Parameters                 parameters,
-        KMIndex<QW []>             referenced,
+        KMIndex<QWD []>            referenced,
         KMIndex<QW []>             outliers,
         KMIndex<AnalysisPeriod []> analysisPeriods
     ) {
@@ -45,11 +45,11 @@
         this.analysisPeriods = analysisPeriods;
     }
 
-    public KMIndex<QW []> getReferenced() {
+    public KMIndex<QWD []> getReferenced() {
         return referenced;
     }
 
-    public void setReferenced(KMIndex<QW []> referenced) {
+    public void setReferenced(KMIndex<QWD []> referenced) {
         this.referenced = referenced;
     }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/QWD.java	Mon Jun 18 14:37:10 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/QWD.java	Mon Jun 18 16:00:19 2012 +0000
@@ -10,6 +10,10 @@
     public QWD() {
     }
 
+    public QWD(double q, double w) {
+        super(q, w);
+    }
+
     public QWD(
         double q,
         double w,

http://dive4elements.wald.intevation.org