annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhCalculation.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 183f42641ab6
children b5600453bb8f
rev   line source
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
2 * Software engineering by
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
5 *
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
9 */
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
10 package org.dive4elements.river.artifacts.sinfo.tkhstate;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
11
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
12 import java.util.ArrayList;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
13 import java.util.Collection;
8942
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
14 import java.util.HashMap;
8916
5d5d0051723f Working on outputmodes of tkh calculation
gernotbelger
parents: 8915
diff changeset
15 import java.util.List;
8942
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
16 import java.util.Map;
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
17 import java.util.Map.Entry;
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
18 import java.util.Set;
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
19 import java.util.TreeSet;
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
20
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
21 import org.apache.commons.lang.math.DoubleRange;
8942
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
22 import org.apache.commons.lang.math.NumberRange;
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
23 import org.dive4elements.artifacts.CallContext;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
24 import org.dive4elements.river.artifacts.WINFOArtifact;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
25 import org.dive4elements.river.artifacts.model.Calculation;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
26 import org.dive4elements.river.artifacts.model.Calculation.Problem;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
27 import org.dive4elements.river.artifacts.model.CalculationResult;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
28 import org.dive4elements.river.artifacts.model.WQKms;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
29 import org.dive4elements.river.artifacts.resources.Resources;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
30 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
31 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider;
8948
a4f1ac81f26d Work on SINFO-FlowDepthMinMax.
gernotbelger
parents: 8946
diff changeset
32 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultRow;
a4f1ac81f26d Work on SINFO-FlowDepthMinMax.
gernotbelger
parents: 8946
diff changeset
33 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
34 import org.dive4elements.river.artifacts.sinfo.tkhcalculation.DischargeValuesFinder;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
35 import org.dive4elements.river.artifacts.sinfo.tkhcalculation.TkhCalculator;
8946
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
36 import org.dive4elements.river.artifacts.sinfo.tkhcalculation.WaterlevelValuesFinder;
8942
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
37 import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo;
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
38 import org.dive4elements.river.artifacts.sinfo.util.CalculationUtils;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
39 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
40 import org.dive4elements.river.artifacts.sinfo.util.WstInfo;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
41 import org.dive4elements.river.artifacts.states.WaterlevelData;
8938
9c02733a1b3c Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents: 8916
diff changeset
42 import org.dive4elements.river.exports.WaterlevelDescriptionBuilder;
8942
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
43 import org.dive4elements.river.model.BedHeight;
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
44 import org.dive4elements.river.model.River;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
45
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
46 /**
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
47 * @author Gernot Belger
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
48 */
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
49 final class TkhCalculation {
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
50
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
51 private final CallContext context;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
52
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
53 public TkhCalculation(final CallContext context) {
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
54 this.context = context;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
55 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
56
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
57 public CalculationResult calculate(final SINFOArtifact sinfo) {
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
58
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
59 /* access input data */
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
60 final TkhAccess access = new TkhAccess(sinfo);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
61 final River river = access.getRiver();
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
62 final RiverInfo riverInfo = new RiverInfo(river);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
63 final DoubleRange calcRange = access.getRange();
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
64
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
65 final Calculation problems = new Calculation();
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
66
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
67 /* find relevant bed-heights */
8942
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
68 final List<BedHeight> defaultBedHeights = new DefaultBedHeights(river).getBedHeights(problems);
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
69 final Collection<BedHeightsFinder> bedHeights = BedHeightsFinder.createTkhBedHeights(problems, calcRange, defaultBedHeights);
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
70
8938
9c02733a1b3c Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents: 8916
diff changeset
71 /* misuse winfo-artifact to calculate waterlevels in the same way */
9c02733a1b3c Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents: 8916
diff changeset
72 final WINFOArtifact winfo = new WinfoArtifactWrapper(sinfo);
9c02733a1b3c Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents: 8916
diff changeset
73
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
74 /* calculate waterlevels */
8938
9c02733a1b3c Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents: 8916
diff changeset
75 final WQKms[] kms = calculateWaterlevels(winfo, problems);
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
76
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
77 final RiverInfoProvider infoProvider = RiverInfoProvider.forRange(this.context, river, calcRange);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
78
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
79 final String user = CalculationUtils.findArtifactUser(this.context, sinfo);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
80
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
81 final String calcModeLabel = Resources.getMsg(this.context.getMeta(), sinfo.getCalculationMode().name());
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
82
8938
9c02733a1b3c Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents: 8916
diff changeset
83 final WaterlevelDescriptionBuilder descBuilder = new WaterlevelDescriptionBuilder(winfo, this.context);
9c02733a1b3c Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents: 8916
diff changeset
84 final String descriptionHeader = descBuilder.getColumnHeader();
9c02733a1b3c Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents: 8916
diff changeset
85
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
86 /* for each waterlevel, do a tkh calculation */
8938
9c02733a1b3c Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents: 8916
diff changeset
87 final TkhCalculationResults results = new TkhCalculationResults(calcModeLabel, user, riverInfo, calcRange, descriptionHeader);
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
88
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
89 /* determine calculation steps */
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
90 final Collection<Double> allStations = determineCalculationSteps(bedHeights);
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
91
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
92 for (final WQKms wqKms : kms) {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
93 final TkhCalculationResult result = calculateResult(calcRange, allStations, infoProvider, wqKms, bedHeights, descBuilder, problems);
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
94 if (result != null)
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
95 results.addResult(result);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
96 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
97
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
98 return new CalculationResult(results, problems);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
99 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
100
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
101 /**
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
102 * Calculation steps are simply the union of all stations of all involved bed-height datasets
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
103 */
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
104 private Collection<Double> determineCalculationSteps(final Collection<BedHeightsFinder> bedHeights) {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
105
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
106 final Collection<Double> allStations = new TreeSet<>();
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
107
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
108 for (final BedHeightsFinder bedHeight : bedHeights) {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
109 final Collection<Double> stations = bedHeight.getStations();
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
110 allStations.addAll(stations);
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
111 }
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
112
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
113 return allStations;
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
114 }
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
115
8938
9c02733a1b3c Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents: 8916
diff changeset
116 private WQKms[] calculateWaterlevels(final WINFOArtifact winfo, final Calculation problems) {
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
117
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
118 final CalculationResult waterlevelData = winfo.getWaterlevelData(this.context);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
119
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
120 /* copy all problems */
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
121 final Calculation winfoProblems = waterlevelData.getReport();
8916
5d5d0051723f Working on outputmodes of tkh calculation
gernotbelger
parents: 8915
diff changeset
122 final List<Problem> problems2 = winfoProblems.getProblems();
5d5d0051723f Working on outputmodes of tkh calculation
gernotbelger
parents: 8915
diff changeset
123 if (problems2 != null) {
5d5d0051723f Working on outputmodes of tkh calculation
gernotbelger
parents: 8915
diff changeset
124 for (final Problem problem : problems2) {
5d5d0051723f Working on outputmodes of tkh calculation
gernotbelger
parents: 8915
diff changeset
125 problems.addProblem(problem);
5d5d0051723f Working on outputmodes of tkh calculation
gernotbelger
parents: 8915
diff changeset
126 }
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
127 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
128
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
129 return (WQKms[]) waterlevelData.getData();
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
130 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
131
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
132 private TkhCalculationResult calculateResult(final DoubleRange calcRange, final Collection<Double> allStations, final RiverInfoProvider riverInfo,
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
133 final WQKms wkms, final Collection<BedHeightsFinder> bedHeights, final WaterlevelDescriptionBuilder descBuilder, final Calculation problems) {
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
134
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
135 // We have no wst year as the wst is created by a calculation; we do not need it though
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
136 final int wspYear = -1;
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
137 // Remark: showAllGauges only true for Fixierungsanalyse, false for WInfo, so false here as well
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
138 final boolean showAllGauges = false;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
139 final WaterlevelData waterlevel = new WaterlevelData(wkms, wspYear, showAllGauges);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
140
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
141 final RiverInfoProvider riverInfoProvider = riverInfo.forWaterlevel(waterlevel);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
142
8938
9c02733a1b3c Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents: 8916
diff changeset
143 // FIXME: check with winfo how the name is generated
9c02733a1b3c Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents: 8916
diff changeset
144 final String wstLabel = waterlevel.getName();
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
145
8938
9c02733a1b3c Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents: 8916
diff changeset
146 final WstInfo wstInfo = new WstInfo(wstLabel, wspYear, riverInfoProvider.getReferenceGauge());
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
147
8942
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
148 /* build tkh calculators per bedheight */
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
149 final Map<NumberRange, TkhCalculator> calculatorsByRanges = buildCalculators(calcRange, wkms, bedHeights, problems, riverInfoProvider, wstLabel);
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
150 if (calculatorsByRanges.isEmpty()) {
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
151 /* there should already be some problems, so just abort */
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
152 return null;
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
153 }
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
154
8948
a4f1ac81f26d Work on SINFO-FlowDepthMinMax.
gernotbelger
parents: 8946
diff changeset
155 final Collection<SInfoResultRow> rows = new ArrayList<>();
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
156
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
157 for (final Double stationDbl : allStations) {
8942
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
158
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
159 final double station = stationDbl;
8942
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
160
8954
183f42641ab6 Fixed: flowd depth calculation without transport bodies heights did not work any more
gernotbelger
parents: 8948
diff changeset
161 /* find the right calculator (i.e. bed height) depending on station, there should only be one maximal */
8942
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
162 final TkhCalculator tkhCalculator = findCalculator(calculatorsByRanges, station);
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
163 if (tkhCalculator == null)
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
164 continue;
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
165
8948
a4f1ac81f26d Work on SINFO-FlowDepthMinMax.
gernotbelger
parents: 8946
diff changeset
166 final SInfoResultRow row = SInfoResultRow.create();
8942
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
167
8948
a4f1ac81f26d Work on SINFO-FlowDepthMinMax.
gernotbelger
parents: 8946
diff changeset
168 row.putValue(SInfoResultType.waterlevelLabel, descBuilder.getDesc(wkms));
a4f1ac81f26d Work on SINFO-FlowDepthMinMax.
gernotbelger
parents: 8946
diff changeset
169 row.putValue(SInfoResultType.gaugeLabel, riverInfoProvider.findGauge(station));
a4f1ac81f26d Work on SINFO-FlowDepthMinMax.
gernotbelger
parents: 8946
diff changeset
170 row.putValue(SInfoResultType.location, riverInfoProvider.getLocation(station));
8942
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
171
8948
a4f1ac81f26d Work on SINFO-FlowDepthMinMax.
gernotbelger
parents: 8946
diff changeset
172 tkhCalculator.calculateTkh(station, row);
a4f1ac81f26d Work on SINFO-FlowDepthMinMax.
gernotbelger
parents: 8946
diff changeset
173
a4f1ac81f26d Work on SINFO-FlowDepthMinMax.
gernotbelger
parents: 8946
diff changeset
174 rows.add(row);
8942
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
175 }
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
176
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
177 return new TkhCalculationResult(wstLabel, wstInfo, true, rows);
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
178 }
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
179
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
180 private TkhCalculator findCalculator(final Map<NumberRange, TkhCalculator> calculators, final double station) {
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
181
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
182 // REMAKR: linear search at this point, put we expect the number of bed heights to be very small (1-2 items)
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
183 final Set<Entry<NumberRange, TkhCalculator>> x = calculators.entrySet();
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
184 for (final Entry<NumberRange, TkhCalculator> entry : x) {
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
185 final NumberRange range = entry.getKey();
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
186 // FIXME: check if we need comparison with a tolerance
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
187 if (range.containsDouble(station))
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
188 return entry.getValue();
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
189 }
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
190
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
191 return null;
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
192 }
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
193
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
194 private Map<NumberRange, TkhCalculator> buildCalculators(final DoubleRange calcRange, final WQKms wkms, final Collection<BedHeightsFinder> bedHeights,
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
195 final Calculation problems, final RiverInfoProvider riverInfoProvider, final String wstLabel) {
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
196 final Map<NumberRange, TkhCalculator> calculatorByRanges = new HashMap<>();
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
197 for (final BedHeightsFinder bedHeightsProvider : bedHeights) {
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
198
8942
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
199 final BedHeightInfo info = bedHeightsProvider.getInfo();
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
200
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
201 final NumberRange range = new NumberRange(info.getFrom(), info.getTo());
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
202
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
203 final WaterlevelValuesFinder waterlevelProvider = WaterlevelValuesFinder.fromKms(problems, wkms);
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
204 final DischargeValuesFinder dischargeProvider = DischargeValuesFinder.fromKms(wkms);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
205
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
206 /* initialize tkh calculator */
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
207 final TkhCalculator tkhCalculator = TkhCalculator.buildTkhCalculator(true, problems, wstLabel, riverInfoProvider.getRiver(), calcRange,
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
208 waterlevelProvider, dischargeProvider, bedHeightsProvider);
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
209
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
210 if (tkhCalculator.hasTkh()) {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8954
diff changeset
211 /* just ignore invalid ones, problems have already been updated by buildTkhCalculator() */
8942
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
212 calculatorByRanges.put(range, tkhCalculator);
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
213 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
214 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
215
8942
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8938
diff changeset
216 return calculatorByRanges;
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
217 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
218 }

http://dive4elements.wald.intevation.org