Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java @ 458:523a256451cd
Use unsharp km lookup (epsilon = 0.0001).
flys-artifacts/trunk@1957 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 19 May 2011 14:38:15 +0000 |
parents | 5d65fe4c08d5 |
children | 4e0ca3890696 |
comparison
equal
deleted
inserted
replaced
457:52532b300483 | 458:523a256451cd |
---|---|
113 return p1 == p2 ? 0.0 : (x-p1)/(p2-p1); | 113 return p1 == p2 ? 0.0 : (x-p1)/(p2-p1); |
114 } | 114 } |
115 | 115 |
116 public static final double weight(double factor, double a, double b) { | 116 public static final double weight(double factor, double a, double b) { |
117 return (1.0-factor)*a + factor*b; | 117 return (1.0-factor)*a + factor*b; |
118 } | |
119 | |
120 public double getWForKM(Row other, int index, double km) { | |
121 double w1 = ws[index]; | |
122 double w2 = other.ws[index]; | |
123 double km1 = this.km; | |
124 double km2 = other.km; | |
125 return linear(km, km1, km2, w1, w2); | |
126 } | 118 } |
127 | 119 |
128 public void interpolateW( | 120 public void interpolateW( |
129 Row other, | 121 Row other, |
130 double km, | 122 double km, |
192 return -1; | 184 return -1; |
193 } | 185 } |
194 | 186 |
195 public int compareTo(Row other) { | 187 public int compareTo(Row other) { |
196 double d = km - other.km; | 188 double d = km - other.km; |
197 if (d < 0.0) return -1; | 189 if (d < -0.0001) return -1; |
198 if (d > 0.0) return +1; | 190 if (d > 0.0001) return +1; |
199 return 0; | 191 return 0; |
200 } | |
201 | |
202 public double [][] cloneWQs() { | |
203 return new double [][] { | |
204 (double [])ws.clone(), | |
205 (double [])qs.clone() }; | |
206 } | 192 } |
207 | 193 |
208 public double [][] interpolateWQ(Row other, double km, int steps) { | 194 public double [][] interpolateWQ(Row other, double km, int steps) { |
209 | 195 |
210 int W = Math.min(ws.length, other.ws.length); | 196 int W = Math.min(ws.length, other.ws.length); |
289 outWs[i] = spline.value(outQs[i] = q); | 275 outWs[i] = spline.value(outQs[i] = q); |
290 } | 276 } |
291 } | 277 } |
292 catch (ArgumentOutsideDomainException aode) { | 278 catch (ArgumentOutsideDomainException aode) { |
293 log.error("Spline interpolation failed.", aode); | 279 log.error("Spline interpolation failed.", aode); |
294 } | |
295 | |
296 return new double [][] { outWs, outQs }; | |
297 } | |
298 | |
299 public int ascendingWs() { | |
300 if (ws.length < 2) { | |
301 return ws.length; | |
302 } | |
303 | |
304 int idx = 1; | |
305 | |
306 for (; idx < ws.length; ++idx) { | |
307 if (Double.isNaN(ws[idx]) || ws[idx] < ws[idx-1]) { | |
308 return idx; | |
309 } | |
310 } | |
311 | |
312 return idx; | |
313 } | |
314 | |
315 public double [][] weightWQs(Row other, double km) { | |
316 int W = Math.min(ws.length, other.ws.length); | |
317 double factor = factor(km, this.km, other.km); | |
318 | |
319 double [] outWs = new double[W]; | |
320 double [] outQs = new double[W]; | |
321 | |
322 for (int i = 0; i < W; ++i) { | |
323 outWs[i] = weight(factor, ws[i], other.ws[i]); | |
324 outQs[i] = weight(factor, qs[i], other.qs[i]); | |
325 } | 280 } |
326 | 281 |
327 return new double [][] { outWs, outQs }; | 282 return new double [][] { outWs, outQs }; |
328 } | 283 } |
329 | 284 |
486 public WstValueTable(Column [] columns) { | 441 public WstValueTable(Column [] columns) { |
487 this(); | 442 this(); |
488 this.columns = columns; | 443 this.columns = columns; |
489 } | 444 } |
490 | 445 |
446 public void sortRows() { | |
447 Collections.sort(rows); | |
448 } | |
449 | |
450 | |
491 public double [] interpolateW(double km, double [] qs) { | 451 public double [] interpolateW(double km, double [] qs) { |
492 return interpolateW(km, qs, new double[qs.length]); | 452 return interpolateW(km, qs, new double[qs.length]); |
493 } | 453 } |
494 | 454 |
495 public double [] interpolateW(double km, double [] qs, double [] ws) { | 455 public double [] interpolateW(double km, double [] qs, double [] ws) { |
617 return null; | 577 return null; |
618 } | 578 } |
619 | 579 |
620 for (int i = 0; i < kms.length; ++i) { | 580 for (int i = 0; i < kms.length; ++i) { |
621 kmKey.km = kms[i]; | 581 kmKey.km = kms[i]; |
582 | |
622 rowIndex = Collections.binarySearch(rows, kmKey); | 583 rowIndex = Collections.binarySearch(rows, kmKey); |
623 | 584 |
624 if (rowIndex >= 0) { | 585 if (rowIndex >= 0) { |
625 // direct row match | 586 // direct row match |
626 rows.get(rowIndex).storeWQ(qPosition, ws, qs, i); | 587 rows.get(rowIndex).storeWQ(qPosition, ws, qs, i); |