changeset 3043:22da13d1b180

Added facet for derivate curve and fixed facet names. flys-artifacts/trunk@4612 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 06 Jun 2012 14:58:25 +0000
parents 2ff802d66b71
children 37982acfe1a3
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/fixanalysis.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisPeriodsFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java
diffstat 10 files changed, 268 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Jun 06 12:20:24 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed Jun 06 14:58:25 2012 +0000
@@ -1,3 +1,26 @@
+2012-06-06  Raimund Renkert <raimund.renkert@intevation.de>
+
+	Added facet for derivate curve and fixed facet names.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java:
+	  New. Facet for derivate curve.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisPeriodsFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java:
+	  Added name for facet to constructor.
+
+	* src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java:
+	  Add one facet for each output using a different name.
+
+	* src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java:
+	  Added facet names.
+
+	* doc/conf/artifacts/fixanalysis.xml:
+	  Changed facet names.
+
 2012-06-06	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/MiddleBedHeightExporter.java:
--- a/flys-artifacts/doc/conf/artifacts/fixanalysis.xml	Wed Jun 06 12:20:24 2012 +0000
+++ b/flys-artifacts/doc/conf/artifacts/fixanalysis.xml	Wed Jun 06 14:58:25 2012 +0000
@@ -131,14 +131,36 @@
                 </outputmode>
                 <outputmode name="fix_wq_curve" description="output.fix_wq_curve" mine-type="image/png" type="chart">
                     <facets>
-                        <facet name="fix_sector_average" description="Average values for Ws in Q sectors."/>
-                        <facet name="fix_analysis_events" description="Raw event values used in the calculation"/>
-                        <facet name="fix_reference_events" description="Raw event values used in the calculation"/>
-                        <facet name="fix_analysis_periods" description="Dateranges of analysis periods."/>
+                        <facet name="fix_sector_average_wq" description="Average values for Ws in Q sectors."/>
+                        <facet name="fix_analysis_events_wq" description="Raw event values used in the calculation"/>
+                        <facet name="fix_reference_events_wq" description="Raw event values used in the calculation"/>
+                        <facet name="fix_analysis_periods_wq" description="Dateranges of analysis periods."/>
                         <facet name="fix_wq_curve" description="WQ curve"/>
                         <facet name="fix_outlier" description="The outliers"/>
                     </facets>
                 </outputmode>
+                <outputmode name="fix_deltawt_curve" description="output.fix_deltawt_curve" mine-type="image/png" type="chart">
+                    <facets>
+                        <facet name="fix_sector_average_dwt" description="Average values for Ws in Q sectors."/>
+                        <facet name="fix_analysis_events_dwt" description="Raw event values used in the calculation"/>
+                        <facet name="fix_reference_events_dwt" description="Raw event values used in the calculation"/>
+                        <facet name="fix_analysis_periods_dwt" description="Dateranges of analysis periods."/>
+                    </facets>
+                </outputmode>
+                <outputmode name="fix_longitudinal_section_curve" description="output.fix_longitudinal_section_curve" mine-type="image/png" type="chart">
+                    <facets>
+                        <facet name="fix_sector_average_ls" description="Average values for Ws in Q sectors."/>
+                        <facet name="fix_analysis_events_ls" description="Raw event values used in the calculation"/>
+                        <facet name="fix_reference_events_ls" description="Raw event values used in the calculation"/>
+                        <facet name="fix_analysis_periods_ls" description="Dateranges of analysis periods."/>
+                        <facet name="longitudinal_section.annotations" description="facet.longitudinal_section.annotations"/>
+                    </facets>
+                </outputmode>
+                <outputmode name="fix_derivate_curve" description="output.fix_derivate_curve" mine-type="image/png" type="chart">
+                    <facets>
+                        <facet name="fix_derivate" description="Derivate curve"/>
+                    </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" />
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Wed Jun 06 12:20:24 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Wed Jun 06 14:58:25 2012 +0000
@@ -158,11 +158,25 @@
 
     String RELATIVE_POINT = "relativepoint";
 
