Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/WstValueTable.java @ 9286:bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
author | mschaefer |
---|---|
date | Mon, 23 Jul 2018 19:20:06 +0200 |
parents | 5e38e2924c07 |
children | 853f2dafc16e |
rev | line source |
---|---|
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4797
diff
changeset
|
9 package org.dive4elements.river.artifacts.model; |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
11 import static org.dive4elements.river.backend.utils.EpsilonComparator.CMP; |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
13 import java.io.Serializable; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
14 import java.util.ArrayList; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
15 import java.util.Arrays; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
16 import java.util.Collections; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
17 import java.util.List; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
18 |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
19 import org.apache.commons.math.ArgumentOutsideDomainException; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
20 import org.apache.commons.math.analysis.interpolation.SplineInterpolator; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
21 import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
22 import org.apache.commons.math.exception.MathIllegalArgumentException; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
23 import org.apache.log4j.Logger; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
24 import org.dive4elements.river.artifacts.math.Function; |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4797
diff
changeset
|
25 import org.dive4elements.river.artifacts.math.Linear; |
6434
898afcce1d0a
Partial fix for flys/1303
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
26 import org.dive4elements.river.utils.DoubleUtil; |
427
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
27 |
1937
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
28 import gnu.trove.TDoubleArrayList; |
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
29 |
1838
853cd2120d69
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1721
diff
changeset
|
30 /** |
853cd2120d69
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1721
diff
changeset
|
31 * W, Q and km data from database 'wsts' spiced with interpolation algorithms. |
853cd2120d69
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1721
diff
changeset
|
32 */ |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 public class WstValueTable |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 implements Serializable |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 { |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
36 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
|
37 |
395
aae8f327425e
'berechnete Abflusskurve': generate ws from qs
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
380
diff
changeset
|
38 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
|
39 |
2253
707b47d8c554
Dont sort the data series in reference curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2248
diff
changeset
|
40 public static final int RELATE_WS_SAMPLES = 200; |
2186
ec2574eb2d32
Added calculation class for "Bezugslinienverfahren" to created by WINFOArtifact.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2166
diff
changeset
|
41 |
8664
b9e5fa7f7a28
(issue1787) Do not accept any non-NaN W-value but check for epsilon.
"Tom Gottfried <tom@intevation.de>"
parents:
8663
diff
changeset
|
42 public static final double W_EPSILON = 0.000001; |
b9e5fa7f7a28
(issue1787) Do not accept any non-NaN W-value but check for epsilon.
"Tom Gottfried <tom@intevation.de>"
parents:
8663
diff
changeset
|
43 |
1721
eb35570df0e8
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1681
diff
changeset
|
44 /** |
eb35570df0e8
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1681
diff
changeset
|
45 * A Column in the table, typically representing one measurement session. |
eb35570df0e8
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1681
diff
changeset
|
46 */ |
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
|
47 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
|
48 implements Serializable |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 { |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 protected String name; |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
632
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
621
diff
changeset
|
52 protected QRangeTree qRangeTree; |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
621
diff
changeset
|
53 |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 public Column() { |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 } |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
57 public Column(final String name) { |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 this.name = name; |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 } |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 public String getName() { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
62 return this.name; |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 } |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
65 public void setName(final String name) { |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 this.name = name; |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 } |
632
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
621
diff
changeset
|
68 |
4797
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4119
diff
changeset
|
69 public QRangeTree getQRangeTree() { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
70 return this.qRangeTree; |
632
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
621
diff
changeset
|
71 } |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
621
diff
changeset
|
72 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
73 public void setQRangeTree(final QRangeTree qRangeTree) { |
632
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
621
diff
changeset
|
74 this.qRangeTree = qRangeTree; |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
621
diff
changeset
|
75 } |
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
|
76 } // class Column |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 |
1721
eb35570df0e8
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1681
diff
changeset
|
78 /** |
eb35570df0e8
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1681
diff
changeset
|
79 * A (weighted) position used for interpolation. |
eb35570df0e8
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1681
diff
changeset
|
80 */ |
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
|
81 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
|
82 |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
83 protected int index; |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
84 protected double weight; |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
85 |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
86 public QPosition() { |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
87 } |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
88 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
89 public QPosition(final int index, final double weight) { |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
90 this.index = index; |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
91 this.weight = weight; |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
92 } |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
93 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
94 public QPosition set(final int index, final double weight) { |
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
|
95 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
|
96 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
|
97 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
|
98 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
99 |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
100 } // class Position |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
101 |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
102 public static final class SplineFunction { |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
103 |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
104 public PolynomialSplineFunction spline; |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
105 public double [] splineQs; |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
106 public double [] splineWs; |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
107 |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
108 public SplineFunction( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
109 final PolynomialSplineFunction spline, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
110 final double [] splineQs, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
111 final double [] splineWs |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
112 ) { |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
113 this.spline = spline; |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
114 this.splineQs = splineQs; |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
115 this.splineWs = splineWs; |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
116 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
117 |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
118 public double [][] sample( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
119 final int numSamples, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
120 final double km, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
121 final Calculation errors |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
122 ) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
123 final double minQ = getQMin(); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
124 final double maxQ = getQMax(); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
125 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
126 final double [] outWs = new double[numSamples]; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
127 final double [] outQs = new double[numSamples]; |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
128 |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
129 Arrays.fill(outWs, Double.NaN); |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
130 Arrays.fill(outQs, Double.NaN); |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
131 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
132 final double stepWidth = (maxQ - minQ)/numSamples; |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
133 |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
134 try { |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
135 double q = minQ; |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
136 for (int i = 0; i < outWs.length; ++i, q += stepWidth) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
137 outWs[i] = this.spline.value(outQs[i] = q); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
138 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
139 } |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
140 catch (final ArgumentOutsideDomainException aode) { |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
141 if (errors != null) { |
2166
2898b1ff6013
I18N for WINFO calculation result messages.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1939
diff
changeset
|
142 errors.addProblem(km, "spline.interpolation.failed"); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
143 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
144 log.error("spline interpolation failed.", aode); |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
145 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
146 |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
147 return new double [][] { outWs, outQs }; |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
148 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
149 |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
150 public double getQMin() { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
151 return Math.min(this.splineQs[0], this.splineQs[this.splineQs.length-1]); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
152 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
153 |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
154 public double getQMax() { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
155 return Math.max(this.splineQs[0], this.splineQs[this.splineQs.length-1]); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
156 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
157 |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
158 /** Constructs a continues index between the columns to Qs. */ |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
159 public PolynomialSplineFunction createIndexQRelation() { |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
160 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
161 final double [] indices = new double[this.splineQs.length]; |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
162 for (int i = 0; i < indices.length; ++i) { |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
163 indices[i] = i; |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
164 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
165 |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
166 try { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
167 final SplineInterpolator interpolator = new SplineInterpolator(); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
168 return interpolator.interpolate(indices, this.splineQs); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
169 } |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
170 catch (final MathIllegalArgumentException miae) { |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
171 // Ignore me! |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
172 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
173 return null; |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
174 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
175 } // class SplineFunction |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
176 |
1721
eb35570df0e8
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1681
diff
changeset
|
177 /** |
1838
853cd2120d69
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1721
diff
changeset
|
178 * A row, typically a position where measurements were taken. |
1721
eb35570df0e8
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1681
diff
changeset
|
179 */ |
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
|
180 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
|
181 implements Serializable, Comparable<Row> |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 { |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 double km; |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
184 double [] ws; |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 public Row() { |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 } |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
189 public Row(final double km) { |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 this.km = km; |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
191 } |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
192 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
193 public Row(final double km, final double [] ws) { |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
194 this(km); |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
195 this.ws = ws; |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
196 } |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
197 |
1838
853cd2120d69
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1721
diff
changeset
|
198 /** |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
199 * Sort Qs and Ws for this Row over Q. |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
200 */ |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
201 private double[][] getSortedWQ( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
202 final WstValueTable table, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
203 final Calculation errors |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
204 ) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
205 final int W = this.ws.length; |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
206 |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
207 if (W < 1) { |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
208 if (errors != null) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
209 errors.addProblem(this.km, "no.ws.found"); |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
210 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
211 return new double[][] {{Double.NaN}, {Double.NaN}}; |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
212 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
213 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
214 final double [] sortedWs = this.ws; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
215 final double [] sortedQs = new double[W]; |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
216 |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
217 for (int i=0; i < W; ++i) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
218 final double q = table.getQIndex(i, this.km); |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
219 if (Double.isNaN(q) && errors != null) { |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
220 errors.addProblem( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
221 this.km, "no.q.found.in.column", i+1); |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
222 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
223 sortedQs[i] = q; |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
224 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
225 |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
226 DoubleUtil.sortByFirst(sortedQs, sortedWs); |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
227 |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
228 return new double[][] { sortedWs, sortedQs }; |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
229 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
230 |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
231 /** |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
232 * Return an array of Qs and Ws for the given km between |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
233 * this Row and another, sorted over Q. |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
234 */ |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
235 private double[][] getSortedWQ( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
236 final Row other, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
237 final double km, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
238 final WstValueTable table, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
239 final Calculation errors |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
240 ) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
241 final int W = Math.min(this.ws.length, other.ws.length); |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
242 |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
243 if (W < 1) { |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
244 if (errors != null) { |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
245 errors.addProblem("no.ws.found"); |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
246 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
247 return new double[][] {{Double.NaN}, {Double.NaN}}; |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
248 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
249 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
250 final double factor = Linear.factor(km, this.km, other.km); |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
251 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
252 final double [] sortedQs = new double[W]; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
253 final double [] sortedWs = new double[W]; |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
254 |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
255 for (int i = 0; i < W; ++i) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
256 final double wws = Linear.weight(factor, this.ws[i], other.ws[i]); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
257 final double wqs = table.getQIndex(i, km); |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
258 |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
259 if (Double.isNaN(wws) || Double.isNaN(wqs)) { |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
260 if (errors != null) { |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
261 errors.addProblem(km, "cannot.find.w.or.q"); |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
262 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
263 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
264 |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
265 sortedWs[i] = wws; |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
266 sortedQs[i] = wqs; |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
267 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
268 |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
269 DoubleUtil.sortByFirst(sortedQs, sortedWs); |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
270 |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
271 return new double[][] { sortedWs, sortedQs }; |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
272 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
273 |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
274 /** |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
275 * Find Qs matching w in an array of Qs and Ws sorted over Q. |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
276 */ |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
277 private double[] findQsForW(final double w, final double[][] sortedWQ) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
278 final int W = sortedWQ[0].length; |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
279 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
280 final double[] sortedQs = sortedWQ[1]; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
281 final double[] sortedWs = sortedWQ[0]; |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
282 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
283 final TDoubleArrayList qs = new TDoubleArrayList(); |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
284 |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
285 if (W > 0 && Math.abs(sortedWs[0]-w) < W_EPSILON) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
286 final double q = sortedQs[0]; |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
287 if (!Double.isNaN(q)) { |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
288 qs.add(q); |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
289 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
290 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
291 |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
292 for (int i = 1; i < W; ++i) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
293 final double w2 = sortedWs[i]; |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
294 if (Double.isNaN(w2)) { |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
295 continue; |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
296 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
297 if (Math.abs(w2-w) < W_EPSILON) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
298 final double q = sortedQs[i]; |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
299 if (!Double.isNaN(q)) { |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
300 qs.add(q); |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
301 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
302 continue; |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
303 } |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
304 final double w1 = sortedWs[i-1]; |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
305 if (Double.isNaN(w1)) { |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
306 continue; |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
307 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
308 |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
309 if (w < Math.min(w1, w2) || w > Math.max(w1, w2)) { |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
310 continue; |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
311 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
312 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
313 final double q1 = sortedQs[i-1]; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
314 final double q2 = sortedQs[i]; |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
315 if (Double.isNaN(q1) || Double.isNaN(q2)) { |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
316 continue; |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
317 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
318 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
319 final double q = Linear.linear(w, w1, w2, q1, q2); |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
320 qs.add(q); |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
321 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
322 |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
323 return qs.toNativeArray(); |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
324 } |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
325 |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
326 /** |
1838
853cd2120d69
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1721
diff
changeset
|
327 * Compare according to place of measurement (km). |
853cd2120d69
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1721
diff
changeset
|
328 */ |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
329 @Override |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
330 public int compareTo(final Row other) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
331 return CMP.compare(this.km, other.km); |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
332 } |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
333 |
1887
d2e217f438bc
Minor doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1860
diff
changeset
|
334 /** |
d2e217f438bc
Minor doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1860
diff
changeset
|
335 * Interpolate Ws, given Qs and a km. |
d2e217f438bc
Minor doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1860
diff
changeset
|
336 * |
d2e217f438bc
Minor doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1860
diff
changeset
|
337 * @param iqs Given ("input") Qs. |
d2e217f438bc
Minor doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1860
diff
changeset
|
338 * @param ows Resulting ("output") Ws. |
d2e217f438bc
Minor doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1860
diff
changeset
|
339 * @param table Table of which to use data for interpolation. |
d2e217f438bc
Minor doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1860
diff
changeset
|
340 */ |
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
|
341 public void interpolateW( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
342 final Row other, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
343 final double km, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
344 final double [] iqs, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
345 final double [] ows, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
346 final WstValueTable table, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
347 final Calculation errors |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
348 ) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
349 final double kmWeight = Linear.factor(km, this.km, other.km); |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
350 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
351 final QPosition qPosition = new QPosition(); |
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
|
352 |
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 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
|
354 if (table.getQPosition(km, iqs[i], qPosition) != null) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
355 final double wt = getW(qPosition); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
356 final double wo = other.getW(qPosition); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
357 if (Double.isNaN(wt) || Double.isNaN(wo)) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
358 if (errors != null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
359 errors.addProblem( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
360 km, "cannot.find.w.for.q", iqs[i]); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
361 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
362 ows[i] = Double.NaN; |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
363 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
364 else { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
365 ows[i] = Linear.weight(kmWeight, wt, wo); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
366 } |
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
|
367 } |
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 else { |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
369 if (errors != null) { |
2166
2898b1ff6013
I18N for WINFO calculation result messages.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1939
diff
changeset
|
370 errors.addProblem(km, "cannot.find.q", iqs[i]); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
371 } |
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
|
372 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
|
373 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
374 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
375 } |
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 |
1938
1d991c91285b
Refactored the code of the 'berechnete Abflusskurve' to be reusable in the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1937
diff
changeset
|
377 |
1d991c91285b
Refactored the code of the 'berechnete Abflusskurve' to be reusable in the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1937
diff
changeset
|
378 public SplineFunction createSpline( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
379 final WstValueTable table, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
380 final Calculation errors |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
381 ) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
382 final double[][] sortedWQ = getSortedWQ(table, errors); |
7000
7a7cb22395b4
Fix for flys/issue1018: Sort the pairs of (q, w) in q before creating a spline also in case of non interpolation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6923
diff
changeset
|
383 |
1938
1d991c91285b
Refactored the code of the 'berechnete Abflusskurve' to be reusable in the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1937
diff
changeset
|
384 try { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
385 final SplineInterpolator interpolator = new SplineInterpolator(); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
386 final PolynomialSplineFunction spline = |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
387 interpolator.interpolate(sortedWQ[1], sortedWQ[0]); |
1938
1d991c91285b
Refactored the code of the 'berechnete Abflusskurve' to be reusable in the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1937
diff
changeset
|
388 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
389 return new SplineFunction(spline, sortedWQ[1], this.ws); |
1938
1d991c91285b
Refactored the code of the 'berechnete Abflusskurve' to be reusable in the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1937
diff
changeset
|
390 } |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
391 catch (final MathIllegalArgumentException miae) { |
1938
1d991c91285b
Refactored the code of the 'berechnete Abflusskurve' to be reusable in the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1937
diff
changeset
|
392 if (errors != null) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
393 errors.addProblem(this.km, "spline.creation.failed"); |
1938
1d991c91285b
Refactored the code of the 'berechnete Abflusskurve' to be reusable in the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1937
diff
changeset
|
394 } |
1d991c91285b
Refactored the code of the 'berechnete Abflusskurve' to be reusable in the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1937
diff
changeset
|
395 log.error("spline creation failed", miae); |
1d991c91285b
Refactored the code of the 'berechnete Abflusskurve' to be reusable in the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1937
diff
changeset
|
396 } |
1d991c91285b
Refactored the code of the 'berechnete Abflusskurve' to be reusable in the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1937
diff
changeset
|
397 return null; |
1d991c91285b
Refactored the code of the 'berechnete Abflusskurve' to be reusable in the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1937
diff
changeset
|
398 } |
1d991c91285b
Refactored the code of the 'berechnete Abflusskurve' to be reusable in the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1937
diff
changeset
|
399 |
1d991c91285b
Refactored the code of the 'berechnete Abflusskurve' to be reusable in the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1937
diff
changeset
|
400 public SplineFunction createSpline( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
401 final Row other, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
402 final double km, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
403 final WstValueTable table, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
404 final Calculation errors |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
405 ) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
406 final double[][] sortedWQ = getSortedWQ(other, km, table, errors); |
6434
898afcce1d0a
Partial fix for flys/1303
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
407 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
408 final SplineInterpolator interpolator = new SplineInterpolator(); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
409 |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
410 try { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
411 final PolynomialSplineFunction spline = |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
412 interpolator.interpolate(sortedWQ[1], sortedWQ[0]); |
1938
1d991c91285b
Refactored the code of the 'berechnete Abflusskurve' to be reusable in the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1937
diff
changeset
|
413 |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
414 return new SplineFunction(spline, sortedWQ[1], sortedWQ[0]); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
415 } |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
416 catch (final MathIllegalArgumentException miae) { |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
417 if (errors != null) { |
2166
2898b1ff6013
I18N for WINFO calculation result messages.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1939
diff
changeset
|
418 errors.addProblem(km, "spline.creation.failed"); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
419 } |
1860
ddd425858169
Improved logging to include exception in fail case of spline interpolation of wst.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1838
diff
changeset
|
420 log.error("spline creation failed", miae); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
421 } |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
422 |
1938
1d991c91285b
Refactored the code of the 'berechnete Abflusskurve' to be reusable in the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1937
diff
changeset
|
423 return null; |
1d991c91285b
Refactored the code of the 'berechnete Abflusskurve' to be reusable in the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1937
diff
changeset
|
424 } |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
425 |
1938
1d991c91285b
Refactored the code of the 'berechnete Abflusskurve' to be reusable in the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1937
diff
changeset
|
426 public double [][] interpolateWQ( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
427 final Row other, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
428 final double km, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
429 final int steps, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
430 final WstValueTable table, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
431 final Calculation errors |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
432 ) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
433 final SplineFunction sf = createSpline(other, km, table, errors); |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
434 |
1938
1d991c91285b
Refactored the code of the 'berechnete Abflusskurve' to be reusable in the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1937
diff
changeset
|
435 return sf != null |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
436 ? sf.sample(steps, km, errors) |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
437 : new double[2][0]; |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
438 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
439 |
1721
eb35570df0e8
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1681
diff
changeset
|
440 |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
441 public double [][] interpolateWQ( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
442 final int steps, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
443 final WstValueTable table, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
444 final Calculation errors |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
445 ) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
446 final SplineFunction sf = createSpline(table, errors); |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
447 |
1938
1d991c91285b
Refactored the code of the 'berechnete Abflusskurve' to be reusable in the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1937
diff
changeset
|
448 return sf != null |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
449 ? sf.sample(steps, this.km, errors) |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
450 : new double[2][0]; |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
451 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
452 |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
453 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
454 public double getW(final QPosition qPosition) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
455 final int index = qPosition.index; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
456 final 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
|
457 |
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
|
458 return weight == 1.0 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
459 ? this.ws[index] |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
460 : Linear.weight(weight, this.ws[index-1], this.ws[index]); |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
461 } |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
462 |
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
|
463 public double getW( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
464 final Row other, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
465 final double km, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
466 final QPosition qPosition |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
467 ) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
468 final double kmWeight = Linear.factor(km, this.km, other.km); |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
469 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
470 final int index = qPosition.index; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
471 final 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
|
472 |
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
|
473 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
|
474 |
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
|
475 if (weight == 1.0) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
476 tw = this.ws[index]; |
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
|
477 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
|
478 } |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
479 else { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
480 tw = Linear.weight(weight, this.ws[index-1], this.ws[index]); |
742
c09c9e05ecfa
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
704
diff
changeset
|
481 ow = Linear.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
|
482 } |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
483 |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
484 return Linear.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
|
485 } |
1937
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
486 |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
487 public double [] findQsForW( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
488 final double w, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
489 final WstValueTable table, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
490 final Calculation errors |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
491 ) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
492 log.debug("Find Qs for given W at tabulated km " + this.km); |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
493 return findQsForW(w, getSortedWQ(table, errors)); |
1937
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
494 } |
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
495 |
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
496 public double [] findQsForW( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
497 final Row other, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
498 final double w, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
499 final double km, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
500 final WstValueTable table, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
501 final Calculation errors |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
502 ) { |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
503 log.debug("Find Qs for given W at non-tabulated km " + km); |
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
504 return findQsForW(w, getSortedWQ(other, km, table, errors)); |
1937
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
505 } |
2423
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
506 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
507 public double [] getMinMaxW(final double [] result) { |
2423
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
508 double minW = Double.MAX_VALUE; |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
509 double maxW = -Double.MAX_VALUE; |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
510 for (int i = 0; i < this.ws.length; ++i) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
511 final double w = this.ws[i]; |
2423
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
512 if (w < minW) minW = w; |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
513 if (w > maxW) maxW = w; |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
514 } |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
515 result[0] = minW; |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
516 result[1] = maxW; |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
517 return result; |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
518 } |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
519 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
520 public double [] getMinMaxW(final Row other, final double km, final double [] result) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
521 final double [] m1 = this .getMinMaxW(new double [2]); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
522 final double [] m2 = other.getMinMaxW(new double [2]); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
523 final double factor = Linear.factor(km, this.km, other.km); |
2423
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
524 result[0] = Linear.weight(factor, m1[0], m2[0]); |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
525 result[1] = Linear.weight(factor, m1[1], m2[1]); |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
526 return result; |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
527 } |
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
|
528 } // class Row |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
529 |
1838
853cd2120d69
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1721
diff
changeset
|
530 /** Rows in table. */ |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
531 protected List<Row> rows; |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
532 |
1838
853cd2120d69
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1721
diff
changeset
|
533 /** Columns in table. */ |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
534 protected Column [] columns; |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
535 |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
536 public WstValueTable() { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
537 this.rows = new ArrayList<>(); |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
538 } |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
539 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
540 public WstValueTable(final Column [] columns) { |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
541 this(); |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
542 this.columns = columns; |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
543 } |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
544 |
8663
b78ca00d4659
Sorting rows is a prerequisite.
"Tom Gottfried <tom@intevation.de>"
parents:
8662
diff
changeset
|
545 /** |
b78ca00d4659
Sorting rows is a prerequisite.
"Tom Gottfried <tom@intevation.de>"
parents:
8662
diff
changeset
|
546 * @param columns The WST-columns. |
b78ca00d4659
Sorting rows is a prerequisite.
"Tom Gottfried <tom@intevation.de>"
parents:
8662
diff
changeset
|
547 * @param rows A list of Rows that must be sorted by km. |
b78ca00d4659
Sorting rows is a prerequisite.
"Tom Gottfried <tom@intevation.de>"
parents:
8662
diff
changeset
|
548 */ |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
549 public WstValueTable(final Column [] columns, final List<Row> rows) { |
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
|
550 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
|
551 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
|
552 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
553 |
4797
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4119
diff
changeset
|
554 public Column [] getColumns() { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
555 return this.columns; |
4797
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4119
diff
changeset
|
556 } |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4119
diff
changeset
|
557 |
1887
d2e217f438bc
Minor doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1860
diff
changeset
|
558 /** |
d2e217f438bc
Minor doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1860
diff
changeset
|
559 * @param km Given kilometer. |
d2e217f438bc
Minor doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1860
diff
changeset
|
560 * @param qs Given Q values. |
d2e217f438bc
Minor doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1860
diff
changeset
|
561 * @param ws output parameter. |
d2e217f438bc
Minor doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1860
diff
changeset
|
562 */ |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
563 public double [] interpolateW(final double km, final double [] qs, final double [] ws) { |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
564 return interpolateW(km, qs, ws, null); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
565 } |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
566 |
1098
1ea7eb72aaa6
Minor cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
742
diff
changeset
|
567 |
1ea7eb72aaa6
Minor cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
742
diff
changeset
|
568 /** |
1ea7eb72aaa6
Minor cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
742
diff
changeset
|
569 * @param ws (output parameter), gets returned. |
1ea7eb72aaa6
Minor cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
742
diff
changeset
|
570 * @return output parameter ws. |
1ea7eb72aaa6
Minor cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
742
diff
changeset
|
571 */ |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
572 public double [] interpolateW( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
573 final double km, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
574 final double [] qs, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
575 final double [] ws, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
576 final Calculation errors |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
577 ) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
578 int rowIndex = Collections.binarySearch(this.rows, new Row(km)); |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
579 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
580 final QPosition qPosition = new QPosition(); |
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
|
581 |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
582 if (rowIndex >= 0) { // direct row match |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
583 final Row row = this.rows.get(rowIndex); |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
584 for (int i = 0; i < qs.length; ++i) { |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
585 if (getQPosition(km, qs[i], qPosition) == null) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
586 if (errors != null) { |
2166
2898b1ff6013
I18N for WINFO calculation result messages.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1939
diff
changeset
|
587 errors.addProblem(km, "cannot.find.q", qs[i]); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
588 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
589 ws[i] = Double.NaN; |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
590 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
591 else { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
592 if (Double.isNaN(ws[i] = row.getW(qPosition)) |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
593 && errors != null) { |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
594 errors.addProblem( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
595 km, "cannot.find.w.for.q", qs[i]); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
596 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
597 } |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
598 } |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
599 } |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
600 else { // needs bilinear interpolation |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
601 rowIndex = -rowIndex -1; |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
602 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
603 if (rowIndex < 1 || rowIndex >= this.rows.size()) { |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
604 // do not extrapolate |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
605 Arrays.fill(ws, Double.NaN); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
606 if (errors != null) { |
2166
2898b1ff6013
I18N for WINFO calculation result messages.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1939
diff
changeset
|
607 errors.addProblem(km, "km.not.found"); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
608 } |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
609 } |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
610 else { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
611 final Row r1 = this.rows.get(rowIndex-1); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
612 final Row r2 = this.rows.get(rowIndex); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
613 r1.interpolateW(r2, km, qs, ws, this, errors); |
335
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
614 } |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
615 } |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
616 |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
617 return ws; |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
618 } |
64cfbd631f29
Implemented the "Wasserstand/Wasserspiegellagen" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
327
diff
changeset
|
619 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
620 /** |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
621 * Interpolates a W for a km using a Q column position |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
622 */ |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
623 public double interpolateW(final double km, final QPosition qPosition, final Calculation errors) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
624 |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
625 int rowIndex = Collections.binarySearch(this.rows, new Row(km)); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
626 |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
627 if (rowIndex >= 0) { // direct row match |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
628 final Row row = this.rows.get(rowIndex); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
629 return row.getW(qPosition); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
630 } |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
631 else { // needs bilinear interpolation |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
632 rowIndex = -rowIndex - 1; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
633 if ((rowIndex <= 0) || (rowIndex >= this.rows.size())) |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
634 return Double.NaN; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
635 else { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
636 final Row r1 = this.rows.get(rowIndex - 1); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
637 final Row r2 = this.rows.get(rowIndex); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
638 final double w1 = r1.getW(qPosition); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
639 final double w2 = r2.getW(qPosition); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
640 if (Double.isNaN(w1) || Double.isNaN(w2)) |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
641 return Double.NaN; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
642 else { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
643 final double kmWeight = Linear.factor(km, r1.km, r2.km); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
644 return Linear.weight(kmWeight, w1, w2); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
645 } |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
646 } |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
647 } |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
648 } |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
649 |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
650 public double [] getMinMaxQ(final double km) { |
2559
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
651 return getMinMaxQ(km, new double [2]); |
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
652 } |
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
653 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
654 public double [] getMinMaxQ(final double km, final double [] result) { |
2559
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
655 double minQ = Double.MAX_VALUE; |
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
656 double maxQ = -Double.MAX_VALUE; |
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
657 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
658 for (int i = 0; i < this.columns.length; ++i) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
659 final double q = this.columns[i].getQRangeTree().findQ(km); |
2559
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
660 if (!Double.isNaN(q)) { |
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
661 if (q < minQ) minQ = q; |
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
662 if (q > maxQ) maxQ = q; |
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
663 } |
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
664 } |
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
665 |
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
666 if (minQ < Double.MAX_VALUE) { |
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
667 result[0] = minQ; |
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
668 result[1] = maxQ; |
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
669 return result; |
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
670 } |
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
671 |
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
672 return null; |
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
673 } |
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
674 |
2560
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
675 public double [] getMinMaxQ(double from, double to, double step) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
676 final double [] result = new double[2]; |
2560
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
677 |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
678 double minQ = Double.MAX_VALUE; |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
679 double maxQ = -Double.MAX_VALUE; |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
680 |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
681 if (from > to) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
682 final double tmp = from; |
2560
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
683 from = to; |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
684 to = tmp; |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
685 } |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
686 |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
687 step = Math.max(Math.abs(step), 0.0001); |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
688 |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
689 double d = from; |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
690 for (; d <= to; d += step) { |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
691 if (getMinMaxQ(d, result) != null) { |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
692 if (result[0] < minQ) minQ = result[0]; |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
693 if (result[1] > maxQ) maxQ = result[1]; |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
694 } |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
695 } |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
696 |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
697 if (d != to) { |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
698 if (getMinMaxQ(to, result) != null) { |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
699 if (result[0] < minQ) minQ = result[0]; |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
700 if (result[1] > maxQ) maxQ = result[1]; |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
701 } |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
702 } |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
703 |
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
704 return minQ < Double.MAX_VALUE |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
705 ? new double [] { minQ, maxQ } |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
706 : null; |
2560
0d8c97374dc9
WstValueTable: Forget to check in the range method of getMinMaxQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2559
diff
changeset
|
707 } |
2559
407bbc74fe0b
WstValueTable: Symmetrical to getMinMaxW() add two methods to find min/max Q for a given
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2558
diff
changeset
|
708 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
709 public double [] getMinMaxW(final double km) { |
2423
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
710 return getMinMaxW(km, new double [2]); |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
711 |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
712 } |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
713 public double [] getMinMaxW(final double km, final double [] result) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
714 int rowIndex = Collections.binarySearch(this.rows, new Row(km)); |
2423
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
715 |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
716 if (rowIndex >= 0) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
717 return this.rows.get(rowIndex).getMinMaxW(result); |
2423
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
718 } |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
719 |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
720 rowIndex = -rowIndex -1; |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
721 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
722 if (rowIndex < 1 || rowIndex >= this.rows.size()) { |
2423
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
723 // do not extrapolate |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
724 return null; |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
725 } |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
726 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
727 final Row r1 = this.rows.get(rowIndex-1); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
728 final Row r2 = this.rows.get(rowIndex); |
2423
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
729 |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
730 return r1.getMinMaxW(r2, km, result); |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
731 } |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
732 |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
733 public double [] getMinMaxW(double from, double to, double step) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
734 final double [] result = new double[2]; |
2423
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
735 |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
736 double minW = Double.MAX_VALUE; |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
737 double maxW = -Double.MAX_VALUE; |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
738 |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
739 if (from > to) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
740 final double tmp = from; |
2423
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
741 from = to; |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
742 to = tmp; |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
743 } |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
744 |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
745 step = Math.max(Math.abs(step), 0.0001); |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
746 |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
747 double d = from; |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
748 for (; d <= to; d += step) { |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
749 if (getMinMaxW(d, result) != null) { |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
750 if (result[0] < minW) minW = result[0]; |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
751 if (result[1] > maxW) maxW = result[1]; |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
752 } |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
753 } |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
754 |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
755 if (d != to) { |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
756 if (getMinMaxW(to, result) != null) { |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
757 if (result[0] < minW) minW = result[0]; |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
758 if (result[1] > maxW) maxW = result[1]; |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
759 } |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
760 } |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
761 |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
762 return minW < Double.MAX_VALUE |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
763 ? new double [] { minW, maxW } |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
764 : null; |
2423
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
765 } |
ac528b883b47
Picked rev 4070,4074,4076,4080 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2404
diff
changeset
|
766 |
1838
853cd2120d69
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1721
diff
changeset
|
767 /** |
853cd2120d69
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1721
diff
changeset
|
768 * Interpolate W and Q values at a given km. |
853cd2120d69
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1721
diff
changeset
|
769 */ |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
770 public double [][] interpolateWQ(final double km) { |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
771 return interpolateWQ(km, null); |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
772 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
773 |
1838
853cd2120d69
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1721
diff
changeset
|
774 /** |
853cd2120d69
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1721
diff
changeset
|
775 * Interpolate W and Q values at a given km. |
3265
c1f445b94d03
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
776 * |
c1f445b94d03
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
777 * @param errors where to store errors. |
c1f445b94d03
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
778 * |
c1f445b94d03
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
779 * @return double double array, first index Ws, second Qs. |
1838
853cd2120d69
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1721
diff
changeset
|
780 */ |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
781 public double [][] interpolateWQ(final double km, final Calculation errors) { |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
782 return interpolateWQ(km, DEFAULT_Q_STEPS, errors); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
783 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
784 |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
785 |
1860
ddd425858169
Improved logging to include exception in fail case of spline interpolation of wst.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1838
diff
changeset
|
786 /** |
ddd425858169
Improved logging to include exception in fail case of spline interpolation of wst.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1838
diff
changeset
|
787 * Interpolate W and Q values at a given km. |
ddd425858169
Improved logging to include exception in fail case of spline interpolation of wst.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1838
diff
changeset
|
788 */ |
8856 | 789 public double [][] interpolateWQ( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
790 final double km, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
791 final int steps, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
792 final Calculation errors |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
793 ) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
794 int rowIndex = Collections.binarySearch(this.rows, new Row(km)); |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
795 |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
796 if (rowIndex >= 0) { // direct row match |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
797 final Row row = this.rows.get(rowIndex); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
798 return row.interpolateWQ(steps, this, errors); |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
799 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
800 |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
801 rowIndex = -rowIndex -1; |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
802 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
803 if (rowIndex < 1 || rowIndex >= this.rows.size()) { |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
804 // do not extrapolate |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
805 if (errors != null) { |
2166
2898b1ff6013
I18N for WINFO calculation result messages.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1939
diff
changeset
|
806 errors.addProblem(km, "km.not.found"); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
807 } |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
808 return new double[2][0]; |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
809 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
810 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
811 final Row r1 = this.rows.get(rowIndex-1); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
812 final Row r2 = this.rows.get(rowIndex); |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
813 |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
814 return r1.interpolateWQ(r2, km, steps, this, errors); |
339
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
815 } |
4509ba8fae68
Implementation of "Abflusskurve/Abflusstafel" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
335
diff
changeset
|
816 |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
817 public boolean interpolate( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
818 final double km, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
819 final double [] out, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
820 final QPosition qPosition, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
821 final Function qFunction |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
822 ) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
823 final int R1 = this.rows.size()-1; |
427
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
824 |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
825 out[1] = qFunction.value(getQ(qPosition, km)); |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
826 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
827 if (Double.isNaN(out[1])) { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
828 return false; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
829 } |
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
|
830 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
831 final QPosition nPosition = new QPosition(); |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
832 if (getQPosition(km, out[1], nPosition) == null) { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
833 return false; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
834 } |
427
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
835 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
836 int rowIndex = Collections.binarySearch(this.rows, new Row(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
|
837 |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
838 if (rowIndex >= 0) { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
839 // direct row match |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
840 out[0] = this.rows.get(rowIndex).getW(nPosition); |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
841 return !Double.isNaN(out[0]); |
427
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
842 } |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
843 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
844 rowIndex = -rowIndex -1; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
845 |
1681
e5f7f25a511c
fixed flys/issue201
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1098
diff
changeset
|
846 if (rowIndex < 1 || rowIndex > R1) { |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
847 // do not extrapolate |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
848 return false; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
849 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
850 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
851 final Row r1 = this.rows.get(rowIndex-1); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
852 final Row r2 = this.rows.get(rowIndex); |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
853 out[0] = r1.getW(r2, km, nPosition); |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
854 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
855 return !Double.isNaN(out[0]); |
427
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
856 } |
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
857 |
1098
1ea7eb72aaa6
Minor cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
742
diff
changeset
|
858 |
1ea7eb72aaa6
Minor cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
742
diff
changeset
|
859 /** |
1ea7eb72aaa6
Minor cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
742
diff
changeset
|
860 * Look up interpolation of a Q at given positions. |
1ea7eb72aaa6
Minor cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
742
diff
changeset
|
861 * |
1ea7eb72aaa6
Minor cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
742
diff
changeset
|
862 * @param q the non-interpolated Q value. |
1ea7eb72aaa6
Minor cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
742
diff
changeset
|
863 * @param referenceKm the reference km (e.g. gauge position). |
1ea7eb72aaa6
Minor cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
742
diff
changeset
|
864 * @param kms positions for which to interpolate. |
1ea7eb72aaa6
Minor cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
742
diff
changeset
|
865 * @param ws (output) resulting interpolated ws. |
1ea7eb72aaa6
Minor cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
742
diff
changeset
|
866 * @param qs (output) resulting interpolated qs. |
1ea7eb72aaa6
Minor cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
742
diff
changeset
|
867 * @param errors calculation object to store errors. |
1ea7eb72aaa6
Minor cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
742
diff
changeset
|
868 */ |
427
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
869 public QPosition interpolate( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
870 final double q, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
871 final double referenceKm, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
872 final double [] kms, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
873 final double [] ws, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
874 final double [] qs, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
875 final Calculation errors |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
876 ) { |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
877 return interpolate( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
878 q, referenceKm, kms, ws, qs, 0, kms.length, errors); |
649
44175d4720f8
Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
879 } |
44175d4720f8
Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
880 |
6711 | 881 /** |
882 * Interpolate Q at given positions. | |
883 * @param kms positions for which to calculate qs and ws | |
884 * @param ws [out] calculated ws for kms | |
885 * @param qs [out] looked up qs for kms. | |
886 */ | |
649
44175d4720f8
Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
887 public QPosition interpolate( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
888 final double q, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
889 final double referenceKm, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
890 final double [] kms, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
891 final double [] ws, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
892 final double [] qs, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
893 final int startIndex, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
894 final int length, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
895 final Calculation errors |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
896 ) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
897 final QPosition qPosition = getQPosition(referenceKm, q); |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
898 |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
899 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
|
900 // we cannot locate q at km |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
901 Arrays.fill(ws, Double.NaN); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
902 Arrays.fill(qs, Double.NaN); |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
903 if (errors != null) { |
2166
2898b1ff6013
I18N for WINFO calculation result messages.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1939
diff
changeset
|
904 errors.addProblem(referenceKm, "cannot.find.q", q); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
905 } |
427
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
906 return null; |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
907 } |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
908 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
909 final Row kmKey = new Row(); |
645
433f67a076aa
Use an explicit reference km for interpolation now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
910 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
911 final int R1 = this.rows.size()-1; |
645
433f67a076aa
Use an explicit reference km for interpolation now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
912 |
649
44175d4720f8
Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
645
diff
changeset
|
913 for (int i = startIndex, end = startIndex+length; i < end; ++i) { |
458
523a256451cd
Use unsharp km lookup (epsilon = 0.0001).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
443
diff
changeset
|
914 |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
915 if (Double.isNaN(qs[i] = getQ(qPosition, kms[i]))) { |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
916 if (errors != null) { |
2166
2898b1ff6013
I18N for WINFO calculation result messages.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1939
diff
changeset
|
917 errors.addProblem(kms[i], "cannot.find.q", q); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
918 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
919 ws[i] = Double.NaN; |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
920 continue; |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
921 } |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
922 |
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
923 kmKey.km = kms[i]; |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
924 int rowIndex = Collections.binarySearch(this.rows, kmKey); |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
925 |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
926 if (rowIndex >= 0) { |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
927 // direct row match |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
928 if (Double.isNaN(ws[i] = this.rows.get(rowIndex).getW(qPosition)) |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
929 && errors != null) { |
2166
2898b1ff6013
I18N for WINFO calculation result messages.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1939
diff
changeset
|
930 errors.addProblem(kms[i], "cannot.find.w.for.q", q); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
931 } |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
932 continue; |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
933 } |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
934 |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
935 rowIndex = -rowIndex -1; |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
936 |
1681
e5f7f25a511c
fixed flys/issue201
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1098
diff
changeset
|
937 if (rowIndex < 1 || rowIndex > R1) { |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
938 // do not extrapolate |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
939 if (errors != null) { |
2166
2898b1ff6013
I18N for WINFO calculation result messages.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1939
diff
changeset
|
940 errors.addProblem(kms[i], "km.not.found"); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
941 } |
1888
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
942 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
|
943 continue; |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
944 } |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
945 final Row r1 = this.rows.get(rowIndex-1); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
946 final Row r2 = this.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
|
947 |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
948 if (Double.isNaN(ws[i] = r1.getW(r2, kms[i], qPosition)) |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
949 && errors != null) { |
2166
2898b1ff6013
I18N for WINFO calculation result messages.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1939
diff
changeset
|
950 errors.addProblem(kms[i], "cannot.find.w.for.q", q); |
686
3dc61e00385e
Merged with trunk and introduced hashing of computed values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
655
diff
changeset
|
951 } |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
952 } |
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
953 |
427
909196be11a0
First step to calculate "W fuer ungleichwertige Abfluesse" correctly. flys/issue55
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
954 return qPosition; |
426
c6b7ca0febcb
Fix step to fix issue69: Do the right calculation
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
955 } |
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
|
956 |
1888
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
957 /** |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
958 * Linearly interpolate w at a km at a column of two rows. |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
959 * |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
960 * @param km position for which to interpolate. |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
961 * @param row1 first row. |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
962 * @param row2 second row. |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
963 * @param col column-index at which to look. |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
964 * |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
965 * @return Linearly interpolated w, NaN if one of the given rows was null. |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
966 */ |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
967 public static double linearW(final double km, final Row row1, final Row row2, final int col) { |
1888
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
968 if (row1 == null || row2 == null) { |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
969 return Double.NaN; |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
970 } |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
971 |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
972 return Linear.linear(km, |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
973 row1.km, row2.km, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
974 row1.ws[col], row2.ws[col]); |
1888
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
975 } |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
976 |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
977 /** |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
978 * Do interpolation/lookup of W and Q within columns (i.e. ignoring values |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
979 * of other columns). |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
980 * @param km position (km) at which to interpolate/lookup. |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
981 * @return [[q0, q1, .. qx] , [w0, w1, .. wx]] (can contain NaNs) |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
982 */ |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
983 public double [][] interpolateWQColumnwise(final double km) { |
1919
9bec7d2f8c35
Prevent ArrayIndexOutOfBounds, log method entry.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1907
diff
changeset
|
984 log.debug("WstValueTable.interpolateWQColumnwise"); |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
985 final double [] qs = new double[this.columns.length]; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
986 final double [] ws = new double[this.columns.length]; |
1888
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
987 |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
988 // Find out row from where we will start searching. |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
989 int rowIndex = Collections.binarySearch(this.rows, new Row(km)); |
1888
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
990 |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
991 if (rowIndex < 0) { |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
992 rowIndex = -rowIndex -1; |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
993 } |
2248 | 994 |
995 // TODO Beyond definition, we could stop more clever. | |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
996 if (rowIndex >= this.rows.size()) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
997 rowIndex = this.rows.size() -1; |
1937
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
998 } |
1888
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
999 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1000 final Row startRow = this.rows.get(rowIndex); |
1888
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1001 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1002 for (int col = 0; col < this.columns.length; col++) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1003 qs[col] = this.columns[col].getQRangeTree().findQ(km); |
7015
a9ff696c2d18
Fixed misuse of x !=/== Double.NaN
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7000
diff
changeset
|
1004 if (startRow.km == km && !Double.isNaN(startRow.ws[col])) { |
1888
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1005 // Great. W is defined at km. |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1006 ws[col] = startRow.ws[col]; |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1007 continue; |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1008 } |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1009 |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1010 // Search neighbouring rows that define w at this col. |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1011 Row rowBefore = null; |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1012 Row rowAfter = null; |
1899
d002198c64a2
Removed logging noise, find better suited rows for W interpolation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1888
diff
changeset
|
1013 for (int before = rowIndex -1; before >= 0; before--) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1014 if (!Double.isNaN(this.rows.get(before).ws[col])) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1015 rowBefore = this.rows.get(before); |
1888
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1016 break; |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1017 } |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1018 } |
2248 | 1019 if (rowBefore != null) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1020 for (int after = rowIndex, R = this.rows.size(); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1021 after < R; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1022 after++ |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1023 ) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1024 if (!Double.isNaN(this.rows.get(after).ws[col])) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1025 rowAfter = this.rows.get(after); |
2248 | 1026 break; |
1027 } | |
1888
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1028 } |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1029 } |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1030 |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1031 ws[col] = linearW(km, rowBefore, rowAfter, col); |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1032 } |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1033 |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1034 return new double [][] {qs, ws}; |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1035 } |
abf5da3b285c
Added new (at fixed columns) interpolation mechanism.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1887
diff
changeset
|
1036 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1037 public double [] findQsForW(final double km, final double w, final Calculation errors) { |
1937
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
1038 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1039 int rowIndex = Collections.binarySearch(this.rows, new Row(km)); |
1937
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
1040 |
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
1041 if (rowIndex >= 0) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1042 return this.rows.get(rowIndex).findQsForW(w, this, errors); |
1937
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
1043 } |
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
1044 |
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
1045 rowIndex = -rowIndex - 1; |
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
1046 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1047 if (rowIndex < 1 || rowIndex >= this.rows.size()) { |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1048 // Do not extrapolate. |
1937
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
1049 return new double[0]; |
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
1050 } |
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
1051 |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1052 // Needs bilinear interpolation. |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1053 final Row r1 = this.rows.get(rowIndex-1); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1054 final Row r2 = this.rows.get(rowIndex); |
1937
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
1055 |
8704
93a31cfb18c0
(issue1787) Sort WQ data locally over Q bevor lookup of Qs for given W.
Tom Gottfried <tom@intevation.de>
parents:
8664
diff
changeset
|
1056 return r1.findQsForW(r2, w, km, this, errors); |
1937
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
1057 } |
f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1919
diff
changeset
|
1058 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1059 protected SplineFunction createSpline(final double km, final Calculation errors) { |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1060 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1061 int rowIndex = Collections.binarySearch(this.rows, new Row(km)); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1062 |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1063 if (rowIndex >= 0) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1064 final SplineFunction sf = this.rows.get(rowIndex).createSpline(this, errors); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1065 if (sf == null && errors != null) { |
2166
2898b1ff6013
I18N for WINFO calculation result messages.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1939
diff
changeset
|
1066 errors.addProblem(km, "cannot.create.wq.relation"); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1067 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1068 return sf; |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1069 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1070 |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1071 rowIndex = -rowIndex - 1; |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1072 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1073 if (rowIndex < 1 || rowIndex >= this.rows.size()) { |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1074 // Do not extrapolate. |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1075 if (errors != null) { |
2166
2898b1ff6013
I18N for WINFO calculation result messages.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1939
diff
changeset
|
1076 errors.addProblem(km, "km.not.found"); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1077 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1078 return null; |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1079 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1080 |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1081 // Needs bilinear interpolation. |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1082 final Row r1 = this.rows.get(rowIndex-1); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1083 final Row r2 = this.rows.get(rowIndex); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1084 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1085 final SplineFunction sf = r1.createSpline(r2, km, this, errors); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1086 if (sf == null && errors != null) { |
2166
2898b1ff6013
I18N for WINFO calculation result messages.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1939
diff
changeset
|
1087 errors.addProblem(km, "cannot.create.wq.relation"); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1088 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1089 |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1090 return sf; |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1091 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1092 |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1093 /** 'Bezugslinienverfahren' */ |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1094 public double [][] relateWs( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1095 final double km1, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1096 final double km2, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1097 final Calculation errors |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1098 ) { |
2186
ec2574eb2d32
Added calculation class for "Bezugslinienverfahren" to created by WINFOArtifact.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2166
diff
changeset
|
1099 return relateWs(km1, km2, RELATE_WS_SAMPLES, errors); |
ec2574eb2d32
Added calculation class for "Bezugslinienverfahren" to created by WINFOArtifact.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2166
diff
changeset
|
1100 } |
ec2574eb2d32
Added calculation class for "Bezugslinienverfahren" to created by WINFOArtifact.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2166
diff
changeset
|
1101 |
2330
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1102 private static class ErrorHandler { |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1103 |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1104 boolean hasErrors; |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1105 Calculation errors; |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1106 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1107 ErrorHandler(final Calculation errors) { |
2330
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1108 this.errors = errors; |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1109 } |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1110 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1111 void error(final double km, final String key, final Object ... args) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1112 if (this.errors != null && !this.hasErrors) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1113 this.hasErrors = true; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1114 this.errors.addProblem(km, key, args); |
2330
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1115 } |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1116 } |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1117 } // class ErrorHandler |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1118 |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1119 |
2186
ec2574eb2d32
Added calculation class for "Bezugslinienverfahren" to created by WINFOArtifact.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2166
diff
changeset
|
1120 /* TODO: Add optimized methods of relateWs to relate one |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2560
diff
changeset
|
1121 * start km to many end kms. The index generation/spline stuff for |
2186
ec2574eb2d32
Added calculation class for "Bezugslinienverfahren" to created by WINFOArtifact.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2166
diff
changeset
|
1122 * the start km is always the same. |
ec2574eb2d32
Added calculation class for "Bezugslinienverfahren" to created by WINFOArtifact.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2166
diff
changeset
|
1123 */ |
ec2574eb2d32
Added calculation class for "Bezugslinienverfahren" to created by WINFOArtifact.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2166
diff
changeset
|
1124 public double [][] relateWs( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1125 final double km1, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1126 final double km2, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1127 final int numSamples, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1128 final Calculation errors |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1129 ) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1130 final SplineFunction sf1 = createSpline(km1, errors); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1131 if (sf1 == null) { |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1132 return new double[2][0]; |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1133 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1134 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1135 final SplineFunction sf2 = createSpline(km2, errors); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1136 if (sf2 == null) { |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1137 return new double[2][0]; |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1138 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1139 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1140 final PolynomialSplineFunction iQ1 = sf1.createIndexQRelation(); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1141 if (iQ1 == null) { |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1142 if (errors != null) { |
2166
2898b1ff6013
I18N for WINFO calculation result messages.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1939
diff
changeset
|
1143 errors.addProblem(km1, "cannot.create.index.q.relation"); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1144 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1145 return new double[2][0]; |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1146 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1147 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1148 final PolynomialSplineFunction iQ2 = sf2.createIndexQRelation(); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1149 if (iQ2 == null) { |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1150 if (errors != null) { |
2166
2898b1ff6013
I18N for WINFO calculation result messages.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1939
diff
changeset
|
1151 errors.addProblem(km2, "cannot.create.index.q.relation"); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1152 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1153 return new double[2][0]; |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1154 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1155 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1156 final int N = Math.min(sf1.splineQs.length, sf2.splineQs.length); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1157 final double stepWidth = N/(double)numSamples; |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1158 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1159 final PolynomialSplineFunction qW1 = sf1.spline; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1160 final PolynomialSplineFunction qW2 = sf2.spline; |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1161 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1162 final TDoubleArrayList ws1 = new TDoubleArrayList(numSamples); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1163 final TDoubleArrayList ws2 = new TDoubleArrayList(numSamples); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1164 final TDoubleArrayList qs1 = new TDoubleArrayList(numSamples); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1165 final TDoubleArrayList qs2 = new TDoubleArrayList(numSamples); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1166 |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1167 final ErrorHandler err = new ErrorHandler(errors); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1168 |
2316
61b32380ffdb
Be more conservative about arrays and indices in "Bezugslinienverfahren".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2282
diff
changeset
|
1169 int i = 0; |
61b32380ffdb
Be more conservative about arrays and indices in "Bezugslinienverfahren".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2282
diff
changeset
|
1170 for (double p = 0d; p <= N-1; p += stepWidth, ++i) { |
2330
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1171 |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1172 double q1; |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1173 try { |
2330
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1174 q1 = iQ1.value(p); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1175 } |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1176 catch (final ArgumentOutsideDomainException aode) { |
2330
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1177 err.error(km1, "w.w.qkm1.failed", p); |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1178 continue; |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1179 } |
2330
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1180 |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1181 double w1; |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1182 try { |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1183 w1 = qW1.value(q1); |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1184 } |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1185 catch (final ArgumentOutsideDomainException aode) { |
2403
177b0c91928d
'Bezugslinienverfahren': Improve the error messages even more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2330
diff
changeset
|
1186 err.error(km1, "w.w.wkm1.failed", q1, p); |
2330
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1187 continue; |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1188 } |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1189 |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1190 double q2; |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1191 try { |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1192 q2 = iQ2.value(p); |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1193 } |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1194 catch (final ArgumentOutsideDomainException aode) { |
2330
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1195 err.error(km2, "w.w.qkm2.failed", p); |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1196 continue; |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1197 } |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1198 |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1199 double w2; |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1200 try { |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1201 w2 = qW2.value(q2); |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1202 } |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1203 catch (final ArgumentOutsideDomainException aode) { |
2403
177b0c91928d
'Bezugslinienverfahren': Improve the error messages even more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2330
diff
changeset
|
1204 err.error(km2, "w.w.wkm2.failed", q2, p); |
2330
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1205 continue; |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1206 } |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1207 |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1208 ws1.add(w1); |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1209 ws2.add(w2); |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1210 qs1.add(q1); |
594885703687
Picked changes r4015:4026 from trunk.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2316
diff
changeset
|
1211 qs2.add(q2); |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1212 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1213 |
2316
61b32380ffdb
Be more conservative about arrays and indices in "Bezugslinienverfahren".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2282
diff
changeset
|
1214 return new double [][] { |
61b32380ffdb
Be more conservative about arrays and indices in "Bezugslinienverfahren".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2282
diff
changeset
|
1215 ws1.toNativeArray(), |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2560
diff
changeset
|
1216 qs1.toNativeArray(), |
2316
61b32380ffdb
Be more conservative about arrays and indices in "Bezugslinienverfahren".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2282
diff
changeset
|
1217 ws2.toNativeArray(), |
61b32380ffdb
Be more conservative about arrays and indices in "Bezugslinienverfahren".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2282
diff
changeset
|
1218 qs2.toNativeArray() }; |
1939
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1219 } |
2730d17df021
Added the implementation of the 'Bezugslinienverfahren'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1938
diff
changeset
|
1220 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1221 public QPosition getQPosition(final double km, final double q) { |
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
|
1222 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
|
1223 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
1224 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1225 public QPosition getQPosition(final double km, final double q, final QPosition qPosition) { |
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
|
1226 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1227 if (this.columns.length == 0) { |
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
|
1228 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
|
1229 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
1230 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1231 double qLast = this.columns[0].getQRangeTree().findQ(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
|
1232 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
1233 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
|
1234 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
|
1235 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
1236 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1237 for (int i = 1; i < this.columns.length; ++i) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1238 final double qCurrent = this.columns[i].getQRangeTree().findQ(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
|
1239 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
|
1240 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
|
1241 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
1242 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
1243 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
|
1244 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
|
1245 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
|
1246 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
1247 if (q > qMin && q < qMax) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1248 final double weight = Linear.factor(q, qLast, qCurrent); |
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
|
1249 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
|
1250 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
1251 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
|
1252 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
1253 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
1254 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
|
1255 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
1256 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1257 public double getQIndex(final int index, final double km) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1258 return this.columns[index].getQRangeTree().findQ(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
|
1259 } |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
1260 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1261 public double getQ(final QPosition qPosition, final double km) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1262 final int index = qPosition.index; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1263 final double weight = qPosition.weight; |
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
|
1264 |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
1265 if (weight == 1d) { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1266 return this.columns[index].getQRangeTree().findQ(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
|
1267 } |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1268 final double q1 = this.columns[index-1].getQRangeTree().findQ(km); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1269 final double q2 = this.columns[index ].getQRangeTree().findQ(km); |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
649
diff
changeset
|
1270 return Linear.weight(weight, q1, q2); |
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
|
1271 } |
3736
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1272 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1273 public double [][] interpolateTabulated(final double km) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1274 return interpolateTabulated(km, new double[2][this.columns.length]); |
3736
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1275 } |
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1276 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1277 public double [][] interpolateTabulated(final double km, final double [][] result) { |
3736
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1278 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1279 int rowIndex = Collections.binarySearch(this.rows, new Row(km)); |
3736
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1280 |
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1281 if (rowIndex >= 0) { |
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1282 // Direct hit -> copy ws. |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1283 final Row row = this.rows.get(rowIndex); |
3736
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1284 System.arraycopy( |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1285 row.ws, 0, result[0], 0, |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1286 Math.min(row.ws.length, result[0].length)); |
3736
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1287 } |
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1288 else { |
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1289 rowIndex = -rowIndex -1; |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1290 if (rowIndex < 1 || rowIndex >= this.rows.size()) { |
3736
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1291 // Out of bounds. |
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1292 return null; |
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1293 } |
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1294 // Interpolate ws. |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1295 final Row r1 = this.rows.get(rowIndex-1); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1296 final Row r2 = this.rows.get(rowIndex); |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1297 final double factor = Linear.factor(km, r1.km, r2.km); |
3736
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1298 Linear.weight(factor, r1.ws, r2.ws, result[0]); |
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1299 } |
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1300 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1301 final double [] qs = result[1]; |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1302 for (int i = Math.min(qs.length, this.columns.length)-1; i >= 0; --i) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1303 qs[i] = this.columns[i].getQRangeTree().findQ(km); |
3736
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1304 } |
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1305 return result; |
da1969b05292
WST tables: Added interpolation of tabulated values only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3271
diff
changeset
|
1306 } |
3743
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3736
diff
changeset
|
1307 |
4119
760e2fe00138
Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3969
diff
changeset
|
1308 |
6923
254a3f3556ee
WstValueTable: Add method to find out wether the Qs are 'fake'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6711
diff
changeset
|
1309 /** True if no QRange is given or Q equals zero. */ |
254a3f3556ee
WstValueTable: Add method to find out wether the Qs are 'fake'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6711
diff
changeset
|
1310 public boolean hasEmptyQ() { |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1311 for (final Column column: this.columns) { |
6923
254a3f3556ee
WstValueTable: Add method to find out wether the Qs are 'fake'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6711
diff
changeset
|
1312 if (column.getQRangeTree() == null) { |
254a3f3556ee
WstValueTable: Add method to find out wether the Qs are 'fake'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6711
diff
changeset
|
1313 return true; |
254a3f3556ee
WstValueTable: Add method to find out wether the Qs are 'fake'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6711
diff
changeset
|
1314 } |
254a3f3556ee
WstValueTable: Add method to find out wether the Qs are 'fake'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6711
diff
changeset
|
1315 else { |
254a3f3556ee
WstValueTable: Add method to find out wether the Qs are 'fake'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6711
diff
changeset
|
1316 if (Math.abs(column.getQRangeTree().maxQ()) <= 0.01d) { |
254a3f3556ee
WstValueTable: Add method to find out wether the Qs are 'fake'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6711
diff
changeset
|
1317 return true; |
254a3f3556ee
WstValueTable: Add method to find out wether the Qs are 'fake'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6711
diff
changeset
|
1318 } |
254a3f3556ee
WstValueTable: Add method to find out wether the Qs are 'fake'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6711
diff
changeset
|
1319 } |
254a3f3556ee
WstValueTable: Add method to find out wether the Qs are 'fake'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6711
diff
changeset
|
1320 } |
254a3f3556ee
WstValueTable: Add method to find out wether the Qs are 'fake'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6711
diff
changeset
|
1321 |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1322 if (this.columns.length == 0) { |
6923
254a3f3556ee
WstValueTable: Add method to find out wether the Qs are 'fake'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6711
diff
changeset
|
1323 log.warn("No columns in WstValueTable."); |
254a3f3556ee
WstValueTable: Add method to find out wether the Qs are 'fake'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6711
diff
changeset
|
1324 } |
254a3f3556ee
WstValueTable: Add method to find out wether the Qs are 'fake'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6711
diff
changeset
|
1325 |
254a3f3556ee
WstValueTable: Add method to find out wether the Qs are 'fake'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6711
diff
changeset
|
1326 return false; |
254a3f3556ee
WstValueTable: Add method to find out wether the Qs are 'fake'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6711
diff
changeset
|
1327 } |
254a3f3556ee
WstValueTable: Add method to find out wether the Qs are 'fake'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6711
diff
changeset
|
1328 |
254a3f3556ee
WstValueTable: Add method to find out wether the Qs are 'fake'
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6711
diff
changeset
|
1329 |
4119
760e2fe00138
Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3969
diff
changeset
|
1330 /** Find ranges that are between km1 and km2 (inclusive?) */ |
9286
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1331 public List<Range> findSegments(final double km1, final double km2) { |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1332 return this.columns.length != 0 |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1333 ? this.columns[this.columns.length-1].getQRangeTree().findSegments(km1, km2) |
bcbae86ce7b3
Improved flood duration curve calculation as specified by BfG
mschaefer
parents:
8856
diff
changeset
|
1334 : Collections.<Range>emptyList(); |
3743
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3736
diff
changeset
|
1335 } |
326
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1336 } |
07eba6d3b4a5
Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1337 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |