[PATCH 4 of 5] Softwaretests...20181219 7.3: no interpolation of missing bed heights for Uinfo/Salix historical scenario and B&U/Bzws

Wald Commits scm-commit at wald.intevation.org
Tue Feb 5 15:52:19 CET 2019


# HG changeset patch
# User mschaefer
# Date 1549378078 -3600
# Node ID 5395c6d4ca509ee935e1389971d9a9979ace2302
# Parent  fbfd66e8fb811753e030eb04bfe2dec4dbba927d
Softwaretests...20181219 7.3: no interpolation of missing bed heights for Uinfo/Salix historical scenario and B&U/Bzws

diff -r fbfd66e8fb81 -r 5395c6d4ca50 artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstDepthProcessor.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstDepthProcessor.java	Tue Feb 05 15:43:27 2019 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstDepthProcessor.java	Tue Feb 05 15:47:58 2019 +0100
@@ -90,7 +90,7 @@
             return generateFieldDepthSeries(generator, bundle, theme, visible, fieldIndex);
         }
 
-        return buildSeriesForType(generator, bundle, theme, visible, doGetType(bundle.getFacetName()), null);
+        return buildSeriesForType(generator, bundle, theme, visible, doGetType(bundle.getFacetName()), GAP_DISTANCE);
     }
 
     protected AbstractResultType doGetType(final String facetName) {
@@ -110,6 +110,6 @@
         final BezugswstMainCalculationResult data = (BezugswstMainCalculationResult) getResult(generator, bundle);
         final double[][] points = data.getFieldValuePoints(fieldIndex, BunduResultType.depthFields);
 
-        return buildSeriesForPoints(points, generator, bundle, theme, visible, null);
+        return buildSeriesForPoints(points, generator, bundle, theme, visible, GAP_DISTANCE);
     }
 }
\ No newline at end of file
diff -r fbfd66e8fb81 -r 5395c6d4ca50 artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstHeightProcessor.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstHeightProcessor.java	Tue Feb 05 15:43:27 2019 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstHeightProcessor.java	Tue Feb 05 15:47:58 2019 +0100
@@ -94,7 +94,7 @@
             return generateFieldHeightSeries(generator, bundle, theme, visible, fieldIndex);
         }
 
-        return buildSeriesForType(generator, bundle, theme, visible, doGetType(bundle.getFacetName()), null);
+        return buildSeriesForType(generator, bundle, theme, visible, doGetType(bundle.getFacetName()), GAP_DISTANCE);
     }
 
     protected AbstractResultType doGetType(final String facetName) {
@@ -114,6 +114,6 @@
         final BezugswstMainCalculationResult data = (BezugswstMainCalculationResult) getResult(generator, bundle);
         final double[][] points = data.getFieldValuePoints(fieldIndex, BunduResultType.bedHeightFields);
 
-        return buildSeriesForPoints(points, generator, bundle, theme, visible, null);
+        return buildSeriesForPoints(points, generator, bundle, theme, visible, GAP_DISTANCE);
     }
 }
\ No newline at end of file
diff -r fbfd66e8fb81 -r 5395c6d4ca50 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsFinder.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsFinder.java	Tue Feb 05 15:43:27 2019 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsFinder.java	Tue Feb 05 15:47:58 2019 +0100
@@ -44,6 +44,8 @@
 
     private final boolean isNull;
 
+    private final boolean doInterpolate;
+
     /**
      * Create bed level finders from a collection of bed levels.
      */