-    String FIX_ANALYSIS_EVENTS = "fix_analysis_events";
-    String FIX_REFERENCE_EVENTS = "fix_reference_events";
-    String FIX_SECTOR_AVERAGE = "fix_sector_average";
+    String FIX_ANALYSIS_EVENTS_DWT = "fix_analysis_events_dwt";
+    String FIX_ANALYSIS_EVENTS_LS = "fix_analysis_events_ls";
+    String FIX_ANALYSIS_EVENTS_WQ = "fix_analysis_events_wq";
+
+    String FIX_REFERENCE_EVENTS_DWT = "fix_reference_events_dwt";
+    String FIX_REFERENCE_EVENTS_LS = "fix_reference_events_ls";
+    String FIX_REFERENCE_EVENTS_WQ = "fix_reference_events_wq";
+
+    String FIX_SECTOR_AVERAGE_DWT = "fix_sector_average_dwt";
+    String FIX_SECTOR_AVERAGE_LS = "fix_sector_average_ls";
+    String FIX_SECTOR_AVERAGE_WQ = "fix_sector_average_wq";
+
     String FIX_WQ_CURVE = "fix_wq_curve";
     String FIX_OUTLIER = "fix_outlier";
-    String FIX_ANALYSIS_PERIODS = "fix_analysis_periods";
+
+    String FIX_ANALYSIS_PERIODS_DWT = "fix_analysis_periods_dwt";
+    String FIX_ANALYSIS_PERIODS_LS = "fix_analysis_periods_ls";
+    String FIX_ANALYSIS_PERIODS_WQ = "fix_analysis_periods_wq";
+
+    String FIX_DERIVATE = "fix_derivate";
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java	Wed Jun 06 12:20:24 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java	Wed Jun 06 14:58:25 2012 +0000
@@ -37,9 +37,9 @@
     /**
      * @param name
      */
