Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowVelocityKmModelValues.java @ 9096:9bd4505a20dc
Fixed removing duplicates
author | mschaefer |
---|---|
date | Sat, 26 May 2018 15:41:47 +0200 |
parents | 45f1ad66560e |
children |
comparison
equal
deleted
inserted
replaced
9095:1b24fdbf7fe2 | 9096:9bd4505a20dc |
---|---|
12 | 12 |
13 import org.apache.commons.math.analysis.interpolation.LinearInterpolator; | 13 import org.apache.commons.math.analysis.interpolation.LinearInterpolator; |
14 import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; | 14 import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; |
15 | 15 |
16 import gnu.trove.TDoubleArrayList; | 16 import gnu.trove.TDoubleArrayList; |
17 import gnu.trove.TIntArrayList; | |
17 | 18 |
18 /** | 19 /** |
19 * Sorted arrays of a station's q, v, and tau model values, running in parallel | 20 * Sorted arrays of a station's q, v, and tau model values, running in parallel |
20 * | 21 * |
21 * @author Matthias Schäfer | 22 * @author Matthias Schäfer |
34 * The station's discharge model values, sorted in ascending order | 35 * The station's discharge model values, sorted in ascending order |
35 */ | 36 */ |
36 private final TDoubleArrayList qs; | 37 private final TDoubleArrayList qs; |
37 | 38 |
38 /** | 39 /** |
40 * Same q values count used to calculate mean | |
41 */ | |
42 private final TIntArrayList counts; | |
43 | |
44 /** | |
39 * The station's main section velocity for the q values | 45 * The station's main section velocity for the q values |
40 */ | 46 */ |
41 private final TDoubleArrayList vmains; | 47 private final TDoubleArrayList vmains; |
42 | 48 |
43 /** | 49 /** |
81 * Constructor with km parameter | 87 * Constructor with km parameter |
82 */ | 88 */ |
83 public FlowVelocityKmModelValues(final double km) { | 89 public FlowVelocityKmModelValues(final double km) { |
84 this.km = km; | 90 this.km = km; |
85 this.qs = new TDoubleArrayList(); | 91 this.qs = new TDoubleArrayList(); |
92 this.counts = new TIntArrayList(); | |
86 this.vmains = new TDoubleArrayList(); | 93 this.vmains = new TDoubleArrayList(); |
87 this.taus = new TDoubleArrayList(); | 94 this.taus = new TDoubleArrayList(); |
88 this.vInterpolator = null; | 95 this.vInterpolator = null; |
89 this.tauInterpolator = null; | 96 this.tauInterpolator = null; |
90 } | 97 } |
92 /** | 99 /** |
93 * Copy constructor with new km | 100 * Copy constructor with new km |
94 */ | 101 */ |
95 public FlowVelocityKmModelValues(final double km, final FlowVelocityKmModelValues src) { | 102 public FlowVelocityKmModelValues(final double km, final FlowVelocityKmModelValues src) { |
96 this(km); | 103 this(km); |
97 src.copyTo(this.qs, this.vmains, this.taus); | 104 src.copyTo(this.qs, this.counts, this.vmains, this.taus); |
98 } | 105 } |
99 | 106 |
100 /***** METHODS *****/ | 107 /***** METHODS *****/ |
101 | 108 |
102 /** | 109 /** |
114 } | 121 } |
115 | 122 |
116 /** | 123 /** |
117 * Adds all q-v-tau to another set of arrays | 124 * Adds all q-v-tau to another set of arrays |
118 */ | 125 */ |
119 void copyTo(final TDoubleArrayList dstqs, final TDoubleArrayList dstvmains, final TDoubleArrayList dsttaus) { | 126 void copyTo(final TDoubleArrayList dstqs, final TIntArrayList dstcounts, final TDoubleArrayList dstvmains, final TDoubleArrayList dsttaus) { |
120 for (int i = 0; i <= this.qs.size(); i++) { | 127 for (int i = 0; i <= this.qs.size(); i++) { |
121 dstqs.add(this.qs.getQuick(i)); | 128 dstqs.add(this.qs.getQuick(i)); |
129 dstcounts.add(this.counts.getQuick(i)); | |
122 dstvmains.add(this.vmains.getQuick(i)); | 130 dstvmains.add(this.vmains.getQuick(i)); |
123 dsttaus.add(this.taus.getQuick(i)); | 131 dsttaus.add(this.taus.getQuick(i)); |
124 } | 132 } |
125 } | 133 } |
126 | 134 |
153 public boolean getIsInterpolated() { | 161 public boolean getIsInterpolated() { |
154 return this.isInterpolated; | 162 return this.isInterpolated; |
155 } | 163 } |
156 | 164 |
157 /** | 165 /** |
158 * Adds a q-v-tau value triple. | 166 * Adds a q-v-tau value triple, averaging the last values if q duplicates. |
159 */ | 167 */ |
160 public void addValues(final double q, final double vmain, final double tau) { | 168 public void addValues(final double q, final double vmain, final double tau) { |
161 this.qs.add(q); | 169 final int j = this.qs.size() - 1; |
162 this.vmains.add(vmain); | 170 if ((j >= 0) && (q < this.qs.getQuick(j) + 0.001)) { |
163 this.taus.add(tau); | 171 this.qs.setQuick(j, (this.qs.getQuick(j) * this.counts.getQuick(j) + q) / (this.counts.getQuick(j) + 1)); |
172 this.vmains.setQuick(j, (this.vmains.getQuick(j) * this.counts.getQuick(j) + vmain) / (this.counts.getQuick(j) + 1)); | |
173 this.taus.setQuick(j, (this.taus.getQuick(j) * this.counts.getQuick(j) + tau) / (this.counts.getQuick(j) + 1)); | |
174 this.counts.setQuick(j, this.counts.getQuick(j) + 1); | |
175 } | |
176 else { | |
177 this.qs.add(q); | |
178 this.counts.add(1); | |
179 this.vmains.add(vmain); | |
180 this.taus.add(tau); | |
181 } | |
164 } | 182 } |
165 | 183 |
166 /** | 184 /** |
167 * Searches a discharge value and returns it or the interpolated value | 185 * Searches a discharge value and returns it or the interpolated value |
168 * | 186 * |