changeset 2792:fe987587ebc9

Merged revisions 4539-4540,4543,4545-4546 via svnmerge from file:///home/clients/bsh/bsh-generischer-viewer/Material/SVN/flys-artifacts/trunk ........ r4539 | teichmann | 2012-05-27 20:02:13 +0200 (So, 27 Mai 2012) | 1 line FixA: Added forgotten csv/report facets/generators to conf. ........ r4540 | teichmann | 2012-05-27 20:11:31 +0200 (So, 27 Mai 2012) | 1 line FixA: Fixed class cast bug in report facet. ........ r4543 | teichmann | 2012-05-28 20:35:01 +0200 (Mo, 28 Mai 2012) | 1 line FixA: Added facet to return delta w/t as CSV ........ r4545 | teichmann | 2012-05-28 22:59:27 +0200 (Mo, 28 Mai 2012) | 1 line FixA: Made Delta W/t calculation finally work ........ r4546 | teichmann | 2012-05-28 23:34:24 +0200 (Mo, 28 Mai 2012) | 1 line FixA: corrected fitting (Q->W instead W->Q). ........ flys-artifacts/tags/2.7@4547 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 29 May 2012 04:58:29 +0000
parents c9815016a3bb
children 6310b1582f2d
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/fixanalysis.xml flys-artifacts/doc/conf/conf.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsColumn.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ReportFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/DeltaWTsKM.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java flys-artifacts/src/main/java/de/intevation/flys/exports/AbstractExporter.java flys-artifacts/src/main/java/de/intevation/flys/exports/DeltaWtExporter.java
diffstat 12 files changed, 182 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Sun May 27 13:39:30 2012 +0000
+++ b/flys-artifacts/ChangeLog	Tue May 29 04:58:29 2012 +0000
@@ -1,3 +1,59 @@
+2012-05-28	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java:
+	  Fit from Q to W not from W to Q!
+	  Delta w/t's are now in cm.
+	  Slimmed down fitting error report.
+
+	* src/main/java/de/intevation/flys/exports/DeltaWtExporter.java:
+	  Changed default column header of delta W to cm.
+	  
+2012-05-28	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	Made Delta W/t calculation work.
+
+	* src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java:
+	  Added toString() method.
+
+	* src/main/java/de/intevation/flys/artifacts/model/FixingsColumn.java:
+	  Fixed problem accessing Ws.
+
+	* src/main/java/de/intevation/flys/artifacts/model/Parameters.java:
+	  Fixed silly 'name.equals(name)' bug. This mainly prevented delta W/t
+	  computation from working.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/DeltaWTsKM.java:
+	  More deug code.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java:
+	  More debug code. Simplified access to data a bit.
+
+	* src/main/java/de/intevation/flys/exports/AbstractExporter.java:
+	  Allow CSV exporter to throw IOExceptions.
+
+	* src/main/java/de/intevation/flys/exports/DeltaWtExporter.java:
+	  More debug output. Flush CSV after writing.
+
+2012-05-28	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java:
+	  Units of step is in meter and not km. Added more debug output.
+
+	* src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java:
+	  Stupidly forgot to add facet to return the delta w/t as CSV.
+
+2012-05-27	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/ReportFacet.java:
+	  There was a cast to WINFOArtifact where a cast to FLYSArtifact
+	  is sufficient. This prevented generating error reports that
+	  does not inherit from WINFOArtifact like FixationArtifact.
+
+2012-05-27	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* doc/conf/artifacts/fixanalysis.xml,
+	  doc/conf/conf.xml: Added CSV and error report generator/facets.
+
 2012-05-27  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/CrossSectionFactory.java:
@@ -16,6 +72,14 @@
 
 2012-05-26	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/DeltaWTsKM.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixResult.java,
+	  src/main/java/de/intevation/flys/artifacts/ExternalWMSArtifact.java:
+	  Removed superfluous imports.
+
+2012-05-26	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
 	* src/main/java/de/intevation/flys/artifacts/model/fixings/DeltaWTsKM.java:
 	  Added getters to access the inner data structures.
 
--- a/flys-artifacts/doc/conf/artifacts/fixanalysis.xml	Sun May 27 13:39:30 2012 +0000
+++ b/flys-artifacts/doc/conf/artifacts/fixanalysis.xml	Tue May 29 04:58:29 2012 +0000
@@ -127,9 +127,14 @@
             description="state.fix.analysis.compute"
             state="de.intevation.flys.artifacts.states.fixation.FixationCompute">
             <outputmodes>
-                <outputmode>
+                <outputmode name="fix_deltawt_export" description="output.fix_deltawt_export" mine-type="text/plain" type="export">
                     <facets>
