comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/GaugeDischargeValuesFinder.java @ 9613:f2473dc34535

Nachtrag Pos. 19: Q calculation with historical discharge tables instead of master discharge table
author mschaefer
date Tue, 08 Oct 2019 15:03:24 +0200
parents d9fda7af24ca
children
comparison
equal deleted inserted replaced
9602:6b2496d71936 9613:f2473dc34535
6 * This file is Free Software under the GNU AGPL (>=v3) 6 * This file is Free Software under the GNU AGPL (>=v3)
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the 7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
8 * documentation coming with Dive4Elements River for details. 8 * documentation coming with Dive4Elements River for details.
9 */ 9 */
10 package org.dive4elements.river.artifacts.sinfo.common; 10 package org.dive4elements.river.artifacts.sinfo.common;
11
12 import java.util.Date;
11 13
12 import org.apache.commons.lang.math.DoubleRange; 14 import org.apache.commons.lang.math.DoubleRange;
13 import org.apache.commons.math.FunctionEvaluationException; 15 import org.apache.commons.math.FunctionEvaluationException;
14 import org.apache.commons.math.analysis.UnivariateRealFunction; 16 import org.apache.commons.math.analysis.UnivariateRealFunction;
15 import org.apache.commons.math.analysis.interpolation.LinearInterpolator; 17 import org.apache.commons.math.analysis.interpolation.LinearInterpolator;
39 41
40 private final UnivariateRealFunction wInterpolator; 42 private final UnivariateRealFunction wInterpolator;
41 43
42 private final DoubleRange wRange; 44 private final DoubleRange wRange;
43 45
46 private final Date startTime;
47
48 private final Date endTime;
49
44 50
45 /***** CONSTRUCTORS *****/ 51 /***** CONSTRUCTORS *****/
46 52
47 private GaugeDischargeValuesFinder(final Gauge gauge, final Calculation problems, final DischargeTable dischargeTable) { 53 private GaugeDischargeValuesFinder(final Gauge gauge, final Calculation problems, final DischargeTable dischargeTable) {
48 // Load W-Q-values from database 54 // Load W-Q-values from database
49 this.gauge = gauge; 55 this.gauge = gauge;
50 this.problems = problems; 56 this.problems = problems;
57 this.startTime = dischargeTable.getTimeInterval().getStartTime();
58 this.endTime = dischargeTable.getTimeInterval().getStopTime();
51 final TDoubleArrayList ws = new TDoubleArrayList(); 59 final TDoubleArrayList ws = new TDoubleArrayList();
52 final TDoubleArrayList qs = new TDoubleArrayList(); 60 final TDoubleArrayList qs = new TDoubleArrayList();
53 for (final DischargeTableValue v : DischargeTable.fetchValuesSortedByW(dischargeTable)) { 61 for (final DischargeTableValue v : DischargeTable.fetchValuesSortedByW(dischargeTable)) {
54 ws.add(v.getW().doubleValue()); 62 ws.add(v.getW().doubleValue());
55 qs.add(v.getQ().doubleValue()); 63 qs.add(v.getQ().doubleValue());
72 80
73 81
74 /***** METHODS *****/ 82 /***** METHODS *****/
75 83
76 /** 84 /**
77 * Loads the the main discharge table of a gauge ({gauge}.at) 85 * Loads the main discharge table of a gauge ({gauge}.at)
78 * 86 *
79 * @return The discharge table values finder of the gauge, or null 87 * @return The discharge table values finder of the gauge, or null
80 */ 88 */
81 public static GaugeDischargeValuesFinder loadValues(final Gauge gauge, final Calculation problems) { 89 public static GaugeDischargeValuesFinder loadValues(final Gauge gauge, final Calculation problems) {
82 return loadValues(gauge, gauge.getName(), problems); 90 return loadValues(gauge, gauge.getName(), problems);
83 } 91 }
84 92
85 /** 93 /**
86 * Loads the the main discharge table of a river's gauge ({gauge}.at) 94 * Loads the main discharge table of a river's gauge ({gauge}.at)
87 * 95 *
88 * @return The discharge table values finder of the gauge, or null 96 * @return The discharge table values finder of the gauge, or null
89 */ 97 */
90 public static GaugeDischargeValuesFinder loadValues(final River river, final String gaugeName, final Calculation problems) { 98 public static GaugeDischargeValuesFinder loadValues(final River river, final String gaugeName, final Calculation problems) {
91 final Gauge gauge = river.determineGaugeByName(gaugeName); 99 final Gauge gauge = river.determineGaugeByName(gaugeName);
92 return loadValues(gauge, gaugeName, problems); 100 return loadValues(gauge, gaugeName, problems);
93 } 101 }
94 102
103 /**
104 * Loads a discharge table of a river's gauge (*.at)
105 *
106 * @return The discharge table values finder, or null
107 */
108 public static GaugeDischargeValuesFinder loadValues(final DischargeTable table, final River river, final String gaugeName, final Calculation problems) {
109 final Gauge gauge = river.determineGaugeByName(gaugeName);
110 return loadValues(table, gauge, gaugeName, problems);
111 }
112
95 private static GaugeDischargeValuesFinder loadValues(final Gauge gauge, final String gaugeName, final Calculation problems) { 113 private static GaugeDischargeValuesFinder loadValues(final Gauge gauge, final String gaugeName, final Calculation problems) {
96 final DischargeTable table = (gauge != null) ? gauge.fetchMasterDischargeTable() : null; 114 return loadValues((gauge != null) ? gauge.fetchMasterDischargeTable() : null, gauge, gaugeName, problems);
115 }
116
117 private static GaugeDischargeValuesFinder loadValues(final DischargeTable table, final Gauge gauge, final String gaugeName, final Calculation problems) {
97 if ((table == null) || (table.getDischargeTableValues().size() == 0)) { 118 if ((table == null) || (table.getDischargeTableValues().size() == 0)) {
98 problems.addProblem("gauge_discharge_table.missing", gaugeName); 119 problems.addProblem("gauge_discharge_table.missing", gaugeName);
99 return null; 120 return null;
100 } 121 }
101 else 122 else
130 catch (@SuppressWarnings("unused") final FunctionEvaluationException e) { 151 catch (@SuppressWarnings("unused") final FunctionEvaluationException e) {
131 // ignore exception because this can/will happen regularly 152 // ignore exception because this can/will happen regularly
132 return Double.NaN; 153 return Double.NaN;
133 } 154 }
134 } 155 }
156
157 /**
158 * Start of the discharge table's time interval.
159 *
160 * @return
161 */
162 public Date getStartTime() {
163 return this.startTime;
164 }
165
166 /**
167 * End of the discharge table's time interval.
168 *
169 * @return
170 */
171 public Date getEndTime() {
172 return this.endTime;
173 }
135 } 174 }

http://dive4elements.wald.intevation.org