@@ -52,7 +54,22 @@
         final List<BedHeightsFinder> result = new ArrayList<>(bedHeights.size());
 
         for (final BedHeight bedHeight : bedHeights) {
-            final BedHeightsFinder finder = createBedHeights(problems, bedHeight, range);
+            final BedHeightsFinder finder = createBedHeights(problems, bedHeight, range, true);
+            result.add(finder);
+        }
+
+        return result;
+    }
+
+    /**
+     * Create not-interpolated bed level finders from a collection of bed levels.
+     */
+    public static Collection<BedHeightsFinder> createScenarioBedHeights(final Calculation problems, final DoubleRange range,
+            final Collection<BedHeight> bedHeights) {
+        final List<BedHeightsFinder> result = new ArrayList<>(bedHeights.size());
+
+        for (final BedHeight bedHeight : bedHeights) {
+            final BedHeightsFinder finder = createBedHeights(problems, bedHeight, range, false);
             result.add(finder);
         }
 
@@ -110,7 +127,22 @@
         if (bedHeight == null)
             return null;
 
-        return BedHeightsFinder.createBedHeights(problems, bedHeight, range);
+        return BedHeightsFinder.createBedHeights(problems, bedHeight, range, true);
+    }
+
+    /**
+     * Creates a interpolated or not-interpolated {@link BedHeightsFinder} for a dataset from the database, specified by its
+     * id.
+     *
+     * @return <code>null</code> if no bed level with the given id exists.
+     */
+    public static BedHeightsFinder forId(final Calculation problems, final int id, final DoubleRange range, final boolean doInterpolate) {
+
+        final BedHeight bedHeight = BedHeight.getBedHeightById(id);
+        if (bedHeight == null)
+            return null;
+
+        return BedHeightsFinder.createBedHeights(problems, bedHeight, range, doInterpolate);
     }
 
     /**
@@ -118,14 +150,15 @@
      */
     public static BedHeightsFinder NullFinder() {
         final NavigableMap<Double, BedHeightValue> values = new TreeMap<>();
-        return new BedHeightsFinder(null, null, values, true);
+        return new BedHeightsFinder(null, null, values, true, false);
     }
 
     /**
      * Create a finder for a given bed level.
      *
      */
