annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsFinder.java @ 9573:b9c87bbff6a4

mean bed height -> mean bed LEVEL
author gernotbelger
date Tue, 06 Nov 2018 10:56:22 +0100
parents 7228bd10a8cc
children 5395c6d4ca50
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;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
14 import java.util.List;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
15 import java.util.Map.Entry;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
16 import java.util.NavigableMap;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
17 import java.util.TreeMap;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
18
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
19 import org.apache.commons.lang.math.DoubleRange;
8946
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
20 import org.dive4elements.artifacts.CallContext;
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
21 import org.dive4elements.river.artifacts.BedHeightsArtifact;
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
22 import org.dive4elements.river.artifacts.math.Linear;
8946
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
23 import org.dive4elements.river.artifacts.model.Calculation;
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
24 import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
25 import org.dive4elements.river.model.BedHeight;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
26 import org.dive4elements.river.model.BedHeightValue;
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
27 import org.dive4elements.river.model.BedHeightValueType;
8946
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
28 import org.dive4elements.river.utils.RiverUtils;
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
29
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
30 /**
9573
b9c87bbff6a4 mean bed height -> mean bed LEVEL
gernotbelger
parents: 9480
diff changeset
31 * Provides bed levels for various calculations.
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
32 *
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
33 * @author Gernot Belger
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
34 */
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
35 public final class BedHeightsFinder {
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
36
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
37 private static double MAX_DISTANCE_KM = 1;
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
38
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
39 private final BedHeightInfo info;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
40
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
41 private final NavigableMap<Double, BedHeightValue> values;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
42
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
43 private Calculation problems;
8955
798d9dcbccdd BedHeightValue (bed_height_values) extended by two columns for minimum and maximum bed height
mschaefer
parents: 8946
diff changeset
44
9480
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
45 private final boolean isNull;
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
46
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
47 /**
9573
b9c87bbff6a4 mean bed height -> mean bed LEVEL
gernotbelger
parents: 9480
diff changeset
48 * Create bed level finders from a collection of bed levels.
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
49 */
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
50 public static Collection<BedHeightsFinder> createTkhBedHeights(final Calculation problems, final DoubleRange range,
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
51 final Collection<BedHeight> bedHeights) {
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
52 final List<BedHeightsFinder> result = new ArrayList<>(bedHeights.size());
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 for (final BedHeight bedHeight : bedHeights) {
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
55 final BedHeightsFinder finder = createBedHeights(problems, bedHeight, range);
8942
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8915
diff changeset
56 result.add(finder);
8915
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 return result;
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
8946
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
62 public static BedHeightsFinder forId(final CallContext context, final String soundingId, final DoubleRange calcRange, final Calculation problems) {
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
63
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
64 // REMARK: absolutely unbelievable....
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
65 // The way how bed-heights (and other data too) is accessed is different for nearly every calculation-type
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
66 // throughout flys.
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
67 // The knowledge on how to parse the datacage-ids is spread through the complete code-base...
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
68
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
69 // We use here the way on how bed-heights are accessed by the BedDifferenceAccess/BedDifferenceCalculation, but
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
70 // this is plain random
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
71 final String[] parts = soundingId.split(";");
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
72
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
73 final BedHeightsArtifact artifact = (BedHeightsArtifact) RiverUtils.getArtifact(parts[0], context);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
74
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
75 final Integer bedheightId = artifact.getDataAsInteger("height_id");
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
76
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
77 // REMARK: this only works with type 'single'; unclear on how to distinguish from epoch data (or whatever the
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
78 // other type means)
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
79 // Luckily, the requirement is to only access 'single' data here.
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
80 // final String bedheightType = artifact.getDataAsString("type");
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
81
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
82 // REMARK: BedDifferences uses this, but we also need the metadata of the BedHeight
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
83 // REMARK: second absolutely awful thing: BedHeight is a hibernate binding class, accessing the database via
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
84 // hibernate stuff
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
85 // BedHeightFactory uses its own (direct) way of accessing the data, with its own implemented data classes.
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
86 // return BedHeightFactory.getHeight(bedheightType, bedheightId, from, to);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
87
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
88 final BedHeightsFinder bedHeight = bedheightId == null ? null : BedHeightsFinder.forId(problems, bedheightId, calcRange);
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
89 if (bedHeight == null) {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
90 problems.addProblem("sinfo.bedheightsfinder.notfound", soundingId);
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
91 return null;
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
92 }
8946
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
93
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
94 if (bedHeight.isEmpty()) {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
95 problems.addProblem("sinfo.bedheightsfinder.empty");
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
96 return null;
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
97 }
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
98
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
99 return bedHeight;
8946
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
100 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
101
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
102 /**
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
103 * Creates a {@link BedHeightsFinder} for a dataset from the database, specified by its id.
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
104 *
9573
b9c87bbff6a4 mean bed height -> mean bed LEVEL
gernotbelger
parents: 9480
diff changeset
105 * @return <code>null</code> if no bed level with the given id exists.
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
106 */
9394
439699ff9b2d Added U-Info iota (prev. salix) calculation for historical scenario
mschaefer
parents: 8964
diff changeset
107 public static BedHeightsFinder forId(final Calculation problems, final int id, final DoubleRange range) {
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 final BedHeight bedHeight = BedHeight.getBedHeightById(id);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
110 if (bedHeight == null)
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
111 return null;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
112
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
113 return BedHeightsFinder.createBedHeights(problems, bedHeight, range);
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
114 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
115
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
116 /**
9480
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
117 * Creates a {@link BedHeightsFinder} that returns always NaN heights
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
118 */
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
119 public static BedHeightsFinder NullFinder() {
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
120 final NavigableMap<Double, BedHeightValue> values = new TreeMap<>();
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
121 return new BedHeightsFinder(null, null, values, true);
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
122 }
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
123
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
124 /**
9573
b9c87bbff6a4 mean bed height -> mean bed LEVEL
gernotbelger
parents: 9480
diff changeset
125 * Create a finder for a given bed level.
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
126 *
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
127 */
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
128 private static BedHeightsFinder createBedHeights(final Calculation problems, final BedHeight bedHeight, final DoubleRange range) {
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
129
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
130 // FIXME: sort by station, but in what direction?
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
131 // FIXME: using river.getKmUp()?
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
132 final NavigableMap<Double, BedHeightValue> values = new TreeMap<>();
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
133
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
134 for (final BedHeightValue bedHeightValue : bedHeight.getValues()) {
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
135 final Double station = bedHeightValue.getStation();
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
136 if (station != null && range.containsDouble(station)) {
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
137
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
138 if (bedHeightValue.getHeight() != null)
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
139 values.put(station, bedHeightValue);
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 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
142
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
143 final BedHeightInfo info = BedHeightInfo.from(bedHeight);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
144
9480
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
145 return new BedHeightsFinder(problems, info, values, false);
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
146 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
147
9480
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
148 private BedHeightsFinder(final Calculation problems, final BedHeightInfo info, final NavigableMap<Double, BedHeightValue> values, final boolean isNull) {
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
149 this.info = info;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
150 this.values = values;
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
151 this.problems = problems;
9480
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
152 this.isNull = isNull;
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
153 }
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
154
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
155 /**
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
156 * Whether this is a null (always NaN) finder.
9573
b9c87bbff6a4 mean bed height -> mean bed LEVEL
gernotbelger
parents: 9480
diff changeset
157 *
9480
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
158 * @return
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
159 */
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
160 public boolean isNull() {
7228bd10a8cc Fixed bundu bzws bedheightfinder todos, added types for excavation volume and costs total
mschaefer
parents: 9444
diff changeset
161 return this.isNull;
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
162 }
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
163
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
164 public boolean isEmpty() {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
165 return this.values.isEmpty();
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
166 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
167
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
168 public BedHeightInfo getInfo() {
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
169 return this.info;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
170 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
171
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
172 public Collection<Double> getStations() {
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
173 return this.values.keySet();
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
174 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
175
9394
439699ff9b2d Added U-Info iota (prev. salix) calculation for historical scenario
mschaefer
parents: 8964
diff changeset
176 public DoubleRange getKmRange() {
439699ff9b2d Added U-Info iota (prev. salix) calculation for historical scenario
mschaefer
parents: 8964
diff changeset
177 if (this.values.isEmpty())
439699ff9b2d Added U-Info iota (prev. salix) calculation for historical scenario
mschaefer
parents: 8964
diff changeset
178 return null;
439699ff9b2d Added U-Info iota (prev. salix) calculation for historical scenario
mschaefer
parents: 8964
diff changeset
179 return new DoubleRange(this.values.firstKey().doubleValue(), this.values.lastKey().doubleValue());
439699ff9b2d Added U-Info iota (prev. salix) calculation for historical scenario
mschaefer
parents: 8964
diff changeset
180 }
439699ff9b2d Added U-Info iota (prev. salix) calculation for historical scenario
mschaefer
parents: 8964
diff changeset
181
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
182 public double getMeanBedHeight(final double km) {
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
183 return interpolateBedHeights(km, BedHeightValueType.value);
8955
798d9dcbccdd BedHeightValue (bed_height_values) extended by two columns for minimum and maximum bed height
mschaefer
parents: 8946
diff changeset
184 }
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
185
8955
798d9dcbccdd BedHeightValue (bed_height_values) extended by two columns for minimum and maximum bed height
mschaefer
parents: 8946
diff changeset
186 public double getMinBedHeight(final double km) {
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
187 return interpolateBedHeights(km, BedHeightValueType.min);
8955
798d9dcbccdd BedHeightValue (bed_height_values) extended by two columns for minimum and maximum bed height
mschaefer
parents: 8946
diff changeset
188 }
798d9dcbccdd BedHeightValue (bed_height_values) extended by two columns for minimum and maximum bed height
mschaefer
parents: 8946
diff changeset
189
798d9dcbccdd BedHeightValue (bed_height_values) extended by two columns for minimum and maximum bed height
mschaefer
parents: 8946
diff changeset
190 public double getMaxBedHeight(final double km) {
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
191 return interpolateBedHeights(km, BedHeightValueType.max);
8955
798d9dcbccdd BedHeightValue (bed_height_values) extended by two columns for minimum and maximum bed height
mschaefer
parents: 8946
diff changeset
192 }
798d9dcbccdd BedHeightValue (bed_height_values) extended by two columns for minimum and maximum bed height
mschaefer
parents: 8946
diff changeset
193
9444
ecadc9ed0ba0 Added heights and depths of cross section fields in the bundu bzws calculation and longitudinal section charts
mschaefer
parents: 9394
diff changeset
194 public double getFieldHeight(final double km, final int index) {
ecadc9ed0ba0 Added heights and depths of cross section fields in the bundu bzws calculation and longitudinal section charts
mschaefer
parents: 9394
diff changeset
195 return interpolateBedHeights(km, BedHeightValueType.field(index));
ecadc9ed0ba0 Added heights and depths of cross section fields in the bundu bzws calculation and longitudinal section charts
mschaefer
parents: 9394
diff changeset
196 }
ecadc9ed0ba0 Added heights and depths of cross section fields in the bundu bzws calculation and longitudinal section charts
mschaefer
parents: 9394
diff changeset
197
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
198 private double interpolateBedHeights(final double km, final BedHeightValueType type) {
9573
b9c87bbff6a4 mean bed height -> mean bed LEVEL
gernotbelger
parents: 9480
diff changeset
199 if (this.values.containsKey(km)) {
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
200 final Double value = type.getValue(this.values.get(km));
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
201 return value == null ? Double.NaN : value.doubleValue();
8955
798d9dcbccdd BedHeightValue (bed_height_values) extended by two columns for minimum and maximum bed height
mschaefer
parents: 8946
diff changeset
202 }
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
203
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
204 final Entry<Double, BedHeightValue> floorEntry = this.values.floorEntry(km);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
205 final Entry<Double, BedHeightValue> ceilingEntry = this.values.ceilingEntry(km);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
206
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
207 if (floorEntry == null || ceilingEntry == null)
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
208 return Double.NaN;
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
209
8955
798d9dcbccdd BedHeightValue (bed_height_values) extended by two columns for minimum and maximum bed height
mschaefer
parents: 8946
diff changeset
210 final double floorKm = floorEntry.getKey().doubleValue();
798d9dcbccdd BedHeightValue (bed_height_values) extended by two columns for minimum and maximum bed height
mschaefer
parents: 8946
diff changeset
211 final double ceilKm = ceilingEntry.getKey().doubleValue();
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
212
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
213 /* report once if the interpolation distance exceeds 1000m */
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
214 if (Math.abs(floorKm - ceilKm) > MAX_DISTANCE_KM && this.problems != null) {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
215 this.problems.addProblem(km, "linearInterpolator.maxdistance", MAX_DISTANCE_KM * 1000);
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
216 this.problems = null;
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
217 return Double.NaN;
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
218 }
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
219
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
220 final Double floorHeight = type.getValue(floorEntry.getValue());
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
221 final Double ceilingHeight = type.getValue(ceilingEntry.getValue());
8955
798d9dcbccdd BedHeightValue (bed_height_values) extended by two columns for minimum and maximum bed height
mschaefer
parents: 8946
diff changeset
222
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
223 if (floorHeight == null || ceilingHeight == null)
8955
798d9dcbccdd BedHeightValue (bed_height_values) extended by two columns for minimum and maximum bed height
mschaefer
parents: 8946
diff changeset
224 return Double.NaN;
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
225
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
226 return Linear.linear(km, floorKm, ceilKm, floorHeight, ceilingHeight);
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
227 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
228 }

http://dive4elements.wald.intevation.org