diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculation.java @ 8901:0a900d605d52

S-INFO Flowdepth work on TKH calculation
author mschaefer
date Thu, 22 Feb 2018 17:04:06 +0100
parents d32c22fc686c
children 37ff7f435912
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculation.java	Thu Feb 22 14:11:19 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculation.java	Thu Feb 22 17:04:06 2018 +0100
@@ -27,7 +27,7 @@
 import org.dive4elements.river.artifacts.model.CalculationResult;
 import org.dive4elements.river.artifacts.model.DateRange;
 import org.dive4elements.river.artifacts.model.LocationProvider;
-import org.dive4elements.river.artifacts.model.WQKms;
+import org.dive4elements.river.artifacts.model.QKms;
 import org.dive4elements.river.artifacts.model.WKms;
 import org.dive4elements.river.artifacts.resources.Resources;
 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact;
@@ -111,7 +111,6 @@
         final String wstId = diffPair.getWstId();
 
         final BedHeight bedHeight = loadBedHeight(soundingId);
-        final BedHeight bedHeight = loadBedHeight(soundingId);
         if (bedHeight == null) {
             final String message = Resources.format(this.context.getMeta(), "Failed to access sounding with id '{0}'", soundingId);
             problems.addProblem(message);
@@ -133,7 +132,7 @@
 
         checkYearDifference(label, waterlevel, bedHeight, problems);
         checkWaterlevelDiscretisation(wstKms, calcRange, problems);
-        // TODO: prüfen, ob sohlhöen die calcRange abdecken/überschneiden
+        // TODO: prüfen, ob sohlhöhen die calcRange abdecken/überschneiden
 
         /* re-determine the reference gauge, in the same way as the WaterlevelArtifact would do it */
         final String notinrange = Resources.getMsg(this.context.getMeta(), CSV_NOT_IN_GAUGE_RANGE, CSV_NOT_IN_GAUGE_RANGE);
@@ -147,19 +146,16 @@
 
         final FlowDepthCalculationResult resultData = new FlowDepthCalculationResult(label, wstInfo, sounding);
 
-        // FIXME: nur prüfen/beschaffen wenn TKH Berechnung aktiv
-        /* Abflusswerte vorhanden? */
-        if (!(wstKms instanceof WQKms)) {
+        boolean doCalcTkh = useTkh;
+        if (doCalcTkh && !(wstKms instanceof QKms)) {
             final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingQ", null, label);
             problems.addProblem(message);
-            // TODO: keine Berechnung TKH
+            doCalcTkh = false;
         }
 
         BedQualityD50KmValueFinder bedMeasurementsFinder = null;
-        if (useTkh)
-            bedMeasurementsFinder = loadBedMeasurements(river, calcRange, sounding.getYear());
-        // FIXME: prüfung ob (genug) werte vorhanden sind? was sind genau die kriterien? falls nein, problem hinzufügen und keine
-        // berechnung tkh
+        if (doCalcTkh)
+            bedMeasurementsFinder = loadBedMeasurements(river, calcRange, sounding.getYear().intValue());
 
         final String bedHeightLabel = bedHeight.getDescription();
         final String wstLabel = wstKms.getName();
@@ -167,9 +163,9 @@
         final UnivariateRealFunction wstInterpolator = DoubleUtil.getLinearInterpolator(wstKms.allKms(), wstKms.allWs());
         UnivariateRealFunction qInterpolator = null;
         DoubleRange qRange = null;
-        if (useTkh && (wstKms instanceof WQKms)) {
-            qInterpolator = DoubleUtil.getLinearInterpolator(((WQKms) wstKms).allKms(), ((WQKms) wstKms).allQs());
-            qRange = new DoubleRange( ((WQKms) wstKms).allQs().min(), ((WQKms) wstKms).allQs().max());
+        if (doCalcTkh) {
+            qInterpolator = DoubleUtil.getLinearInterpolator(((QKms) wstKms).allKms(), ((QKms) wstKms).allQs());
+            qRange = new DoubleRange( ((QKms) wstKms).allQs().min(), ((QKms) wstKms).allQs().max());
         }
         
         // FIXME: sort by station first, but in what direction?
@@ -182,13 +178,13 @@
         // FIXME: wie wird ggf. interpoliert? prüfung ob werte vorhanden?
         /* SoilKind lastKind = SoilKind.mobil; */
         SoilKindKmValueFinder soilKindFinder = null;
-        if (useTkh) {
+        if (doCalcTkh) {
             soilKindFinder = new SoilKindKmValueFinder();
             soilKindFinder.loadValues(river, calcRange);
         }
         
         FlowVelocityModelKmValueFinder flowVelocitiesFinder = null;
-        if (useTkh) {
+        if (doCalcTkh) {
             flowVelocitiesFinder = new FlowVelocityModelKmValueFinder();
             flowVelocitiesFinder.loadValues(river, calcRange, qRange);
         }
@@ -208,8 +204,6 @@
 
             if (!calcRange.containsDouble(km))
                 continue;
-            if (!calcRange.containsDouble(km))
-                continue;
 
             try {
                 // FIXME: check out of range
@@ -227,33 +221,38 @@
 
                 // FIXME: calculate tkh
                 double tkh = 0;
-                if (useTkh) {
-                    double d50 = 0;
-                    try {
-                        d50 = bedMeasurementsFinder.findD50(km);
-                    } catch (Exception e) {
+                if (doCalcTkh) {
+                    double d50 = bedMeasurementsFinder.findD50(km);
+                    if (Double.isNaN(d50)) {
                         final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingD50", null, label);
                         problems.addProblem(km, message);
-                        //FIXME: cumulate problems
+                        //FIXME: cumulate problems to one message?
                     }
-                    if (flowVelocitiesFinder.findKmQValues(km, discharge)) {
-                        tkh = calculateTkh(wst - meanBedHeight, flowVelocitiesFinder.getFindVmainFound(), d50, flowVelocitiesFinder.getFindTauFound());
-                        log.debug(String.format("calculateTkh km %.3f q %.0f w %.2f mbh %.2f vm %.1f tau %.1f d50(mm) %.1f tkh(cm) %.1f",
-                            km, discharge, wst, meanBedHeight, flowVelocitiesFinder.getFindVmainFound(), flowVelocitiesFinder.getFindTauFound(), d50*1000, tkh));
+                    if (!Double.isNaN(d50)) {
+                        if (flowVelocitiesFinder.findKmQValues(km, discharge)) {
+                            tkh = calculateTkh(wst - meanBedHeight, flowVelocitiesFinder.getFindVmainFound(), d50, flowVelocitiesFinder.getFindTauFound());
+                            /* log.debug(String.format("calculateTkh km %.3f q %.0f w %.2f mbh %.2f vm %.1f tau %.1f d50(mm) %.1f tkh(cm) %.1f",
+                                km, discharge, wst, meanBedHeight, flowVelocitiesFinder.getFindVmainFound(), flowVelocitiesFinder.getFindTauFound(), d50*1000, tkh)); */
+                        }
+                        else {
+                            final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingQ", null, label);
+                            problems.addProblem(km, message);
+                            //FIXME: cumulate problems to one message?
+                        }
                     }
                     else
                         tkh = Double.NaN;
                 }
                 
                 // Soil kind
-                SoilKind kind = SoilKind.starr;
-                if (useTkh) {
+                SoilKind kind = SoilKind.mobil;
+                if (doCalcTkh) {
                     try {
                         kind = soilKindFinder.findSoilKind(km);                        
                     } catch (Exception e) {
                         final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingSoilKind", null, label);
                         problems.addProblem(km, message);
-                        //FIXME: cumulate problems
+                        //FIXME: cumulate problems to one message?
                     }
                 }
                 

http://dive4elements.wald.intevation.org