annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedQualityCalculation.java @ 8653:dbec49147f54

(issue1755) Do not create interpolated themes and disable export of non interpolatable data. Due to the fact that data can contain NaN's which will be filtered out before creating the interpolator this requires the actual check for interpolatable data when data is set in the ResultValue
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 01 Apr 2015 17:10:03 +0200
parents 36faef4f8acb
children 4054c7fce43e
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: 4806
diff changeset
9 package org.dive4elements.river.artifacts.model.minfo;
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
11 import gnu.trove.TDoubleArrayList;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
12
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
13 import java.util.LinkedList;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14 import java.util.List;
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
15 import java.util.Map;
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
17 import org.apache.log4j.Logger;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4806
diff changeset
19 import org.dive4elements.river.artifacts.access.BedQualityAccess;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4806
diff changeset
20 import org.dive4elements.river.artifacts.model.Calculation;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4806
diff changeset
21 import org.dive4elements.river.artifacts.model.CalculationResult;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4806
diff changeset
22 import org.dive4elements.river.artifacts.model.DateRange;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4806
diff changeset
23 import org.dive4elements.river.backend.SedDBSessionHolder;
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
26 public class BedQualityCalculation extends Calculation {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7707
diff changeset
28 private static final Logger log = Logger
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29 .getLogger(BedQualityCalculation.class);
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
30
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31 protected String river;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32 protected double from;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33 protected double to;
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
34 protected List<String> bedDiameter;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
35 protected List<String> bedloadDiameter;
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
36 protected List<DateRange> ranges;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
38 public BedQualityCalculation() {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
39 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
40
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41 public CalculationResult calculate(BedQualityAccess access) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7707
diff changeset
42 log.info("BedQualityCalculation.calculate");
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43
7261
a56fe3bc6700 Refactoring: Let RiverAccess.getRiver return an River.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6257
diff changeset
44 String river = access.getRiverName();
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 Double from = access.getFrom();
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46 Double to = access.getTo();
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
47 List<String> bedDiameter = access.getBedDiameter();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
48 List<String> bedloadDiameter = access.getBedloadDiameter();
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49 List<DateRange> ranges = access.getDateRanges();
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
50
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
51 if (river == null) {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52 // TODO: i18n
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 addProblem("minfo.missing.river");
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
54 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
55
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
56 if (from == null) {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
57 // TODO: i18n
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58 addProblem("minfo.missing.from");
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
59 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
60
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
61 if (to == null) {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62 // TODO: i18n
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
63 addProblem("minfo.missing.to");
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
66 if (ranges == null) {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67 // TODO: i18n
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
68 addProblem("minfo.missing.periods");
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
69 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
70
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
71 if (!hasProblems()) {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 this.river = river;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 this.from = from;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 this.to = to;
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75 this.ranges = ranges;
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
76 this.bedDiameter = bedDiameter;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
77 this.bedloadDiameter = bedloadDiameter;
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79 SedDBSessionHolder.acquire();
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
80 try {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
81 return internalCalculate();
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
82 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
83 finally {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
84 SedDBSessionHolder.release();
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
85 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
86 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
87
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
88 return new CalculationResult();
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
89 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
90
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
91 protected CalculationResult internalCalculate() {
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
92
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
93 List<BedQualityResult> results = new LinkedList<BedQualityResult>();
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
94 // Calculate for all time periods.
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
95 for (DateRange dr : ranges) {
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
96 QualityMeasurements loadMeasurements =
3785
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3784
diff changeset
97 QualityMeasurementFactory.getBedloadMeasurements(
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
98 river,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
99 from,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
100 to,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
101 dr.getFrom(),
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
102 dr.getTo());
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
103 QualityMeasurements bedMeasurements =
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
104 QualityMeasurementFactory.getBedMeasurements(
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
105 river,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
106 from,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
107 to,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
108 dr.getFrom(),
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
109 dr.getTo());
3784
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
110 BedQualityResult result = new BedQualityResult();
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
111 result.setDateRange(dr);
8592
36faef4f8acb (issue1755) Add interpolated facets and update themes accordingly
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8587
diff changeset
112 if (!bedDiameter.isEmpty()) {
36faef4f8acb (issue1755) Add interpolated facets and update themes accordingly
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8587
diff changeset
113 log.debug("Bed diameter is not empty + " + bedDiameter);
8587
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
114 result.add(calculateBedParameter(bedMeasurements));
3780
7fa38f8bcd8d Avoid NPE if the user selects onlyone sort of characteristic diameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3772
diff changeset
115 for (String bd : bedDiameter) {
8587
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
116 result.add (calculateBed(bedMeasurements, bd));
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
117 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
118 }
8592
36faef4f8acb (issue1755) Add interpolated facets and update themes accordingly
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8587
diff changeset
119 if (!bedloadDiameter.isEmpty()) {
3780
7fa38f8bcd8d Avoid NPE if the user selects onlyone sort of characteristic diameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3772
diff changeset
120 for (String bld : bedloadDiameter) {
8587
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
121 result.add(calculateBedload(loadMeasurements, bld));
3780
7fa38f8bcd8d Avoid NPE if the user selects onlyone sort of characteristic diameter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3772
diff changeset
122 }
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
123 }
3784
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
124 results.add(result);
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
125 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
126
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
127 return new CalculationResult(
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
128 results.toArray(new BedQualityResult[results.size()]), this);
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
129 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
130
8587
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
131 private BedQualityResultValue[] calculateBedParameter(
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
132 QualityMeasurements qm
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
133 ) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
134 List<Double> kms = qm.getKms();
8587
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
135 TDoubleArrayList location = new TDoubleArrayList();
3784
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
136 QualityMeasurements capFiltered = filterCapMeasurements(qm);
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
137 QualityMeasurements subFiltered = filterSubMeasurements(qm);
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
138 TDoubleArrayList porosityCap = new TDoubleArrayList();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
139 TDoubleArrayList porositySub = new TDoubleArrayList();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
140 TDoubleArrayList densityCap = new TDoubleArrayList();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
141 TDoubleArrayList densitySub = new TDoubleArrayList();
3785
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3784
diff changeset
142
3784
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
143 for(double km : kms) {
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
144 double[] pCap = calculatePorosity(capFiltered, km);
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
145 double[] pSub = calculatePorosity(subFiltered, km);
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
146 double[] dCap = calculateDensity(capFiltered, pCap);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
147 double[] dSub = calculateDensity(subFiltered, pSub);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
148
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
149 double pCapRes = 0d;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
150 double pSubRes = 0d;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
151 double dCapRes = 0d;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
152 double dSubRes = 0d;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
153 for (int i = 0; i < pCap.length; i++) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
154 pCapRes += pCap[i];
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
155 dCapRes += dCap[i];
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
156 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
157 for (int i = 0; i < pSub.length; i++) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
158 pSubRes += pSub[i];
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
159 dSubRes += dSub[i];
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
160 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
161 location.add(km);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
162 porosityCap.add((pCapRes / pCap.length) * 100 );
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
163 porositySub.add((pSubRes / pSub.length) * 100);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
164 densityCap.add((dCapRes / dCap.length) / 1000);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
165 densitySub.add((dSubRes / dSub.length) / 1000);
3785
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3784
diff changeset
166
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
167 }
8587
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
168 return new BedQualityResultValue[] {
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
169 new BedQualityResultValue("porosity",
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
170 new double[][] {location.toNativeArray(), porositySub.toNativeArray()},
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
171 "sublayer"),
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
172 new BedQualityResultValue("porosity",
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
173 new double[][] {location.toNativeArray(), porosityCap.toNativeArray()},
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
174 "toplayer"),
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
175 new BedQualityResultValue("density",
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
176 new double[][] {location.toNativeArray(), densitySub.toNativeArray()},
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
177 "sublayer"),
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
178 new BedQualityResultValue("density",
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
179 new double[][] {location.toNativeArray(), densityCap.toNativeArray()},
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
180 "toplayer")};
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
181 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
182
8587
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
183 protected BedQualityResultValue[] calculateBed(
3784
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
184 QualityMeasurements qm,
8587
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
185 String diameter
3784
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
186 ) {
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
187 List<Double> kms = qm.getKms();
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
188 TDoubleArrayList location = new TDoubleArrayList();
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
189 TDoubleArrayList avDiameterCap = new TDoubleArrayList();
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
190 TDoubleArrayList avDiameterSub = new TDoubleArrayList();
8563
59b4f6cf1cf4 Move static operation out of loop.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
191 QualityMeasurements capFiltered = filterCapMeasurements(qm);
59b4f6cf1cf4 Move static operation out of loop.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
192 QualityMeasurements subFiltered = filterSubMeasurements(qm);
59b4f6cf1cf4 Move static operation out of loop.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
193
3784
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
194 for (double km : kms) {
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
195 //Filter cap and sub measurements.
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
196 List<QualityMeasurement> cm = capFiltered.getMeasurements(km);
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
197 List<QualityMeasurement> sm = subFiltered.getMeasurements(km);
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
198
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
199 double avCap = calculateAverage(cm, diameter);
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
200 double avSub = calculateAverage(sm, diameter);
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
201 location.add(km);
4642
ca18d8d06218 Multiplicate diameter with 1000 to have mm instead of m.
Raimund Renkert <rrenkert@intevation.de>
parents: 3974
diff changeset
202 avDiameterCap.add(avCap * 1000);// bring to mm.
ca18d8d06218 Multiplicate diameter with 1000 to have mm instead of m.
Raimund Renkert <rrenkert@intevation.de>
parents: 3974
diff changeset
203 avDiameterSub.add(avSub * 1000);
3784
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
204 }
8587
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
205 return new BedQualityResultValue[] {
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
206 new BedQualityResultValue(diameter,
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
207 new double[][] {location.toNativeArray(), avDiameterSub.toNativeArray()},
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
208 "sublayer"),
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
209 new BedQualityResultValue(diameter,
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
210 new double[][] {location.toNativeArray(), avDiameterCap.toNativeArray()},
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
211 "toplayer")};
3784
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
212 }
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
213
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
214 private double[] calculateDensity(
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
215 QualityMeasurements capFiltered,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
216 double[] porosity
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
217 ) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
218 double[] density = new double[porosity.length];
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
219 for (int i = 0; i < porosity.length; i++) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
220 density[i] = (1 - porosity[i]) * 2650;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
221 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
222 return density;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
223 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
224
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
225 private double[] calculatePorosity(
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
226 QualityMeasurements capFiltered,
3784
9f9d5ada96ca Merged revisions 5498-5499 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3780
diff changeset
227 double km
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
228 ) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
229 List<QualityMeasurement> list = capFiltered.getMeasurements(km);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
230 double[] results = new double[list.size()];
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
231 int i = 0;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
232 for (QualityMeasurement qm : list) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
233 double deviation = calculateDeviation(qm);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
234 double p = calculateP(qm);
7670
03dc5cc22e26 Update coefficients in porosity formula.
Tom Gottfried <tom.gottfried@intevation.de>
parents: 7261
diff changeset
235 double porosity = 0.362 - 0.088 * deviation + 0.219 * p;
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
236 results[i] = porosity;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
237 i++;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
238 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
239
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
240 return results;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
241 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
242
8587
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
243 protected BedQualityResultValue calculateBedload(
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
244 QualityMeasurements qm,
8587
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
245 String diameter
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
246 ) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
247 List<Double> kms = qm.getKms();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
248 TDoubleArrayList location = new TDoubleArrayList();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
249 TDoubleArrayList avDiameter = new TDoubleArrayList();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
250 for (double km : kms) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
251 List<QualityMeasurement> measurements = qm.getMeasurements(km);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
252 double mid = calculateAverage(measurements, diameter);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
253 location.add(km);
6257
165f60f420cf Bring bedload average diameter to 'mm'.
Raimund Renkert <rrenkert@intevation.de>
parents: 6151
diff changeset
254 avDiameter.add(mid * 1000);
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
255 }
8587
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
256 return new BedQualityResultValue(diameter,
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
257 new double[][] {location.toNativeArray(), avDiameter.toNativeArray()},
07c9ac22f611 (issue1755) Generalise BedQuality result handling
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8563
diff changeset
258 "bedload");
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
259 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
260
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
261 protected double calculateAverage(
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
262 List<QualityMeasurement> list,
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
263 String diameter
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
264 ) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
265 double av = 0;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
266 for (QualityMeasurement qm : list) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
267 av += qm.getDiameter(diameter);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
268 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
269 return av/list.size();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
270 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
271
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
272 protected QualityMeasurements filterCapMeasurements(
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
273 QualityMeasurements qms
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
274 ) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
275 List<QualityMeasurement> result = new LinkedList<QualityMeasurement>();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
276 for (QualityMeasurement qm : qms.getMeasurements()) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
277 if (qm.getDepth1() == 0d && qm.getDepth2() <= 0.3) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
278 result.add(qm);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
279 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
280 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
281 return new QualityMeasurements(result);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
282 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
283
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
284 protected QualityMeasurements filterSubMeasurements(
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
285 QualityMeasurements qms
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
286 ) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
287 List<QualityMeasurement> result = new LinkedList<QualityMeasurement>();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
288 for (QualityMeasurement qm : qms.getMeasurements()) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
289 if (qm.getDepth1() > 0d && qm.getDepth2() <= 0.5) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
290 result.add(qm);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
291 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
292 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
293 return new QualityMeasurements(result);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
294 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
295
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
296 public double calculateDeviation(QualityMeasurement qm) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
297 Map<String, Double> dm = qm.getAllDiameter();
6151
63d1e2a9b311 Bed quality calculation: Replaced another iteration over the key set + directly fetching the values withan iteration over the entry set.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6150
diff changeset
298 int size = dm.size();
63d1e2a9b311 Bed quality calculation: Replaced another iteration over the key set + directly fetching the values withan iteration over the entry set.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6150
diff changeset
299
63d1e2a9b311 Bed quality calculation: Replaced another iteration over the key set + directly fetching the values withan iteration over the entry set.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6150
diff changeset
300 double phiM = 0;
63d1e2a9b311 Bed quality calculation: Replaced another iteration over the key set + directly fetching the values withan iteration over the entry set.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6150
diff changeset
301 double [] phis = new double[size];
63d1e2a9b311 Bed quality calculation: Replaced another iteration over the key set + directly fetching the values withan iteration over the entry set.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6150
diff changeset
302 double [] ps = new double[size];
63d1e2a9b311 Bed quality calculation: Replaced another iteration over the key set + directly fetching the values withan iteration over the entry set.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6150
diff changeset
303 double scale = -1d/Math.log(2d);
63d1e2a9b311 Bed quality calculation: Replaced another iteration over the key set + directly fetching the values withan iteration over the entry set.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6150
diff changeset
304
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
305 int i = 0;
6151
63d1e2a9b311 Bed quality calculation: Replaced another iteration over the key set + directly fetching the values withan iteration over the entry set.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6150
diff changeset
306 for (Map.Entry<String, Double> entry: dm.entrySet()) {
63d1e2a9b311 Bed quality calculation: Replaced another iteration over the key set + directly fetching the values withan iteration over the entry set.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6150
diff changeset
307 double phi = scale*Math.log(entry.getValue());
63d1e2a9b311 Bed quality calculation: Replaced another iteration over the key set + directly fetching the values withan iteration over the entry set.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6150
diff changeset
308 double p = calculateWeight(qm, entry.getKey());
63d1e2a9b311 Bed quality calculation: Replaced another iteration over the key set + directly fetching the values withan iteration over the entry set.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6150
diff changeset
309 phiM += phi * p;
63d1e2a9b311 Bed quality calculation: Replaced another iteration over the key set + directly fetching the values withan iteration over the entry set.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6150
diff changeset
310 ps[i] = p;
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
311 phis[i] = phi;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
312 i++;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
313 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
314
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
315 double sig = 0d;
6151
63d1e2a9b311 Bed quality calculation: Replaced another iteration over the key set + directly fetching the values withan iteration over the entry set.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6150
diff changeset
316 for (i = 0; i < size; i++) {
7707
cead6df5b7b3 Variance is defined as the sum of squared differences.
Tom Gottfried <tom.gottfried@intevation.de>
parents: 7670
diff changeset
317 sig += ps[i] * Math.pow((phis[i] - phiM), 2);
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
318 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
319 double deviation = Math.sqrt(sig);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
320 return deviation;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
321 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
322
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
323 protected double calculateP(QualityMeasurement qm) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
324 return calculateWeight(qm, "dmin");
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
325 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
326
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
327 public double calculateWeight(QualityMeasurement qm, String diameter) {
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
328 Map<String, Double> dm = qm.getAllDiameter();
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
329 double value = qm.getDiameter(diameter);
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
330
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
331 double sum = 0d;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
332 for (Double d : dm.values()) {
6150
1f057463765b Bed quality calculation: Fixed a calculation typo: s/sum =+ d/sum += d/
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
333 sum += d.doubleValue();
3769
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
334 }
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
335 double weight = sum/100*value;
728ecd2afa20 Implemented bed quality calculation in minfo module.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 3760
diff changeset
336 return weight;
3760
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
337 }
312870fded7e Added result objects for minfo bed quality calculation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
338 }
4806
750d72a16f4e BedQualityCalculation: Added vim-line.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4642
diff changeset
339 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org