Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/TkhCalculation.java @ 9510:9ea704de63ee
Error message added if no bed height found for a calc range
author | mschaefer |
---|---|
date | Mon, 01 Oct 2018 09:56:14 +0200 |
parents | 853f2dafc16e |
children | 55c187a0a31e |
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; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
43 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
|
44 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
|
45 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
|
46 import org.dive4elements.river.model.River; |
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 /** |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
49 * @author Gernot Belger |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
50 */ |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
51 final class TkhCalculation { |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
52 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
53 private final CallContext context; |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
54 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
55 public TkhCalculation(final CallContext context) { |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
56 this.context = context; |
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 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
59 public CalculationResult calculate(final SINFOArtifact sinfo) { |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
60 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
61 /* access input data */ |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
62 final TkhAccess access = new TkhAccess(sinfo); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
63 final River river = access.getRiver(); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
64 final RiverInfo riverInfo = new RiverInfo(river); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
65 final DoubleRange calcRange = access.getRange(); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
66 |
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
|
67 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
|
68 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
|
69 |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
70 final Calculation problems = new Calculation(); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
71 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
72 /* find relevant bed-heights */ |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
73 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
|
74 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
|
75 |
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 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
|
77 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
|
78 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
|
79 } |
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
|
80 |
9105
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
81 final double[] stations = extractStations(bedHeights); |
9510
9ea704de63ee
Error message added if no bed height found for a calc range
mschaefer
parents:
9499
diff
changeset
|
82 if (stations.length == 0) { |
9ea704de63ee
Error message added if no bed height found for a calc range
mschaefer
parents:
9499
diff
changeset
|
83 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
|
84 problems.addProblem("sinfo.bedheightsfinder.empty"); |
9ea704de63ee
Error message added if no bed height found for a calc range
mschaefer
parents:
9499
diff
changeset
|
85 return new CalculationResult(results, problems); |
9ea704de63ee
Error message added if no bed height found for a calc range
mschaefer
parents:
9499
diff
changeset
|
86 } |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
87 |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8916
diff
changeset
|
88 /* 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
|
89 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
|
90 |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
91 /* calculate waterlevels */ |
9105
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
92 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
|
93 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
94 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
|
95 |
8938
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8916
diff
changeset
|
96 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
|
97 final String descriptionHeader = descBuilder.getColumnHeader(); |
9c02733a1b3c
Work on Sinfo-tkh - exports; using same logic for wst-description as winfo
gernotbelger
parents:
8916
diff
changeset
|
98 |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
99 /* 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
|
100 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
|
101 |
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
|
102 /* 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
|
103 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
|
104 |
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
|
105 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
|
106 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
|
107 results.addResult(result, problems); |
8915
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 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
110 return new CalculationResult(results, problems); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
111 } |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
112 |
9105
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
113 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
|
114 |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
115 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
|
116 |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
117 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
|
118 allStations.addAll(bedHeight.getStations()); |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
119 |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
120 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
|
121 } |
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
122 |
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
|
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 * 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
|
125 */ |
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 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
|
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 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
|
129 |
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 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
|
131 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
|
132 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
|
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 |
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 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
|
136 } |
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8954
diff
changeset
|
137 |
9105
ae3565385e6a
Some finetuning an Tkh calculation, preparation for wsp calculation with bed height stations only
gernotbelger
parents:
9094
diff
changeset
|
138 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
|
139 |
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
|
140 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
|
141 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
142 /* copy all problems */ |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
143 final Calculation winfoProblems = waterlevelData.getReport(); |
8916 | 144 final List<Problem> problems2 = winfoProblems.getProblems(); |
145 if (problems2 != null) { | |
146 for (final Problem problem : problems2) { | |
147 problems.addProblem(problem); | |
148 } | |
8915
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 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
151 return (WQKms[]) waterlevelData.getData(); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
152 } |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
153 |
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
|
154 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
|
155 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
|
156 |
8964
45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents:
8954
diff
changeset
|
157 // 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
|
158 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
|
159 // 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
|
160 final boolean showAllGauges = false; |
9362
392745cccede
Fixed: waterlevels from database should not get the "Bezugspegel" column in the result output.
gernotbelger
parents:
9335
diff
changeset
|
161 final WaterlevelData waterlevel = new WaterlevelData(wkms, wspYear, showAllGauges, true); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
162 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
163 final RiverInfoProvider riverInfoProvider = riverInfo.forWaterlevel(waterlevel); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
164 |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9131
diff
changeset
|
165 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
|
166 |
9362
392745cccede
Fixed: waterlevels from database should not get the "Bezugspegel" column in the result output.
gernotbelger
parents:
9335
diff
changeset
|
167 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
|
168 |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
169 /* build tkh calculators per bedheight */ |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9131
diff
changeset
|
170 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
|
171 if (calculatorsByRanges.isEmpty()) { |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
172 /* 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
|
173 return null; |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
174 } |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
175 |
8996 | 176 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
|
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 for (final Double stationDbl : allStations) { |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
179 |
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
|
180 final double station = stationDbl; |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
181 |
8954
183f42641ab6
Fixed: flowd depth calculation without transport bodies heights did not work any more
gernotbelger
parents:
8948
diff
changeset
|
182 /* 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
|
183 final TkhCalculator tkhCalculator = findCalculator(calculatorsByRanges, station); |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
184 if (tkhCalculator == null) |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
185 continue; |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
186 |
8996 | 187 final ResultRow row = ResultRow.create(); |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
188 |
9318
7b2b086e45f0
collision pdf details, ResultType refactoring, bezugswst result
gernotbelger
parents:
9312
diff
changeset
|
189 row.putValue(GeneralResultType.waterlevelLabel, waterlevelLabel); |
7b2b086e45f0
collision pdf details, ResultType refactoring, bezugswst result
gernotbelger
parents:
9312
diff
changeset
|
190 row.putValue(GeneralResultType.gaugeLabel, riverInfoProvider.findGauge(station)); |
9312 | 191 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
|
192 |
9335
7dc238bd062c
Fixed: calculation of flow depth and tkh with rounding to cm, calculator return differentiated
mschaefer
parents:
9318
diff
changeset
|
193 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
|
194 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
|
195 rows.add(row); |
8942
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 |
9205
3dae6b78e1da
inundationDuration/floodDuration multiple columns+chartLines refactoring
gernotbelger
parents:
9131
diff
changeset
|
198 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
|
199 } |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
200 |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
201 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
|
202 |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
203 // 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
|
204 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
|
205 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
|
206 final NumberRange range = entry.getKey(); |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
207 // 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
|
208 if (range.containsDouble(station)) |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
209 return entry.getValue(); |
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 |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
212 return null; |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
213 } |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
214 |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
215 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
|
216 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
|
217 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
|
218 for (final BedHeightsFinder bedHeightsProvider : bedHeights) { |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
219 |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
220 final BedHeightInfo info = bedHeightsProvider.getInfo(); |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
221 |
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
222 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
|
223 |
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 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
|
225 final DischargeValuesFinder dischargeProvider = DischargeValuesFinder.fromKms(wkms); |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
226 |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
227 /* 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
|
228 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
|
229 waterlevelProvider, dischargeProvider, bedHeightsProvider); |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
230 |
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
|
231 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
|
232 /* 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
|
233 calculatorByRanges.put(range, tkhCalculator); |
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 } |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
236 |
8942
11bf13cf0463
Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents:
8938
diff
changeset
|
237 return calculatorByRanges; |
8915
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
238 } |
d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff
changeset
|
239 } |