-                        <facet/>
+                        <facet name="csv" description="face.fix_deltawt.csv" />
+                    </facets>
+                </outputmode>
+                <outputmode name="fix_report" description="output.fix_report.report" mime-type="text/plain" type="report">
+                    <facets>
+                        <facet name="report" description="facet.fix.report" />
                     </facets>
                 </outputmode>
             </outputmodes>
--- a/flys-artifacts/doc/conf/conf.xml	Sun May 27 13:39:30 2012 +0000
+++ b/flys-artifacts/doc/conf/conf.xml	Tue May 29 04:58:29 2012 +0000
@@ -241,6 +241,7 @@
         <output-generator name="bedheight_middle">de.intevation.flys.exports.MiddleBedHeightGenerator</output-generator>
         <output-generator name="bedheight_middle_chartinfo">de.intevation.flys.exports.MiddleBedHeightInfoGenerator</output-generator>
         <output-generator name="bedheight_middle_export">de.intevation.flys.exports.MiddleBedHeightExporter</output-generator>
+        <output-generator name="fix_deltawt_export">de.intevation.flys.exports.DeltaWtExporter</output-generator>
         <!-- Error report generators. -->
         <output-generator name="discharge_longitudinal_section_report">de.intevation.flys.exports.ReportGenerator</output-generator>
         <output-generator name="waterlevel_report">de.intevation.flys.exports.ReportGenerator</output-generator>
@@ -249,6 +250,7 @@
         <output-generator name="wsplgen_report">de.intevation.flys.exports.ReportGenerator</output-generator>
         <output-generator name="historical_discharge_report">de.intevation.flys.exports.ReportGenerator</output-generator>
         <output-generator name="reference_curve_report">de.intevation.flys.exports.ReportGenerator</output-generator>
+        <output-generator name="fix_report">de.intevation.flys.exports.ReportGenerator</output-generator>
         <!-- AT exporter. -->
         <output-generator name="computed_dischargecurve_at_export">de.intevation.flys.exports.ATExporter</output-generator>
     </output-generators>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsColumn.java	Sun May 27 13:39:30 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsColumn.java	Tue May 29 04:58:29 2012 +0000
@@ -47,12 +47,16 @@
 
         idx = -idx - 1;
 
-        w[index] = Linear.linear(km, kms[idx], kms[idx+1], ws[idx], ws[idx+1]);
+        w[index] = Linear.linear(km, kms[idx-1], kms[idx], ws[idx-1], ws[idx]);
         return false;
     }
 
     public double getQ(double km) {
         return qs.findQ(km);
     }