-    private static BedHeightsFinder createBedHeights(final Calculation problems, final BedHeight bedHeight, final DoubleRange range) {
+    private static BedHeightsFinder createBedHeights(final Calculation problems, final BedHeight bedHeight, final DoubleRange range,
+            final boolean doInterpolate) {
 
         // FIXME: sort by station, but in what direction?
         // FIXME: using river.getKmUp()?
@@ -142,14 +175,16 @@
 
         final BedHeightInfo info = BedHeightInfo.from(bedHeight);
 
-        return new BedHeightsFinder(problems, info, values, false);
+        return new BedHeightsFinder(problems, info, values, false, doInterpolate);
     }
 
-    private BedHeightsFinder(final Calculation problems, final BedHeightInfo info, final NavigableMap<Double, BedHeightValue> values, final boolean isNull) {
+    private BedHeightsFinder(final Calculation problems, final BedHeightInfo info, final NavigableMap<Double, BedHeightValue> values, final boolean isNull,
+            final boolean doInterpolate) {
         this.info = info;
         this.values = values;
         this.problems = problems;
         this.isNull = isNull;
+        this.doInterpolate = doInterpolate;
     }
 
     /**
@@ -207,13 +242,23 @@
         if (floorEntry == null || ceilingEntry == null)
             return Double.NaN;
 
+        // return NaN if value not found and no-interpolation mode, and report once
+        if (!this.doInterpolate && (floorEntry != ceilingEntry)) {
+            if (this.problems != null) {
+                this.problems.addProblem(km, "sinfo.bedheightsfinder.missing_bedheights");
+                this.problems = null;
+            }
+            return Double.NaN;
+        }
+
         final double floorKm = floorEntry.getKey().doubleValue();
         final double ceilKm = ceilingEntry.getKey().doubleValue();
-
         /* report once if the interpolation distance exceeds 1000m */
-        if (Math.abs(floorKm - ceilKm) > MAX_DISTANCE_KM && this.problems != null) {
-            this.problems.addProblem(km, "linearInterpolator.maxdistance", MAX_DISTANCE_KM * 1000);
-            this.problems = null;
+        if (Math.abs(floorKm - ceilKm) > MAX_DISTANCE_KM) {
+            if (this.problems != null) {
+                this.problems.addProblem(km, "linearInterpolator.maxdistance", MAX_DISTANCE_KM * 1000);
+                this.problems = null;
+            }
             return Double.NaN;
         }
 
diff -r fbfd66e8fb81 -r 5395c6d4ca50 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	Tue Feb 05 15:43:27 2019 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculation.java	Tue Feb 05 15:47:58 2019 +0100
@@ -156,11 +156,11 @@
         if (defaultBedHeights.isEmpty())
             return;
         final DoubleRange scenarioRange = new DoubleRange(partFrom, partTo);
-        final Collection<BedHeightsFinder> allFinders = BedHeightsFinder.createTkhBedHeights(this.problems, scenarioRange, defaultBedHeights);
+        final Collection<BedHeightsFinder> allFinders = BedHeightsFinder.createScenarioBedHeights(this.problems, scenarioRange, defaultBedHeights);
         final Collection<BedHeightsFinder> currentFinders = new ArrayList<>(allFinders);
 
         // Add historical bed-heights
-        final BedHeightsFinder historicalFinder = BedHeightsFinder.forId(this.problems, historicalBedHeightId, scenarioRange);
+        final BedHeightsFinder historicalFinder = BedHeightsFinder.forId(this.problems, historicalBedHeightId, scenarioRange, false);
         allFinders.add(historicalFinder);
         final Collection<Double> stations = BedHeightsUtils.extractStationCollection(allFinders, true);
         final List<Double> nulls = new ArrayList<>();
diff -r fbfd66e8fb81 -r 5395c6d4ca50 artifacts/src/main/resources/messages.properties
--- a/artifacts/src/main/resources/messages.properties	Tue Feb 05 15:43:27 2019 +0100
+++ b/artifacts/src/main/resources/messages.properties	Tue Feb 05 15:47:58 2019 +0100
@@ -806,6 +806,8 @@
 sinfo.bedheightsfinder.configfile.loaderror = Failed to load config file ''{0}'': {1}
 sinfo.bedheightsfinder.notfound = Failed to access sounding with id ''{0}''
 sinfo.bedheightsfinder.empty = The bed levels do not contain any values for the selected calculation stretch
+sinfo.bedheightsfinder.missing_bedheights = Missing bed levels
+
 sinfo.bedqualityd50config.configfile.loaderror = Failed to read config file ''{0}'' which contains period specs for D50 bed diameter calculation: {1}
 
 sinfo_calc_flow_depth_development=Flow Depth Development
diff -r fbfd66e8fb81 -r 5395c6d4ca50 artifacts/src/main/resources/messages_de.properties
--- a/artifacts/src/main/resources/messages_de.properties	Tue Feb 05 15:43:27 2019 +0100
+++ b/artifacts/src/main/resources/messages_de.properties	Tue Feb 05 15:47:58 2019 +0100
@@ -806,6 +806,8 @@
 sinfo.bedheightsfinder.configfile.loaderror = Fehler beim Laden der Konfigurationsdatei ''{0}'': {1}
 sinfo.bedheightsfinder.notfound = Keine Sohlh\u00f6he mit id ''{0}'' vorhanden
 sinfo.bedheightsfinder.empty = Die Sohlh\u00f6hen enthalten keine Werte f\u00fcr die gew\u00e4hlte Berechnungsstrecke 
+sinfo.bedheightsfinder.missing_bedheights = Es fehlen Sohlh\u00f6hen
+
 sinfo.bedqualityd50config.configfile.loaderror = Fehler beim Auslesen der Datei ''{0}'' zur Spezifikation der Zeitr\u00e4ume zur Berechnung der D50-Sohlkorndurchmesser: {1}
 
 sinfo_calc_flow_depth_development=Flie\u00dftiefenentwicklung


More information about the Dive4Elements-commits mailing list