[PATCH] Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only

Wald Commits scm-commit at wald.intevation.org
Tue May 29 11:36:48 CEST 2018


# HG changeset patch
# User gernotbelger
# Date 1527586602 -7200
# Node ID ae3565385e6a68ed7ddd6a6a2ac243f0ca318449
# Parent  07d51fd4864c42277e6a482793950ec6225b513f
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only

diff -r 07d51fd4864c -r ae3565385e6a artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhCalculation.java	Tue May 29 11:35:44 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhCalculation.java	Tue May 29 11:36:42 2018 +0200
@@ -18,6 +18,7 @@
 import java.util.Set;
 import java.util.TreeSet;
 
+import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.math.DoubleRange;
 import org.apache.commons.lang.math.NumberRange;
 import org.dive4elements.artifacts.CallContext;
@@ -67,12 +68,13 @@
         /* find relevant bed-heights */
         final List<BedHeight> defaultBedHeights = new DefaultBedHeights(river).getBedHeights(problems);
         final Collection<BedHeightsFinder> bedHeights = BedHeightsFinder.createTkhBedHeights(problems, calcRange, defaultBedHeights);
+        final double[] stations = extractStations(bedHeights);
 
         /* misuse winfo-artifact to calculate waterlevels in the same way */
         final WINFOArtifact winfo = new WinfoArtifactWrapper(sinfo);
 
         /* calculate waterlevels */
-        final WQKms[] kms = calculateWaterlevels(winfo, problems);
+        final WQKms[] kms = calculateWaterlevels(winfo, stations, problems);
 
         final RiverInfoProvider infoProvider = RiverInfoProvider.forRange(this.context, river, calcRange);
 
@@ -97,6 +99,16 @@
         return new CalculationResult(results, problems);
     }
 
+    private double[] extractStations(final Collection<BedHeightsFinder> bedHeights) {
+
+        final Set<Double> allStations = new TreeSet<>();
+
+        for (final BedHeightsFinder bedHeight : bedHeights)
+            allStations.addAll(bedHeight.getStations());
+
+        return ArrayUtils.toPrimitive(allStations.toArray(new Double[allStations.size()]));
+    }
+
     /**
      * Calculation steps are simply the union of all stations of all involved bed-height datasets
      */
@@ -112,7 +124,10 @@
         return allStations;
     }
 
-    private WQKms[] calculateWaterlevels(final WINFOArtifact winfo, final Calculation problems) {
+    private WQKms[] calculateWaterlevels(final WINFOArtifact winfo, final double[] stations, final Calculation problems) {
+
+        // FIXME: we take kms from step, but instead we would like to take kms from bedheights
+        // FIXME: this will definitely break the serialization of the winfo artifact
 
         final CalculationResult waterlevelData = winfo.getWaterlevelData(this.context);
 
diff -r 07d51fd4864c -r ae3565385e6a artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhExporter.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhExporter.java	Tue May 29 11:35:44 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhExporter.java	Tue May 29 11:36:42 2018 +0200
@@ -53,8 +53,6 @@
 
         // "# Berechnungsgrundlage: Gleichung nach GILL (1971)"
         writeCSVMetaEntry(writer, CSV_META_CALCULATION_FORMULA);
-
-        writer.writeNext(new String[] { "" });
     }
 
     /**
@@ -85,15 +83,25 @@
     }
 
     @Override
-    // FIXME: rename
     protected void writeCSVResultMetadata(final CSVWriter writer, final TkhCalculationResults results, final TkhCalculationResult result) {
 
         final WstInfo wst = result.getWst();
         super.writeCSVWaterlevelMetadata(writer, wst);
-        writer.writeNext(new String[] { "" }); // break line
-        // FIXME:
+
+        // REAMRK:
         // "# W/Pegel [cm]: " (nur bei Eingabe des Wasserstands am Pegel)
         // "# Q (m³/s): " (nur bei Eingabe des Durchflusses)
+        // WaterlevelEXporter does this
+        // final WaterlevelDescriptionBuilder descBuilder = new WaterlevelDescriptionBuilder((D4EArtifact) this.master,
+        // this.context);
+        // final String metadata = descBuilder.getMetadata();
+        // BUT:
+        // - the WINFO results do not contain this info per wst
+        // - the WaterlevelExporter prints this in the global header for all waterlevels, simply based on the input fields
+        // - instead we would want tis information per waterlevel
+        // - the metadata 'Bezeichnung WST' contains exactly the wanted data
+
+        writer.writeNext(new String[] { "" }); // break line
     }
 
     /**
@@ -166,5 +174,4 @@
             getLog().warn("Error generating PDF Report!", je);
         }
     }
-
 }
\ No newline at end of file


More information about the Dive4Elements-commits mailing list