Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java @ 643:a9bde508824a
flys/issue82: Only successful interpolations are named.
flys-artifacts/trunk@2027 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 30 May 2011 09:19:57 +0000 |
parents | d08f77e7f7e8 |
children | 433f67a076aa |
rev | line source |
---|---|
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model; |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.io.Serializable; |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 |
427
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
6 import de.intevation.flys.artifacts.math.LinearRemap; |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
7 |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
8 import java.util.Arrays; |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 import java.util.ArrayList; |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 import java.util.List; |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import java.util.Collections; |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
13 import org.apache.log4j.Logger; |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
14 |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
15 import org.apache.commons.math.analysis.interpolation.SplineInterpolator; |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
16 |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
17 import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
18 |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
19 import org.apache.commons.math.ArgumentOutsideDomainException; |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
20 |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 public class WstValueTable |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 implements Serializable |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 { |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
24 private static Logger log = Logger.getLogger(WstValueTable.class); |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 |
395
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
26 public static final int DEFAULT_Q_STEPS = 500; |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
27 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
28 public static final class Column |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
29 implements Serializable |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 { |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 protected String name; |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 |
632
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
621
diff
changeset
|
33 protected QRangeTree qRangeTree; |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
621
diff
changeset
|
34 |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 public Column() { |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 } |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 public Column(String name) { |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 this.name = name; |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 } |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 public String getName() { |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 return name; |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 } |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 public void setName(String name) { |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 this.name = name; |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 } |
632
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
621
diff
changeset
|
49 |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
621
diff
changeset
|
50 public QRangeTree getQRangeTree() { |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
621
diff
changeset
|
51 return qRangeTree; |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
621
diff
changeset
|
52 } |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
621
diff
changeset
|
53 |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
621
diff
changeset
|
54 public void setQRangeTree(QRangeTree qRangeTree) { |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
621
diff
changeset
|
55 this.qRangeTree = qRangeTree; |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
621
diff
changeset
|
56 } |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
57 } // class Column |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
59 public static final class QPosition { |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
60 |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
61 protected int index; |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
62 protected double weight; |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
63 |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
64 public QPosition() { |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
65 } |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
66 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
67 public QPosition(int index, double weight) { |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
68 this.index = index; |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
69 this.weight = weight; |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
70 } |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
71 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
72 public QPosition set(int index, double weight) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
73 this.index = index; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
74 this.weight = weight; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
75 return this; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
76 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
77 |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
78 } // class Position |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
79 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
80 public static final class Row |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
81 implements Serializable, Comparable<Row> |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 { |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 double km; |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
84 double [] ws; |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 public Row() { |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 } |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
89 public Row(double km) { |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 this.km = km; |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
91 } |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
92 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
93 public Row(double km, double [] ws) { |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
94 this(km); |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
95 this.ws = ws; |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
96 } |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
97 |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
98 public int compareTo(Row other) { |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
99 double d = km - other.km; |
458
523a256451cd
Use unsharp km lookup (epsilon = 0.0001).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
443
diff
changeset
|
100 if (d < -0.0001) return -1; |
523a256451cd
Use unsharp km lookup (epsilon = 0.0001).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
443
diff
changeset
|
101 if (d > 0.0001) return +1; |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
102 return 0; |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 } |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
104 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
105 public void interpolateW( |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
106 Row other, |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
107 double km, |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
108 double [] iqs, |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
109 double [] ows, |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
110 WstValueTable table |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
111 ) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
112 double kmWeight = factor(km, this.km, other.km); |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
113 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
114 QPosition qPosition = new QPosition(); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
115 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
116 for (int i = 0; i < iqs.length; ++i) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
117 if (table.getQPosition(km, iqs[i], qPosition) != null) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
118 double wt = getW(qPosition); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
119 double wo = other.getW(qPosition); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
120 ows[i] = weight(kmWeight, wt, wo); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
121 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
122 else { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
123 ows[i] = Double.NaN; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
124 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
125 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
126 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
127 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
128 public double [][] interpolateWQ( |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
129 Row other, |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
130 double km, |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
131 int steps, |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
132 WstValueTable table |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
133 ) { |
395
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
134 int W = Math.min(ws.length, other.ws.length); |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
135 |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
136 if (W < 1) { |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
137 return new double[2][0]; |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
138 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
139 |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
140 double factor = factor(km, this.km, other.km); |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
141 |
395
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
142 double [] splineQ = new double[W]; |
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
143 double [] splineW = new double[W]; |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
144 |
395
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
145 double minQ = Double.MAX_VALUE; |
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
146 double maxQ = -Double.MAX_VALUE; |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
147 |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
148 for (int i = 0; i < W; ++i) { |
395
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
149 double wws = weight(factor, ws[i], other.ws[i]); |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
150 double wqs = weight( |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
151 factor, |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
152 table.getQIndex(i, km), |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
153 table.getQIndex(i, other.km)); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
154 |
395
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
155 splineW[i] = wws; |
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
156 splineQ[i] = wqs; |
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
157 if (wqs < minQ) minQ = wqs; |
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
158 if (wqs > maxQ) maxQ = wqs; |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
159 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
160 |
395
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
161 double stepWidth = (maxQ - minQ)/steps; |
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
162 |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
163 SplineInterpolator interpolator = new SplineInterpolator(); |
395
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
164 PolynomialSplineFunction spline = |
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
165 interpolator.interpolate(splineQ, splineW); |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
166 |
395
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
167 double [] outWs = new double[steps]; |
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
168 double [] outQs = new double[steps]; |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
169 |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
170 try { |
395
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
171 double q = minQ; |
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
172 for (int i = 0; i < outWs.length; ++i, q += stepWidth) { |
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
173 outWs[i] = spline.value(outQs[i] = q); |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
174 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
175 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
176 catch (ArgumentOutsideDomainException aode) { |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
177 log.error("Spline interpolation failed.", aode); |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
178 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
179 |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
180 return new double [][] { outWs, outQs }; |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
181 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
182 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
183 public double [][] interpolateWQ(int steps, WstValueTable table) { |
395
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
184 |
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
185 int W = ws.length; |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
186 |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
187 if (W < 1) { |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
188 return new double[2][0]; |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
189 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
190 |
395
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
191 double [] splineQ = new double[W]; |
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
192 |
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
193 double minQ = Double.MAX_VALUE; |
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
194 double maxQ = -Double.MAX_VALUE; |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
195 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
196 QPosition qPosition = new QPosition(); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
197 |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
198 for (int i = 0; i < W; ++i) { |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
199 splineQ[i] = table.getQIndex(i, km); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
200 if (splineQ[i] < minQ) minQ = splineQ[i]; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
201 if (splineQ[i] > maxQ) maxQ = splineQ[i]; |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
202 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
203 |
395
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
204 double stepWidth = (maxQ - minQ)/steps; |
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
205 |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
206 SplineInterpolator interpolator = new SplineInterpolator(); |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
207 |
395
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
208 PolynomialSplineFunction spline = |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
209 interpolator.interpolate(splineQ, ws); |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
210 |
395
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
211 double [] outWs = new double[steps]; |
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
212 double [] outQs = new double[steps]; |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
213 |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
214 try { |
395
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
215 double q = minQ; |
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
216 for (int i = 0; i < outWs.length; ++i, q += stepWidth) { |
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
217 outWs[i] = spline.value(outQs[i] = q); |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
218 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
219 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
220 catch (ArgumentOutsideDomainException aode) { |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
221 log.error("Spline interpolation failed.", aode); |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
222 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
223 |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
224 return new double [][] { outWs, outQs }; |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
225 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
226 |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
227 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
228 public double getW(QPosition qPosition) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
229 int index = qPosition.index; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
230 double weight = qPosition.weight; |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
231 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
232 return weight == 1.0 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
233 ? ws[index] |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
234 : weight(weight, ws[index-1], ws[index]); |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
235 } |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
236 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
237 public double getW( |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
238 Row other, |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
239 double km, |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
240 QPosition qPosition |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
241 ) { |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
242 double kmWeight = factor(km, this.km, other.km); |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
243 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
244 int index = qPosition.index; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
245 double weight = qPosition.weight; |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
246 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
247 double tw, ow; |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
248 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
249 if (weight == 1.0) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
250 tw = ws[index]; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
251 ow = other.ws[index]; |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
252 } |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
253 else { |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
254 tw = weight(weight, ws[index-1], ws[index]); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
255 ow = weight(weight, other.ws[index-1], other.ws[index]); |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
256 } |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
257 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
258 return weight(kmWeight, tw, ow); |
427
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
259 } |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
260 } // class Row |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
261 |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
262 protected List<Row> rows; |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
263 |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
264 protected Column [] columns; |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
265 |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
266 public WstValueTable() { |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
267 rows = new ArrayList<Row>(); |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
268 } |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
269 |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
270 public WstValueTable(Column [] columns) { |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
271 this(); |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
272 this.columns = columns; |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
273 } |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
274 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
275 public WstValueTable(Column [] columns, List<Row> rows) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
276 this.columns = columns; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
277 this.rows = rows; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
278 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
279 |
458
523a256451cd
Use unsharp km lookup (epsilon = 0.0001).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
443
diff
changeset
|
280 public void sortRows() { |
523a256451cd
Use unsharp km lookup (epsilon = 0.0001).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
443
diff
changeset
|
281 Collections.sort(rows); |
523a256451cd
Use unsharp km lookup (epsilon = 0.0001).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
443
diff
changeset
|
282 } |
523a256451cd
Use unsharp km lookup (epsilon = 0.0001).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
443
diff
changeset
|
283 |
380
5f55047a17e8
Moved expensive allocation of result arrays out of km loop.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
374
diff
changeset
|
284 public double [] interpolateW(double km, double [] qs, double [] ws) { |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
285 |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
286 int rowIndex = Collections.binarySearch(rows, new Row(km)); |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
287 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
288 QPosition qPosition = new QPosition(); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
289 |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
290 if (rowIndex >= 0) { // direct row match |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
291 Row row = rows.get(rowIndex); |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
292 for (int i = 0; i < qs.length; ++i) { |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
293 ws[i] = getQPosition(km, qs[i], qPosition) != null |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
294 ? row.getW(qPosition) |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
295 : Double.NaN; |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
296 } |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
297 } |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
298 else { // needs bilinear interpolation |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
299 rowIndex = -rowIndex -1; |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
300 |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
301 if (rowIndex < 1 || rowIndex >= rows.size()) { |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
302 // do not extrapolate |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
303 Arrays.fill(ws, Double.NaN); |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
304 } |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
305 else { |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
306 Row r1 = rows.get(rowIndex-1); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
307 Row r2 = rows.get(rowIndex); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
308 r1.interpolateW(r2, km, qs, ws, this); |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
309 } |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
310 } |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
311 |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
312 return ws; |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
313 } |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
314 |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
315 public double [][] interpolateWQ(double km) { |
395
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
316 return interpolateWQ(km, DEFAULT_Q_STEPS); |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
317 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
318 |
395
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
319 public double [][] interpolateWQ(double km, int steps) { |
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
320 |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
321 int rowIndex = Collections.binarySearch(rows, new Row(km)); |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
322 |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
323 if (rowIndex >= 0) { // direct row match |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
324 Row row = rows.get(rowIndex); |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
325 return row.interpolateWQ(steps, this); |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
326 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
327 |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
328 rowIndex = -rowIndex -1; |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
329 |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
330 if (rowIndex < 1 || rowIndex >= rows.size()) { |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
331 // do not extrapolate |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
332 return new double[2][0]; |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
333 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
334 |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
335 Row r1 = rows.get(rowIndex-1); |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
336 Row r2 = rows.get(rowIndex); |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
337 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
338 return r1.interpolateWQ(r2, km, steps, this); |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
339 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
340 |
427
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
341 public void interpolate( |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
342 double [] kms, |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
343 double [] ws, |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
344 double [] qs, |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
345 QPosition qPosition, |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
346 LinearRemap remap |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
347 ) { |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
348 int R1 = rows.size()-1; |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
349 |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
350 Row kmKey = new Row(); |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
351 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
352 QPosition nPosition = new QPosition(); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
353 |
427
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
354 for (int i = 0; i < kms.length; ++i) { |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
355 kmKey.km = kms[i]; |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
356 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
357 qs[i] = remap.eval(kms[i], getQ(qPosition, kms[i])); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
358 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
359 if (getQPosition(kms[i], qs[i], nPosition) == null) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
360 ws[i] = Double.NaN; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
361 continue; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
362 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
363 |
427
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
364 int rowIndex = Collections.binarySearch(rows, kmKey); |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
365 |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
366 if (rowIndex >= 0) { |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
367 // direct row match |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
368 ws[i] = rows.get(rowIndex).getW(nPosition); |
427
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
369 continue; |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
370 } |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
371 |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
372 rowIndex = -rowIndex -1; |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
373 |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
374 if (rowIndex < 1 || rowIndex >= R1) { |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
375 // do not extrapolate |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
376 ws[i] = Double.NaN; |
427
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
377 continue; |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
378 } |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
379 Row r1 = rows.get(rowIndex-1); |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
380 Row r2 = rows.get(rowIndex); |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
381 ws[i] = r1.getW(r2, kms[i], nPosition); |
427
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
382 } |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
383 } |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
384 |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
385 public QPosition interpolate( |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
386 double q, |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
387 int referenceIndex, |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
388 double [] kms, |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
389 double [] ws, |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
390 double [] qs |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
391 ) { |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
392 Row kmKey = new Row(kms[referenceIndex]); |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
393 |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
394 int rowIndex = Collections.binarySearch(rows, kmKey); |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
395 |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
396 int R1 = rows.size()-1; |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
397 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
398 QPosition qPosition = getQPosition(kms[referenceIndex], q); |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
399 |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
400 if (qPosition == null) { |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
401 // we cannot locate q at km |
427
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
402 return null; |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
403 } |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
404 |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
405 for (int i = 0; i < kms.length; ++i) { |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
406 kmKey.km = kms[i]; |
458
523a256451cd
Use unsharp km lookup (epsilon = 0.0001).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
443
diff
changeset
|
407 |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
408 rowIndex = Collections.binarySearch(rows, kmKey); |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
409 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
410 qs[i] = getQ(qPosition, kms[i]); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
411 |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
412 if (rowIndex >= 0) { |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
413 // direct row match |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
414 ws[i] = rows.get(rowIndex).getW(qPosition); |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
415 continue; |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
416 } |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
417 |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
418 rowIndex = -rowIndex -1; |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
419 |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
420 if (rowIndex < 1 || rowIndex >= R1) { |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
421 // do not extrapolate |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
422 ws[i] = Double.NaN; |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
423 continue; |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
424 } |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
425 Row r1 = rows.get(rowIndex-1); |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
426 Row r2 = rows.get(rowIndex); |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
427 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
428 ws[i] = r1.getW(r2, kms[i], qPosition); |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
429 } |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
430 |
427
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
431 return qPosition; |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
432 } |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
433 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
434 public QPosition getQPosition(double km, double q) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
435 return getQPosition(km, q, new QPosition()); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
436 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
437 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
438 public QPosition getQPosition(double km, double q, QPosition qPosition) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
439 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
440 if (columns.length == 0) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
441 return null; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
442 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
443 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
444 double qLast = columns[0].getQRangeTree().findQ(km); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
445 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
446 if (Math.abs(qLast - q) < 0.00001) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
447 return qPosition.set(0, 1d); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
448 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
449 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
450 for (int i = 1; i < columns.length; ++i) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
451 double qCurrent = columns[i].getQRangeTree().findQ(km); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
452 if (Math.abs(qCurrent - q) < 0.00001) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
453 return qPosition.set(i, 1d); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
454 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
455 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
456 double qMin, qMax; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
457 if (qLast < qCurrent) { qMin = qLast; qMax = qCurrent; } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
458 else { qMin = qCurrent; qMax = qLast; } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
459 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
460 if (q > qMin && q < qMax) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
461 double weight = factor(q, qLast, qCurrent); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
462 return qPosition.set(i, weight); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
463 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
464 qLast = qCurrent; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
465 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
466 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
467 return null; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
468 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
469 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
470 public double getQIndex(int index, double km) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
471 return columns[index].getQRangeTree().findQ(km); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
472 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
473 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
474 public double getQ(QPosition qPosition, double km) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
475 int index = qPosition.index; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
476 double weight = qPosition.weight; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
477 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
478 if (weight == 1d) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
479 return columns[index].getQRangeTree().findQ(km); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
480 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
481 double q1 = columns[index-1].getQRangeTree().findQ(km); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
482 double q2 = columns[index ].getQRangeTree().findQ(km); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
483 return weight(weight, q1, q2); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
484 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
485 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
486 public static final double linear( |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
487 double x, |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
488 double x1, double x2, |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
489 double y1, double y2 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
490 ) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
491 // y1 = m*x1 + b |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
492 // y2 = m*x2 + b |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
493 // y2 - y1 = m*(x2 - x1) |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
494 // m = (y2 - y1)/(x2 - x1) # x2 != x1 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
495 // b = y1 - m*x1 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
496 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
497 if (x1 == x2) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
498 return 0.5*(y1 + y2); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
499 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
500 double m = (y2 - y1)/(x2 - x1); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
501 double b = y1 - m*x1; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
502 return x*m + b; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
503 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
504 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
505 public static final double factor(double x, double p1, double p2) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
506 // 0 = m*p1 + b <=> b = -m*p1 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
507 // 1 = m*p2 + b |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
508 // 1 = m*(p2 - p1) |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
509 // m = 1/(p2 - p1) # p1 != p2 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
510 // f(x) = x/(p2-p1) - p1/(p2-p1) <=> (x-p1)/(p2-p1) |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
511 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
512 return p1 == p2 ? 0.0 : (x-p1)/(p2-p1); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
513 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
514 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
515 public static final double weight(double factor, double a, double b) { |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
516 //return (1.0-factor)*a + factor*b; |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
517 return a + factor*(b-a); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
518 } |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
519 } |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
520 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |