Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensity.java @ 8856:5e38e2924c07 3.2.x
Fix code style.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 18 Jan 2018 20:12:01 +0100 |
parents | e4606eae8ea5 |
children | 0a5239a1e46e |
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:
5712
diff
changeset
|
9 package org.dive4elements.river.artifacts.model.minfo; |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
10 |
7460
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
11 import java.io.Serializable; |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
12 import java.util.ArrayList; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
13 import java.util.Collections; |
8064
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
14 import java.util.Comparator; |
8063
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
15 import java.util.Iterator; |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
16 import java.util.List; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
17 import java.util.Map; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
18 import java.util.Set; |
7200
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
19 import java.util.TreeMap; |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
20 |
7460
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
21 import org.apache.log4j.Logger; |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
22 import org.dive4elements.artifacts.common.utils.Config; |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
23 |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
24 |
7200
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
25 /** Sediment Densities for multiple years. */ |
7414
2facd4066a28
issue1205: made SedimentDensity serializable.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7309
diff
changeset
|
26 public class SedimentDensity implements Serializable |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
27 { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8065
diff
changeset
|
28 private static final Logger log = Logger |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
29 .getLogger(SedimentDensity.class); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
30 |
7460
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
31 public static final double DEFAULT_SEDIMNET_DENSITY_FACTOR = 1.9; |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
32 |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
33 public static String SEDIMENT_DENSITY_FACTOR_XPATH = |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
34 "/artifact-database/options/sediment-density-factor/text()"; |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
35 |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
36 public static final double SEDIMNET_DENSITY_FACTOR = |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
37 getSedimentDensityFactor(); |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
38 |
8063
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
39 private TreeMap<Integer, List<SedimentDensityValue>> densities; |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
40 |
7460
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
41 |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
42 /** Figures out the sediment density factor from global config. */ |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
43 private static final double getSedimentDensityFactor() { |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
44 |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
45 double factor = DEFAULT_SEDIMNET_DENSITY_FACTOR; |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
46 |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
47 String factorString = |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
48 Config.getStringXPath(SEDIMENT_DENSITY_FACTOR_XPATH); |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
49 |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
50 if (factorString != null) { |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
51 try { |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
52 factor = Double.parseDouble(factorString.trim()); |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
53 } |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
54 catch (NumberFormatException nfe) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8065
diff
changeset
|
55 log.error(nfe); |
7460
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
56 } |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
57 } |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
58 |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8065
diff
changeset
|
59 log.info("Sedmiment density factor: " + factor); |
7460
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
60 |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
61 return factor; |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
62 } |
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
63 |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
64 public SedimentDensity() { |
8063
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
65 densities = new TreeMap<Integer, List<SedimentDensityValue>>(); |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
66 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
67 |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
68 public Map<Integer, List<SedimentDensityValue>> getDensities() { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
69 return densities; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
70 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
71 |
8064
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
72 private static final Comparator<SedimentDensityValue> BY_KM = |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
73 new Comparator<SedimentDensityValue>() { |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
74 @Override |
8856 | 75 public int compare( |
76 SedimentDensityValue a, | |
77 SedimentDensityValue b | |
78 ) { | |
8064
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
79 double diff = a.getKm() - b.getKm(); |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
80 if (diff < 0.0) return -1; |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
81 if (diff > 0.0) return +1; |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
82 return 0; |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
83 } |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
84 }; |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
85 |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
86 public void addDensity(double km, double density, int year) { |
7463
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
87 |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8065
diff
changeset
|
88 if (log.isDebugEnabled()) { |
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8065
diff
changeset
|
89 log.debug("adding " + year); |
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:
8064
diff
changeset
|
90 } |
7463
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
91 |
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
92 Integer key = Integer.valueOf(year); |
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
93 |
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
94 List<SedimentDensityValue> list = densities.get(key); |
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
95 |
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
96 if (list == null) { |
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
97 list = new ArrayList<SedimentDensityValue>(); |
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
98 densities.put(key, list); |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
99 } |
7463
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
100 |
8064
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
101 // Keep list sorted by km. |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
102 SedimentDensityValue sdv = new SedimentDensityValue(km, density, year); |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
103 int index = Collections.binarySearch(list, sdv, BY_KM); |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
104 |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
105 if (index < 0) { |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
106 // index = -(insertion point) - 1 |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
107 // -(index + 1) = insertion point |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
108 index = -(index + 1); |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
109 } |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
110 |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
111 list.add(index, sdv); |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
112 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
113 |
6937
0a3dd5be6f81
issue1436: Towards finding the best match in years for densities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6910
diff
changeset
|
114 /** |
0a3dd5be6f81
issue1436: Towards finding the best match in years for densities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6910
diff
changeset
|
115 * Get the density at year. |
7200
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
116 * Measured densities are valid until the next measurement. |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
117 * If no measurement was found 1.8 is returned. |
6937
0a3dd5be6f81
issue1436: Towards finding the best match in years for densities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6910
diff
changeset
|
118 */ |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
119 public double getDensity(double km, int year) { |
8063
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
120 |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
121 if (densities.isEmpty()) { |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
122 return SEDIMNET_DENSITY_FACTOR; |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
123 } |
8063
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
124 |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
125 if (densities.size() == 1) { |
8856 | 126 Map.Entry<Integer, List<SedimentDensityValue>> entry = |
127 densities.firstEntry(); | |
8063
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
128 return entry.getKey() <= year |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
129 ? getDensityAtKm(entry.getValue(), km) |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
130 : SEDIMNET_DENSITY_FACTOR; |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
131 } |
8064
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
132 |
8063
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
133 Iterator<Map.Entry<Integer, List<SedimentDensityValue>>> iter = |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
134 densities.entrySet().iterator(); |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
135 |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
136 Map.Entry<Integer, List<SedimentDensityValue>> last = iter.next(); |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
137 |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
138 while (iter.hasNext()) { |
8856 | 139 Map.Entry<Integer, List<SedimentDensityValue>> current = |
140 iter.next(); | |
8063
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
141 last = current; |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
142 int y1 = last.getKey(); |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
143 int y2 = current.getKey(); |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
144 if (year >= y1 && year < y2) { |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
145 return getDensityAtKm(last.getValue(), km); |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
146 } |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
147 if (year >= y2 && !iter.hasNext()) { |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
148 return getDensityAtKm(current.getValue(), km); |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
149 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
150 } |
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:
8064
diff
changeset
|
151 |
7460
2733b4aae74b
flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7414
diff
changeset
|
152 return SEDIMNET_DENSITY_FACTOR; |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
153 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
154 |
7200
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
155 /** Get (sorted) map of km to density of all years. */ |
7309
a6ceb4b333c3
SedimentDensity: Fix getAllDensities and made it public.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7254
diff
changeset
|
156 public double[][] getAllDensities() |
7200
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
157 { |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
158 TreeMap<Double, Double> map = new TreeMap<Double,Double>(); |
8063
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
159 // XXX: This looks stupid. |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
160 for (List<SedimentDensityValue> sdvs: densities.values()) { |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
161 for (SedimentDensityValue sdv: sdvs) { |
7200
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
162 map.put(sdv.getKm(), sdv.getDensity()); |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
163 } |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
164 } |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
165 double[][] points = new double[2][map.keySet().size()]; |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
166 int i = 0; |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
167 for (Map.Entry<Double, Double> kmDens: map.entrySet()) { |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
168 points[0][i] = kmDens.getKey(); |
7309
a6ceb4b333c3
SedimentDensity: Fix getAllDensities and made it public.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7254
diff
changeset
|
169 points[1][i] = kmDens.getValue(); |
7200
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
170 i++; |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
171 } |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
172 |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
173 return points; |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
174 } |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
175 |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
176 /** Get points km,density (sorted by km), for a given year. */ |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
177 public double[][] getDensities(int year) |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
178 { |
8063
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
179 List<SedimentDensityValue> list = densities.get(year); |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
180 if (list == null) { |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
181 return new double[2][0]; |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
182 } |
8064
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
183 // List is sorted in km. |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
184 double[][] points = new double[2][list.size()]; |
7200
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
185 int i = 0; |
8064
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
186 for (SedimentDensityValue sdv: list) { |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
187 points[0][i] = sdv.getKm(); |
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
188 points[1][i] = sdv.getDensity(); |
7200
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
189 i++; |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
190 } |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
191 |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
192 return points; |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
193 } |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
194 |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
195 /** Get value at km, interpolated. */ |
8064
50102c41151e
Sediment load: Ensure that the lists of values are always ordered station wise. This was a hidden bug. :-/
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8063
diff
changeset
|
196 private static double getDensityAtKm( |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
197 List<SedimentDensityValue> values, |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
198 double km |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
199 ) { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
200 SedimentDensityValue prev = null; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
201 SedimentDensityValue next = null; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
202 for (SedimentDensityValue sdv: values) { |
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:
6949
diff
changeset
|
203 if (Math.abs(sdv.getKm() - km) < 0.00001) { |
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:
6949
diff
changeset
|
204 return prev.getDensity(); |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
205 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
206 if (sdv.getKm() > km) { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
207 next = sdv; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
208 break; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
209 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
210 prev = sdv; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
211 } |
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:
6949
diff
changeset
|
212 return spline(prev, next, km); |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
213 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
214 |
7200
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
215 /** Linearly interpolate between density values. */ |
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:
6949
diff
changeset
|
216 private static double spline( |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
217 SedimentDensityValue prev, |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
218 SedimentDensityValue next, |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
219 double km |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
220 ) { |
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:
6949
diff
changeset
|
221 if (prev == null && next == null) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8065
diff
changeset
|
222 log.warn("prev and next are null -> NaN"); |
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:
6949
diff
changeset
|
223 return Double.NaN; |
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:
6949
diff
changeset
|
224 } |
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:
6949
diff
changeset
|
225 |
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:
6949
diff
changeset
|
226 if (prev == null) return next.getDensity(); |
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:
6949
diff
changeset
|
227 if (next == null) return prev.getDensity(); |
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:
6949
diff
changeset
|
228 |
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:
6949
diff
changeset
|
229 // XXX: This is no spline interpolation! |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
230 double lower = prev.getKm(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
231 double upper = next.getKm(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
232 double upperDensity = next.getDensity(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
233 double lowerDensity = prev.getDensity(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
234 |
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:
6949
diff
changeset
|
235 double m = (upperDensity - lowerDensity)/(upper - lower); |
6949
13c2762270a6
issue1462: 1) & 4) Fix wrong density interpolation code.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6948
diff
changeset
|
236 double b = lowerDensity - (m * lower); |
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:
6949
diff
changeset
|
237 return m * km + b; |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
238 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
239 |
6948
d4108d6c4000
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6938
diff
changeset
|
240 |
d4108d6c4000
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6938
diff
changeset
|
241 /** If multiple values for same year and station are found, |
d4108d6c4000
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6938
diff
changeset
|
242 * build and store average, dismiss multiple values. */ |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
243 public void cleanUp() { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
244 Set<Integer> keys = densities.keySet(); |
6948
d4108d6c4000
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6938
diff
changeset
|
245 // Walk over years |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
246 for (Integer key : keys) { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
247 List<SedimentDensityValue> list = densities.get(key); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
248 if (list.size() == 0) { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
249 return; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
250 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
251 List<SedimentDensityValue> cleaned = |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
252 new ArrayList<SedimentDensityValue>(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
253 double prevkm = list.get(0).getKm(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
254 int counter = 0; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
255 double sum = 0d; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
256 for (SedimentDensityValue value : list) { |
6948
d4108d6c4000
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6938
diff
changeset
|
257 // Apparently we can assume that values are ordered by km. |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
258 if (value.getKm() == prevkm) { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
259 sum += value.getDensity(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
260 counter++; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
261 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
262 else { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
263 cleaned.add(new SedimentDensityValue( |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
264 prevkm, |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
265 sum / counter, |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
266 value.getYear())); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
267 sum = value.getDensity(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
268 counter = 1; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
269 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
270 prevkm = value.getKm(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
271 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
272 this.densities.put(key, cleaned); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
273 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
274 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
275 } |
6948
d4108d6c4000
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6938
diff
changeset
|
276 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |