annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsFinder.java @ 9394:439699ff9b2d

Added U-Info iota (prev. salix) calculation for historical scenario
author mschaefer
date Fri, 10 Aug 2018 17:31:46 +0200
parents 45f1ad66560e
children ecadc9ed0ba0
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 /**
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
31 * Provides bed heights 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
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
45 /**
8942
11bf13cf0463 Minor changes to tkh calculation. Loading default bed heights form config file.
gernotbelger
parents: 8915
diff changeset
46 * Create bed height finders from a collection of bed heights.
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
47 */
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
48 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
49 final Collection<BedHeight> bedHeights) {
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
50 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
51
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
52 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
53 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
54 result.add(finder);
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
55 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
56
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
57 return result;
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
8946
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
60 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
61
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
62 // REMARK: absolutely unbelievable....
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
63 // 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
64 // throughout flys.
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
65 // 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
66
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
67 // 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
68 // this is plain random
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
69 final String[] parts = soundingId.split(";");
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
70
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
71 final BedHeightsArtifact artifact = (BedHeightsArtifact) RiverUtils.getArtifact(parts[0], context);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
72
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
73 final Integer bedheightId = artifact.getDataAsInteger("height_id");
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
74
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
75 // 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
76 // other type means)
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
77 // Luckily, the requirement is to only access 'single' data here.
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
78 // final String bedheightType = artifact.getDataAsString("type");
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
79
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
80 // REMARK: BedDifferences uses this, but we also need the metadata of the BedHeight
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
81 // 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
82 // hibernate stuff
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
83 // 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
84 // return BedHeightFactory.getHeight(bedheightType, bedheightId, from, to);
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
85
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
86 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
87 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
88 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
89 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
90 }
8946
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
91
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
92 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
93 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
94 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
95 }
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
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 return bedHeight;
8946
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
98 }
5d5d482da3e9 Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents: 8942
diff changeset
99
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
100 /**
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
101 * 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
102 *
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
103 * @return <code>null</code> if no bed height with the given id exists.
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
104 */
9394
439699ff9b2d Added U-Info iota (prev. salix) calculation for historical scenario
mschaefer
parents: 8964
diff changeset
105 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
106
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
107 final BedHeight bedHeight = BedHeight.getBedHeightById(id);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
108 if (bedHeight == null)
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
109 return null;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
110
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
111 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
112 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
113
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 * Create a finder for a given bed height.
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
116 *
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
117 */
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
118 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
119
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
120 // 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
121 // FIXME: using river.getKmUp()?
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
122 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
123
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
124 for (final BedHeightValue bedHeightValue : bedHeight.getValues()) {
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
125 final Double station = bedHeightValue.getStation();
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
126 if (station != null && range.containsDouble(station)) {
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
127
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
128 if (bedHeightValue.getHeight() != null)
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
129 values.put(station, bedHeightValue);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
130 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
131 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
132
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
133 final BedHeightInfo info = BedHeightInfo.from(bedHeight);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
134
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
135 return new BedHeightsFinder(problems, info, values);
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
136 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
137
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
138 private BedHeightsFinder(final Calculation problems, final BedHeightInfo info, final NavigableMap<Double, BedHeightValue> values) {
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
139 this.info = info;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
140 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
141 this.problems = problems;
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
142 }
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
143
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
144 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
145 return this.values.isEmpty();
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
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
148 public BedHeightInfo getInfo() {
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
149 return this.info;
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
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
152 public Collection<Double> getStations() {
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
153 return this.values.keySet();
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
154 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
155
9394
439699ff9b2d Added U-Info iota (prev. salix) calculation for historical scenario
mschaefer
parents: 8964
diff changeset
156 public DoubleRange getKmRange() {
439699ff9b2d Added U-Info iota (prev. salix) calculation for historical scenario
mschaefer
parents: 8964
diff changeset
157 if (this.values.isEmpty())
439699ff9b2d Added U-Info iota (prev. salix) calculation for historical scenario
mschaefer
parents: 8964
diff changeset
158 return null;
439699ff9b2d Added U-Info iota (prev. salix) calculation for historical scenario
mschaefer
parents: 8964
diff changeset
159 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
160 }
439699ff9b2d Added U-Info iota (prev. salix) calculation for historical scenario
mschaefer
parents: 8964
diff changeset
161
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
162 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
163 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
164 }
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
165
8955
798d9dcbccdd BedHeightValue (bed_height_values) extended by two columns for minimum and maximum bed height
mschaefer
parents: 8946
diff changeset
166 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
167 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
168 }
798d9dcbccdd BedHeightValue (bed_height_values) extended by two columns for minimum and maximum bed height
mschaefer
parents: 8946
diff changeset
169
798d9dcbccdd BedHeightValue (bed_height_values) extended by two columns for minimum and maximum bed height
mschaefer
parents: 8946
diff changeset
170 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
171 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
172 }
798d9dcbccdd BedHeightValue (bed_height_values) extended by two columns for minimum and maximum bed height
mschaefer
parents: 8946
diff changeset
173
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
174 private double interpolateBedHeights(final double km, final BedHeightValueType type) {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
175 if (this.values.containsKey(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
176 {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
177 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
178 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
179 }
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
180
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
181 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
182 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
183
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
184 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
185 return Double.NaN;
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
186
8955
798d9dcbccdd BedHeightValue (bed_height_values) extended by two columns for minimum and maximum bed height
mschaefer
parents: 8946
diff changeset
187 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
188 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
189
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
190 /* 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
191 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
192 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
193 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
194 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
195 }
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
196
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
197 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
198 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
199
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 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
201 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
202
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8955
diff changeset
203 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
204 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents:
diff changeset
205 }

http://dive4elements.wald.intevation.org