Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentCalculation.java @ 8964:45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
author | gernotbelger |
---|---|
date | Thu, 29 Mar 2018 15:48:17 +0200 |
parents | c40db8e8dcae |
children | b5600453bb8f |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentCalculation.java Wed Mar 28 17:04:20 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentCalculation.java Thu Mar 29 15:48:17 2018 +0200 @@ -11,6 +11,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.TreeSet; import org.apache.commons.lang.math.DoubleRange; import org.dive4elements.artifacts.CallContext; @@ -79,11 +80,11 @@ final WstSoundingIdPair histPair, final Calculation problems, final RiverInfoProvider infoProvider) { /* access real input data from database */ - final WaterlevelData currentWaterlevel = loadWaterlevel(currentPair, problems); + final WaterlevelData currentWaterlevel = loadWaterlevel(currentPair, calcRange, problems); if (currentWaterlevel == null) return null; - final WaterlevelData historicalWaterlevel = loadWaterlevel(histPair, problems); + final WaterlevelData historicalWaterlevel = loadWaterlevel(histPair, calcRange, problems); if (historicalWaterlevel == null) return null; @@ -112,9 +113,6 @@ FlowDepthUtils.checkYearDifference("", currentWstYear, currentSoundingYear, problems); FlowDepthUtils.checkYearDifference("", historicalWstYear, historicalSoundingYear, problems); - // checkWaterlevelDiscretisation(wstKms, calcRange, problems); - // 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 RiverInfoProvider currentRiverInfoProvider = infoProvider.forWaterlevel(currentWaterlevel); final RiverInfoProvider histRiverInfoProvider = infoProvider.forWaterlevel(historicalWaterlevel); @@ -123,35 +121,27 @@ final WstInfo historicalWstInfo = new WstInfo(historicalWaterlevel.getName(), historicalWstYear, histRiverInfoProvider.getReferenceGauge()); final WKms currentWkms = currentWaterlevel.getWkms(); - final WaterlevelValuesFinder currentWstProvider = WaterlevelValuesFinder.fromKms(currentWkms); - // final DischargeValuesFinder currentDischargeProvider = DischargeValuesFinder.fromKms(currentWkms); + final WaterlevelValuesFinder currentWstProvider = WaterlevelValuesFinder.fromKms(problems, currentWkms); final WKms historicalWkms = historicalWaterlevel.getWkms(); - final WaterlevelValuesFinder historicalWstProvider = WaterlevelValuesFinder.fromKms(historicalWkms); - // final DischargeValuesFinder historicalDischargeProvider = DischargeValuesFinder.fromKms(historicalWkms); + final WaterlevelValuesFinder historicalWstProvider = WaterlevelValuesFinder.fromKms(problems, historicalWkms); final int currentMeanYear = (currentWstYear + currentSoundingYear) / 2; final int historcialMeanYear = (historicalWstYear + historicalSoundingYear) / 2; - // final String waterlevelLabel = waterlevel.getName(); - // final String soundingLabel = buildSoundingLabel(minBedHeight, maxBedHeight); - final double diffYear = currentMeanYear - historcialMeanYear; /* real calculation loop */ final Collection<SInfoResultRow> rows = new ArrayList<>(); - // FIXME: determine what is the spatial discretisation that we will use... - final double[] allKms = currentWkms.allKms().toNativeArray(); - for (final double station : allKms) { + final Collection<Double> stations = determineCalculationSteps(currentSounding, historicalSounding); + for (final double station : stations) { if (calcRange.containsDouble(station)) { final double currentWst = currentWstProvider.getWaterlevel(station); - // final double currentDischarge = currentDischargeProvider.getDischarge(station); final double currentBedHeight = currentSounding.getMeanBedHeight(station); final double historicalWst = historicalWstProvider.getWaterlevel(station); - // final double historicalDischarge = historicalDischargeProvider.getDischarge(station); final double historicalBedHeight = historicalSounding.getMeanBedHeight(station); final double diffWst = (currentWst - historicalWst) * 100; @@ -186,6 +176,19 @@ rows); } + /** + * Calculation steps are simply the union of all stations of all involved bed-height datasets + */ + private Collection<Double> determineCalculationSteps(final BedHeightsFinder currentSounding, final BedHeightsFinder historicalSounding) { + + final Collection<Double> allStations = new TreeSet<>(); + + allStations.addAll(currentSounding.getStations()); + allStations.addAll(historicalSounding.getStations()); + + return allStations; + } + private String buildLabel(final WaterlevelData currentWaterlevel, final BedHeightInfo currentSounding, final WaterlevelData historicalWaterlevel, final BedHeightInfo historicalSounding) { @@ -201,9 +204,9 @@ } /* REMARK: fetch ALL wst kms, because we need to determine the original reference gauge */ - private WaterlevelData loadWaterlevel(final WstSoundingIdPair pair, final Calculation problems) { + private WaterlevelData loadWaterlevel(final WstSoundingIdPair pair, final DoubleRange calcRange, final Calculation problems) { final String wstId = pair.getWstId(); - return new WaterlevelFetcher().findWaterlevel(this.context, wstId, Double.NaN, Double.NaN, problems); + return new WaterlevelFetcher().findWaterlevel(this.context, wstId, calcRange, problems); } private BedHeightsFinder loadBedHeight(final WstSoundingIdPair pair, final DoubleRange calcRange, final Calculation problems) {