[PATCH] SINFO Calculations: do not produce result rows if some input data has missing values
Wald Commits
scm-commit at wald.intevation.org
Thu Apr 5 11:57:59 CEST 2018
# HG changeset patch
# User gernotbelger
# Date 1522922274 -7200
# Node ID b5600453bb8f6a16a683ea88b7fc1d961bdd0f93
# Parent bf8a9df86f321e4b5e931f39e5eeba7b14f50095
SINFO Calculations: do not produce result rows if some input data has missing values.
Also check for years of waterlevels in flow depth development calculation.
diff -r bf8a9df86f32 -r b5600453bb8f artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculator.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculator.java Tue Apr 03 17:23:51 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculator.java Thu Apr 05 11:57:54 2018 +0200
@@ -77,8 +77,7 @@
final String location = this.riverInfoProvider.getLocation(station);
row.putValue(SInfoResultType.location, location);
- this.tkhCalculator.calculateTkh(station, row);
-
- this.rows.add(row);
+ if (this.tkhCalculator.calculateTkh(station, row))
+ this.rows.add(row);
}
}
\ No newline at end of file
diff -r bf8a9df86f32 -r b5600453bb8f artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentCalculation.java Tue Apr 03 17:23:51 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentCalculation.java Thu Apr 05 11:57:54 2018 +0200
@@ -97,18 +97,26 @@
return null;
// FIXME: check current/hist wst have same discharge...
+ // FIXME: what means 'same discharge'
final BedHeightInfo currentSoundingInfo = currentSounding.getInfo();
final BedHeightInfo historicalSoundingInfo = historicalSounding.getInfo();
- // final String label = createLabel(waterlevel, minBedHeight, maxBedHeight);
-
- // final WKms wstKms = waterlevel.getWkms();
final int currentWstYear = currentWaterlevel.getYear();
final int historicalWstYear = historicalWaterlevel.getYear();
final int currentSoundingYear = currentSoundingInfo.getYear();
final int historicalSoundingYear = historicalSoundingInfo.getYear();
+ if (currentWstYear < 0) {
+ problems.addProblem("flowdepthdevelopmentcalculation.missingCurrentYear", currentWaterlevel.getName());
+ return null;
+ }
+
+ if (historicalWstYear < 0) {
+ problems.addProblem("flowdepthdevelopmentcalculation.missingHistoricalYear", historicalWaterlevel.getName());
+ return null;
+ }
+
// FIXME: distinguish error messages
FlowDepthUtils.checkYearDifference("", currentWstYear, currentSoundingYear, problems);
FlowDepthUtils.checkYearDifference("", historicalWstYear, historicalSoundingYear, problems);
@@ -144,6 +152,10 @@
final double historicalWst = historicalWstProvider.getWaterlevel(station);
final double historicalBedHeight = historicalSounding.getMeanBedHeight(station);
+ /* ignore invalid lines */
+ if (Double.isNaN(currentWst) || Double.isNaN(currentBedHeight) || Double.isNaN(historicalWst) || Double.isNaN(historicalBedHeight))
+ continue;
+
final double diffWst = (currentWst - historicalWst) * 100;
final double diffBedHeight = (currentBedHeight - historicalBedHeight) * 100;
diff -r bf8a9df86f32 -r b5600453bb8f artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxCalculation.java Tue Apr 03 17:23:51 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxCalculation.java Thu Apr 05 11:57:54 2018 +0200
@@ -149,6 +149,10 @@
// REMARK: access the gauge once only during calculation
final String gaugeLabel = riverInfoProvider.findGauge(station);
+ /* ignore invalid lines */
+ if (Double.isNaN(wst) || Double.isNaN(minBedHeightValue) || Double.isNaN(maxBedHeightValue))
+ continue;
+
final SInfoResultRow row = SInfoResultRow.create().//
putValue(SInfoResultType.station, station). //
putValue(SInfoResultType.flowdepthmin, minFlowDepth). //
diff -r bf8a9df86f32 -r b5600453bb8f artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/TkhCalculator.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/TkhCalculator.java Tue Apr 03 17:23:51 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/TkhCalculator.java Thu Apr 05 11:57:54 2018 +0200
@@ -108,7 +108,7 @@
return this.bedMeasurementsFinder.findD50(km);
}
- public void calculateTkh(final double km, final SInfoResultRow row) {
+ public boolean calculateTkh(final double km, final SInfoResultRow row) {
row.putValue(SInfoResultType.station, km);
@@ -117,37 +117,53 @@
final double wst = this.waterlevelProvider.getWaterlevel(km);
row.putValue(SInfoResultType.waterlevel, wst);
+ if (Double.isNaN(wst))
+ return false;
final double meanBedHeight = this.bedHeightsProvider.getMeanBedHeight(km);
row.putValue(SInfoResultType.meanBedHeight, meanBedHeight);
+ if (Double.isNaN(meanBedHeight))
+ return false;
final double flowDepth = wst - meanBedHeight;
row.putValue(SInfoResultType.flowdepth, flowDepth);
+ if (Double.isNaN(flowDepth))
+ return false;
final double discharge = this.dischargeProvider.getDischarge(km);
row.putValue(SInfoResultType.discharge, discharge);
- if (Double.isNaN(discharge))
- return;
if (!this.hasTkh())
- return;
+ return true;
+
+ // Missing discharge or kind is only a problem if we want to calculate tkh
+ if (Double.isNaN(discharge))
+ return false;
+ if (kind == null)
+ return false;
final double d50 = getBedMeasurement(km);
+ row.putValue(SInfoResultType.d50, d50);
if (Double.isNaN(d50))
- return;
- row.putValue(SInfoResultType.d50, d50);
+ return false;
if (!this.flowVelocitiesFinder.findKmQValues(km, discharge))
- return;
+ return false;
final double velocity = this.flowVelocitiesFinder.getFindVmainFound();
row.putValue(SInfoResultType.velocity, velocity);
+ if (Double.isNaN(velocity))
+ return false;
final double tau = this.flowVelocitiesFinder.getFindTauFound();
row.putValue(SInfoResultType.tau, tau);
+ if (Double.isNaN(tau))
+ return false;
final double tkh = calculateTkh(wst - meanBedHeight, velocity, d50, tau);
row.putValue(SInfoResultType.tkh, tkh);
+ if (Double.isNaN(tkh))
+ return false;
switch (kind) {
case starr:
@@ -164,6 +180,8 @@
final double flowDepthTkh = calculateFlowDepthTkh(tkh, kind, wst, meanBedHeight);
row.putValue(SInfoResultType.flowdepthtkh, flowDepthTkh);
+
+ return true;
}
/**
@@ -202,9 +220,6 @@
private double calculateFlowDepthTkh(final double tkhValue, final SoilKind tkhKind, final double wst, final double meanBedHeight) {
- if (Double.isNaN(tkhValue) || tkhKind == null)
- return Double.NaN;
-
switch (tkhKind) {
case starr:
return wst - (meanBedHeight + tkhValue / 100);
diff -r bf8a9df86f32 -r b5600453bb8f 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 Apr 03 17:23:51 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhCalculation.java Thu Apr 05 11:57:54 2018 +0200
@@ -169,9 +169,8 @@
row.putValue(SInfoResultType.gaugeLabel, riverInfoProvider.findGauge(station));
row.putValue(SInfoResultType.location, riverInfoProvider.getLocation(station));
- tkhCalculator.calculateTkh(station, row);
-
- rows.add(row);
+ if (tkhCalculator.calculateTkh(station, row))
+ rows.add(row);
}
return new TkhCalculationResult(wstLabel, wstInfo, true, rows);
diff -r bf8a9df86f32 -r b5600453bb8f artifacts/src/main/resources/messages.properties
--- a/artifacts/src/main/resources/messages.properties Tue Apr 03 17:23:51 2018 +0200
+++ b/artifacts/src/main/resources/messages.properties Thu Apr 05 11:57:54 2018 +0200
@@ -958,4 +958,7 @@
sinfo.export.csv.header.waterlevel.difference = \u0394WSPL
sinfo.export.csv.header.mean_bed_height.difference = \u0394MSH
sinfo.export.csv.header.flowdepth.current = Flie\u00dftiefe h-aktuell
-sinfo.export.csv.header.flowdepth.historical = Flie\u00dftiefe h-historisch
\ No newline at end of file
+sinfo.export.csv.header.flowdepth.historical = Flie\u00dftiefe h-historisch
+
+flowdepthdevelopmentcalculation.missingCurrentYear = Failed to determine date of current watterlevel ({0}), calculation not possible.
+flowdepthdevelopmentcalculation.missingHistoricalYear = Failed to determine date of historical watterlevel ({0}), calculation not possible.
\ No newline at end of file
diff -r bf8a9df86f32 -r b5600453bb8f artifacts/src/main/resources/messages_de.properties
--- a/artifacts/src/main/resources/messages_de.properties Tue Apr 03 17:23:51 2018 +0200
+++ b/artifacts/src/main/resources/messages_de.properties Thu Apr 05 11:57:54 2018 +0200
@@ -958,4 +958,7 @@
sinfo.export.csv.header.waterlevel.difference = \u0394WSPL
sinfo.export.csv.header.mean_bed_height.difference = \u0394MSH
sinfo.export.csv.header.flowdepth.current = Flie\u00dftiefe h-aktuell
-sinfo.export.csv.header.flowdepth.historical = Flie\u00dftiefe h-historisch
\ No newline at end of file
+sinfo.export.csv.header.flowdepth.historical = Flie\u00dftiefe h-historisch
+
+flowdepthdevelopmentcalculation.missingCurrentYear = Datum des aktuellen Wasserspiegels ({0}) konnte nicht ermittelt werden, Berechnung nicht m\u00f6glich.
+flowdepthdevelopmentcalculation.missingHistoricalYear = Datum des historischen Wasserspiegels ({0}) konnte nicht ermittelt werden, Berechnung nicht m\u00f6glich.
\ No newline at end of file
More information about the Dive4Elements-commits
mailing list