annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java @ 4655:cd44d28d0fbc

Move the access to artifact data to the Access object Use BedHeightAccess class to receive the data from the artifact. This abstracts the data access from the actual artifact.
author Björn Ricks <bjoern.ricks@intevation.de>
date Tue, 11 Dec 2012 09:44:04 +0100
parents 5642a83420f2
children
rev   line source
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.math;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import java.util.ArrayList;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 import java.util.List;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import java.io.Serializable;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 import org.apache.commons.math.analysis.interpolation.SplineInterpolator;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 import org.apache.commons.math.ArgumentOutsideDomainException;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13
649
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
14 import org.apache.commons.math.exception.MathIllegalArgumentException;
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
15
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import org.apache.log4j.Logger;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17
674
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 662
diff changeset
18 import de.intevation.flys.artifacts.model.Calculation;
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 662
diff changeset
19
1672
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 742
diff changeset
20 import de.intevation.flys.utils.DoubleUtil;
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 742
diff changeset
21
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 public class BackJumpCorrector
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 implements Serializable
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 private static Logger log = Logger.getLogger(BackJumpCorrector.class);
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 protected ArrayList<Double> backjumps;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 protected double [] corrected;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 public BackJumpCorrector() {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 backjumps = new ArrayList<Double>();
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 public boolean hasBackJumps() {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 return !backjumps.isEmpty();
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 public List<Double> getBackJumps() {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 return backjumps;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 public double [] getCorrected() {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 return corrected;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46
674
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 662
diff changeset
47 public boolean doCorrection(
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 662
diff changeset
48 double [] km,
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 662
diff changeset
49 double [] ws,
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 662
diff changeset
50 Calculation errors
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 662
diff changeset
51 ) {
1672
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 742
diff changeset
52 boolean wsUp = DoubleUtil.isIncreasing(ws);
642
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
53
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
54 if (wsUp) {
1672
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 742
diff changeset
55 km = DoubleUtil.swapClone(km);
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 742
diff changeset
56 ws = DoubleUtil.swapClone(ws);
406
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
57 }
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
58
1672
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 742
diff changeset
59 boolean kmUp = DoubleUtil.isIncreasing(km);
642
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
60
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
61 if (!kmUp) {
1672
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 742
diff changeset
62 km = DoubleUtil.sumDiffs(km);
642
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
63 }
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
64
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
65 if (log.isDebugEnabled()) {
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
66 log.debug("BackJumpCorrector.doCorrection ------- enter");
1672
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 742
diff changeset
67 log.debug(" km increasing: " + DoubleUtil.isIncreasing(km));
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 742
diff changeset
68 log.debug(" ws increasing: " + DoubleUtil.isIncreasing(ws));
642
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
69 log.debug("BackJumpCorrector.doCorrection ------- leave");
406
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
70 }
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
71
674
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 662
diff changeset
72 boolean hasBackJumps = doCorrectionClean(km, ws, errors);
406
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
73
642
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
74 if (hasBackJumps && wsUp) {
406
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
75 // mirror back
1672
0b6dac664bbb Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 742
diff changeset
76 DoubleUtil.swap(corrected);
406
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
77 }
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
78
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
79 return hasBackJumps;
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
80 }
663aa18bee7f Back jump correction should work now for both flow directions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 343
diff changeset
81
674
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 662
diff changeset
82 protected boolean doCorrectionClean(
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 662
diff changeset
83 double [] km,
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 662
diff changeset
84 double [] ws,
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 662
diff changeset
85 Calculation errors
d5f9ba1d055f Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 662
diff changeset
86 ) {
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 int N = km.length;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 if (N != ws.length) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 throw new IllegalArgumentException("km.length != ws.length");
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 if (N < 2) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 return false;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 SplineInterpolator interpolator = null;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 for (int i = 1; i < N; ++i) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 if (ws[i] <= ws[i-1]) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 // no back jump
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 continue;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 backjumps.add(km[i]);
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 if (corrected == null) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 // lazy cloning
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 ws = corrected = (double [])ws.clone();
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110
1674
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
111 double above = aboveWaterKM(km, ws, i);
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112
1674
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
113 if (Double.isNaN(above)) { // run over start km
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
114 // fill all previous
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115 for (int j = 0; j < i; ++j) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
116 ws[j] = ws[i];
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
118 continue;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
119 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120
1674
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
121 double distance = Math.abs(km[i] - above);
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
122
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123 double quarterDistance = 0.25*distance;
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124
1674
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
125 double start = above - quarterDistance;
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
126
1674
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
127 double startHeight = DoubleUtil.interpolateSorted(km, ws, start);
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
128
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
129 if (Double.isNaN(startHeight)) {
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
130 // run over start km
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
131 startHeight = ws[0];
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
132 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
133
1674
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
134 double between = above + quarterDistance;
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
135
1676
6e840e213fdf Backjump correction: Finally looks fine.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1674
diff changeset
136 double aboveHeight = ws[i] + 0.25*(startHeight - ws[i]);
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
137
1676
6e840e213fdf Backjump correction: Finally looks fine.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1674
diff changeset
138 double [] x = { start, above, between };
6e840e213fdf Backjump correction: Finally looks fine.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1674
diff changeset
139 double [] y = { startHeight, aboveHeight, ws[i] };
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
140
642
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
141 if (log.isDebugEnabled()) {
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
142 for (int j = 0; j < x.length; ++j) {
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
143 log.debug(" " + x[j] + " -> " + y[j]);
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
144 }
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
145 }
2dbbb5be30a1 Re-eanbled the calculation of the backjump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 406
diff changeset
146
1674
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
147 if (interpolator == null) {
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
148 interpolator = new SplineInterpolator();
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
149 }
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
150
649
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
151 PolynomialSplineFunction spline;
742
c09c9e05ecfa Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 674
diff changeset
152
649
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
153 try {
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
154 spline = interpolator.interpolate(x, y);
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
155 }
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
156 catch (MathIllegalArgumentException miae) {
2166
2898b1ff6013 I18N for WINFO calculation result messages.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1676
diff changeset
157 errors.addProblem("spline.creation.failed");
649
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
158 log.error(miae);
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
159 continue;
44175d4720f8 Fix crashes in back jump correction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 642
diff changeset
160 }
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 try {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163 if (log.isDebugEnabled()) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164 log.debug("spline points:");
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165 for (int j = 0; j < x.length; ++j) {
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
166 log.debug(x[j] + " " + y[j] + " " + spline.value(x[j]));
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
168 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
169
1676
6e840e213fdf Backjump correction: Finally looks fine.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1674
diff changeset
170 int j = i-1;
6e840e213fdf Backjump correction: Finally looks fine.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1674
diff changeset
171
6e840e213fdf Backjump correction: Finally looks fine.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1674
diff changeset
172 for (; j >= 0 && km[j] >= between; --j) {
6e840e213fdf Backjump correction: Finally looks fine.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1674
diff changeset
173 ws[j] = ws[i];
6e840e213fdf Backjump correction: Finally looks fine.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1674
diff changeset
174 }
6e840e213fdf Backjump correction: Finally looks fine.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1674
diff changeset
175
6e840e213fdf Backjump correction: Finally looks fine.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1674
diff changeset
176 for (; j >= 0 && ws[j] < startHeight; --j) {
1674
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
177 ws[j] = spline.value(km[j]);
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
179 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
180 catch (ArgumentOutsideDomainException aode) {
2166
2898b1ff6013 I18N for WINFO calculation result messages.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1676
diff changeset
181 errors.addProblem("spline.interpolation.failed");
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
182 log.error("spline interpolation failed", aode);
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
183 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
184 } // for all km
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
185
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
186 return !backjumps.isEmpty();
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
187 }
1674
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
188
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
189
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
190 protected static double aboveWaterKM(
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2166
diff changeset
191 double [] km,
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2166
diff changeset
192 double [] ws,
1674
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
193 int wIndex
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
194 ) {
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
195 double w = ws[wIndex];
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
196
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
197 while (--wIndex >= 0) {
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
198 // still under water
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
199 if (ws[wIndex] < w) continue;
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
200
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
201 if (ws[wIndex] > w) {
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
202 // f(ws[wIndex]) = km[wIndex]
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
203 // f(ws[wIndex+1]) = km[wIndex+1]
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
204 return Linear.linear(
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
205 w,
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
206 ws[wIndex], ws[wIndex+1],
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
207 km[wIndex], km[wIndex+1]);
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
208 }
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
209 else {
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
210 return km[wIndex];
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
211 }
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
212 }
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
213
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
214 return Double.NaN;
b5209452f6bb flys/issue31: Simplified the back jump correction code a lot.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1672
diff changeset
215 }
343
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
216 }
f165c7d5d6db Implementation of the "Ruecksprungkorrektur" to be done in "W fuer angepassten Abflusslaengschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
217 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org