Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/GaugeDurationValuesFinder.java @ 9358:8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
author | mschaefer |
---|---|
date | Wed, 01 Aug 2018 13:20:38 +0200 |
parents | 9b16f58c62a7 |
children |
rev | line source |
---|---|
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
2 * Software engineering by |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
3 * Björnsen Beratende Ingenieure GmbH |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
5 * |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
6 * This file is Free Software under the GNU AGPL (>=v3) |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
8 * documentation coming with Dive4Elements River for details. |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
9 */ |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
10 package org.dive4elements.river.artifacts.sinfo.common; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
11 |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
12 import org.apache.commons.lang.math.DoubleRange; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
13 import org.apache.commons.math.FunctionEvaluationException; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
14 import org.apache.commons.math.analysis.UnivariateRealFunction; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
15 import org.apache.commons.math.analysis.interpolation.LinearInterpolator; |
9358
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
16 import org.apache.log4j.Logger; |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
17 import org.dive4elements.river.artifacts.model.Calculation; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
18 import org.dive4elements.river.model.Gauge; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
19 import org.dive4elements.river.model.MainValue; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
20 import org.dive4elements.river.model.MainValueType.MainValueTypeKey; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
21 |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
22 import gnu.trove.TDoubleArrayList; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
23 |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
24 /** |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
25 * Search/interpolation of the duration main values of a gauge |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
26 * |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
27 * @author Matthias Schäfer |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
28 * |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
29 */ |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
30 public final class GaugeDurationValuesFinder { |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
31 |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
32 /***** FIELDS *****/ |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
33 |
9358
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
34 private static Logger log = Logger.getLogger(GaugeDurationValuesFinder.class); |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
35 |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
36 private final Gauge gauge; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
37 |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
38 private Calculation problems; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
39 |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
40 private UnivariateRealFunction qInterpolator; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
41 |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
42 private DoubleRange qRange; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
43 |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
44 private UnivariateRealFunction durInterpolator; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
45 |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
46 private DoubleRange durRange; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
47 |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
48 |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
49 /***** CONSTRUCTORS *****/ |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
50 |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
51 private GaugeDurationValuesFinder(final Gauge gauge, final Calculation problems) { |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
52 // Load the duration main values from the database (each duration has a Q) |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
53 this.gauge = gauge; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
54 this.problems = problems; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
55 final TDoubleArrayList qs = new TDoubleArrayList(); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
56 final TDoubleArrayList durs = new TDoubleArrayList(); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
57 for (final MainValue v : MainValue.getValuesOfGaugeAndType(gauge, MainValueTypeKey.DURATION)) { |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
58 qs.add(v.getValue().doubleValue()); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
59 durs.add(Integer.valueOf(v.getMainValue().getName()).doubleValue()); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
60 } |
9358
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
61 // Merge out-of-order Qs |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
62 final TDoubleArrayList q1s = new TDoubleArrayList(); |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
63 final TDoubleArrayList dur1s = new TDoubleArrayList(); |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
64 boolean writeWarn = true; |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
65 int cnt = 0; |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
66 int i = -1; |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
67 while ((i + 1) <= qs.size() - 1) { |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
68 i++; |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
69 if ((i == 0) || (qs.getQuick(i - 1) < qs.getQuick(i) - 0.001)) { |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
70 q1s.add(qs.getQuick(i)); |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
71 dur1s.add(durs.getQuick(i)); |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
72 cnt = 1; |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
73 } |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
74 else { |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
75 q1s.set(q1s.size() - 1, (q1s.getQuick(q1s.size() - 1) * cnt + qs.getQuick(i)) / (cnt + 1)); |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
76 dur1s.set(dur1s.size() - 1, (dur1s.getQuick(dur1s.size() - 1) * cnt + durs.getQuick(i)) / (cnt + 1)); |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
77 cnt++; |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
78 if (writeWarn) { |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
79 log.warn("Nicht streng monotone Q in D(Q) des Pegels " + gauge.getName()); |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
80 writeWarn = false; |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
81 } |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
82 } |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
83 } |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
84 // Build the duration-by-Q interpolator |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
85 try { |
9358
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
86 this.qInterpolator = new LinearInterpolator().interpolate(q1s.toNativeArray(), dur1s.toNativeArray()); |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
87 this.qRange = new DoubleRange(q1s.getQuick(0), q1s.getQuick(q1s.size() - 1)); |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
88 } |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
89 catch (final Exception e) { |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
90 this.qInterpolator = null; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
91 this.qRange = null; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
92 } |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
93 // Load the Q values by duration from the database |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
94 qs.clear(); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
95 durs.clear(); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
96 for (final MainValue v : MainValue.getDurationDischargesOfGauge(gauge)) { |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
97 durs.add(Integer.valueOf(v.getMainValue().getName()).doubleValue()); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
98 qs.add(v.getValue().doubleValue()); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
99 } |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
100 // Build the Q-by-duration interpolator |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
101 try { |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
102 this.durInterpolator = new LinearInterpolator().interpolate(durs.toNativeArray(), qs.toNativeArray()); |
9358
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
103 this.durRange = new DoubleRange(durs.getQuick(0), durs.getQuick(durs.size() - 1)); |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
104 } |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
105 catch (final Exception e) { |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
106 this.durInterpolator = null; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
107 this.durRange = null; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
108 } |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
109 // Report problems |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
110 if (((this.qInterpolator == null) || (this.durInterpolator == null)) && (this.problems != null)) { |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
111 this.problems.addProblem("gauge_duration.missing", gauge.getName()); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
112 // Report only once |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
113 this.problems = null; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
114 } |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
115 } |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
116 |
9285 | 117 |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
118 /***** METHODS *****/ |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
119 |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
120 /** |
9202
b4402594213b
More work on calculations and output for S-Info flood duration workflow (chart types 1 and 2)
mschaefer
parents:
9195
diff
changeset
|
121 * Loads the the discharge-duration table of a gauge ({gauge}.sta) |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
122 * |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
123 * @return The main values finder of a a gauge, or null |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
124 */ |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
125 public static GaugeDurationValuesFinder loadValues(final Gauge gauge, final Calculation problems) { |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
126 return new GaugeDurationValuesFinder(gauge, problems); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
127 } |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
128 |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
129 /** |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
130 * If this provider may return valid data at all. |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
131 */ |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
132 public boolean isValid() { |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
133 return (this.qInterpolator != null); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
134 } |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
135 |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
136 /** |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
137 * Discharge for a duration |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
138 * |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
139 * @return Q, or NegInf for duration less than all, or PosInf for duration greater then all, or NaN in case of exception |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
140 */ |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
141 public double getDischarge(final int duration) { |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
142 try { |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
143 if (this.durInterpolator == null) |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
144 return Double.NaN; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
145 else if (duration < this.durRange.getMinimumDouble()) |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
146 return Double.NEGATIVE_INFINITY; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
147 else if (duration > this.durRange.getMaximumDouble()) |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
148 return Double.POSITIVE_INFINITY; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
149 else |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
150 return this.durInterpolator.value(duration); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
151 } |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
152 catch (@SuppressWarnings("unused") final FunctionEvaluationException e) { |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
153 // ignore exception because this can/will happen regularly |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
154 return Double.NaN; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
155 } |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
156 } |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
157 |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
158 /** |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
159 * Duration for a discharge |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
160 * |
9358
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
161 * @return duration, or 0 for Q less than all, or 365 for duration greater then all, or NaN in case of missing |
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
162 * interpolator or exception |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
163 */ |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
164 public double getDuration(final double q) { |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
165 try { |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
166 if (this.qInterpolator == null) |
9358
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
167 return Double.NaN; |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
168 else if (q < this.qRange.getMinimumDouble()) |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
169 return 0; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
170 else if (q > this.qRange.getMaximumDouble()) |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
171 return 365; |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
172 else |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
173 return this.qInterpolator.value(q); |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
174 } |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
175 catch (@SuppressWarnings("unused") final FunctionEvaluationException e) { |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
176 // ignore exception because this can/will happen regularly |
9358
8eddc2393750
Fixed: S-Info flood duration Q-D interpolation for non monotonous Q values, NaN instead of -1 in error cases
mschaefer
parents:
9285
diff
changeset
|
177 return Double.NaN; |
9176
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
178 } |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
179 } |
1614cb14308f
Work on calculations for S-Info flood duration workflow
mschaefer
parents:
diff
changeset
|
180 } |