Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/DischargeValuesFinder.java @ 8946:5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
author | gernotbelger |
---|---|
date | Tue, 13 Mar 2018 18:49:33 +0100 |
parents | b10f8415798c |
children | 45f1ad66560e |
comparison
equal
deleted
inserted
replaced
8945:4a6b6a3c279c | 8946:5d5d482da3e9 |
---|---|
44 return new DischargeValuesFinder(qKms); | 44 return new DischargeValuesFinder(qKms); |
45 } | 45 } |
46 | 46 |
47 public DischargeValuesFinder(final QKms qKms) { | 47 public DischargeValuesFinder(final QKms qKms) { |
48 this.qKms = qKms; | 48 this.qKms = qKms; |
49 this.qInterpolator = qKms == null ? null : DoubleUtil.getLinearInterpolator(qKms.allKms(), qKms.allQs()); | |
50 | 49 |
51 this.exactValues = new TDoubleDoubleHashMap(qKms.size()); | 50 if (qKms == null) { |
51 this.qInterpolator = null; | |
52 this.exactValues = null; | |
53 } else { | |
54 this.qInterpolator = DoubleUtil.getLinearInterpolator(qKms.allKms(), qKms.allQs()); | |
52 | 55 |
53 for (int i = 0; i < qKms.size(); i++) { | 56 this.exactValues = new TDoubleDoubleHashMap(qKms.size()); |
54 final double station = qKms.getKm(i); | 57 |
55 final double discharge = qKms.getQ(i); | 58 for (int i = 0; i < qKms.size(); i++) { |
56 this.exactValues.put(station, discharge); | 59 final double station = qKms.getKm(i); |
60 final double discharge = qKms.getQ(i); | |
61 this.exactValues.put(station, discharge); | |
62 } | |
57 } | 63 } |
58 } | 64 } |
59 | 65 |
60 /** | 66 /** |
61 * If this provider may return valid data at all. | 67 * If this provider may return valid data at all. |
66 | 72 |
67 public DoubleRange getRange() { | 73 public DoubleRange getRange() { |
68 return new DoubleRange(this.qKms.allQs().min(), this.qKms.allQs().max()); | 74 return new DoubleRange(this.qKms.allQs().min(), this.qKms.allQs().max()); |
69 } | 75 } |
70 | 76 |
71 public double getDischarge(final double station) throws FunctionEvaluationException { | 77 public double getDischarge(final double station) { |
72 | 78 |
73 // IMPORTANT: we first try to retreive the exact value if it is present, to avoid rounding changes due to interpolation. | 79 try { |
74 // This is important because in the WaterlevelExporter code, these values are double-compared (with '==' ...) in order | 80 // IMPORTANT: we first try to retrieve the exact value if it is present, to avoid rounding changes due to interpolation. |
75 // to find the corresponding main-value. | 81 // This is important because in the WaterlevelExporter code, these values are double-compared (with '==' ...) in order |
76 if (this.exactValues.contains(station)) | 82 // to find the corresponding main-value. |
77 return this.exactValues.get(station); | 83 if (this.exactValues != null && this.exactValues.contains(station)) |
84 return this.exactValues.get(station); | |
78 | 85 |
79 return this.qInterpolator.value(station); | 86 if (this.qInterpolator == null) |
87 return Double.NaN; | |
88 | |
89 return this.qInterpolator.value(station); | |
90 } | |
91 catch (final FunctionEvaluationException e) { | |
92 e.printStackTrace(); | |
93 return Double.NaN; | |
94 } | |
80 } | 95 } |
81 } | 96 } |