Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensity.java @ 9801:1d7a72a50183 3.2.x tip
Assume Compose V2, consistently
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 23 Nov 2023 10:14:13 +0100 |
parents | 0a5239a1e46e |
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:
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 |
9726 | 21 import org.apache.logging.log4j.Logger; |
22 import org.apache.logging.log4j.LogManager; | |
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
|
23 import org.dive4elements.artifacts.common.utils.Config; |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
24 |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
25 |
7200
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
26 /** Sediment Densities for multiple years. */ |
7414
2facd4066a28
issue1205: made SedimentDensity serializable.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7309
diff
changeset
|
27 public class SedimentDensity implements Serializable |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
28 { |
9726 | 29 private static final Logger log = LogManager |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
30 .getLogger(SedimentDensity.class); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
31 |
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
|
32 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
|
33 |
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 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
|
35 "/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
|
36 |
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 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
|
38 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
|
39 |
8063
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
40 private TreeMap<Integer, List<SedimentDensityValue>> densities; |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
41 |
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
|
42 |
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 /** 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
|
44 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
|
45 |
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 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
|
47 |
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 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
|
49 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
|
50 |
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 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
|
52 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
|
53 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
|
54 } |
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
|
55 catch (NumberFormatException nfe) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8065
diff
changeset
|
56 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
|
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 } |
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
|
59 |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8065
diff
changeset
|
60 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
|
61 |
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 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
|
63 } |
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
|
64 |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
65 public SedimentDensity() { |
8063
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
66 densities = new TreeMap<Integer, List<SedimentDensityValue>>(); |
4521
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 |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
69 public Map<Integer, List<SedimentDensityValue>> getDensities() { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
70 return densities; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
71 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
72 |
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
|
73 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
|
74 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
|
75 @Override |
8856 | 76 public int compare( |
77 SedimentDensityValue a, | |
78 SedimentDensityValue b | |
79 ) { | |
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
|
80 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
|
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 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
|
83 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
|
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 }; |
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
|
86 |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
87 public void addDensity(double km, double density, int year) { |
7463
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
88 |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8065
diff
changeset
|
89 if (log.isDebugEnabled()) { |
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8065
diff
changeset
|
90 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
|
91 } |
7463
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
92 |
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
93 Integer key = Integer.valueOf(year); |
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
94 |
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
95 List<SedimentDensityValue> list = densities.get(key); |
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
96 |
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
97 if (list == null) { |
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
98 list = new ArrayList<SedimentDensityValue>(); |
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
99 densities.put(key, list); |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
100 } |
7463
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
101 |
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
|
102 // 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
|
103 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
|
104 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
|
105 |
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 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
|
107 // 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
|
108 // -(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
|
109 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
|
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 |
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
|
112 list.add(index, sdv); |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
113 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
114 |
6937
0a3dd5be6f81
issue1436: Towards finding the best match in years for densities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6910
diff
changeset
|
115 /** |
0a3dd5be6f81
issue1436: Towards finding the best match in years for densities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6910
diff
changeset
|
116 * 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
|
117 * 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
|
118 * 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
|
119 */ |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
120 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
|
121 |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
122 if (densities.isEmpty()) { |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
123 return SEDIMNET_DENSITY_FACTOR; |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
124 } |
8063
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
125 |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
126 if (densities.size() == 1) { |
8856 | 127 Map.Entry<Integer, List<SedimentDensityValue>> entry = |
128 densities.firstEntry(); | |
8063
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
129 return entry.getKey() <= year |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
130 ? getDensityAtKm(entry.getValue(), km) |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
131 : SEDIMNET_DENSITY_FACTOR; |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
132 } |
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
|
133 |
8063
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
134 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
|
135 densities.entrySet().iterator(); |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
136 |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
137 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
|
138 |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
139 while (iter.hasNext()) { |
8856 | 140 Map.Entry<Integer, List<SedimentDensityValue>> current = |
141 iter.next(); | |
8063
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
142 last = current; |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
143 int y1 = last.getKey(); |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
144 int y2 = current.getKey(); |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
145 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
|
146 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
|
147 } |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
148 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
|
149 return getDensityAtKm(current.getValue(), km); |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
150 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
151 } |
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
|
152 |
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
|
153 return SEDIMNET_DENSITY_FACTOR; |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
154 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
155 |
7200
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
156 /** 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
|
157 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
|
158 { |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
159 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
|
160 // XXX: This looks stupid. |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
161 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
|
162 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
|
163 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
|
164 } |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
165 } |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
166 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
|
167 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
|
168 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
|
169 points[0][i] = kmDens.getKey(); |
7309
a6ceb4b333c3
SedimentDensity: Fix getAllDensities and made it public.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7254
diff
changeset
|
170 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
|
171 i++; |
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 |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
174 return points; |
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 |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
177 /** 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
|
178 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
|
179 { |
8063
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
180 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
|
181 if (list == null) { |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
182 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
|
183 } |
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
|
184 // 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 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
|
190 i++; |
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 |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
193 return points; |
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 |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
196 /** 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
|
197 private static double getDensityAtKm( |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
198 List<SedimentDensityValue> values, |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
199 double km |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
200 ) { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
201 SedimentDensityValue prev = null; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
202 SedimentDensityValue next = null; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
203 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
|
204 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
|
205 return prev.getDensity(); |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
206 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
207 if (sdv.getKm() > km) { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
208 next = sdv; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
209 break; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
210 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
211 prev = sdv; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
212 } |
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
|
213 return spline(prev, next, km); |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
214 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
215 |
7200
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
216 /** 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
|
217 private static double spline( |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
218 SedimentDensityValue prev, |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
219 SedimentDensityValue next, |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
220 double km |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
221 ) { |
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
|
222 if (prev == null && next == null) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8065
diff
changeset
|
223 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
|
224 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
|
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 |
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 (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
|
228 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
|
229 |
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
|
230 // XXX: This is no spline interpolation! |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
231 double lower = prev.getKm(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
232 double upper = next.getKm(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
233 double upperDensity = next.getDensity(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
234 double lowerDensity = prev.getDensity(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
235 |
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
|
236 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
|
237 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
|
238 return m * km + b; |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
239 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
240 |
6948
d4108d6c4000
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6938
diff
changeset
|
241 |
d4108d6c4000
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6938
diff
changeset
|
242 /** If multiple values for same year and station are found, |
d4108d6c4000
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6938
diff
changeset
|
243 * build and store average, dismiss multiple values. */ |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
244 public void cleanUp() { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
245 Set<Integer> keys = densities.keySet(); |
6948
d4108d6c4000
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6938
diff
changeset
|
246 // Walk over years |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
247 for (Integer key : keys) { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
248 List<SedimentDensityValue> list = densities.get(key); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
249 if (list.size() == 0) { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
250 return; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
251 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
252 List<SedimentDensityValue> cleaned = |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
253 new ArrayList<SedimentDensityValue>(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
254 double prevkm = list.get(0).getKm(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
255 int counter = 0; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
256 double sum = 0d; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
257 for (SedimentDensityValue value : list) { |
6948
d4108d6c4000
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6938
diff
changeset
|
258 // 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
|
259 if (value.getKm() == prevkm) { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
260 sum += value.getDensity(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
261 counter++; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
262 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
263 else { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
264 cleaned.add(new SedimentDensityValue( |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
265 prevkm, |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
266 sum / counter, |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
267 value.getYear())); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
268 sum = value.getDensity(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
269 counter = 1; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
270 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
271 prevkm = value.getKm(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
272 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
273 this.densities.put(key, cleaned); |
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 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
276 } |
6948
d4108d6c4000
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6938
diff
changeset
|
277 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |