annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java @ 668:5523f5b889a8

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

http://dive4elements.wald.intevation.org