[PATCH] Fixed NaN handling in salix historical scenarion calculation, added problem report

Wald Commits scm-commit at wald.intevation.org
Fri Aug 17 11:13:43 CEST 2018


# HG changeset patch
# User mschaefer
# Date 1534497211 -7200
# Node ID 53e26734e4d2576786b753ace0116f0118a7f623
# Parent  2c8ba17b807ee2e16179708458cd99ff7e4af6ac
Fixed NaN handling in salix historical scenarion calculation, added problem report

diff -r 2c8ba17b807e -r 53e26734e4d2 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculation.java	Fri Aug 17 09:41:40 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculation.java	Fri Aug 17 11:13:31 2018 +0200
@@ -166,7 +166,16 @@
         rangeScenarios.put(Double.valueOf(calcRange.getLowerKm() - 0.0001), nulls);
         for (final Double station : stations) {
             rangeScenarios.put(station, new ArrayList<Double>());
-            rangeScenarios.get(station).add(Double.valueOf(bedHeightDifference(station.doubleValue(), currentFinders, historicalFinder)));
+            final double delta = bedHeightDifference(station, currentFinders, historicalFinder);
+            if (Double.isNaN(delta)) {
+                rangeScenarios.get(station).add(null);
+                if (!this.problems.hasProblems()) {
+                    final String msg = Resources.getMsg(this.context.getMeta(), "uinfo_salix_calc.warning.missing_bedheights");
+                    this.problems.addProblem(station, msg);
+                }
+            }
+            else
+                rangeScenarios.get(station).add(Double.valueOf(delta));
         }
         rangeScenarios.put(Double.valueOf(partTo + 0.0001), nulls);
     }
@@ -181,7 +190,12 @@
             if (!Double.isNaN(currentMSH))
                 break;
         }
-        return Formatter.roundFlowDepth(historicalFinder.getMeanBedHeight(station)).subtract(Formatter.roundFlowDepth(currentMSH)).doubleValue();
+        if (Double.isNaN(currentMSH))
+            return Double.NaN;
+        final double historicalMSH = historicalFinder.getMeanBedHeight(station);
+        if (Double.isNaN(historicalMSH))
+            return Double.NaN;
+        return Formatter.roundFlowDepth(historicalMSH).subtract(Formatter.roundFlowDepth(currentMSH)).doubleValue();
     }
 
     /**
diff -r 2c8ba17b807e -r 53e26734e4d2 artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java
--- a/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java	Fri Aug 17 09:41:40 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/Formatter.java	Fri Aug 17 11:13:31 2018 +0200
@@ -387,7 +387,7 @@
 
     /**
      * Decimal half even rounding of a flow depth value
-     * (throws an exception for NaN or Infinity)
+     * (ATTENTION: throws an exception for NaN or Infinity!)
      */
     public static BigDecimal roundFlowDepth(final double value) {
         return BigDecimal.valueOf(value).setScale(FLOWDEPTH_MAX_DIGITS, RoundingMode.HALF_EVEN);
@@ -399,7 +399,7 @@
 
     /**
      * Decimal half even rounding of a W value
-     * (throws an exception for NaN or Infinity)
+     * (ATTENTION: throws an exception for NaN or Infinity!)
      */
     public static BigDecimal roundW(final double value) {
         return BigDecimal.valueOf(value).setScale(WATERLEVEL_W_MAX_DIGITS, RoundingMode.HALF_EVEN);
diff -r 2c8ba17b807e -r 53e26734e4d2 artifacts/src/main/resources/messages.properties
--- a/artifacts/src/main/resources/messages.properties	Fri Aug 17 09:41:40 2018 +0200
+++ b/artifacts/src/main/resources/messages.properties	Fri Aug 17 11:13:31 2018 +0200
@@ -1183,7 +1183,8 @@
 uinfo_facet_salix_rank.description = Bewertungsschema
 uinfo_salix_calc.warning.missing_mq = MQ (MW) missing at reference gauge, no calculation possible
 uinfo_salix_calc.warning.missing_mhq = MHQ (MHW) missing at reference gauge, no salix calculation possible 
-uinfo_salix_calc.warning.missing_mnq = MNQ (MNW) missing at reference gauge, no (MW-MNW) calculation possible 
+uinfo_salix_calc.warning.missing_mnq = MNQ (MNW) missing at reference gauge, no (MW-MNW) calculation possible
+uinfo_salix_calc.warning.missing_bedheights = missing bed height values in the scenario range 
 
 predefineddepthevol.total.title = Gesamt: {0}
 predefineddepthevol.peryear.title = J\u00e4hrlich: {0}
diff -r 2c8ba17b807e -r 53e26734e4d2 artifacts/src/main/resources/messages_de.properties
--- a/artifacts/src/main/resources/messages_de.properties	Fri Aug 17 09:41:40 2018 +0200
+++ b/artifacts/src/main/resources/messages_de.properties	Fri Aug 17 11:13:31 2018 +0200
@@ -1184,6 +1184,7 @@
 uinfo_salix_calc.warning.missing_mq = MQ (MW) fehlt am Bezugspegel, Berechnung nicht m\u00f6glich
 uinfo_salix_calc.warning.missing_mhq = MHQ (MHW) fehlt am Bezugspegel, Berechnung des Iota nicht m\u00f6glich
 uinfo_salix_calc.warning.missing_mnq = MNQ (MNW) fehlt am Bezugspegel, Berechnung von (MW-MNW) nicht m\u00f6glich
+uinfo_salix_calc.warning.missing_bedheights = Im Teilabschnitt fehlen Sohlh\u00f6hen 
 
 predefineddepthevol.total.title = Gesamt: {0}
 predefineddepthevol.peryear.title = J\u00e4hrlich: {0}


More information about the Dive4Elements-commits mailing list