changeset 6301:20a32dbdbb59

Remove discharge table scaling but add reference system to W - Discharge_Tables are now always W[cm] Q[m³] no need for special case handling depending on historical / master tables - W now has a referenceSystem value that can be CENTIMETER_AT_GAUGE or METER_OVER_REFPOINT. The default is METER_OVER_REFPOINT as this is the case for everything except the objects created from discharge tables Known issue: WINFO input validation is currently broken as it still scales the user input.
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 12 Jun 2013 10:54:27 +0200
parents 0711ce5ca701
children d5af7b17efc2
files artifacts/src/main/java/org/dive4elements/river/artifacts/GaugeDischargeArtifact.java artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/Calculation6.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/DischargeTables.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/GaugeDischargeCurveFacet.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/Segment.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/W.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQKms.java artifacts/src/main/java/org/dive4elements/river/artifacts/services/DischargeTablesOverview.java
diffstat 9 files changed, 55 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/GaugeDischargeArtifact.java	Wed Jun 12 16:36:34 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/GaugeDischargeArtifact.java	Wed Jun 12 10:54:27 2013 +0200
@@ -168,7 +168,7 @@
 
         DischargeTables dt = new DischargeTables(river.getName(), getDataAsString("ids"));
 
-        Map<String, double [][]> map = dt.getValues(100);
+        Map<String, double [][]> map = dt.getValues();
 
         ArrayList<WQKms> res = new ArrayList<WQKms>();
 
@@ -185,7 +185,7 @@
         }
         double [] kms = new double[values[0].length];
         Arrays.fill(kms, gauge.getStation().doubleValue());
-        res.add(new WQKms(kms, values[0], values[1], name));
+        res.add(new WQKms(kms, values[0], values[1], name, WQKms.CENTIMETER_AT_GAUGE));
 
         return new CalculationResult(
             res.toArray(new WQKms[res.size()]),
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java	Wed Jun 12 16:36:34 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java	Wed Jun 12 10:54:27 2013 +0200
@@ -745,7 +745,7 @@
             return null;
         }
 
-        double [][] values = DischargeTables.loadDischargeTableValues(dt, 1);
+        double [][] values = DischargeTables.loadDischargeTableValues(dt);
 
         TDoubleArrayList wsOut = new TDoubleArrayList(ws.length);
         TDoubleArrayList qsOut = new TDoubleArrayList(ws.length);
@@ -757,8 +757,7 @@
                 logger.warn("W is NaN: ignored");
                 continue;
             }