+
+    public QRangeTree getQRanges() {
+        return qs;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java	Sun May 27 13:39:30 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java	Tue May 29 04:58:29 2012 +0000
@@ -30,7 +30,7 @@
 
     public int columnIndex(String name) {
         for (int i = 0; i < columnNames.length; ++i) {
-            if (name.equals(name)) {
+            if (columnNames[i].equals(name)) {
                 return i;
             }
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java	Sun May 27 13:39:30 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java	Tue May 29 04:58:29 2012 +0000
@@ -212,6 +212,27 @@
         return root != null ? root.findQ(pos) : Double.NaN;
     }
 
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        inorder(root, sb);
+        return sb.toString();
+    }
+
+    protected static void inorder(Node node, StringBuilder sb) {
+        if (node != null) {
+            inorder(node.left, sb);
+            sb.append('[')
+              .append(node.a)
+              .append(", ")
+              .append(node.b)
+              .append(": ")
+              .append(node.q)
+              .append(']');
+            inorder(node.right, sb);
+        }
+    }
+
     private static final String name(Object o) {
         return String.valueOf(System.identityHashCode(o) & 0xffffffffL);
     }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ReportFacet.java	Sun May 27 13:39:30 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ReportFacet.java	Tue May 29 04:58:29 2012 +0000
@@ -8,7 +8,7 @@
 
 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
 
-import de.intevation.flys.artifacts.WINFOArtifact;
+import de.intevation.flys.artifacts.FLYSArtifact;
 
 
 import org.apache.log4j.Logger;
@@ -43,9 +43,9 @@
     public Object getData(Artifact artifact, CallContext context) {
         logger.debug("get report data");
 
-        WINFOArtifact winfo = (WINFOArtifact)artifact;
+        FLYSArtifact flys = (FLYSArtifact)artifact;
 
-        CalculationResult cr = (CalculationResult)winfo.compute(
+        CalculationResult cr = (CalculationResult)flys.compute(
             context, hash, stateId, type, false);
 
         return cr.getReport();
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/DeltaWTsKM.java	Sun May 27 13:39:30 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/DeltaWTsKM.java	Tue May 29 04:58:29 2012 +0000
@@ -47,6 +47,10 @@
             deltaWTs.add(deltaWT);
         }
 
+        public int size() {
+            return deltaWTs.size();
+        }
+
         @Override
         public int compareTo(KM other) {
             double d = km - other.km;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java	Sun May 27 13:39:30 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixCalculation.java	Tue May 29 04:58:29 2012 +0000
@@ -125,6 +125,8 @@
 
     public CalculationResult calculate() {
 
+        boolean debug = log.isDebugEnabled();
+
         FixingsOverview overview =
             FixingsOverviewFactory.getOverview(river);
 
@@ -173,7 +175,7 @@
             return new CalculationResult(this);
         }
 
-        double [] kms = DoubleUtil.explode(from, to, step);
+        double [] kms = DoubleUtil.explode(from, to, step / 1000.0);
 
         double [] ws = new double[dataColumns.size()];
         double [] qs = new double[ws.length];
@@ -185,6 +187,12 @@
 
         boolean invalid = false;
 
+        if (debug) {
+            log.debug("number of kms: " + kms.length);
+        }
+
+        int numFailed = 0;
+
         for (int i = 0; i < kms.length; ++i) {
             double km = kms[i];
 
@@ -198,6 +206,7 @@
             // TODO: Do preprocessing here!
             double [] parameters = fit(func, km, ws, qs);
             if (parameters == null) { // Problems are reported already.
+                ++numFailed;
                 continue;
             }
 
@@ -215,6 +224,11 @@
             // TODO: Calculate statistics, too!
         }
 
+        if (debug) {
+            log.debug("success: " + (kms.length - numFailed));
+            log.debug("failed: " + numFailed);
+        }
+
         if (invalid) {
             // TODO: i18n
             addProblem("fix.invalid.values");
@@ -237,6 +251,8 @@
         FixingsOverview overview,
         Parameters      results
     ) {
+        boolean debug = log.isDebugEnabled();
+
         DeltaWTsKM deltaWTsKM = new DeltaWTsKM(results.size());
 
         Column [][] analysisColumns = getAnalysisColumns(overview);
@@ -249,8 +265,10 @@
 
         double [] ow = new double[1];
 
+        int kmIdx = results.columnIndex("km");
+
         for (int i = 0, N = results.size(); i < N; ++i) {
-            double km = results.get(i, "km");
+            double km = results.get(i, kmIdx);
             results.get(i, parameterIndices, parameterValues);
 
             DeltaWTsKM.KM dwtkm = new DeltaWTsKM.KM(km);
@@ -264,18 +282,24 @@
             for (int j = 0; j < analysisColumns.length; ++j) {
                 Column [] periodColumns = analysisColumns[j];
 
+                int failedQ = 0;
+                int failedW = 0;
+                int failedC = 0;
+
                 for (int k = 0; k < periodColumns.length; ++k) {
                     Column pc = periodColumns[k];
 
                     // Q from real data.
                     double q = pc.data.getQ(km);
                     if (Double.isNaN(q)) {
+                        ++failedQ;
                         continue;
                     }
 
                     // Calculate W from function.
                     double nw = instance.value(q);
                     if (Double.isNaN(nw)) {
+                        ++failedC;
                         continue;
                     }
 
@@ -283,10 +307,11 @@
                     pc.data.getW(km, ow);
 
                     if (Double.isNaN(ow[0])) {
+                        ++failedW;
                         continue;
                     }
 
-                    double deltaW = ow[0] - nw;
+                    double deltaW = (ow[0] - nw)*100.0; // in cm
 
                     DeltaWT deltaWT = new DeltaWT(
                         deltaW,
@@ -295,6 +320,13 @@
 
                     dwtkm.add(deltaWT);
                 }
+                if (debug) {
+                    log.debug("failed W: " + failedW);
+                    log.debug("failed Q: " + failedQ);
+                    log.debug("failed C: " + failedC);
+                    log.debug("input size: " + periodColumns.length);
+                    log.debug("outpt size: " + dwtkm.size());
+                }
             }
         }
 
@@ -321,6 +353,11 @@
     /** Fetch meta and data columns for analysis periods. */
     protected Column [][] getAnalysisColumns(FixingsOverview overview) {
 
+        boolean debug = log.isDebugEnabled();
+        if (debug) {
+            log.debug("number analysis periods: " + analysisPeriods.length);
+        }
+
         Column columns [][] = new Column[analysisPeriods.length][];
 
         Range range = new Range(from, to);
@@ -346,6 +383,10 @@
 
             List<Fixing.Column> metaCols = overview.filter(range, filter);
 
+            if (debug) {
+                log.debug("number of filtered columns: " + metaCols.size());
+            }
+
             ArrayList<Column> cols = new ArrayList<Column>(metaCols.size());
 
             // Only use columns which have data.
@@ -355,6 +396,10 @@
                     cols.add(new Column(meta, data));
                 }
             }
+
+            if (debug) {
+                log.debug("failed loading: " + (metaCols.size()-cols.size()));
+            }
             columns[i] = cols.toArray(new Column[cols.size()]);
         }
 
@@ -378,29 +423,9 @@
         LevenbergMarquardtOptimizer lmo = new LevenbergMarquardtOptimizer();
         CurveFitter cf = new CurveFitter(lmo);
 
-        boolean missingWs = false;
-        boolean missingQs = false;
-
         for (int i = 0; i < ws.length; ++i) {
-            boolean ignore = false;
-            if (Double.isNaN(ws[i])) {
-                ignore = true;
-                if (!missingWs) {
-                    missingWs = true;
-                    // TODO: i18n
-                    addProblem(km, "fix.missing.w");
-                }
-            }
-            if (Double.isNaN(qs[i])) {
-                ignore = true;
-                if (!missingQs) {
-                    missingQs = true;
-                    // TODO: i18n
-                    addProblem(km, "fix.missing.q");
-                }
-            }
-            if (!ignore) {
-                cf.addObservedPoint(ws[i], qs[i]);
+            if (!Double.isNaN(ws[i]) && !Double.isNaN(qs[i])) {
+                cf.addObservedPoint(qs[i], ws[i]);
             }
         }
 
@@ -408,6 +433,7 @@
             return cf.fit(function, function.getInitialGuess());
         }
         catch (MathException me) {
+            log.warn(me, me);
             addProblem(km, "fix.fitting.failed");
         }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java	Sun May 27 13:39:30 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java	Tue May 29 04:58:29 2012 +0000
@@ -8,6 +8,8 @@
 import de.intevation.flys.artifacts.FixationArtifactAccess;
 
 import de.intevation.flys.artifacts.model.CalculationResult;
+import de.intevation.flys.artifacts.model.DataFacet;
+import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.ReportFacet;
 
 import de.intevation.flys.artifacts.model.fixings.FixCalculation;
@@ -21,7 +23,10 @@
 /**
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
-public class FixationCompute extends DefaultState {
+public class FixationCompute
+extends      DefaultState
+implements   FacetTypes
+{
 
     /** The log used in this class. */
     private static Logger log = Logger.getLogger(FixationCompute.class);
@@ -65,6 +70,8 @@
         if (res.getReport().hasProblems()) {
             facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id));
         }
+        facets.add(
+            new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id));
 
         return res;
     }
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/AbstractExporter.java	Sun May 27 13:39:30 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/AbstractExporter.java	Tue May 29 04:58:29 2012 +0000
@@ -76,7 +76,7 @@
      *
      * @param writer The CSVWriter.
      */
