Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixCalculation.java @ 9099:850ce16034e9
2.3.4.1.10 Berechnung mit Start-km > End-km
author | gernotbelger |
---|---|
date | Mon, 28 May 2018 13:22:45 +0200 |
parents | 6650485c2c9b |
children | 202fd59b4f21 |
rev | line source |
---|---|
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5741
diff
changeset
|
9 package org.dive4elements.river.artifacts.model.fixings; |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import java.util.ArrayList; |
2744
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
12 import java.util.Date; |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
13 import java.util.HashMap; |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
14 import java.util.List; |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
15 import java.util.Map; |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import org.apache.log4j.Logger; |
9099 | 18 import org.dive4elements.artifacts.common.utils.StringUtils; |
19 import org.dive4elements.river.artifacts.access.FixAccess; | |
20 import org.dive4elements.river.artifacts.math.fitting.Function; | |
21 import org.dive4elements.river.artifacts.math.fitting.FunctionFactory; | |
22 import org.dive4elements.river.artifacts.model.Calculation; | |
23 import org.dive4elements.river.artifacts.model.CalculationResult; | |
24 import org.dive4elements.river.artifacts.model.FixingsColumn; | |
25 import org.dive4elements.river.artifacts.model.FixingsColumnFactory; | |
26 import org.dive4elements.river.artifacts.model.FixingsOverview; | |
27 import org.dive4elements.river.artifacts.model.FixingsOverview.Fixing; | |
28 import org.dive4elements.river.artifacts.model.FixingsOverview.Fixing.Filter; | |
29 import org.dive4elements.river.artifacts.model.FixingsOverview.IdsFilter; | |
30 import org.dive4elements.river.artifacts.model.FixingsOverviewFactory; | |
31 import org.dive4elements.river.artifacts.model.Parameters; | |
32 import org.dive4elements.river.utils.DoubleUtil; | |
33 import org.dive4elements.river.utils.KMIndex; | |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
5150
345f3bba6f15
Doc fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3970
diff
changeset
|
35 /** Calculation base class for fix. */ |
9099 | 36 public abstract class FixCalculation extends Calculation { |
2786
f9e62e76ee1f
FixA: Return correct data structure from calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2783
diff
changeset
|
37 private static Logger log = Logger.getLogger(FixCalculation.class); |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
39 public static final double EPSILON = 1e-4; |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
40 |
9099 | 41 public static final String[] STANDARD_COLUMNS = { "km", "chi_sqr", "max_q", "std-dev" }; |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
42 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
43 protected static class FitResult { |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
44 |
9099 | 45 protected Parameters parameters; |
46 protected KMIndex<QWD[]> referenced; | |
47 protected KMIndex<QWI[]> outliers; | |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
48 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
49 public FitResult() { |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
50 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
51 |
9099 | 52 public FitResult(final Parameters parameters, final KMIndex<QWD[]> referenced, final KMIndex<QWI[]> outliers) { |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
53 this.parameters = parameters; |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
54 this.referenced = referenced; |
9099 | 55 this.outliers = outliers; |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
56 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
57 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
58 public Parameters getParameters() { |
9099 | 59 return this.parameters; |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
60 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
61 |
9099 | 62 public KMIndex<QWD[]> getReferenced() { |
63 return this.referenced; | |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
64 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
65 |
9099 | 66 public KMIndex<QWI[]> getOutliers() { |
67 return this.outliers; | |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
68 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
69 } // class FitResult |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
70 |
9099 | 71 /** |
72 * Helper class to bundle the meta information of a column | |
73 * and the real data. | |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
74 */ |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
75 protected static class Column { |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
76 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
77 protected Fixing.Column meta; |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
78 protected FixingsColumn data; |
9099 | 79 protected int index; |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
80 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
81 public Column() { |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
82 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
83 |
9099 | 84 public Column(final Fixing.Column meta, final FixingsColumn data, final int index) { |
85 this.meta = meta; | |
86 this.data = data; | |
3603
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3451
diff
changeset
|
87 this.index = index; |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
88 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
89 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
90 public Date getDate() { |
9099 | 91 return this.meta.getStartTime(); |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
92 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
93 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
94 public String getDescription() { |
9099 | 95 return this.meta.getDescription(); |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
96 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
97 |
3603
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3451
diff
changeset
|
98 public int getIndex() { |
9099 | 99 return this.index; |
3603
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3451
diff
changeset
|
100 } |
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3451
diff
changeset
|
101 |
6875
437856cec419
FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
102 public int getId() { |
9099 | 103 return this.meta.getId(); |
6875
437856cec419
FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
104 } |
437856cec419
FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
105 |
9099 | 106 public boolean getQW(final double km, final double[] qs, final double[] ws, final int index) { |
107 qs[index] = this.data.getQ(km); | |
108 return this.data.getW(km, ws, index); | |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
109 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
110 |
9099 | 111 public boolean getQW(final double km, final double[] wq) { |
112 this.data.getW(km, wq, 0); | |
113 if (Double.isNaN(wq[0])) | |
114 return false; | |
115 wq[1] = this.data.getQ(km); | |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
116 return !Double.isNaN(wq[1]); |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
117 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
118 } // class Column |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
119 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
120 /** |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
121 * Helper class to find the data belonging to meta info more quickly. |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
122 */ |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
123 protected static class ColumnCache { |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
124 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
125 protected Map<Integer, Column> columns; |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
126 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
127 public ColumnCache() { |
9099 | 128 this.columns = new HashMap<>(); |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
129 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
130 |
9099 | 131 public Column getColumn(final Fixing.Column meta) { |
132 final Integer key = meta.getId(); | |
133 Column column = this.columns.get(key); | |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
134 if (column == null) { |
9099 | 135 final FixingsColumn data = FixingsColumnFactory.getInstance().getColumnData(meta); |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
136 if (data != null) { |
9099 | 137 column = new Column(meta, data, this.columns.size()); |
138 this.columns.put(key, column); | |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
139 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
140 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
141 return column; |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
142 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
143 } // class ColumnCache |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
144 |
9099 | 145 protected String river; |
146 protected double from; | |
147 protected double to; | |
148 protected double step; | |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 protected boolean preprocessing; |
9099 | 150 protected String function; |
151 protected int[] events; | |
152 protected int qSectorStart; | |
153 protected int qSectorEnd; | |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 public FixCalculation() { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 |
9099 | 158 public FixCalculation(final FixAccess access) { |
159 final String river = access.getRiverName(); | |
160 final Double from = access.getLowerKm(); | |
161 final Double to = access.getUpperKm(); | |
162 final Double step = access.getStep(); | |
163 final String function = access.getFunction(); | |
164 final int[] events = access.getEvents(); | |
165 final Integer qSectorStart = access.getQSectorStart(); | |
166 final Integer qSectorEnd = access.getQSectorEnd(); | |
167 final Boolean preprocessing = access.getPreprocessing(); | |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 if (river == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 addProblem("fix.missing.river"); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 if (from == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 addProblem("fix.missing.from"); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 if (to == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 addProblem("fix.missing.to"); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 if (step == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 addProblem("fix.missing.step"); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 if (function == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 addProblem("fix.missing.function"); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 if (events == null || events.length < 1) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 addProblem("fix.missing.events"); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 |
2744
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
193 if (qSectorStart == null) { |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
194 addProblem("fix.missing.qstart.sector"); |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
195 } |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
196 |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
197 if (qSectorEnd == null) { |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
198 addProblem("fix.missing.qend.sector"); |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
199 } |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
200 |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 if (preprocessing == null) { |
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 addProblem("fix.missing.preprocessing"); |
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 } |
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
204 |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 if (!hasProblems()) { |
9099 | 206 this.river = river; |
207 this.from = from; | |
208 this.to = to; | |
209 this.step = step; | |
210 this.function = function; | |
211 this.events = events; | |
212 this.qSectorStart = qSectorStart; | |
213 this.qSectorEnd = qSectorEnd; | |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 this.preprocessing = preprocessing; |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 |
9099 | 218 protected static String toString(final String[] parameterNames, final double[] values) { |
219 final StringBuilder sb = new StringBuilder(); | |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
220 for (int i = 0; i < parameterNames.length; ++i) { |
9099 | 221 if (i > 0) |
222 sb.append(", "); | |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
223 sb.append(parameterNames[i]).append(": ").append(values[i]); |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
224 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
225 return sb.toString(); |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
226 } |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
227 |
9099 | 228 /** |
229 * Create filter to accept only the chosen events. | |
230 * This factored out out to be overwritten. | |
5741
6e6753b9757f
FLYS artifacts: Rollback function renaming.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5733
diff
changeset
|
231 */ |
6e6753b9757f
FLYS artifacts: Rollback function renaming.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5733
diff
changeset
|
232 protected Filter createFilter() { |
9099 | 233 return new IdsFilter(this.events); |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
234 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
235 |
9099 | 236 protected List<Column> getEventColumns(final FixingsOverview overview, final ColumnCache cc) { |
237 final FixingsColumnFactory fcf = FixingsColumnFactory.getInstance(); | |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
238 |
9099 | 239 final Filter filter = createFilter(); |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
240 |
9099 | 241 final List<Fixing.Column> metas = overview.filter(null, filter); |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
242 |
9099 | 243 final List<Column> columns = new ArrayList<>(metas.size()); |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
244 |
9099 | 245 for (final Fixing.Column meta : metas) { |
246 | |
247 final Column data = cc.getColumn(meta); | |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
248 if (data == null) { |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
249 addProblem("fix.cannot.load.data"); |
9099 | 250 } else { |
3603
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3451
diff
changeset
|
251 columns.add(data); |
3434
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
252 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
253 } |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
254 |
1a636be7612b
FixA: Moved more common calculation code into base class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
255 return columns; |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
256 } |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
257 |
5733
b7d631e45ee7
FixCalculation: Cosmetics, renamed function, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5150
diff
changeset
|
258 // Fit a function to the given points from fixation. |
9099 | 259 protected FitResult doFitting(final FixingsOverview overview, final ColumnCache cc, final Function func) { |
260 final boolean debug = log.isDebugEnabled(); | |
2792
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2788
diff
changeset
|
261 |
3603
d2ae58f6730d
FixA: Use the column cache to establish a consistent index scheme.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3451
diff
changeset
|
262 final List<Column> eventColumns = getEventColumns(overview, cc); |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
263 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
264 if (eventColumns.size() < 2) { |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
265 addProblem("fix.too.less.data.columns"); |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
266 return null; |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
267 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
268 |
9099 | 269 final double[] qs = new double[eventColumns.size()]; |
270 final double[] ws = new double[qs.length]; | |
271 final boolean[] interpolated = new boolean[ws.length]; | |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
272 |
9099 | 273 final Fitting.QWDFactory qwdFactory = new Fitting.QWDFactory() { |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
274 @Override |
9099 | 275 public QWD create(final double q, final double w) { |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
276 // Check all the event columns for close match |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
277 // and take the description and the date from meta. |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
278 for (int i = 0; i < qs.length; ++i) { |
9099 | 279 if (Math.abs(qs[i] - q) < EPSILON && Math.abs(ws[i] - w) < EPSILON) { |
280 final Column column = eventColumns.get(i); | |
281 return new QWD(qs[i], ws[i], column.getDescription(), column.getDate(), interpolated[i], 0d, column.getId()); // Use database id here | |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
282 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
283 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
284 log.warn("cannot find column for (" + q + ", " + w + ")"); |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
285 return new QWD(q, w); |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
286 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
287 }; |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
288 |
9099 | 289 final Fitting fitting = new Fitting(func, qwdFactory, this.preprocessing); |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
290 |
9099 | 291 final String[] parameterNames = func.getParameterNames(); |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
292 |
9099 | 293 final Parameters results = new Parameters(StringUtils.join(STANDARD_COLUMNS, parameterNames)); |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
294 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
295 boolean invalid = false; |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
296 |
9099 | 297 final double[] kms = DoubleUtil.explode(this.from, this.to, this.step / 1000.0); |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
298 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
299 if (debug) { |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
300 log.debug("number of kms: " + kms.length); |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
301 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
302 |
9099 | 303 final KMIndex<QWI[]> outliers = new KMIndex<>(); |
304 final KMIndex<QWD[]> referenced = new KMIndex<>(kms.length); | |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
305 |
9099 | 306 final int kmIndex = results.columnIndex("km"); |
307 final int chiSqrIndex = results.columnIndex("chi_sqr"); | |
308 final int maxQIndex = results.columnIndex("max_q"); | |
309 final int stdDevIndex = results.columnIndex("std-dev"); | |
310 final int[] parameterIndices = results.columnIndices(parameterNames); | |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
311 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
312 int numFailed = 0; |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
313 |
9099 | 314 for (final double km2 : kms) { |
315 final double km = km2; | |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
316 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
317 // Fill Qs and Ws from event columns. |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
318 for (int j = 0; j < ws.length; ++j) { |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
319 interpolated[j] = !eventColumns.get(j).getQW(km, qs, ws, j); |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
320 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
321 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
322 fitting.reset(); |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
323 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
324 if (!fitting.fit(qs, ws)) { |
7300
83bb52fa0c32
(issue1529) Be more tolerant in the fitting.
Andre Heinecke <aheinecke@intevation.de>
parents:
7261
diff
changeset
|
325 log.debug("Fitting for km: " + km + " failed"); |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
326 ++numFailed; |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
327 addProblem(km, "fix.fitting.failed"); |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
328 continue; |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
329 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
330 |
9099 | 331 final QWD[] refs = fitting.referencedToArray(); |
6875
437856cec419
FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
332 |
437856cec419
FixA: Fixed reference events mapping. TODO: Same for analysis periods.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
333 referenced.add(km, refs); |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
334 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
335 if (fitting.hasOutliers()) { |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
336 outliers.add(km, fitting.outliersToArray()); |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
337 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
338 |
9099 | 339 final int row = results.newRow(); |
340 final double[] values = fitting.getParameters(); | |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
341 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
342 results.set(row, kmIndex, km); |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
343 results.set(row, chiSqrIndex, fitting.getChiSquare()); |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
344 results.set(row, stdDevIndex, fitting.getStandardDeviation()); |
9099 | 345 results.set(row, maxQIndex, fitting.getMaxQ()); |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
346 invalid |= results.set(row, parameterIndices, values); |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
347 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
348 if (debug) { |
9099 | 349 log.debug("km: " + km + " " + toString(parameterNames, values)); |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
350 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
351 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
352 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
353 if (debug) { |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
354 log.debug("success: " + (kms.length - numFailed)); |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
355 log.debug("failed: " + numFailed); |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
356 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
357 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
358 if (invalid) { |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
359 addProblem("fix.invalid.values"); |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
360 results.removeNaNs(); |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
361 } |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
362 |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
363 outliers.sort(); |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
364 referenced.sort(); |
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
365 |
9099 | 366 return new FitResult(results, referenced, outliers); |
3435
262e7d7e58fe
FixA: Made curve fitting over the given calculation range reusable. Removed dead code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3434
diff
changeset
|
367 } |
3437
e111902834d3
FixA: Made calculation base class abstract. Sub classes are called with fixings overview an function to fit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3435
diff
changeset
|
368 |
e111902834d3
FixA: Made calculation base class abstract. Sub classes are called with fixings overview an function to fit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3435
diff
changeset
|
369 public CalculationResult calculate() { |
9099 | 370 final FixingsOverview overview = FixingsOverviewFactory.getOverview(this.river); |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
371 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
372 if (overview == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
373 addProblem("fix.no.overview.available"); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
374 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
375 |
9099 | 376 final Function func = FunctionFactory.getInstance().getFunction(this.function); |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
377 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
378 if (func == null) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
379 addProblem("fix.invalid.function.name"); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
380 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
381 |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
382 if (hasProblems()) { |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
383 return new CalculationResult(this); |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
384 } |
9099 | 385 final CalculationResult result = innerCalculate(overview, func); |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
386 |
7525
6650485c2c9b
Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7300
diff
changeset
|
387 if (result != null) { |
6650485c2c9b
Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7300
diff
changeset
|
388 // Workaraound to deal with same dates in data set |
9099 | 389 final Object o = result.getData(); |
7525
6650485c2c9b
Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7300
diff
changeset
|
390 if (o instanceof FixResult) { |
9099 | 391 final FixResult fr = (FixResult) o; |
7525
6650485c2c9b
Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7300
diff
changeset
|
392 fr.makeReferenceEventsDatesUnique(); |
6650485c2c9b
Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7300
diff
changeset
|
393 fr.remapReferenceIndicesToRank(); |
6650485c2c9b
Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7300
diff
changeset
|
394 } |
6650485c2c9b
Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7300
diff
changeset
|
395 } |
6650485c2c9b
Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7300
diff
changeset
|
396 |
6650485c2c9b
Part fix for flys/issue1585: Use result from fitting to display interpolated W/Q points, too. TODO: Draw interpolated as circles.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7300
diff
changeset
|
397 return result; |
2744
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
398 } |
c1f2e792704a
FixA: Calculate Delta W/t, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2729
diff
changeset
|
399 |
9099 | 400 protected abstract CalculationResult innerCalculate(FixingsOverview overview, Function function); |
2729
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
401 } |
a441be7f1589
Added Fix calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
402 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |