comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculation.java @ 8900:d32c22fc686c

Merge
author mschaefer
date Thu, 22 Feb 2018 14:11:19 +0100
parents 89f3c5462a16 b6f7961e4cc5
children 0a900d605d52
comparison
equal deleted inserted replaced
8899:3dd0c77a4b27 8900:d32c22fc686c
30 import org.dive4elements.river.artifacts.model.WQKms; 30 import org.dive4elements.river.artifacts.model.WQKms;
31 import org.dive4elements.river.artifacts.model.WKms; 31 import org.dive4elements.river.artifacts.model.WKms;
32 import org.dive4elements.river.artifacts.resources.Resources; 32 import org.dive4elements.river.artifacts.resources.Resources;
33 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; 33 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact;
34 import org.dive4elements.river.artifacts.sinfo.flowdepth.FlowDepthAccess.DifferencesPair; 34 import org.dive4elements.river.artifacts.sinfo.flowdepth.FlowDepthAccess.DifferencesPair;
35 import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo;
36 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
37 import org.dive4elements.river.artifacts.sinfo.util.WstInfo;
35 import org.dive4elements.river.artifacts.states.WaterlevelData; 38 import org.dive4elements.river.artifacts.states.WaterlevelData;
36 import org.dive4elements.river.artifacts.states.WaterlevelFetcher; 39 import org.dive4elements.river.artifacts.states.WaterlevelFetcher;
37 import org.dive4elements.river.model.BedHeight; 40 import org.dive4elements.river.model.BedHeight;
38 import org.dive4elements.river.model.BedHeightValue; 41 import org.dive4elements.river.model.BedHeightValue;
39 import org.dive4elements.river.model.Gauge; 42 import org.dive4elements.river.model.Gauge;
66 final String user = database.findArtifactUser(sinfo.identifier()); 69 final String user = database.findArtifactUser(sinfo.identifier());
67 70
68 /* access input data */ 71 /* access input data */
69 final FlowDepthAccess access = new FlowDepthAccess(sinfo); 72 final FlowDepthAccess access = new FlowDepthAccess(sinfo);
70 final River river = access.getRiver(); 73 final River river = access.getRiver();
74 final RiverInfo riverInfo = new RiverInfo(river);
71 75
72 final Collection<DifferencesPair> diffPairs = access.getDifferencePairs(); 76 final Collection<DifferencesPair> diffPairs = access.getDifferencePairs();
73 77
74 final double from = access.getFrom(); 78 final double from = access.getFrom();
75 final double to = access.getTo(); 79 final double to = access.getTo();
83 final List<Gauge> gauges = river.determineGauges(from, to); 87 final List<Gauge> gauges = river.determineGauges(from, to);
84 final GaugeIndex gaugeIndex = new GaugeIndex(gauges); 88 final GaugeIndex gaugeIndex = new GaugeIndex(gauges);
85 89
86 final String calcModeLabel = Resources.getMsg(this.context.getMeta(), sinfo.getCalculationMode().name()); 90 final String calcModeLabel = Resources.getMsg(this.context.getMeta(), sinfo.getCalculationMode().name());
87 91
88 final FlowDepthCalculationResults results = new FlowDepthCalculationResults(calcModeLabel, user, river, from, to, useTkh); 92 final FlowDepthCalculationResults results = new FlowDepthCalculationResults(calcModeLabel, user, riverInfo, calcRange, useTkh);
89 93
90 for (final DifferencesPair diffPair : diffPairs) { 94 for (final DifferencesPair diffPair : diffPairs) {
91 final FlowDepthCalculationResult result = calculateResult(river, calcRange, diffPair, problems, gaugeIndex, useTkh); 95 final FlowDepthCalculationResult result = calculateResult(river, calcRange, diffPair, problems, gaugeIndex, useTkh);
92 if (result != null) 96 if (result != null)
93 results.addResult(result); 97 results.addResult(result);
104 108
105 /* access real input data from database */ 109 /* access real input data from database */
106 final String soundingId = diffPair.getSoundingId(); 110 final String soundingId = diffPair.getSoundingId();
107 final String wstId = diffPair.getWstId(); 111 final String wstId = diffPair.getWstId();
108 112
113 final BedHeight bedHeight = loadBedHeight(soundingId);
109 final BedHeight bedHeight = loadBedHeight(soundingId); 114 final BedHeight bedHeight = loadBedHeight(soundingId);
110 if (bedHeight == null) { 115 if (bedHeight == null) {
111 final String message = Resources.format(this.context.getMeta(), "Failed to access sounding with id '{0}'", soundingId); 116 final String message = Resources.format(this.context.getMeta(), "Failed to access sounding with id '{0}'", soundingId);
112 problems.addProblem(message); 117 problems.addProblem(message);
113 return null; 118 return null;
125 final String wspLabel = wstKms.getName(); 130 final String wspLabel = wstKms.getName();
126 final String soundingLabel = bedHeight.getDescription(); 131 final String soundingLabel = bedHeight.getDescription();
127 final String label = String.format("%s - %s", wspLabel, soundingLabel); 132 final String label = String.format("%s - %s", wspLabel, soundingLabel);
128 133
129 checkYearDifference(label, waterlevel, bedHeight, problems); 134 checkYearDifference(label, waterlevel, bedHeight, problems);
130 checkWaterlevelDiscretisation(wstKms, problems); 135 checkWaterlevelDiscretisation(wstKms, calcRange, problems);
136 // TODO: prüfen, ob sohlhöen die calcRange abdecken/überschneiden
131 137
132 /* re-determine the reference gauge, in the same way as the WaterlevelArtifact would do it */ 138 /* re-determine the reference gauge, in the same way as the WaterlevelArtifact would do it */
133 final String notinrange = Resources.getMsg(this.context.getMeta(), CSV_NOT_IN_GAUGE_RANGE, CSV_NOT_IN_GAUGE_RANGE); 139 final String notinrange = Resources.getMsg(this.context.getMeta(), CSV_NOT_IN_GAUGE_RANGE, CSV_NOT_IN_GAUGE_RANGE);
134 140
135 final Gauge refGauge = waterlevel.findReferenceGauge(river); 141 final Gauge refGauge = waterlevel.findReferenceGauge(river);
200 final double km = station; 206 final double km = station;
201 final double meanBedHeight = meanBedHeightDbl; 207 final double meanBedHeight = meanBedHeightDbl;
202 208
203 if (!calcRange.containsDouble(km)) 209 if (!calcRange.containsDouble(km))
204 continue; 210 continue;
205 211 if (!calcRange.containsDouble(km))
212 continue;
213
206 try { 214 try {
207 // FIXME: check out of range 215 // FIXME: check out of range
208 final double wst = wstInterpolator.value(km); 216 final double wst = wstInterpolator.value(km);
209 217
210 final double flowDepth = wst - meanBedHeight; 218 final double flowDepth = wst - meanBedHeight;
285 tkhUp = tkh / 2; 293 tkhUp = tkh / 2;
286 tkhDown = -tkh / 2; 294 tkhDown = -tkh / 2;
287 break; 295 break;
288 } 296 }
289 297
290
291 // REMARK: access the location once only during calculation 298 // REMARK: access the location once only during calculation
292 final String location = LocationProvider.getLocation(river.getName(), km); 299 final String location = LocationProvider.getLocation(river.getName(), km);
293 300
294 // REMARK: access the gauge once only during calculation 301 // REMARK: access the gauge once only during calculation
295 final Gauge gauge = findGauge(waterlevel, refGauge, gaugeIndex, km); 302 final Gauge gauge = findGauge(waterlevel, refGauge, gaugeIndex, km);
354 361
355 final int maxDifference = getMaxDifferenceYears(soundingYear); 362 final int maxDifference = getMaxDifferenceYears(soundingYear);
356 363
357 final int difference = Math.abs(soundingYear - wstYear); 364 final int difference = Math.abs(soundingYear - wstYear);
358 if (difference > maxDifference) { 365 if (difference > maxDifference) {
359 final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.year_difference", null, label, difference); 366 final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.year_difference", null, label, wstYear,
367 soundingYear);
360 problems.addProblem(message); 368 problems.addProblem(message);
361 } 369 }
362 } 370 }
363 371
364 private int getMaxDifferenceYears(final int year) { 372 private int getMaxDifferenceYears(final int year) {
390 398
391 return null; 399 return null;
392 } 400 }
393 401
394 /* Checks if the discretisation of the waterlevel exceeds 1000m */ 402 /* Checks if the discretisation of the waterlevel exceeds 1000m */
395 // FIXME: vermutlich sollten wir diesen check auf den gültigkeitsbereich einschränken 403
396 private void checkWaterlevelDiscretisation(final WKms wstKms, final Calculation problems) { 404 private void checkWaterlevelDiscretisation(final WKms wstKms, final DoubleRange calcRange, final Calculation problems) {
405
397 final int size = wstKms.size(); 406 final int size = wstKms.size();
398 for (int i = 0; i < size - 2; i++) { 407 for (int i = 0; i < size - 2; i++) {
399 final double kmPrev = wstKms.getKm(i); 408 final double kmPrev = wstKms.getKm(i);
400 final double kmNext = wstKms.getKm(i + 1); 409 final double kmNext = wstKms.getKm(i + 1);
401 410
402 if (Math.abs(kmPrev - kmNext) > 1) { 411 /* only check if we are within the calculation range */
403 final String label = wstKms.getName(); 412 if (calcRange.overlapsRange(new DoubleRange(kmPrev, kmNext))) {
404 413 if (Math.abs(kmPrev - kmNext) > 1) {
405 final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.waterlevel_discretisation", null, label); 414 final String label = wstKms.getName();
406 problems.addProblem(kmPrev, message); 415
416 final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.waterlevel_discretisation", null, label);
417 problems.addProblem(kmPrev, message);
418 }
407 } 419 }
408 } 420 }
409 } 421 }
410 422
411 private BedHeight loadBedHeight(final String soundingId) { 423 private BedHeight loadBedHeight(final String soundingId) {

http://dive4elements.wald.intevation.org