-    protected abstract void writeCSVData(CSVWriter writer);
+    protected abstract void writeCSVData(CSVWriter writer) throws IOException;
 
 
     /**
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DeltaWtExporter.java	Sun May 27 13:39:30 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DeltaWtExporter.java	Tue May 29 04:58:29 2012 +0000
@@ -49,7 +49,7 @@
 
     public static final String DEFAULT_CSV_KM_HEADER = "km";
 
-    public static final String DEFAULT_CSV_DELTA_W_HEADER = "\u0394 W";
+    public static final String DEFAULT_CSV_DELTA_W_HEADER = "\u0394 W [cm]";
 
     public static final String DEFAULT_CSV_T_HEADER = "Datum";
 
@@ -98,7 +98,9 @@
     }
 
     @Override
-    protected void writeCSVData(CSVWriter writer) {
+    protected void writeCSVData(CSVWriter writer) throws IOException {
+
+        boolean debug = log.isDebugEnabled();
 
         writeCSVHeader(writer);
 
@@ -109,12 +111,22 @@
         Locale locale = Resources.getLocale(meta);
         DateFormat dF = DateFormat.getDateInstance(DateFormat.SHORT, locale);
 
+        if (debug) {
+            log.debug("DeltaWTsKMs: " + deltaWTsKMs.size());
+        }
+
         for (DeltaWTsKM deltaWTsKM: deltaWTsKMs) {
             List<DeltaWTsKM.KM> dkms = deltaWTsKM.getKms();
+            if (debug) {
+                log.debug("DeltaWTsKM.KM: " + dkms.size());
+            }
             for (DeltaWTsKM.KM dkm: dkms) {
                 double km = dkm.getKm();
                 String kmS = kmF.format(km);
                 List<DeltaWT> deltaWTs = dkm.getDeltaWTs();
+                if (debug) {
+                    log.debug("deltaWTs: " + deltaWTs.size());
+                }
                 for (DeltaWT dwt: deltaWTs) {
                     double deltaW = dwt.getDeltaW();
                     Date   date   = dwt.getDate();
@@ -131,6 +143,7 @@
                 }
             }
         }
+        writer.flush();
     }
 
 

http://dive4elements.wald.intevation.org