Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhCalculation.java @ 9573:b9c87bbff6a4
mean bed height -> mean bed LEVEL
author | gernotbelger |
---|---|
date | Tue, 06 Nov 2018 10:56:22 +0100 |
parents | 55c187a0a31e |
children |
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; |
9312 | 26 import org.dive4elements.river.artifacts.common.GeneralResultType; |
8996 | 27 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
|
28 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
|
29 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
|
30 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
|
31 import org.dive4elements.river.artifacts.model.WQKms; |
9510
9ea704de63ee
Error message added if no bed height found for a calc range
mschaefer
parents:
9499
diff
changeset
|
32 import org.dive4elements.river.artifacts.model.river.RiverInfoProvider; |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
33 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
|
34 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
|
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; |
9335
7dc238bd062c
Fixed: calculation of flow depth and tkh with rounding to cm, calculator return differentiated
mschaefer
parents:
9318
diff
changeset
|
37 import org.dive4elements.river.artifacts.sinfo.tkhcalculation.TkhCalculator.TkhCalculateState; |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8942
diff
changeset
|
38 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
|
39 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
|
40 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
|
41 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
|
42 import org.dive4elements.river.artifacts.sinfo.util.WstInfo; |
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); |
9510
9ea704de63ee
Error message added if no bed height found for a calc range
mschaefer
parents:
9499
diff
changeset
|
81 if (stations.length == 0) { |
9ea704de63ee
Error message added if no bed height found for a calc range
mschaefer
parents:
9499
diff
changeset
|
82 final TkhCalculationResults results = new TkhCalculationResults(calcModeLabel, user, riverInfo, calcRange, ""); |
9ea704de63ee
Error message added if no bed height found for a calc range
mschaefer
parents:
9499
diff
changeset
|
83 problems.addProblem("sinfo.bedheightsfinder.empty"); |
9ea704de63ee
Error message added if no bed height found for a calc range
mschaefer
parents:
9499
diff
changeset
|
84 return new CalculationResult(results, problems); |
9ea704de63ee
Error message added if no bed height found for a calc range
mschaefer
parents:
9499
diff
changeset
|
85 } |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
86 |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8916
diff
changeset
|
87 /* 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
|
88 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
|
89 |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
90 /* calculate waterlevels */ |
9105
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
91 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
|
92 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
93 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
|
94 |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8916
diff
changeset
|
95 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
|
96 final String descriptionHeader = descBuilder.getColumnHeader(); |
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8916
diff
changeset
|
97 |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
98 /* 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
|
99 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
|
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 /* 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
|
102 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
|
103 |
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
|
104 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
|
105 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
|
106 results.addResult(result, problems); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
107 } |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
108 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
109 return new CalculationResult(results, problems); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
110 } |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
111 |
9105
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
112 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
|
113 |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
114 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
|
115 |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
116 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
|
117 allStations.addAll(bedHeight.getStations()); |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
118 |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
119 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
|
120 } |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
121 |
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
|
122 /** |
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 * 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
|
124 */ |
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 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
|
126 |
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 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
|
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 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
|
130 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
|
131 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
|
132 } |
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 |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8954
diff
changeset
|
134 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
|
135 } |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8954
diff
changeset
|
136 |
9105
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
137 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
|
138 |
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
|
139 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
|
140 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
141 /* copy all problems */ |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
142 final Calculation winfoProblems = waterlevelData.getReport(); |
8916 | 143 final List<Problem> problems2 = winfoProblems.getProblems(); |
144 if (problems2 != null) { | |
145 for (final Problem problem : problems2) { | |
146 problems.addProblem(problem); | |
147 } | |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
148 } |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
149 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
150 return (WQKms[]) waterlevelData.getData(); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
151 } |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
152 |
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 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
|
154 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
|
155 |
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
|
156 // 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
|
157 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
|
158 // 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
|
159 final boolean showAllGauges = false; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
160 |
9528
55c187a0a31e
Fixed: consistent gauge assignment with downstream gauge as reference gauge for calc range starting at a gauge range limit
mschaefer
parents:
9510
diff
changeset
|
161 final RiverInfoProvider riverInfoProvider = riverInfo.forReferenceRange(calcRange, showAllGauges); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
162 |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9131
diff
changeset
|
163 final String waterlevelLabel = descBuilder.getDesc(wkms); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
164 |
9362
392745cccede
Fixed: waterlevels from database should not get the "Bezugspegel" column in the result output.
gernotbelger
parents:
9335
diff
changeset
|
165 final WstInfo wstInfo = new WstInfo(waterlevelLabel, wspYear, riverInfoProvider.getReferenceGauge(), true); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
166 |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
167 /* build tkh calculators per bedheight */ |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9131
diff
changeset
|
168 final Map<NumberRange, TkhCalculator> calculatorsByRanges = buildCalculators(calcRange, wkms, bedHeights, problems, riverInfoProvider, waterlevelLabel); |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
169 if (calculatorsByRanges.isEmpty()) { |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
170 /* 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
|
171 return null; |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
172 } |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
173 |
8996 | 174 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
|
175 |
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
|
176 for (final Double stationDbl : allStations) { |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
177 |
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
|
178 final double station = stationDbl; |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
179 |
9573 | 180 /* find the right calculator (i.e. bed level) 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
|
181 final TkhCalculator tkhCalculator = findCalculator(calculatorsByRanges, station); |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
182 if (tkhCalculator == null) |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
183 continue; |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
184 |
8996 | 185 final ResultRow row = ResultRow.create(); |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
186 |
9318
7b2b086e45f0
collision pdf details, ResultType refactoring, bezugswst result
gernotbelger
parents:
9312
diff
changeset
|
187 row.putValue(GeneralResultType.waterlevelLabel, waterlevelLabel); |
7b2b086e45f0
collision pdf details, ResultType refactoring, bezugswst result
gernotbelger
parents:
9312
diff
changeset
|
188 row.putValue(GeneralResultType.gaugeLabel, riverInfoProvider.findGauge(station)); |
9312 | 189 row.putValue(GeneralResultType.location, riverInfoProvider.getLocation(station)); |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
190 |
9335
7dc238bd062c
Fixed: calculation of flow depth and tkh with rounding to cm, calculator return differentiated
mschaefer
parents:
9318
diff
changeset
|
191 final TkhCalculateState calcState = tkhCalculator.calculateTkh(station, row); |
7dc238bd062c
Fixed: calculation of flow depth and tkh with rounding to cm, calculator return differentiated
mschaefer
parents:
9318
diff
changeset
|
192 if (calcState == TkhCalculateState.SUCCESS) |
8978
b5600453bb8f
SINFO Calculations: do not produce result rows if some input data has missing values.
gernotbelger
parents:
8964
diff
changeset
|
193 rows.add(row); |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
194 } |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
195 |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9131
diff
changeset
|
196 return new TkhCalculationResult(waterlevelLabel, wstInfo, true, rows); |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
197 } |
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 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
|
200 |
9573 | 201 // REMAKR: linear search at this point, put we expect the number of bed levels to be very small (1-2 items) |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
202 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
|
203 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
|
204 final NumberRange range = entry.getKey(); |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
205 // 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
|
206 if (range.containsDouble(station)) |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
207 return entry.getValue(); |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
208 } |
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 return null; |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
211 } |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
212 |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
213 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
|
214 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
|
215 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
|
216 for (final BedHeightsFinder bedHeightsProvider : bedHeights) { |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
217 |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
218 final BedHeightInfo info = bedHeightsProvider.getInfo(); |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
219 |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
220 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
|
221 |
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
|
222 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
|
223 final DischargeValuesFinder dischargeProvider = DischargeValuesFinder.fromKms(wkms); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
224 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
225 /* 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
|
226 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
|
227 waterlevelProvider, dischargeProvider, bedHeightsProvider); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
228 |
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
|
229 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
|
230 /* 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
|
231 calculatorByRanges.put(range, tkhCalculator); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
232 } |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
233 } |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
234 |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
235 return calculatorByRanges; |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
236 } |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
237 } |