-            double w = ws[i] / 100d;
-            double [] qs = DischargeTables.getQsForW(values, w);
+            double [] qs = DischargeTables.getQsForW(values, ws[i]);
 
             if (qs.length == 0) {
                 logger.warn("No Qs found for W = " + ws[i]);
@@ -766,7 +765,7 @@
             else {
                 for (double q: qs) {
                     wsOut.add(ws[i]);
-                    qsOut.add(q * 100d);
+                    qsOut.add(q);
                 }
             }
             generatedWs |= qs.length != 1;
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Calculation6.java	Wed Jun 12 16:36:34 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Calculation6.java	Wed Jun 12 10:54:27 2013 +0200
@@ -39,8 +39,6 @@
     private Long      officialGaugeNumber;
 
 
-    public static final double SCALE = 1d;
-
     public Calculation6(HistoricalDischargeAccess access) {
         EvaluationMode mode = access.getEvaluationMode();
         Timerange tr = access.getEvaluationTimerange();
@@ -329,8 +327,7 @@
             Integer id = dt.getId();
             double [][] vs = cache.get(id);
             if (vs == null) {
-                vs = DischargeTables.loadDischargeTableValues(
-                    dt, DischargeTables.HISTORICAL_SCALE);
+                vs = DischargeTables.loadDischargeTableValues(dt);
                 cache.put(id, vs);
             }
             return vs;
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/DischargeTables.java	Wed Jun 12 16:36:34 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/DischargeTables.java	Wed Jun 12 10:54:27 2013 +0200
@@ -34,20 +34,12 @@
     /** Private logger. */
     private static Logger log = Logger.getLogger(DischargeTables.class);
 
-    /** Scale to convert discharge table values of master table into [cm]. */
-    public static final double MASTER_SCALE = 100d;
-
-    /** Scale to convert discharge table values of historical tables into [cm]. */
-    public static final double HISTORICAL_SCALE = 1d;
-
     public static final int MASTER = 0;
 
     protected List<String> gaugeNames;
 
     protected String riverName;
 
-    protected double scale;
-
     protected int    kind;
 
     protected Map<String, double [][]> values;
@@ -76,18 +68,13 @@
         List<String> gaugeNames,
         int          kind
     ) {
-        scale           = Double.NaN;
         this.kind       = kind;
         this.riverName  = riverName;
         this.gaugeNames = gaugeNames;
     }
 
     public double [][] getFirstTable() {
-        return getFirstTable(MASTER_SCALE);
-    }
-
-    public double [][] getFirstTable(double scale) {
-        Map<String, double [][]> values = getValues(scale);
+        Map<String, double [][]> values = getValues();
         for (double [][] table: values.values()) {
             return table;
         }
@@ -95,13 +82,8 @@
     }
 
     public Map<String, double [][]> getValues() {
-        return getValues(MASTER_SCALE);
-    }
-
-    public Map<String, double [][]> getValues(double scale) {
-        if (values == null || scale != this.scale) {
-            values = loadValues(scale);
-            this.scale = scale;
+        if (values == null) {
+            values = loadValues();
         }
         return values;
     }
@@ -109,7 +91,7 @@
     /**
      * Returns mapping of gauge name to values.
      */
-    protected Map<String, double [][]> loadValues(double scale) {
+    protected Map<String, double [][]> loadValues() {
         Map<String, double [][]> values = new HashMap<String, double [][]>();
 
         Session session = SessionHolder.HOLDER.get();
@@ -147,7 +129,7 @@
             if (table == null) {
                 table = tables.get(0);
             }
-            double [][] vs = loadDischargeTableValues(table, scale);
+            double [][] vs = loadDischargeTableValues(table);
 
             values.put(gaugeName, vs);
         }
@@ -158,14 +140,10 @@
 
     /**
      * @param table The discharge table
-     * @param scale The scale factor to adjust W and Q values.
      *
      * @return the values of a discharge table.
      */
-    public static double[][] loadDischargeTableValues(
-        DischargeTable table,
-        double         scale
-    ) {
+    public static double[][] loadDischargeTableValues(DischargeTable table) {
         List<DischargeTableValue> dtvs = table.getDischargeTableValues();
 
         final double [][] vs = new double[2][dtvs.size()];
@@ -173,8 +151,8 @@
         int idx = 0;
         for (DischargeTableValue dtv: dtvs) {
             double q = dtv.getQ().doubleValue();
-            vs[0][idx] = q * scale;
-            vs[1][idx] = dtv.getW().doubleValue() * scale;
+            vs[0][idx] = q;
+            vs[1][idx] = dtv.getW().doubleValue();
             ++idx;
         }
 
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/GaugeDischargeCurveFacet.java	Wed Jun 12 16:36:34 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/GaugeDischargeCurveFacet.java	Wed Jun 12 10:54:27 2013 +0200
@@ -67,8 +67,7 @@
 
         DischargeTables dt = new DischargeTables(river, name);
 
-        Map<String, double [][]> map = dt.getValues(
-                DischargeTables.MASTER_SCALE);
+        Map<String, double [][]> map = dt.getValues();
 
         double [][] values = map.get(name);
         if (values == null) {
@@ -76,7 +75,7 @@
         }
         double [] kms = new double[values[0].length];
         Arrays.fill(kms, gauge.getStation().doubleValue());
-        return new WQKms(kms, values[0], values[1], name);
+        return new WQKms(kms, values[0], values[1], name, WQKms.CENTIMETER_AT_GAUGE);
     }
 
     @Override
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Segment.java	Wed Jun 12 16:36:34 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/Segment.java	Wed Jun 12 10:54:27 2013 +0200
@@ -187,17 +187,14 @@
 
                 DischargeTable dt = gauge.fetchMasterDischargeTable();
 
-                //TODO: Change scale from 100 to 1 immediately after
-                //      discharge table import changed to cm!
                 double [][] table =
-                    DischargeTables.loadDischargeTableValues(dt, 100);
+                    DischargeTables.loadDischargeTableValues(dt);
 
                 // need the original values for naming
                 segment.backup();
 
                 for (int i = 0; i < values.length; ++i) {
-                    //TODO: s.o.
-                    double w = values[i]; /* / 100.0; */
+                    double w = values[i] * 100.0;
                     double [] qs = DischargeTables.getQsForW(table, w);
                     if (qs.length == 0) {
                         log.warn("No Qs found for W = " + values[i]);
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/W.java	Wed Jun 12 16:36:34 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/W.java	Wed Jun 12 10:54:27 2013 +0200
@@ -22,6 +22,12 @@
 
     protected TDoubleArrayList ws;
 
+    public static final int METER_OVER_REFPOINT = 0;
+
+    public static final int CENTIMETER_AT_GAUGE = 1;
+
+    protected int referenceSystem;
+
     public W() {
         ws = new TDoubleArrayList();
     }
@@ -36,10 +42,35 @@
     }
 
     public W(int capacity, String name) {
+        this(capacity, "", METER_OVER_REFPOINT);
+    }
+
+    public W(int capacity, String name, int referenceSystem) {
         super(name);
+        this.referenceSystem = referenceSystem;
         ws = new TDoubleArrayList(capacity);
     }
 
+    public void setReferenceSystem(int val) {
+        referenceSystem = val;
+    }
+
+    /** Return the used reference system for W.
+     * If the W's refer to values in meters over a reference
+     * point (e.g. NN+m) they are in meter. If they are
+     * relative to the PNP of a gauge they are in centimeter*/
+    public int getReferenceSystem() {
+        return referenceSystem;
+    }
+
+    /** Convenience function to get the correct unit for W values. */
+    public String getWUnit() {
+        if (getReferenceSystem() == CENTIMETER_AT_GAUGE) {
+            return "cm";
+        }
+        return "m";
+    }
+
     public void add(double value) {
         ws.add(value);
     }
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQKms.java	Wed Jun 12 16:36:34 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQKms.java	Wed Jun 12 10:54:27 2013 +0200
@@ -58,8 +58,13 @@
 
 
     public WQKms(double [] kms, double [] qs, double [] ws, String name) {
+        this(kms, qs, ws, name, 0);
+    }
+
+    public WQKms(double [] kms, double [] qs, double [] ws, String name, int wReferenceSystem) {
         super(qs, ws, name);
         this.kms = new TDoubleArrayList(kms);
+        setReferenceSystem(wReferenceSystem);
     }
 
     @Override
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/DischargeTablesOverview.java	Wed Jun 12 16:36:34 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/DischargeTablesOverview.java	Wed Jun 12 10:54:27 2013 +0200
@@ -147,14 +147,7 @@
 
         double[][] xy = null;
 
-        if (dt.getKind() == DischargeTables.MASTER) {
-            xy = DischargeTables.loadDischargeTableValues(dt,
-                DischargeTables.MASTER_SCALE);
-        }
-        else {
-            xy = DischargeTables.loadDischargeTableValues(dt,
-                DischargeTables.HISTORICAL_SCALE);
-        }
+        xy = DischargeTables.loadDischargeTableValues(dt);
 
         XYSeries series = new XYSeries(createSeriesTitle(callMeta, dt), false);
         for (int i = 0, n = xy[0].length; i < n; i++) {

http://dive4elements.wald.intevation.org