-    public FixAnalysisEventsFacet(int index, String description) {
+    public FixAnalysisEventsFacet(int index, String name, String description) {
         super(index,
-             FIX_ANALYSIS_EVENTS,
+             name,
              description,
              ComputeType.ADVANCE,
              null,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisPeriodsFacet.java	Wed Jun 06 12:20:24 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisPeriodsFacet.java	Wed Jun 06 14:58:25 2012 +0000
@@ -37,9 +37,9 @@
     /**
      * @param name
      */
-    public FixAnalysisPeriodsFacet(int index, String description) {
+    public FixAnalysisPeriodsFacet(int index, String name, String description) {
         super(index,
-            FIX_ANALYSIS_PERIODS,
+            name,
             description,
             ComputeType.ADVANCE,
             null,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java	Wed Jun 06 12:20:24 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java	Wed Jun 06 14:58:25 2012 +0000
@@ -34,10 +34,10 @@
     }
 
 
-    public FixAvSectorFacet(int ndx, String description) {
+    public FixAvSectorFacet(int ndx, String name, String description) {
         super(
             ndx,
-            FIX_SECTOR_AVERAGE,
+            name,
             description,
             ComputeType.ADVANCE,
             null,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java	Wed Jun 06 14:58:25 2012 +0000
@@ -0,0 +1,147 @@
+package de.intevation.flys.artifacts.model.fixings;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.flys.utils.KMIndex;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.FixationArtifactAccess;
+
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.DataFacet;
+import de.intevation.flys.artifacts.model.CalculationResult;
+import de.intevation.flys.artifacts.model.Parameters;
+
+import de.intevation.flys.artifacts.math.fitting.FunctionFactory;
+import de.intevation.flys.artifacts.math.fitting.Function;
+
+import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
+
+
+/**
+ * Facet to show the W|Q values.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class FixDerivateFacet
+extends      DataFacet
+implements   FacetTypes {
+
+    /** House logger. */
+    private static Logger logger = Logger.getLogger(FixDerivateFacet.class);
+
+    /** Trivial Constructor. */
+    public FixDerivateFacet() {
+    }
+
+
+    /**
+     * @param name
+     */
+    public FixDerivateFacet(String name, String description) {
+        super(0, name, description, ComputeType.ADVANCE, null, null);
+    }
+
+
+    /**
+     * Returns the data this facet requires.
+     *
+     * @param artifact the owner artifact.
+     * @param context  the CallContext (ignored).
+     *
+     * @return the data.
+     */
+    @Override
+    public Object getData(Artifact artifact, CallContext context) {
+        logger.debug("FixDerivateFacet.getData");
+        if (artifact instanceof FLYSArtifact) {
+            FLYSArtifact flys = (FLYSArtifact)artifact;
+            FixationArtifactAccess access = new FixationArtifactAccess(flys);
+
+            CalculationResult res =
+                (CalculationResult) flys.compute(context,
+                                                 ComputeType.ADVANCE,
+                                                 false);
+
+            FixResult result = (FixResult) res.getData();
+
+            double km = access.getCurrentKm();
+
+            String function = access.getFunction();
+            Function ff = FunctionFactory.getInstance().getFunction(function);
+            Function.Derivative fd = ff.getDerivative();
+
+            Parameters params = result.getParameters();
+            int row = params.binarySearch("km", km, Math.pow(10, -4));
+            String[] paramNames = ff.getParameterNames();
+            int[] paramInd = params.columnIndices(paramNames);
+            double[] coeffs = new double[paramNames.length];
+            params.get(row, paramInd, coeffs);
+
+            de.intevation.flys.artifacts.math.Function mf =
+                fd.instantiate(coeffs);
+
+            double maxQ = getMaxQ(result, km);
+
+            FixFunction fix = new FixFunction(
+                "",
+                ff.getDescription(),
+                mf,
+                maxQ);
+
+            return fix;
+        }
+        else {
+            logger.debug("Not an instance of FixationArtifact.");
+            return null;
+        }
+    }
+
+
+    protected double getMaxQ(FixResult result, double km) {
+        double maxQ = 0;
+
+        KMIndex<QW []> kmQWRef = result.getReferenced();
+
+        QW[] qwRef = kmQWRef.binarySearch(km).getValue();
+        if (qwRef != null) {
+            for (int i = 0; i < qwRef.length; i++) {
+                if (qwRef[i].getQ() > maxQ) {
+                    maxQ = qwRef[i].getQ();
+                }
+            }
+        }
+
+        KMIndex<AnalysisPeriod []> kmQWDAna = result.getAnalysisPeriods();
+        AnalysisPeriod[] periods = kmQWDAna.binarySearch(km).getValue();
+
+        if(periods != null) {
+            for (int i = 0; i < periods.length; i++) {
+                QWD[] qwdAna = periods[i].getQWDs();
+                if (qwdAna != null) {
+                    for (int j = 0; j < qwdAna.length; j++) {
+                        if (qwdAna[j].getQ() > maxQ) {
+                            maxQ = qwdAna[j].getQ();
+                        }
+                    }
+                }
+            }
+        }
+        return maxQ;
+    }
+
+    /**
+     * Create a deep copy of this Facet.
+     * @return a deep copy.
+     */
+    @Override
+    public FixDerivateFacet deepCopy() {
+        FixDerivateFacet copy = new FixDerivateFacet();
+        copy.set(this);
+        return copy;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java	Wed Jun 06 12:20:24 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java	Wed Jun 06 14:58:25 2012 +0000
@@ -37,8 +37,8 @@
     /**
      * @param name
      */
-    public FixOutlierFacet(String description) {
-        super(0, FIX_OUTLIER, description, ComputeType.ADVANCE, null, null);
+    public FixOutlierFacet(String name, String description) {
+        super(0, name, description, ComputeType.ADVANCE, null, null);
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java	Wed Jun 06 12:20:24 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java	Wed Jun 06 14:58:25 2012 +0000
@@ -37,9 +37,9 @@
     /**
      * @param name
      */
-    public FixReferenceEventsFacet(int index, String description) {
+    public FixReferenceEventsFacet(int index, String name, String description) {
         super(index,
-             FIX_REFERENCE_EVENTS,
+             name,
              description,
              ComputeType.ADVANCE,
              null,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java	Wed Jun 06 12:20:24 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixationCompute.java	Wed Jun 06 14:58:25 2012 +0000
@@ -16,10 +16,11 @@
 
 import de.intevation.flys.artifacts.model.fixings.FixAvSectorFacet;
 import de.intevation.flys.artifacts.model.fixings.FixAnalysisEventsFacet;
+import de.intevation.flys.artifacts.model.fixings.FixAnalysisPeriodsFacet;
 import de.intevation.flys.artifacts.model.fixings.FixReferenceEventsFacet;
 import de.intevation.flys.artifacts.model.fixings.FixOutlierFacet;
 import de.intevation.flys.artifacts.model.fixings.FixWQCurveFacet;
-
+import de.intevation.flys.artifacts.model.fixings.FixDerivateFacet;
 
 import de.intevation.flys.artifacts.model.fixings.DateRange;
 
@@ -86,7 +87,7 @@
         for (int i = 0; i < count; i++) {
             DateRange period = access.getAnalysisPeriods()[i];
             for (int j = access.getQSectorStart().intValue();
-                 j < access.getQSectorEnd().intValue();
+                 j <= access.getQSectorEnd().intValue();
                  j++) {
                 //TODO: replace j with q sector string.
                 String description = j + ": " +
@@ -94,16 +95,54 @@
                                      period.getTo().toString();
                 facets.add(
                     new FixAvSectorFacet(j - access.getQSectorStart().intValue(),
+                                         FIX_SECTOR_AVERAGE_DWT,
                                          description));
+                facets.add(
+                    new FixAvSectorFacet(j - access.getQSectorStart().intValue(),
+                                         FIX_SECTOR_AVERAGE_LS,
+                                         description));
+                facets.add(
+                    new FixAvSectorFacet(j - access.getQSectorStart().intValue(),
+                                         FIX_SECTOR_AVERAGE_WQ,
+                                         description));
+
             }
             String eventDesc = period.getFrom().toString() +
                                " - " +
                                period.getTo().toString();
-            facets.add(new FixAnalysisEventsFacet(i, eventDesc));
+            facets.add(new FixAnalysisEventsFacet(i,
+                FIX_ANALYSIS_EVENTS_DWT,
+                eventDesc));
+            facets.add(new FixAnalysisEventsFacet(i,
+                FIX_ANALYSIS_EVENTS_LS,
+                eventDesc));
+            facets.add(new FixAnalysisEventsFacet(i,
+                FIX_ANALYSIS_EVENTS_WQ,
+                eventDesc));
         }
-        facets.add(new FixReferenceEventsFacet(0, "Referenceperiod"));
+        facets.add(new FixReferenceEventsFacet(0,
+            FIX_REFERENCE_EVENTS_DWT,
+            "Referenceperiod"));
+        facets.add(new FixReferenceEventsFacet(1,
+            FIX_REFERENCE_EVENTS_LS,
+            "Referenceperiod"));
+        facets.add(new FixReferenceEventsFacet(2,
+            FIX_REFERENCE_EVENTS_WQ,
+            "Referenceperiod"));
+
+        facets.add(new FixAnalysisPeriodsFacet(0,
+            FIX_ANALYSIS_PERIODS_DWT,
+            "Analysis periods"));
+        facets.add(new FixAnalysisPeriodsFacet(1,
+            FIX_ANALYSIS_PERIODS_LS,
+            "Analysis periods"));
+        facets.add(new FixAnalysisPeriodsFacet(2,
+            FIX_ANALYSIS_PERIODS_WQ,
+            "Analysis periods"));
+
         facets.add(new FixWQCurveFacet("W/Q"));
-        facets.add(new FixOutlierFacet("Outlier"));
+        facets.add(new FixOutlierFacet(FIX_OUTLIER, "Outlier"));
+        facets.add(new FixDerivateFacet(FIX_DERIVATE, "Derivative"));
 
         return res;
     }

http://dive4elements.wald.intevation.org