comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsFinder.java @ 9597:5395c6d4ca50

Softwaretests...20181219 7.3: no interpolation of missing bed heights for Uinfo/Salix historical scenario and B&U/Bzws
author mschaefer
date Tue, 05 Feb 2019 15:47:58 +0100
parents b9c87bbff6a4
children
comparison
equal deleted inserted replaced
9596:fbfd66e8fb81 9597:5395c6d4ca50
42 42
43 private Calculation problems; 43 private Calculation problems;
44 44
45 private final boolean isNull; 45 private final boolean isNull;
46 46
47 private final boolean doInterpolate;
48
47 /** 49 /**
48 * Create bed level finders from a collection of bed levels. 50 * Create bed level finders from a collection of bed levels.
49 */ 51 */
50 public static Collection<BedHeightsFinder> createTkhBedHeights(final Calculation problems, final DoubleRange range, 52 public static Collection<BedHeightsFinder> createTkhBedHeights(final Calculation problems, final DoubleRange range,
51 final Collection<BedHeight> bedHeights) { 53 final Collection<BedHeight> bedHeights) {
52 final List<BedHeightsFinder> result = new ArrayList<>(bedHeights.size()); 54 final List<BedHeightsFinder> result = new ArrayList<>(bedHeights.size());
53 55
54 for (final BedHeight bedHeight : bedHeights) { 56 for (final BedHeight bedHeight : bedHeights) {
55 final BedHeightsFinder finder = createBedHeights(problems, bedHeight, range); 57 final BedHeightsFinder finder = createBedHeights(problems, bedHeight, range, true);
58 result.add(finder);
59 }
60
61 return result;
62 }
63
64 /**
65 * Create not-interpolated bed level finders from a collection of bed levels.
66 */
67 public static Collection<BedHeightsFinder> createScenarioBedHeights(final Calculation problems, final DoubleRange range,
68 final Collection<BedHeight> bedHeights) {
69 final List<BedHeightsFinder> result = new ArrayList<>(bedHeights.size());
70
71 for (final BedHeight bedHeight : bedHeights) {
72 final BedHeightsFinder finder = createBedHeights(problems, bedHeight, range, false);
56 result.add(finder); 73 result.add(finder);
57 } 74 }
58 75
59 return result; 76 return result;
60 } 77 }
108 125
109 final BedHeight bedHeight = BedHeight.getBedHeightById(id); 126 final BedHeight bedHeight = BedHeight.getBedHeightById(id);
110 if (bedHeight == null) 127 if (bedHeight == null)
111 return null; 128 return null;
112 129
113 return BedHeightsFinder.createBedHeights(problems, bedHeight, range); 130 return BedHeightsFinder.createBedHeights(problems, bedHeight, range, true);
131 }
132
133 /**
134 * Creates a interpolated or not-interpolated {@link BedHeightsFinder} for a dataset from the database, specified by its
135 * id.
136 *
137 * @return <code>null</code> if no bed level with the given id exists.
138 */
139 public static BedHeightsFinder forId(final Calculation problems, final int id, final DoubleRange range, final boolean doInterpolate) {
140
141 final BedHeight bedHeight = BedHeight.getBedHeightById(id);
142 if (bedHeight == null)
143 return null;
144
145 return BedHeightsFinder.createBedHeights(problems, bedHeight, range, doInterpolate);
114 } 146 }
115 147
116 /** 148 /**
117 * Creates a {@link BedHeightsFinder} that returns always NaN heights 149 * Creates a {@link BedHeightsFinder} that returns always NaN heights
118 */ 150 */
119 public static BedHeightsFinder NullFinder() { 151 public static BedHeightsFinder NullFinder() {
120 final NavigableMap<Double, BedHeightValue> values = new TreeMap<>(); 152 final NavigableMap<Double, BedHeightValue> values = new TreeMap<>();
121 return new BedHeightsFinder(null, null, values, true); 153 return new BedHeightsFinder(null, null, values, true, false);
122 } 154 }
123 155
124 /** 156 /**
125 * Create a finder for a given bed level. 157 * Create a finder for a given bed level.
126 * 158 *
127 */ 159 */
128 private static BedHeightsFinder createBedHeights(final Calculation problems, final BedHeight bedHeight, final DoubleRange range) { 160 private static BedHeightsFinder createBedHeights(final Calculation problems, final BedHeight bedHeight, final DoubleRange range,
161 final boolean doInterpolate) {
129 162
130 // FIXME: sort by station, but in what direction? 163 // FIXME: sort by station, but in what direction?
131 // FIXME: using river.getKmUp()? 164 // FIXME: using river.getKmUp()?
132 final NavigableMap<Double, BedHeightValue> values = new TreeMap<>(); 165 final NavigableMap<Double, BedHeightValue> values = new TreeMap<>();
133 166
140 } 173 }
141 } 174 }
142 175
143 final BedHeightInfo info = BedHeightInfo.from(bedHeight); 176 final BedHeightInfo info = BedHeightInfo.from(bedHeight);
144 177
145 return new BedHeightsFinder(problems, info, values, false); 178 return new BedHeightsFinder(problems, info, values, false, doInterpolate);
146 } 179 }
147 180
148 private BedHeightsFinder(final Calculation problems, final BedHeightInfo info, final NavigableMap<Double, BedHeightValue> values, final boolean isNull) { 181 private BedHeightsFinder(final Calculation problems, final BedHeightInfo info, final NavigableMap<Double, BedHeightValue> values, final boolean isNull,
182 final boolean doInterpolate) {
149 this.info = info; 183 this.info = info;
150 this.values = values; 184 this.values = values;
151 this.problems = problems; 185 this.problems = problems;
152 this.isNull = isNull; 186 this.isNull = isNull;
187 this.doInterpolate = doInterpolate;
153 } 188 }
154 189
155 /** 190 /**
156 * Whether this is a null (always NaN) finder. 191 * Whether this is a null (always NaN) finder.
157 * 192 *
205 final Entry<Double, BedHeightValue> ceilingEntry = this.values.ceilingEntry(km); 240 final Entry<Double, BedHeightValue> ceilingEntry = this.values.ceilingEntry(km);
206 241
207 if (floorEntry == null || ceilingEntry == null) 242 if (floorEntry == null || ceilingEntry == null)
208 return Double.NaN; 243 return Double.NaN;
209 244
245 // return NaN if value not found and no-interpolation mode, and report once
246 if (!this.doInterpolate && (floorEntry != ceilingEntry)) {
247 if (this.problems != null) {
248 this.problems.addProblem(km, "sinfo.bedheightsfinder.missing_bedheights");
249 this.problems = null;
250 }
251 return Double.NaN;
252 }
253
210 final double floorKm = floorEntry.getKey().doubleValue(); 254 final double floorKm = floorEntry.getKey().doubleValue();
211 final double ceilKm = ceilingEntry.getKey().doubleValue(); 255 final double ceilKm = ceilingEntry.getKey().doubleValue();
212
213 /* report once if the interpolation distance exceeds 1000m */ 256 /* report once if the interpolation distance exceeds 1000m */
214 if (Math.abs(floorKm - ceilKm) > MAX_DISTANCE_KM && this.problems != null) { 257 if (Math.abs(floorKm - ceilKm) > MAX_DISTANCE_KM) {
215 this.problems.addProblem(km, "linearInterpolator.maxdistance", MAX_DISTANCE_KM * 1000); 258 if (this.problems != null) {
216 this.problems = null; 259 this.problems.addProblem(km, "linearInterpolator.maxdistance", MAX_DISTANCE_KM * 1000);
260 this.problems = null;
261 }
217 return Double.NaN; 262 return Double.NaN;
218 } 263 }
219 264
220 final Double floorHeight = type.getValue(floorEntry.getValue()); 265 final Double floorHeight = type.getValue(floorEntry.getValue());
221 final Double ceilingHeight = type.getValue(ceilingEntry.getValue()); 266 final Double ceilingHeight = type.getValue(ceilingEntry.getValue());

http://dive4elements.wald.intevation.org