changeset 9534:b380a5693514

Calculation of Dauerlinie corrected in WInfo (fix wst position according to a reference gauge, km specific discharge instead of that of the gauge); using same calculation in SInfo flood duration
author mschaefer
date Thu, 11 Oct 2018 18:39:21 +0200 (2018-10-11)
parents d9fda7af24ca
children 3fa8551c3d1b
files artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/Calculation3.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculation.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java
diffstat 4 files changed, 47 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java	Thu Oct 04 12:48:57 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java	Thu Oct 11 18:39:21 2018 +0200
@@ -319,7 +319,7 @@
         final int[] days = (int[]) obj[0];
         final double[] qs = (double[]) obj[1];
 
-        final Calculation3 calculation = new Calculation3(location, days, qs);
+        final Calculation3 calculation = new Calculation3(location, days, qs, gauge.getStation().doubleValue());
 
         return calculation.calculate(wst);
     }
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Calculation3.java	Thu Oct 04 12:48:57 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Calculation3.java	Thu Oct 11 18:39:21 2018 +0200
@@ -9,7 +9,11 @@
 package org.dive4elements.river.artifacts.model;
 
 import org.apache.log4j.Logger;
+import org.dive4elements.river.artifacts.model.WstValueTable.QPosition;
 
+/**
+ * Duration curve calculation of a km based on the duration curve of a gauge
+ */
 public class Calculation3
 extends      Calculation
 {
@@ -18,33 +22,50 @@
     protected double    km;
     protected int    [] days;
     protected double [] qs;
+    private double gaugeKm;
 
     public Calculation3() {
     }
 
-    public Calculation3(double km, int [] days, double [] qs) {
+    public Calculation3(final double km, final int[] days, final double[] qs, final double gaugeKm) {
         this.km   = km;
         this.days = days;
         this.qs   = qs;
+        this.gaugeKm = gaugeKm;
     }
 
-    public CalculationResult calculate(WstValueTable wst) {
+    /**
+     * Calculates the W and Q duration curve of the active km
+     */
+    public CalculationResult calculate(final WstValueTable wst) {
 
-        double [] ws = wst.interpolateW(km, qs, new double[qs.length], this);
+        if (this.days == null || this.days.length == 0) {
+            addProblem(this.km, "cannot.find.ds");
+        }
 
-        if (days == null || days.length == 0) {
-            addProblem(km, "cannot.find.ds");
+        final double[] ws = new double[this.days.length];
+        final double[] kmqs = new double[this.days.length];
+        for (int i = 0; i <= this.days.length - 1; i++) {
+            final QPosition qpos = wst.getQPosition(this.gaugeKm, this.qs[i]);
+            if (qpos != null) {
+                ws[i] = wst.interpolateW(this.km, qpos);
+                kmqs[i] = wst.getQ(qpos, this.km);
+            }
+            else {
+                addProblem(this.km, "cannot.find.q", this.qs[i]);
+                ws[i] = Double.NaN;
+            }
         }
 
         if (log.isDebugEnabled()) {
             log.debug("Calculate duration curve data:");
-            log.debug("    km       : " + km);
-            log.debug("    num Days : " + (days != null ? days.length : 0));
-            log.debug("    num Qs   : " + (qs != null ? qs.length : 0));
+            log.debug("    km       : " + this.km);
+            log.debug("    num Days : " + (this.days != null ? this.days.length : 0));
+            log.debug("    num Qs   : " + (this.qs != null ? this.qs.length : 0));
             log.debug("    result Ws: " + (ws != null ? ws.length : 0));
         }
 
-        WQDay wqday = new WQDay(days, ws, qs);
+        final WQDay wqday = new WQDay(this.days, ws, kmqs);
 
         if (hasProblems()) {
             log.debug("calculation caused "+numProblems()+" problem(s).");
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculation.java	Thu Oct 04 12:48:57 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculation.java	Thu Oct 11 18:39:21 2018 +0200
@@ -95,13 +95,16 @@
         // Calculate the selected main values, if any
         /* misuse winfo-artifact to calculate waterlevels in the same way */
         final WINFOArtifact winfo = new WinfoArtifactWrapper(sinfo);
-        winfo.addStringData("ld_locations", Double.toString(station));
 
         final FloodDurationCalculator calculator = new FloodDurationCalculator(this.context, infoProvider);
-        if (!Double.isNaN(station))
+        if (!Double.isNaN(station)) {
+            winfo.addStringData("ld_locations", Double.toString(station));
             return calculator.calcWQDays(problems, station, winfo);
-        else
-            return calculator.calcWQDays(problems, calcRange.getMinimumFloat(), winfo);
+        }
+        else {
+            winfo.addStringData("ld_locations", Double.toString(calcRange.getMinimumDouble()));
+            return calculator.calcWQDays(problems, calcRange.getMinimumDouble(), winfo);
+        }
     }
 
     /**
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java	Thu Oct 04 12:48:57 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculator.java	Thu Oct 11 18:39:21 2018 +0200
@@ -137,26 +137,15 @@
      */
     public WQDay calcWQDays(final Calculation problems, final double station, final WINFOArtifact winfo) {
 
-        final WstValueTable wst = WstValueTableFactory.getTable(this.riverInfoProvider.getRiver());
-        final Gauge gauge = this.riverInfoProvider.getGauge(station, true);
-        final Object[] obj = gauge.fetchDurationCurveData();
-        final int[] udays = (int[]) obj[0];
-        final double[] qs = (double[]) obj[1];
-        final int[] odays = new int[udays.length];
-        final double[] oqs = new double[udays.length];
-        final double[] ows = new double[udays.length];
-        for (int i = 0, j = udays.length - 1; i <= udays.length - 1; i++, j--) {
-            odays[j] = 365 - udays[i];
-            final QPosition qpos = wst.getQPosition(gauge.getStation().doubleValue(), qs[i]);
-            if (qpos != null) {
-                ows[j] = wst.interpolateW(station, qpos);
-                oqs[j] = wst.getQ(qpos, station);
-            } else {
-                ows[j] = Double.NaN;
-                oqs[j] = qs[i];
-            }
-        }
-        return new WQDay(odays, ows, oqs);
+        final CalculationResult res = winfo.getDurationCurveData();
+        final WQDay wqday = (WQDay) res.getData();
+        if (wqday == null)
+            return null;
+
+        final int[] odays = new int[wqday.size()];
+        for (int i = 0; i <= odays.length - 1; i++)
+            odays[i] = 365 - wqday.getDay(i);
+        return new WQDay(odays, wqday.getWs(), wqday.getQs());
     }
 
     /**

http://dive4elements.wald.intevation.org