Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensity.java @ 8587:07c9ac22f611
(issue1755) Generalise BedQuality result handling
The bedquality calculation now produces a result for each time period
which has BedQualityResultValues for each specific result type.
Formally this was split up in density, porosity and diameter classes
with some bedload diameter classes mixed in for extra fun.
The intent of this commit is to allow more shared code and generic
access patterns to the BedQuality results.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 18 Mar 2015 18:42:08 +0100 |
parents | e4606eae8ea5 |
children | 5e38e2924c07 |
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 |
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 public int compare(SedimentDensityValue a, SedimentDensityValue b) { |
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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 } |
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 }; |
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 |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
83 public void addDensity(double km, double density, int year) { |
7463
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
84 |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8065
diff
changeset
|
85 if (log.isDebugEnabled()) { |
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8065
diff
changeset
|
86 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
|
87 } |
7463
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
88 |
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
89 Integer key = Integer.valueOf(year); |
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
90 |
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
91 List<SedimentDensityValue> list = densities.get(key); |
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 if (list == null) { |
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
94 list = new ArrayList<SedimentDensityValue>(); |
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
95 densities.put(key, list); |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
96 } |
7463
52c364813cb1
Code cleanup.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7460
diff
changeset
|
97 |
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
|
98 // 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
|
99 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
|
100 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
|
101 |
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 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
|
103 // 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
|
104 // -(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
|
105 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
|
106 } |
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 |
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 list.add(index, sdv); |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
109 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
110 |
6937
0a3dd5be6f81
issue1436: Towards finding the best match in years for densities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6910
diff
changeset
|
111 /** |
0a3dd5be6f81
issue1436: Towards finding the best match in years for densities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6910
diff
changeset
|
112 * 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
|
113 * 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
|
114 * 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
|
115 */ |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
116 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
|
117 |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
118 if (densities.isEmpty()) { |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
119 return SEDIMNET_DENSITY_FACTOR; |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
120 } |
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.size() == 1) { |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
123 Map.Entry<Integer, List<SedimentDensityValue>> entry = densities.firstEntry(); |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
124 return entry.getKey() <= year |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
125 ? getDensityAtKm(entry.getValue(), km) |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
126 : SEDIMNET_DENSITY_FACTOR; |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
127 } |
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
|
128 |
8063
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
129 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
|
130 densities.entrySet().iterator(); |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
131 |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
132 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
|
133 |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
134 while (iter.hasNext()) { |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
135 Map.Entry<Integer, List<SedimentDensityValue>> current = iter.next(); |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
136 last = current; |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
137 int y1 = last.getKey(); |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
138 int y2 = current.getKey(); |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
139 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
|
140 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
|
141 } |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
142 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
|
143 return getDensityAtKm(current.getValue(), km); |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
144 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
145 } |
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
|
146 |
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
|
147 return SEDIMNET_DENSITY_FACTOR; |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
148 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
149 |
7200
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
150 /** 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
|
151 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
|
152 { |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
153 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
|
154 // XXX: This looks stupid. |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
155 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
|
156 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
|
157 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
|
158 } |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
159 } |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
160 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
|
161 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
|
162 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
|
163 points[0][i] = kmDens.getKey(); |
7309
a6ceb4b333c3
SedimentDensity: Fix getAllDensities and made it public.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7254
diff
changeset
|
164 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
|
165 i++; |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
166 } |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
167 |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
168 return points; |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
169 } |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
170 |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
171 /** 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
|
172 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
|
173 { |
8063
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
174 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
|
175 if (list == null) { |
41d9014bfa02
Sediment density: Got rid of stupid extra year tracking.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7463
diff
changeset
|
176 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
|
177 } |
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
|
178 // 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 i++; |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
185 } |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
186 |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
187 return points; |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
188 } |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
189 |
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
190 /** 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
|
191 private static double getDensityAtKm( |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
192 List<SedimentDensityValue> values, |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
193 double km |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
194 ) { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
195 SedimentDensityValue prev = null; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
196 SedimentDensityValue next = null; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
197 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
|
198 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
|
199 return prev.getDensity(); |
4521
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 if (sdv.getKm() > km) { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
202 next = sdv; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
203 break; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
204 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
205 prev = sdv; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
206 } |
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
|
207 return spline(prev, next, km); |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
208 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
209 |
7200
483cae8915f6
issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6970
diff
changeset
|
210 /** 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
|
211 private static double spline( |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
212 SedimentDensityValue prev, |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
213 SedimentDensityValue next, |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
214 double km |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
215 ) { |
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 if (prev == null && next == null) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8065
diff
changeset
|
217 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
|
218 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
|
219 } |
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
|
220 |
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) 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
|
222 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
|
223 |
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 // XXX: This is no spline interpolation! |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
225 double lower = prev.getKm(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
226 double upper = next.getKm(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
227 double upperDensity = next.getDensity(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
228 double lowerDensity = prev.getDensity(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
229 |
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
|
230 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
|
231 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
|
232 return m * km + b; |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
233 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
234 |
6948
d4108d6c4000
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6938
diff
changeset
|
235 |
d4108d6c4000
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6938
diff
changeset
|
236 /** If multiple values for same year and station are found, |
d4108d6c4000
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6938
diff
changeset
|
237 * build and store average, dismiss multiple values. */ |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
238 public void cleanUp() { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
239 Set<Integer> keys = densities.keySet(); |
6948
d4108d6c4000
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6938
diff
changeset
|
240 // Walk over years |
4521
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
241 for (Integer key : keys) { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
242 List<SedimentDensityValue> list = densities.get(key); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
243 if (list.size() == 0) { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
244 return; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
245 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
246 List<SedimentDensityValue> cleaned = |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
247 new ArrayList<SedimentDensityValue>(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
248 double prevkm = list.get(0).getKm(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
249 int counter = 0; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
250 double sum = 0d; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
251 for (SedimentDensityValue value : list) { |
6948
d4108d6c4000
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6938
diff
changeset
|
252 // 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
|
253 if (value.getKm() == prevkm) { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
254 sum += value.getDensity(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
255 counter++; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
256 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
257 else { |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
258 cleaned.add(new SedimentDensityValue( |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
259 prevkm, |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
260 sum / counter, |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
261 value.getYear())); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
262 sum = value.getDensity(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
263 counter = 1; |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
264 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
265 prevkm = value.getKm(); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
266 } |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
267 this.densities.put(key, cleaned); |
71e6fe870c1d
Added objects and factory for sediment densities.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
268 } |
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 } |
6948
d4108d6c4000
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6938
diff
changeset
|
271 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |