annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhcalculation/BedQualityD50KmValueFinder.java @ 8964:45f1ad66560e

Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
author gernotbelger
date Thu, 29 Mar 2018 15:48:17 +0200
parents 48d5812e8fd5
children 9b9f5f4ddb80
rev   line source
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
2 * Software engineering by
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
5 *
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
9 */
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
10
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
11 package org.dive4elements.river.artifacts.sinfo.tkhcalculation;
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
12
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
13 import java.util.Calendar;
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
14 import java.util.Date;
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
15 import java.util.List;
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
16
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
17 import org.apache.commons.lang.math.DoubleRange;
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
18 import org.apache.commons.math.ArgumentOutsideDomainException;
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
19 import org.apache.commons.math.analysis.interpolation.LinearInterpolator;
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
20 import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction;
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
21 import org.apache.log4j.Logger;
8920
29442c03c6e3 d50 aggregation by median instead of arithmetic mean,
mschaefer
parents: 8915
diff changeset
22 import org.dive4elements.river.artifacts.math.Utils;
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
23 import org.dive4elements.river.artifacts.model.Calculation;
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
24 import org.dive4elements.river.backend.SedDBSessionHolder;
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
25 import org.dive4elements.river.model.River;
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
26 import org.hibernate.SQLQuery;
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
27 import org.hibernate.Session;
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
28 import org.hibernate.type.StandardBasicTypes;
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
29
8920
29442c03c6e3 d50 aggregation by median instead of arithmetic mean,
mschaefer
parents: 8915
diff changeset
30 import gnu.trove.TDoubleArrayList;
29442c03c6e3 d50 aggregation by median instead of arithmetic mean,
mschaefer
parents: 8915
diff changeset
31
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
32 /**
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
33 * Searchable sorted km array with parallel bed measurements value array and linear interpolation for km and d50 between
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
34 * the array elements.<br />
8901
0a900d605d52 S-INFO Flowdepth work on TKH calculation
mschaefer
parents: 8898
diff changeset
35 * <br />
0a900d605d52 S-INFO Flowdepth work on TKH calculation
mschaefer
parents: 8898
diff changeset
36 * See comment of SQL command on how the values are filtered and aggregated.
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
37 *
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
38 * @author Matthias Schäfer
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
39 *
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
40 */
8920
29442c03c6e3 d50 aggregation by median instead of arithmetic mean,
mschaefer
parents: 8915
diff changeset
41 public class BedQualityD50KmValueFinder {
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
42
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
43 /***** FIELDS *****/
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
44
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
45 /**
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
46 * Private log to use here.
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
47 */
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
48 private static Logger log = Logger.getLogger(BedQualityD50KmValueFinder.class);
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
49
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
50 /**
8920
29442c03c6e3 d50 aggregation by median instead of arithmetic mean,
mschaefer
parents: 8915
diff changeset
51 * Query selecting all sub layer bed measurements with their d50 for a km range and a time period<br />
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
52 * <br />
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
53 * A km may have bed measurements for multiple dates, multiple distances from the river bank, and multiple depth layers.
8920
29442c03c6e3 d50 aggregation by median instead of arithmetic mean,
mschaefer
parents: 8915
diff changeset
54 * The query filters by km range, time period and layer (sub layer: below bed to max. 50 cm depth).<br />
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
55 *
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
56 * If PostgreSQL would support a median aggregate function like Oracle does, the aggregation could be placed into this
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
57 * query.
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
58 */
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
59 private static final String SQL_BED_D50_SUBLAYER_MEASUREMENT = "SELECT t.km, t.datum, p.tiefevon, p.tiefebis, a.d50"
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
60 + " FROM sohltest t INNER JOIN station s ON t.stationid = s.stationid" + " INNER JOIN gewaesser g ON s.gewaesserid = g.gewaesserid"
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
61 + " INNER JOIN sohlprobe p ON t.sohltestid = p.sohltestid" + " INNER JOIN siebanalyse a ON p.sohlprobeid = a.sohlprobeid"
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
62 + " WHERE (g.name = :name) AND (s.km BETWEEN :fromkm - 0.0001 AND :tokm + 0.0001)" + " AND (p.tiefevon > 0.0) AND (p.tiefebis <= 0.5)"
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
63 + " AND (t.datum BETWEEN :fromdate AND :todate)" + " ORDER BY t.km ASC, a.d50 ASC";
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
64
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
65 private Calculation problems;
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
66
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
67 /**
8920
29442c03c6e3 d50 aggregation by median instead of arithmetic mean,
mschaefer
parents: 8915
diff changeset
68 * Real linear interpolator for kms and d50 values (m)
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
69 */
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
70 private final PolynomialSplineFunction interpolator;
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
71
8920
29442c03c6e3 d50 aggregation by median instead of arithmetic mean,
mschaefer
parents: 8915
diff changeset
72 /***** CONSTRUCTORS *****/
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
73
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
74 private BedQualityD50KmValueFinder(final Calculation problems, final double[] kms, final double[] values) {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
75 this.problems = problems;
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
76
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
77 // FIXME: check: max distance prüfen? dann D4E-LinearInterpolator verwenden
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
78 this.interpolator = new LinearInterpolator().interpolate(kms, values);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
79 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
80
8920
29442c03c6e3 d50 aggregation by median instead of arithmetic mean,
mschaefer
parents: 8915
diff changeset
81 /***** METHODS *****/
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
82
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
83 /**
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
84 * Sohlbeschaffenheit (D50 Korndurchmesser aus Seddb)
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
85 * Abhängig von Peiljahr
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
86 *
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
87 * @param problems
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
88 */
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
89 public static BedQualityD50KmValueFinder loadBedMeasurements(final Calculation problems, final River river, final DoubleRange kmRange,
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
90 final int soundingYear, final int validYears) {
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
91
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
92 /* construct valid measurement time range */
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
93 final Calendar cal = Calendar.getInstance();
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
94 cal.clear();
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
95
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
96 cal.set(soundingYear - validYears, 0, 1);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
97 final Date startTime = cal.getTime();
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
98
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
99 cal.set(soundingYear + validYears, 11, 31);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
100 final Date endTime = cal.getTime();
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
101
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
102 log.debug(String.format("loadValues km %.3f - %.3f %tF - %tF", kmRange.getMinimumDouble(), kmRange.getMaximumDouble(), startTime, endTime));
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
103 final Session session = SedDBSessionHolder.HOLDER.get();
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
104 final SQLQuery sqlQuery = session.createSQLQuery(SQL_BED_D50_SUBLAYER_MEASUREMENT).addScalar("km", StandardBasicTypes.DOUBLE)
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
105 .addScalar("datum", StandardBasicTypes.DATE).addScalar("tiefevon", StandardBasicTypes.DOUBLE).addScalar("tiefebis", StandardBasicTypes.DOUBLE)
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
106 .addScalar("d50", StandardBasicTypes.DOUBLE);
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
107 final String seddbRiver = river.nameForSeddb();
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
108 sqlQuery.setString("name", seddbRiver);
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
109 sqlQuery.setDouble("fromkm", kmRange.getMinimumDouble());
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
110 sqlQuery.setDouble("tokm", kmRange.getMaximumDouble());
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
111 sqlQuery.setDate("fromdate", startTime);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
112 sqlQuery.setDate("todate", endTime);
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
113
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
114 final List<Object[]> rows = sqlQuery.list();
8920
29442c03c6e3 d50 aggregation by median instead of arithmetic mean,
mschaefer
parents: 8915
diff changeset
115 final TDoubleArrayList kms = new TDoubleArrayList();
29442c03c6e3 d50 aggregation by median instead of arithmetic mean,
mschaefer
parents: 8915
diff changeset
116 final TDoubleArrayList values = new TDoubleArrayList();
29442c03c6e3 d50 aggregation by median instead of arithmetic mean,
mschaefer
parents: 8915
diff changeset
117 final TDoubleArrayList kmd50s = new TDoubleArrayList();
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
118
8920
29442c03c6e3 d50 aggregation by median instead of arithmetic mean,
mschaefer
parents: 8915
diff changeset
119 for (int i = 0; i <= rows.size() - 1; i++) {
29442c03c6e3 d50 aggregation by median instead of arithmetic mean,
mschaefer
parents: 8915
diff changeset
120 kmd50s.add((double) rows.get(i)[4]);
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
121 if (((i == rows.size() - 1) || !Utils.epsilonEquals((double) rows.get(i)[0], (double) rows.get(i + 1)[0], 0.0001))) {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
122 final int k = kmd50s.size() / 2;
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
123 values.add(((k + k < kmd50s.size()) ? kmd50s.get(k) : (kmd50s.get(k - 1) + kmd50s.get(k)) / 2) / 1000);
8920
29442c03c6e3 d50 aggregation by median instead of arithmetic mean,
mschaefer
parents: 8915
diff changeset
124 kms.add((double) rows.get(i)[0]);
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
125 log.debug(String.format("loadValues km %.3f d50(mm) %.1f count %d", kms.get(kms.size() - 1), values.get(values.size() - 1), kmd50s.size()));
8920
29442c03c6e3 d50 aggregation by median instead of arithmetic mean,
mschaefer
parents: 8915
diff changeset
126 kmd50s.clear();
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
127 }
8920
29442c03c6e3 d50 aggregation by median instead of arithmetic mean,
mschaefer
parents: 8915
diff changeset
128 }
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
129
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
130 if (kms.size() < 2 || values.size() < 2) {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
131 problems.addProblem("bedqualityd50kmvaluefinder.empty", soundingYear);
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
132 return null;
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
133 }
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
134
8911
37ff7f435912 SINFO Flowdepth: more error checks, d50 interpolation, avoid negative tkh
mschaefer
parents: 8901
diff changeset
135 try {
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
136 return new BedQualityD50KmValueFinder(problems, kms.toNativeArray(), values.toNativeArray());
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
137 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
138 catch (final Exception e) {
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
139 e.printStackTrace();
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
140 problems.addProblem("bedqualityd50kmvaluefinder.error", e.getLocalizedMessage());
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
141 return null;
8911
37ff7f435912 SINFO Flowdepth: more error checks, d50 interpolation, avoid negative tkh
mschaefer
parents: 8901
diff changeset
142 }
8898
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
143 }
89f3c5462a16 Implemented S-INFO Flowdepth TKH calculation
mschaefer
parents:
diff changeset
144
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
145 /**
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
146 * Returns the d50 value interpolated according to a km
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
147 *
8920
29442c03c6e3 d50 aggregation by median instead of arithmetic mean,
mschaefer
parents: 8915
diff changeset
148 * @return d50 (m) of the km, or NaN
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
149 */
8964
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
150 public double findD50(final double km) {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
151 try {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
152 return this.interpolator.value(km);
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
153 }
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
154 catch (final ArgumentOutsideDomainException e) {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
155 e.printStackTrace();
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
156
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
157 if (this.problems != null) {
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
158 this.problems.addProblem(km, "bedqualityd50kmvaluefinder.missing");
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
159 // Report only once
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
160 this.problems = null;
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
161 }
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
162
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
163 return Double.NaN;
45f1ad66560e Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
gernotbelger
parents: 8921
diff changeset
164 }
8915
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
165 }
d9dbf0b74bc2 Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
gernotbelger
parents: 8911
diff changeset
166 }

http://dive4elements.wald.intevation.org