Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhCalculation.java @ 9131:0a19a79663dd
TKH calculation now takes the stations of the bed heights for the waterlevel calculation instead of letting the user define a km-step
author | gernotbelger |
---|---|
date | Wed, 06 Jun 2018 14:17:18 +0200 |
parents | ae3565385e6a |
children | 3dae6b78e1da |
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 | 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 |
9105
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
21 import org.apache.commons.lang.ArrayUtils; |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
22 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
|
23 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
|
24 import org.dive4elements.artifacts.CallContext; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
25 import org.dive4elements.river.artifacts.WINFOArtifact; |
8996 | 26 import org.dive4elements.river.artifacts.common.ResultRow; |
8915
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.Calculation; |
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.Calculation.Problem; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
29 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
|
30 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
|
31 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
|
32 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
|
33 import org.dive4elements.river.artifacts.sinfo.common.RiverInfoProvider; |
8948 | 34 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
|
35 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
|
36 import org.dive4elements.river.artifacts.sinfo.tkhcalculation.TkhCalculator; |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8942
diff
changeset
|
37 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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 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
|
45 import org.dive4elements.river.model.River; |
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 /** |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
48 * @author Gernot Belger |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
49 */ |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
50 final class TkhCalculation { |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
51 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
52 private final CallContext context; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
53 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
54 public TkhCalculation(final CallContext context) { |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
55 this.context = context; |
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 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
58 public CalculationResult calculate(final SINFOArtifact sinfo) { |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
59 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
60 /* access input data */ |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
61 final TkhAccess access = new TkhAccess(sinfo); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
62 final River river = access.getRiver(); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
63 final RiverInfo riverInfo = new RiverInfo(river); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
64 final DoubleRange calcRange = access.getRange(); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
65 |
9131
0a19a79663dd
TKH calculation now takes the stations of the bed heights for the waterlevel calculation instead of letting the user define a km-step
gernotbelger
parents:
9105
diff
changeset
|
66 final String calcModeLabel = Resources.getMsg(this.context.getMeta(), sinfo.getCalculationMode().name()); |
0a19a79663dd
TKH calculation now takes the stations of the bed heights for the waterlevel calculation instead of letting the user define a km-step
gernotbelger
parents:
9105
diff
changeset
|
67 final String user = CalculationUtils.findArtifactUser(this.context, sinfo); |
0a19a79663dd
TKH calculation now takes the stations of the bed heights for the waterlevel calculation instead of letting the user define a km-step
gernotbelger
parents:
9105
diff
changeset
|
68 |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
69 final Calculation problems = new Calculation(); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
70 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
71 /* find relevant bed-heights */ |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
72 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
|
73 final Collection<BedHeightsFinder> bedHeights = BedHeightsFinder.createTkhBedHeights(problems, calcRange, defaultBedHeights); |
9131
0a19a79663dd
TKH calculation now takes the stations of the bed heights for the waterlevel calculation instead of letting the user define a km-step
gernotbelger
parents:
9105
diff
changeset
|
74 |
0a19a79663dd
TKH calculation now takes the stations of the bed heights for the waterlevel calculation instead of letting the user define a km-step
gernotbelger
parents:
9105
diff
changeset
|
75 if (defaultBedHeights.isEmpty()) { |
0a19a79663dd
TKH calculation now takes the stations of the bed heights for the waterlevel calculation instead of letting the user define a km-step
gernotbelger
parents:
9105
diff
changeset
|
76 final TkhCalculationResults results = new TkhCalculationResults(calcModeLabel, user, riverInfo, calcRange, ""); |
0a19a79663dd
TKH calculation now takes the stations of the bed heights for the waterlevel calculation instead of letting the user define a km-step
gernotbelger
parents:
9105
diff
changeset
|
77 return new CalculationResult(results, problems); |
0a19a79663dd
TKH calculation now takes the stations of the bed heights for the waterlevel calculation instead of letting the user define a km-step
gernotbelger
parents:
9105
diff
changeset
|
78 } |
0a19a79663dd
TKH calculation now takes the stations of the bed heights for the waterlevel calculation instead of letting the user define a km-step
gernotbelger
parents:
9105
diff
changeset
|
79 |
9105
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
80 final double[] stations = extractStations(bedHeights); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
81 |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8916
diff
changeset
|
82 /* 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
|
83 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
|
84 |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
85 /* calculate waterlevels */ |
9105
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
86 final WQKms[] kms = calculateWaterlevels(winfo, stations, problems); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
87 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
88 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
|
89 |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8916
diff
changeset
|
90 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
|
91 final String descriptionHeader = descBuilder.getColumnHeader(); |
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8916
diff
changeset
|
92 |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
93 /* 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
|
94 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
|
95 |
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
|
96 /* 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
|
97 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
|
98 |
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
|
99 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
|
100 final TkhCalculationResult result = calculateResult(calcRange, allStations, infoProvider, wqKms, bedHeights, descBuilder, problems); |
8980
b194fa64506a
SINFO - show results themes according to spec, either raw data or floating mean values.
gernotbelger
parents:
8978
diff
changeset
|
101 results.addResult(result, problems); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
102 } |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
103 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
104 return new CalculationResult(results, problems); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
105 } |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
106 |
9105
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
107 private double[] extractStations(final Collection<BedHeightsFinder> bedHeights) { |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
108 |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
109 final Set<Double> allStations = new TreeSet<>(); |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
110 |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
111 for (final BedHeightsFinder bedHeight : bedHeights) |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
112 allStations.addAll(bedHeight.getStations()); |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
113 |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
114 return ArrayUtils.toPrimitive(allStations.toArray(new Double[allStations.size()])); |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
115 } |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
116 |
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
|
117 /** |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8954
diff
changeset
|
118 * 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
|
119 */ |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8954
diff
changeset
|
120 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
|
121 |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8954
diff
changeset
|
122 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
|
123 |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8954
diff
changeset
|
124 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
|
125 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
|
126 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
|
127 } |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8954
diff
changeset
|
128 |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8954
diff
changeset
|
129 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
|
130 } |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8954
diff
changeset
|
131 |
9105
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
132 private WQKms[] calculateWaterlevels(final WINFOArtifact winfo, final double[] stations, final Calculation problems) { |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
133 |
9131
0a19a79663dd
TKH calculation now takes the stations of the bed heights for the waterlevel calculation instead of letting the user define a km-step
gernotbelger
parents:
9105
diff
changeset
|
134 final CalculationResult waterlevelData = winfo.computeWaterlevelData(stations); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
135 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
136 /* copy all problems */ |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
137 final Calculation winfoProblems = waterlevelData.getReport(); |
8916 | 138 final List<Problem> problems2 = winfoProblems.getProblems(); |
139 if (problems2 != null) { | |
140 for (final Problem problem : problems2) { | |
141 problems.addProblem(problem); | |
142 } | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
143 } |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
144 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
145 return (WQKms[]) waterlevelData.getData(); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
146 } |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
147 |
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
|
148 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
|
149 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
|
150 |
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
|
151 // 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
|
152 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
|
153 // 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
|
154 final boolean showAllGauges = false; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
155 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
|
156 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
157 final RiverInfoProvider riverInfoProvider = riverInfo.forWaterlevel(waterlevel); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
158 |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8916
diff
changeset
|
159 // 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
|
160 final String wstLabel = waterlevel.getName(); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
161 |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8916
diff
changeset
|
162 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
|
163 |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
164 /* build tkh calculators per bedheight */ |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
165 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
|
166 if (calculatorsByRanges.isEmpty()) { |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
167 /* 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
|
168 return null; |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
169 } |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
170 |
8996 | 171 final Collection<ResultRow> rows = new ArrayList<>(); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
172 |
9094
5488166d32ee
Fixed: major performance bug in tkh calculation leads to many river requests
gernotbelger
parents:
8996
diff
changeset
|
173 final String waterlevelLabel = descBuilder.getDesc(wkms); |
5488166d32ee
Fixed: major performance bug in tkh calculation leads to many river requests
gernotbelger
parents:
8996
diff
changeset
|
174 |
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
|
175 for (final Double stationDbl : allStations) { |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
176 |
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
|
177 final double station = stationDbl; |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
178 |
8954
183f42641ab6
Fixed: flowd depth calculation without transport bodies heights did not work any more
gernotbelger
parents:
8948
diff
changeset
|
179 /* 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
|
180 final TkhCalculator tkhCalculator = findCalculator(calculatorsByRanges, station); |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
181 if (tkhCalculator == null) |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
182 continue; |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
183 |
8996 | 184 final ResultRow row = ResultRow.create(); |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
185 |
9094
5488166d32ee
Fixed: major performance bug in tkh calculation leads to many river requests
gernotbelger
parents:
8996
diff
changeset
|
186 row.putValue(SInfoResultType.waterlevelLabel, waterlevelLabel); |
8948 | 187 row.putValue(SInfoResultType.gaugeLabel, riverInfoProvider.findGauge(station)); |
188 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
|
189 |
8978
b5600453bb8f
SINFO Calculations: do not produce result rows if some input data has missing values.
gernotbelger
parents:
8964
diff
changeset
|
190 if (tkhCalculator.calculateTkh(station, row)) |
b5600453bb8f
SINFO Calculations: do not produce result rows if some input data has missing values.
gernotbelger
parents:
8964
diff
changeset
|
191 rows.add(row); |
8942
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 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
|
195 } |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
196 |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
197 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
|
198 |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
199 // 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
|
200 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
|
201 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
|
202 final NumberRange range = entry.getKey(); |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
203 // 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
|
204 if (range.containsDouble(station)) |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
205 return entry.getValue(); |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
206 } |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
207 |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
208 return null; |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
209 } |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
210 |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
211 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
|
212 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
|
213 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
|
214 for (final BedHeightsFinder bedHeightsProvider : bedHeights) { |
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 final BedHeightInfo info = bedHeightsProvider.getInfo(); |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
217 |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
218 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
|
219 |
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
|
220 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
|
221 final DischargeValuesFinder dischargeProvider = DischargeValuesFinder.fromKms(wkms); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
222 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
223 /* 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
|
224 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
|
225 waterlevelProvider, dischargeProvider, bedHeightsProvider); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
226 |
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
|
227 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
|
228 /* 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
|
229 calculatorByRanges.put(range, tkhCalculator); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
230 } |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
231 } |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
232 |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
233 return calculatorByRanges; |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
234 } |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
235 } |