annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java @ 8065:fdb26fe898dc

Sediment load: Cached sediment values dont depend on year. The cached object is an index over year so there is not need to ask the factory for this.
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 30 Jul 2014 19:06:35 +0200
parents 963ede7b32bb
children
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: 5788
diff changeset
9 package org.dive4elements.river.artifacts.model.minfo;
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
10
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11 import gnu.trove.TDoubleArrayList;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13 import java.util.ArrayList;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14 import java.util.List;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
15
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
16 import org.apache.log4j.Logger;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
17
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5788
diff changeset
18 import org.dive4elements.river.artifacts.access.SedimentLoadAccess;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5788
diff changeset
19 import org.dive4elements.river.artifacts.model.Calculation;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5788
diff changeset
20 import org.dive4elements.river.artifacts.model.CalculationResult;
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
21 import org.dive4elements.river.artifacts.model.Range;
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23
4483
cc6323401643 Cosmetics: Removed some WSP, obsolete imports. Documentation added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4373
diff changeset
24 /** Calculate sediment load. */
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
25 public class SedimentLoadCalculation
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26 extends Calculation
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27 {
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28
4483
cc6323401643 Cosmetics: Removed some WSP, obsolete imports. Documentation added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4373
diff changeset
29 /** Private logger. */
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30 private static final Logger logger = Logger
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31 .getLogger(SedimentLoadCalculation.class);
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33 protected String river;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 protected String yearEpoch;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
35 protected double kmUp;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36 protected double kmLow;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37 protected int[] period;
7532
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7462
diff changeset
38 /** Years of chosen epochs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7462
diff changeset
39 * epoch[0][0] is the start year of first entered epoch, e[0][1] the end-year. */
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40 protected int[][] epoch;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
41 protected String unit;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 public SedimentLoadCalculation() {
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
45
6678
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6543
diff changeset
46 /** Returns CalculationResult with array of SedimentLoadResults. */
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
47 public CalculationResult calculate(SedimentLoadAccess access) {
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
48 logger.info("SedimentLoadCalculation.calculate");
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
49
7261
a56fe3bc6700 Refactoring: Let RiverAccess.getRiver return an River.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7254
diff changeset
50 String river = access.getRiverName();
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
51 String yearEpoch = access.getYearEpoch();
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
52 String unit = access.getUnit();
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
53 int[] period = null;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
54 int[][] epoch = null;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
55 double kmUp = access.getUpperKM();
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
56 double kmLow = access.getLowerKM();
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57 if (yearEpoch.equals("year")) {
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58 period = access.getPeriod();
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 epoch = null;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60 }
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
61 else if (yearEpoch.equals("epoch") || yearEpoch.equals("off_epoch")) {
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62 epoch = access.getEpochs();
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 period = null;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
65 else {
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 addProblem("minfo.missing.year_epoch");
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69 if (river == null) {
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70 // TODO: i18n
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 addProblem("minfo.missing.river");
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
73
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74 if (period == null && epoch == null) {
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75 addProblem("minfo.missing.time");
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
76 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
77
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
78 if (!hasProblems()) {
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
79 this.river = river;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
80 this.yearEpoch = yearEpoch;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
81 this.unit = unit;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
82 this.period = period;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
83 this.epoch = epoch;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
84 this.kmUp = kmUp;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
85 this.kmLow = kmLow;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
86 return internalCalculate();
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
87 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
88
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
89 return new CalculationResult();
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
90 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
91
6678
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6543
diff changeset
92 /** Returns CalculationResult with array of SedimentLoadResults. */
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
93 private CalculationResult internalCalculate() {
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
94 logger.debug("internalCalulate; mode:" + yearEpoch);
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
95 if (yearEpoch.equals("year")) {
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
96 List<SedimentLoadResult> results =
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
97 new ArrayList<SedimentLoadResult>();
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
98 for (int i = period[0]; i <= period[1]; i++) {
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
99 SedimentLoadResult res = calculateYear(i);
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
100 results.add(res);
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
101 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
102 return new CalculationResult(
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
103 results.toArray(new SedimentLoadResult[results.size()]), this);
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
104 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
105 else if (yearEpoch.equals("epoch")) {
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
106 List<SedimentLoadResult> results =
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
107 new ArrayList<SedimentLoadResult>();
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
108 for (int i = 0; i < epoch.length; i++) {
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
109 SedimentLoadResult res = calculateEpoch(i);
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
110 results.add(res);
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
111 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
112 return new CalculationResult(
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
113 results.toArray(new SedimentLoadResult[results.size()]), this);
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
114 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
115 else if (yearEpoch.equals("off_epoch")) {
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
116 List<SedimentLoadResult> results =
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
117 new ArrayList<SedimentLoadResult>();
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
118 for (int i = 0; i < epoch.length; i++) {
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
119 SedimentLoadResult res = calculateOffEpoch(i);
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
120 results.add(res);
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
121 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
122 return new CalculationResult(
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
123 results.toArray(new SedimentLoadResult[results.size()]), this);
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
124 }
6950
40da4a6e2cfb SedimentLoadCalculation: Log an error on unknown mode.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6948
diff changeset
125 else {
40da4a6e2cfb SedimentLoadCalculation: Log an error on unknown mode.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6948
diff changeset
126 logger.error("Unknown mode " + yearEpoch);
40da4a6e2cfb SedimentLoadCalculation: Log an error on unknown mode.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6948
diff changeset
127 }
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
128 return null;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
129 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
130
7054
f4d6ef50665a issue1436: Repair sedimentload epoch calculation,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7031
diff changeset
131
f4d6ef50665a issue1436: Repair sedimentload epoch calculation,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7031
diff changeset
132 /** Returns val if not NaN, 0d otherwise. */
f4d6ef50665a issue1436: Repair sedimentload epoch calculation,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7031
diff changeset
133 private static double makeNaN0(double val) {
f4d6ef50665a issue1436: Repair sedimentload epoch calculation,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7031
diff changeset
134 return Double.isNaN(val)
f4d6ef50665a issue1436: Repair sedimentload epoch calculation,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7031
diff changeset
135 ? 0d
f4d6ef50665a issue1436: Repair sedimentload epoch calculation,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7031
diff changeset
136 : val;
f4d6ef50665a issue1436: Repair sedimentload epoch calculation,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7031
diff changeset
137 }
f4d6ef50665a issue1436: Repair sedimentload epoch calculation,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7031
diff changeset
138
6948
d4108d6c4000 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6928
diff changeset
139 /**
7031
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7023
diff changeset
140 * Take Loads and build average of all fractions at given km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7023
diff changeset
141 * The average fractions value is set in resLoad.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7023
diff changeset
142 *
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7023
diff changeset
143 * @param km km at which to build fractions average.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7023
diff changeset
144 * @param epochLoads the loads to build average over.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7023
diff changeset
145 * @param[out] resLoad resulting SedimentLoad.
6948
d4108d6c4000 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6928
diff changeset
146 */
6928
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
147 private void calculateEpochKm(
8024
963ede7b32bb Renamed SedimentLoad to SedimentLoadLSData to make place for SedimentLoad in backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7931
diff changeset
148 List<SedimentLoadLSData> epochLoads,
963ede7b32bb Renamed SedimentLoad to SedimentLoadLSData to make place for SedimentLoad in backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7931
diff changeset
149 SedimentLoadLSData resLoad,
6928
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
150 double km
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
151 ) {
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
152 int cSum = 0;
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
153 int fmSum = 0;
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
154 int sSum = 0;
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
155 int ssSum = 0;
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
156 int ssbSum = 0;
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
157 int sseSum = 0;
8024
963ede7b32bb Renamed SedimentLoad to SedimentLoadLSData to make place for SedimentLoad in backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7931
diff changeset
158 for (SedimentLoadLSData load : epochLoads) {
6928
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
159 SedimentLoadFraction f = load.getFraction(km);
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
160 if (f.getCoarse() > 0d) {
7054
f4d6ef50665a issue1436: Repair sedimentload epoch calculation,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7031
diff changeset
161 double c = makeNaN0(resLoad.getFraction(km).getCoarse());
6928
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
162 resLoad.setCoarse(km, c + f.getCoarse(), f.getCoarseRange());
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
163 cSum++;
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
164 }
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
165 if (f.getFineMiddle() > 0d) {
7054
f4d6ef50665a issue1436: Repair sedimentload epoch calculation,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7031
diff changeset
166 double fm = makeNaN0(resLoad.getFraction(km).getFineMiddle());
6928
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
167 resLoad.setFineMiddle(km, fm + f.getFineMiddle(), f.getFineMiddleRange());
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
168 fmSum++;
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
169 }
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
170 if (f.getSand() > 0d) {
7054
f4d6ef50665a issue1436: Repair sedimentload epoch calculation,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7031
diff changeset
171 double s = makeNaN0(resLoad.getFraction(km).getSand());
6928
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
172 resLoad.setSand(km, s + f.getSand(), f.getSandRange());
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
173 sSum++;
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
174 }
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
175 if (f.getSuspSand() > 0d) {
7054
f4d6ef50665a issue1436: Repair sedimentload epoch calculation,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7031
diff changeset
176 double s = makeNaN0(resLoad.getFraction(km).getSuspSand());
6928
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
177 resLoad.setSuspSand(km, s + f.getSuspSand(), f.getSuspSandRange());
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
178 ssSum++;
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
179 }
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
180 if (f.getSuspSandBed() > 0d) {
7054
f4d6ef50665a issue1436: Repair sedimentload epoch calculation,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7031
diff changeset
181 double s = makeNaN0(resLoad.getFraction(km).getSuspSandBed());
6928
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
182 resLoad.setSuspSandBed(km, s + f.getSuspSandBed(), f.getSuspSandBedRange());
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
183 ssbSum++;
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
184 }
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
185 if (f.getSuspSediment() > 0d) {
7054
f4d6ef50665a issue1436: Repair sedimentload epoch calculation,
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7031
diff changeset
186 double s = makeNaN0(resLoad.getFraction(km).getSuspSediment());
6928
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
187 resLoad.setSuspSediment(km, s + f.getSuspSediment(), f.getSuspSedimentRange());
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
188 sseSum++;
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
189 }
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
190 }
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
191
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
192 SedimentLoadFraction fr = resLoad.getFraction(km);
7031
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7023
diff changeset
193 // Prevent divisions by zero.
6928
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
194 if (cSum != 0) {
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
195 resLoad.setCoarse(km, fr.getCoarse()/cSum, fr.getCoarseRange());
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
196 }
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
197 if (fmSum != 0) {
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
198 resLoad.setFineMiddle(km, fr.getFineMiddle()/fmSum,
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
199 fr.getFineMiddleRange());
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
200 }
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
201 if (sSum != 0) {
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
202 resLoad.setSand(km, fr.getSand()/sSum, fr.getSandRange());
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
203 }
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
204 if (ssSum != 0) {
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
205 resLoad.setSuspSand(km, fr.getSuspSand()/ssSum,
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
206 fr.getSuspSandRange());
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
207 }
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
208 if (ssbSum != 0) {
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
209 resLoad.setSuspSandBed(km, fr.getSuspSandBed()/ssbSum,
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
210 fr.getSuspSandBedRange());
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
211 }
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
212 if (sseSum != 0) {
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
213 resLoad.setSuspSediment(km, fr.getSuspSediment()/sseSum, fr.getSuspSedimentRange());
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
214 }
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
215 }
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
216
7532
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7462
diff changeset
217 /**
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7462
diff changeset
218 * Calculate result for the ith given epoch.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7462
diff changeset
219 * @param i index of epoch (if multiple given).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7462
diff changeset
220 */
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
221 private SedimentLoadResult calculateEpoch(int i) {
8024
963ede7b32bb Renamed SedimentLoad to SedimentLoadLSData to make place for SedimentLoad in backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7931
diff changeset
222 List<SedimentLoadLSData> epochLoads = new ArrayList<SedimentLoadLSData>();
7931
b4117b8adb79 Include last year of epoch in calculation.
"Tom Gottfried <tom@intevation.de>"
parents: 7532
diff changeset
223 for (int j = epoch[i][0]; j <= epoch[i][1]; j++) {
5661
b6297a67823e SedimentLoadFactory: Renamed getLoadwithData to getLoadWithData, update callers.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4543
diff changeset
224 epochLoads.add(SedimentLoadFactory.getLoadWithData(
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
225 this.river,
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
226 this.yearEpoch,
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
227 this.kmLow,
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
228 this.kmUp,
7064
fabb5e7a3b66 Doc, comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7054
diff changeset
229 j, //syear
fabb5e7a3b66 Doc, comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7054
diff changeset
230 j)); //eyear
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
231 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
232
8024
963ede7b32bb Renamed SedimentLoad to SedimentLoadLSData to make place for SedimentLoad in backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7931
diff changeset
233 SedimentLoadLSData resLoad = new SedimentLoadLSData();
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
234 TDoubleArrayList kms = new TDoubleArrayList();
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
235
8024
963ede7b32bb Renamed SedimentLoad to SedimentLoadLSData to make place for SedimentLoad in backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7931
diff changeset
236 for (SedimentLoadLSData load : epochLoads) {
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
237 for (double km : load.getKms()) {
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
238 if (!kms.contains(km)) {
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
239 kms.add(km);
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
240 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
241 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
242 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
243
7254
fe32a7f9655e Reduce usage of careless 'for (int i = 0; i < x.size(); i++)' pattern.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7065
diff changeset
244 for (int j = 0, J = kms.size(); j < J; j++) {
6928
2119f13f95ab SedimentLoadCalculation: Refactoring, extracted method.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6740
diff changeset
245 calculateEpochKm(epochLoads, resLoad, kms.get(j));
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
246 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
247 resLoad.setDescription("");
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
248 resLoad.setEpoch(true);
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
249
8024
963ede7b32bb Renamed SedimentLoad to SedimentLoadLSData to make place for SedimentLoad in backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7931
diff changeset
250 SedimentLoadLSData sl = calculateTotalLoad(resLoad, this.epoch[i][0]);
7065
b17634649e61 Simplify code a bit.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7064
diff changeset
251
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
252 if (this.unit.equals("m3_per_a")) {
7065
b17634649e61 Simplify code a bit.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7064
diff changeset
253 sl = calculateUnit(sl, this.epoch[i][0]);
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
254 }
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
255
7065
b17634649e61 Simplify code a bit.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7064
diff changeset
256 return new SedimentLoadResult(
b17634649e61 Simplify code a bit.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7064
diff changeset
257 this.epoch[i][0],
b17634649e61 Simplify code a bit.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7064
diff changeset
258 this.epoch[i][1],
b17634649e61 Simplify code a bit.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7064
diff changeset
259 sl);
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
260 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
261
6948
d4108d6c4000 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6928
diff changeset
262 /**
d4108d6c4000 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6928
diff changeset
263 * Calculate/Fetch values at off. epochs.
d4108d6c4000 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6928
diff changeset
264 * @param i index in epochs.
d4108d6c4000 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6928
diff changeset
265 */
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
266 private SedimentLoadResult calculateOffEpoch(int i) {
8024
963ede7b32bb Renamed SedimentLoad to SedimentLoadLSData to make place for SedimentLoad in backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7931
diff changeset
267 SedimentLoadLSData load = SedimentLoadFactory.getLoadWithData(
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
268 this.river,
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
269 this.yearEpoch,
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
270 kmLow,
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
271 kmUp,
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
272 this.epoch[i][0],
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
273 this.epoch[i][1]);
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
274 SedimentLoadResult result;
8024
963ede7b32bb Renamed SedimentLoad to SedimentLoadLSData to make place for SedimentLoad in backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7931
diff changeset
275 SedimentLoadLSData sl = calculateTotalLoad(load, this.epoch[i][0]);
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
276 if (unit.equals("m3_per_a")) {
8024
963ede7b32bb Renamed SedimentLoad to SedimentLoadLSData to make place for SedimentLoad in backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7931
diff changeset
277 SedimentLoadLSData slu = calculateUnit(sl, epoch[i][0]);
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
278 result = new SedimentLoadResult(
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
279 this.epoch[i][0],
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
280 this.epoch[i][1],
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
281 slu);
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
282 }
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
283 else {
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
284 result = new SedimentLoadResult(
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
285 this.epoch[i][0],
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
286 this.epoch[i][1],
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
287 sl);
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
288 }
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
289
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
290 return result;
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
291 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
292
6678
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6543
diff changeset
293 /**
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6543
diff changeset
294 * Fetch loads for a single year, calculate total and
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6543
diff changeset
295 * return the result containing both.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6543
diff changeset
296 * @param y year, e.g. 1980
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6543
diff changeset
297 */
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
298 private SedimentLoadResult calculateYear(int y) {
8024
963ede7b32bb Renamed SedimentLoad to SedimentLoadLSData to make place for SedimentLoad in backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7931
diff changeset
299 SedimentLoadLSData load = SedimentLoadFactory.getLoadWithData(
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
300 this.river,
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
301 this.yearEpoch,
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
302 this.kmLow,
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
303 this.kmUp,
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
304 y,
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
305 y);
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
306
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
307 SedimentLoadResult result;
8024
963ede7b32bb Renamed SedimentLoad to SedimentLoadLSData to make place for SedimentLoad in backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7931
diff changeset
308 SedimentLoadLSData sl = calculateTotalLoad(load, y);
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
309 if (unit.equals("m3_per_a")) {
8024
963ede7b32bb Renamed SedimentLoad to SedimentLoadLSData to make place for SedimentLoad in backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7931
diff changeset
310 SedimentLoadLSData slu = calculateUnit(sl, y);
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
311 result = new SedimentLoadResult(y, 0, slu);
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
312 }
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
313 else {
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
314 result = new SedimentLoadResult(y, 0, sl);
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
315 }
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
316 return result;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
317 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
318
6374
48e92ff57f23 SedimentLoad*: Set range to fraction/fractions values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5994
diff changeset
319 /** Add up the loads of a year. */
8024
963ede7b32bb Renamed SedimentLoad to SedimentLoadLSData to make place for SedimentLoad in backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7931
diff changeset
320 private SedimentLoadLSData calculateTotalLoad(SedimentLoadLSData load, int year) {
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
321 logger.debug("calculateTotalLoad");
5685
756df79274e1 SedimentLoadCalculation: Partly fix 1250 (calculate more than one total if possible).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5661
diff changeset
322 boolean problemThisYear = false;
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
323 if (!load.hasCoarse()) {
5742
a4a894b15c35 Minor part of issue1235: dont show decimals of years.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5685
diff changeset
324 addProblem("missing.fraction.coarse", Integer.toString(year));
5685
756df79274e1 SedimentLoadCalculation: Partly fix 1250 (calculate more than one total if possible).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5661
diff changeset
325 problemThisYear = true;
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
326 }
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
327 if (!load.hasFineMiddle()) {
5742
a4a894b15c35 Minor part of issue1235: dont show decimals of years.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5685
diff changeset
328 addProblem("missing.fraction.fine_middle", Integer.toString(year));
5685
756df79274e1 SedimentLoadCalculation: Partly fix 1250 (calculate more than one total if possible).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5661
diff changeset
329 problemThisYear = true;
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
330 }
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
331 if (!load.hasSand()) {
5742
a4a894b15c35 Minor part of issue1235: dont show decimals of years.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5685
diff changeset
332 addProblem("missing.fraction.sand", Integer.toString(year));
5685
756df79274e1 SedimentLoadCalculation: Partly fix 1250 (calculate more than one total if possible).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5661
diff changeset
333 problemThisYear = true;
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
334 }
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
335 if (!load.hasSuspSand()) {
5742
a4a894b15c35 Minor part of issue1235: dont show decimals of years.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5685
diff changeset
336 addProblem("missing.fraction.susp_sand", Integer.toString(year));
5685
756df79274e1 SedimentLoadCalculation: Partly fix 1250 (calculate more than one total if possible).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5661
diff changeset
337 problemThisYear = true;
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
338 }
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
339 if (!load.hasSuspSediment()) {
5742
a4a894b15c35 Minor part of issue1235: dont show decimals of years.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5685
diff changeset
340 addProblem("missing.fraction.susp_sediment", Integer.toString(year));
5685
756df79274e1 SedimentLoadCalculation: Partly fix 1250 (calculate more than one total if possible).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5661
diff changeset
341 problemThisYear = true;
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
342 }
5685
756df79274e1 SedimentLoadCalculation: Partly fix 1250 (calculate more than one total if possible).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5661
diff changeset
343 if (problemThisYear) {
756df79274e1 SedimentLoadCalculation: Partly fix 1250 (calculate more than one total if possible).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5661
diff changeset
344 logger.warn("Some problem, not calculating total load.");
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
345 return load;
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
346 }
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
347 return partialTotal(load);
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
348 }
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
349
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
350
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
351
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
352 /**
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
353 * Set total values in load.
6678
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6543
diff changeset
354 *
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6543
diff changeset
355 * Therefore, run over the sorted kms and find ranges where either all
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
356 * or all Geschiebe or just the Schwebstoff fractions are set.
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
357 * Merge these ranges and add (maybe new) respective fractions to
6678
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6543
diff changeset
358 * load. In the process, remember any 'unfished' ends from measurements
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6543
diff changeset
359 * where the km-ranges did not completely match.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6543
diff changeset
360 *
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
361 * @param load SedimentLoad to add total values (and ranges) to.
6678
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6543
diff changeset
362 * @return input param load, with total values set.
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
363 */
8024
963ede7b32bb Renamed SedimentLoad to SedimentLoadLSData to make place for SedimentLoad in backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7931
diff changeset
364 private SedimentLoadLSData partialTotal(SedimentLoadLSData load) {
7022
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6989
diff changeset
365 // The load with balanced ranges, will be returned.
8024
963ede7b32bb Renamed SedimentLoad to SedimentLoadLSData to make place for SedimentLoad in backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7931
diff changeset
366 SedimentLoadLSData fairLoad = load;
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
367
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
368 Range lastOtherRange = null;
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
369 double lastOtherValue = 0d;
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
370
6404
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
371 Range lastSuspRange = null;
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
372 double lastSuspValue = 0d;
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
373
6970
7be97faf5848 flys/issue1235: Same kicks against a few inconsistencies and bugs in the calculation of sediment loads. I believe it _do_not_ delivers the right results.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6953
diff changeset
374 for (double km: load.getKms()) { // kms are already sorted!
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
375 logger.debug ("Trying to add at km " + km);
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
376 SedimentLoadFraction fraction = load.getFraction(km);
6970
7be97faf5848 flys/issue1235: Same kicks against a few inconsistencies and bugs in the calculation of sediment loads. I believe it _do_not_ delivers the right results.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6953
diff changeset
377 if (fraction.isComplete()) {
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
378 double total = fraction.getCoarse() +
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
379 fraction.getFineMiddle() +
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
380 fraction.getSand() +
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
381 fraction.getSuspSand() +
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
382 fraction.getSuspSediment();
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
383 // Easiest case. Add values up and set'em.
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
384 if (fraction.getCoarseRange().equals(
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
385 fraction.getSuspSedimentRange())) {
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
386 lastOtherRange = null;
6404
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
387 lastSuspRange = null;
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
388 fairLoad.setTotal(km, total, fraction.getCoarseRange());
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
389 }
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
390 else {
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
391 // Need to split a range.
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
392 if (fraction.getCoarseRange().getEnd()
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
393 < fraction.getSuspSedimentRange().getEnd()) {
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
394 // Schwebstoff is longer.
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
395 // Adjust and remember schwebstoffs range and value.
6404
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
396 lastSuspRange = (Range) fraction.getSuspSedimentRange().clone();
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
397 lastSuspRange.setStart(fraction.getCoarseRange().getEnd());
6411
a21f7a3e4be5 Revert to rev 6404 for issue1235
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6405
diff changeset
398 lastSuspValue = fraction.getSuspSediment();
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
399 lastOtherRange = null;
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
400 fairLoad.setTotal(km, total, fraction.getCoarseRange());
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
401 }
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
402 else {
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
403 // Geschiebe is longer.
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
404 // Adjust and remember other values.
7023
a18a43764793 issue1235: Do not add 'other' values twice to suspended sed. values, fix range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7022
diff changeset
405 lastOtherRange = (Range) fraction.getCoarseRange().clone();
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
406 lastOtherRange.setStart(fraction.getSuspSedimentRange().getEnd());
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
407 lastOtherValue = (total - fraction.getSuspSediment());
6404
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
408 lastSuspRange = null;
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
409 fairLoad.setTotal(km, total, fraction.getSuspSedimentRange());
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
410 }
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
411 }
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
412 }
6970
7be97faf5848 flys/issue1235: Same kicks against a few inconsistencies and bugs in the calculation of sediment loads. I believe it _do_not_ delivers the right results.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6953
diff changeset
413 else if (fraction.hasOnlySuspValues() && lastOtherRange != null) {
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
414 // Split stuff.
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
415 Range suspSedimentRange = fraction.getSuspSedimentRange();
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
416 // if intersects with last other range, cool! merge and add!
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
417 if (lastOtherRange.contains(km)) {
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
418 double maxStart = 0d;
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
419 double minEnd = 0d;
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
420 maxStart = Math.max(suspSedimentRange.getStart(),
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
421 lastOtherRange.getStart());
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
422
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
423 minEnd = Math.min(suspSedimentRange.getEnd(),
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
424 lastOtherRange.getEnd());
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
425 double total = lastOtherValue + fraction.getSuspSediment();
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
426 Range totalRange = new Range(maxStart, minEnd);
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
427 if (suspSedimentRange.getEnd() > lastOtherRange.getEnd()) {
6404
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
428 lastSuspRange = (Range) suspSedimentRange.clone();
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
429 lastSuspRange.setStart(lastOtherRange.getEnd());
6411
a21f7a3e4be5 Revert to rev 6404 for issue1235
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6405
diff changeset
430 lastSuspValue = fraction.getSuspSediment();
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
431 lastOtherRange = null;
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
432 }
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
433 else {
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
434 // Other is "longer".
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
435 lastOtherRange.setStart(suspSedimentRange.getEnd());
6404
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
436 lastSuspRange = null;
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
437 }
6970
7be97faf5848 flys/issue1235: Same kicks against a few inconsistencies and bugs in the calculation of sediment loads. I believe it _do_not_ delivers the right results.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6953
diff changeset
438 if (lastOtherRange != null
7be97faf5848 flys/issue1235: Same kicks against a few inconsistencies and bugs in the calculation of sediment loads. I believe it _do_not_ delivers the right results.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6953
diff changeset
439 && Math.abs(suspSedimentRange.getEnd() - lastOtherRange.getEnd()) < 0.1d) {
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
440 lastOtherRange = null;
6404
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
441 lastSuspRange = null;
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
442 }
7023
a18a43764793 issue1235: Do not add 'other' values twice to suspended sed. values, fix range.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 7022
diff changeset
443 fairLoad.setTotal(km, total, totalRange);
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
444 }
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
445 else {
6404
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
446 lastSuspRange = suspSedimentRange;
6411
a21f7a3e4be5 Revert to rev 6404 for issue1235
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6405
diff changeset
447 lastSuspValue = fraction.getSuspSediment();
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
448 lastOtherRange = null;
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
449 }
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
450 }
6970
7be97faf5848 flys/issue1235: Same kicks against a few inconsistencies and bugs in the calculation of sediment loads. I believe it _do_not_ delivers the right results.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6953
diff changeset
451 else if (fraction.hasButSuspValues() && lastSuspRange != null) {
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
452 // If intersects with last suspsed range, merge and add
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
453 double total = fraction.getCoarse() +
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
454 fraction.getFineMiddle() +
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
455 fraction.getSand() +
6411
a21f7a3e4be5 Revert to rev 6404 for issue1235
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6405
diff changeset
456 fraction.getSuspSand() +
6404
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
457 lastSuspValue;
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
458 double maxStart = Math.max(fraction.getCoarseRange().getStart(),
6404
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
459 lastSuspRange.getStart());
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
460 if (lastSuspRange.contains(km)) {
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
461 double minEnd = Math.min(fraction.getCoarseRange().getEnd(),
6404
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
462 lastSuspRange.getEnd());
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
463 Range totalRange = new Range(maxStart, minEnd);
6404
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
464 if (lastSuspRange.getEnd() > fraction.getCoarseRange().getEnd()) {
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
465 // SuspSed longer.
6404
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
466 lastSuspRange.setStart(fraction.getCoarseRange().getEnd());
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
467 lastOtherRange = null;
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
468 }
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
469 else {
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
470 // Other longer
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
471 lastOtherRange = (Range) fraction.getCoarseRange().clone();
6404
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
472 lastOtherRange.setStart(lastSuspRange.getEnd());
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
473 lastSuspRange = null;
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
474 lastOtherValue = total - lastSuspValue;
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
475 }
6970
7be97faf5848 flys/issue1235: Same kicks against a few inconsistencies and bugs in the calculation of sediment loads. I believe it _do_not_ delivers the right results.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6953
diff changeset
476 if (lastSuspRange != null
7be97faf5848 flys/issue1235: Same kicks against a few inconsistencies and bugs in the calculation of sediment loads. I believe it _do_not_ delivers the right results.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6953
diff changeset
477 && lastOtherRange != null
7be97faf5848 flys/issue1235: Same kicks against a few inconsistencies and bugs in the calculation of sediment loads. I believe it _do_not_ delivers the right results.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6953
diff changeset
478 && Math.abs(lastSuspRange.getEnd() - lastOtherRange.getEnd()) < 0.1d) {
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
479 lastOtherRange = null;
6404
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
480 lastSuspRange = null;
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
481 }
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
482 fairLoad.setTotal(km, total, totalRange);
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
483 }
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
484 else {
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
485 // Ranges are disjoint.
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
486 lastOtherRange = fraction.getCoarseRange();
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
487 lastOtherValue = total - fraction.getSuspSediment();
6404
e6ceab9e3091 prep issue1235: Rename functions and variable to indicate use of other susp values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6381
diff changeset
488 lastSuspRange = null;
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
489 }
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
490 }
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
491 else {
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
492 // Some values are missing or no intersection with former values.
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
493 // Stay as we are.
6970
7be97faf5848 flys/issue1235: Same kicks against a few inconsistencies and bugs in the calculation of sediment loads. I believe it _do_not_ delivers the right results.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6953
diff changeset
494 if (fraction.hasButSuspValues()) {
6500
f3b3742fbdad SedimentLoadCalculation: Handle boring cases in total sed load calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6499
diff changeset
495 double total = fraction.getCoarse() +
f3b3742fbdad SedimentLoadCalculation: Handle boring cases in total sed load calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6499
diff changeset
496 fraction.getFineMiddle() +
f3b3742fbdad SedimentLoadCalculation: Handle boring cases in total sed load calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6499
diff changeset
497 fraction.getSand() +
f3b3742fbdad SedimentLoadCalculation: Handle boring cases in total sed load calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6499
diff changeset
498 fraction.getSuspSand();
f3b3742fbdad SedimentLoadCalculation: Handle boring cases in total sed load calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6499
diff changeset
499 lastOtherRange = fraction.getCoarseRange();
f3b3742fbdad SedimentLoadCalculation: Handle boring cases in total sed load calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6499
diff changeset
500 lastOtherValue = total;
f3b3742fbdad SedimentLoadCalculation: Handle boring cases in total sed load calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6499
diff changeset
501 lastSuspRange = null;
f3b3742fbdad SedimentLoadCalculation: Handle boring cases in total sed load calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6499
diff changeset
502 }
6970
7be97faf5848 flys/issue1235: Same kicks against a few inconsistencies and bugs in the calculation of sediment loads. I believe it _do_not_ delivers the right results.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6953
diff changeset
503 else if (fraction.hasOnlySuspValues()) {
6500
f3b3742fbdad SedimentLoadCalculation: Handle boring cases in total sed load calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6499
diff changeset
504 lastSuspRange = fraction.getSuspSedimentRange();
f3b3742fbdad SedimentLoadCalculation: Handle boring cases in total sed load calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6499
diff changeset
505 lastSuspValue = fraction.getSuspSediment();
f3b3742fbdad SedimentLoadCalculation: Handle boring cases in total sed load calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6499
diff changeset
506 lastOtherRange = null;
f3b3742fbdad SedimentLoadCalculation: Handle boring cases in total sed load calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6499
diff changeset
507 }
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
508 }
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
509 }
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
510 return fairLoad;
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
511 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
512
6381
df1a3826c691 SedimentLoadCalculation: Calculate and set Total Load values ind a brutal range merging manner.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6377
diff changeset
513
6678
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6543
diff changeset
514 /**
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6543
diff changeset
515 * Transform values in load.
6948
d4108d6c4000 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6928
diff changeset
516 * Background is to transform values measured in
6951
f5f60b3d9180 Doc fix.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6950
diff changeset
517 * t/a to m^3/a using the specific measured densities.
6948
d4108d6c4000 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6928
diff changeset
518 *
6678
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6543
diff changeset
519 * @param load The load of which values should be transformed.
6948
d4108d6c4000 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6928
diff changeset
520 * @param year The year at which to look at density (e.g. 2003).
d4108d6c4000 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6928
diff changeset
521 *
6678
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6543
diff changeset
522 * @return parameter load with transformed values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6543
diff changeset
523 */
8024
963ede7b32bb Renamed SedimentLoad to SedimentLoadLSData to make place for SedimentLoad in backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7931
diff changeset
524 private SedimentLoadLSData calculateUnit(SedimentLoadLSData load, int year) {
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
525 SedimentDensity density =
8065
fdb26fe898dc Sediment load: Cached sediment values dont depend on year. The cached object is an index over year so there is not need to ask the factory for this.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8024
diff changeset
526 SedimentDensityFactory.getSedimentDensity(river, kmLow, kmUp);
6951
f5f60b3d9180 Doc fix.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6950
diff changeset
527
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
528 for (double km: load.getKms()) {
7462
906ed0b1f3f1 Fix for flys/issue1654: Divide through denisity, do not multiply.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7261
diff changeset
529 double dens = 1d/density.getDensity(km, year);
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
530 SedimentLoadFraction fraction = load.getFraction(km);
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
531 double coarse = fraction.getCoarse();
6376
8d6f23243d1d SedimentLoad*: Switch from snake_case to camelCase.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6375
diff changeset
532 double fineMiddle = fraction.getFineMiddle();
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
533 double sand = fraction.getSand();
6376
8d6f23243d1d SedimentLoad*: Switch from snake_case to camelCase.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6375
diff changeset
534 double suspSand = fraction.getSuspSand();
8d6f23243d1d SedimentLoad*: Switch from snake_case to camelCase.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6375
diff changeset
535 double bedSand = fraction.getSuspSandBed();
8d6f23243d1d SedimentLoad*: Switch from snake_case to camelCase.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6375
diff changeset
536 double sediment = fraction.getSuspSediment();
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
537 double total = fraction.getTotal();
6953
733c35239fe7 issue1462/3: When changing units (t/a -> m^3/a), also change total load.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6951
diff changeset
538 double loadTotal = fraction.getLoadTotal();
6374
48e92ff57f23 SedimentLoad*: Set range to fraction/fractions values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5994
diff changeset
539 load.setCoarse(km, (coarse * dens), fraction.getCoarseRange());
48e92ff57f23 SedimentLoad*: Set range to fraction/fractions values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5994
diff changeset
540 load.setFineMiddle(km, (fineMiddle * dens), fraction.getFineMiddleRange());
48e92ff57f23 SedimentLoad*: Set range to fraction/fractions values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5994
diff changeset
541 load.setSand(km, (sand * dens), fraction.getSandRange());
48e92ff57f23 SedimentLoad*: Set range to fraction/fractions values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5994
diff changeset
542 load.setSuspSand(km, (suspSand * dens), fraction.getSuspSandRange());
48e92ff57f23 SedimentLoad*: Set range to fraction/fractions values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5994
diff changeset
543 load.setSuspSandBed(km, (bedSand * dens), fraction.getSuspSandBedRange());
48e92ff57f23 SedimentLoad*: Set range to fraction/fractions values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5994
diff changeset
544 load.setSuspSediment(km, (sediment * dens), fraction.getSuspSedimentRange());
48e92ff57f23 SedimentLoad*: Set range to fraction/fractions values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5994
diff changeset
545 load.setTotal(km, (total * dens), fraction.getTotalRange());
6953
733c35239fe7 issue1462/3: When changing units (t/a -> m^3/a), also change total load.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6951
diff changeset
546 load.setLoadTotal(km, (loadTotal * dens), fraction.getLoadTotalRange());
4522
a9753f717b3d Completed and fixed sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents: 4483
diff changeset
547 }
4373
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
548 return load;
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
549 }
1fb224bb2c6b Added sediment load calculation.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
550 }
4483
cc6323401643 Cosmetics: Removed some WSP, obsolete imports. Documentation added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4373
diff changeset
551 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org