Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java @ 8733:8dbb969091c5
Removed obsolete imports.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 30 Apr 2015 19:57:45 +0200 |
parents | 6b68777aaeab |
children | 5e38e2924c07 |
rev | line source |
---|---|
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
1 /* Copyright (C) 2014 by Bundesanstalt für Gewässerkunde |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
2 * Software engineering by Intevation GmbH |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
3 * |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
7 */ |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
8 package org.dive4elements.river.artifacts.model.minfo; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
9 |
8067
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
10 import java.util.ArrayList; |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
11 import java.util.List; |
8067
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
12 import java.util.Map; |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
13 import java.util.TreeMap; |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
14 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
15 import org.dive4elements.river.artifacts.access.SedimentLoadAccess; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
16 import org.dive4elements.river.artifacts.model.Calculation; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
17 import org.dive4elements.river.artifacts.model.CalculationResult; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
18 import org.apache.log4j.Logger; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
19 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData.Value; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
20 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData.Station; |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
21 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.And; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
22 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.IsEpoch; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
23 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.Not; |
8238
be3c11bef6e8
(issue1448) Finally use the sq time interval as filter in the calculation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8213
diff
changeset
|
24 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.SQTimeInterval; |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
25 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataValueFilter.TimeRangeIntersects; |
8053
72760ca2fc2b
Sediment load: dispatch calculation modes.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8052
diff
changeset
|
26 import org.dive4elements.river.utils.DoubleUtil; |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
27 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
28 public class SedimentLoadDataCalculation |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
29 extends Calculation |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
30 { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
31 private static final Logger log = Logger |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
32 .getLogger(SedimentLoadDataCalculation.class); |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
33 |
8175
d2673ca68e70
Precalculated sums from the database will come through recommendations.
Tom Gottfried <tom@intevation.de>
parents:
8172
diff
changeset
|
34 public static final int [] TOTAL_LOAD = { |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
35 SedimentLoadData.GF_COARSE, |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
36 SedimentLoadData.GF_FINE_MIDDLE, |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
37 SedimentLoadData.GF_SAND, |
8258
155a886ab19b
Suspended sand is part of total load.
Tom Gottfried <tom@intevation.de>
parents:
8244
diff
changeset
|
38 SedimentLoadData.GF_SUSP_SAND, |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
39 SedimentLoadData.GF_SUSP_SEDIMENT |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
40 }; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
41 |
8175
d2673ca68e70
Precalculated sums from the database will come through recommendations.
Tom Gottfried <tom@intevation.de>
parents:
8172
diff
changeset
|
42 public static final int [] BED_LOAD = { |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
43 SedimentLoadData.GF_COARSE, |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
44 SedimentLoadData.GF_FINE_MIDDLE, |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
45 SedimentLoadData.GF_SAND |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
46 }; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
47 |
8175
d2673ca68e70
Precalculated sums from the database will come through recommendations.
Tom Gottfried <tom@intevation.de>
parents:
8172
diff
changeset
|
48 public static final int [] BED_LOAD_SUSP_SAND = { |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
49 SedimentLoadData.GF_COARSE, |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
50 SedimentLoadData.GF_FINE_MIDDLE, |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
51 SedimentLoadData.GF_SAND, |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
52 SedimentLoadData.GF_SUSP_SAND |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
53 }; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
54 |
8175
d2673ca68e70
Precalculated sums from the database will come through recommendations.
Tom Gottfried <tom@intevation.de>
parents:
8172
diff
changeset
|
55 public static final int [] COARSE = { |
8050
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
56 SedimentLoadData.GF_COARSE |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
57 }; |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
58 |
8175
d2673ca68e70
Precalculated sums from the database will come through recommendations.
Tom Gottfried <tom@intevation.de>
parents:
8172
diff
changeset
|
59 public static final int [] FINE_MIDDLE = { |
8050
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
60 SedimentLoadData.GF_FINE_MIDDLE |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
61 }; |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
62 |
8175
d2673ca68e70
Precalculated sums from the database will come through recommendations.
Tom Gottfried <tom@intevation.de>
parents:
8172
diff
changeset
|
63 public static final int [] SAND = { |
8050
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
64 SedimentLoadData.GF_SAND |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
65 }; |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
66 |
8175
d2673ca68e70
Precalculated sums from the database will come through recommendations.
Tom Gottfried <tom@intevation.de>
parents:
8172
diff
changeset
|
67 public static final int [] SUSP_SAND = { |
8050
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
68 SedimentLoadData.GF_SUSP_SAND |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
69 }; |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
70 |
8175
d2673ca68e70
Precalculated sums from the database will come through recommendations.
Tom Gottfried <tom@intevation.de>
parents:
8172
diff
changeset
|
71 public static final int [] SUSP_SAND_BED = { |
8050
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
72 SedimentLoadData.GF_SUSP_SAND_BED |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
73 }; |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
74 |
8175
d2673ca68e70
Precalculated sums from the database will come through recommendations.
Tom Gottfried <tom@intevation.de>
parents:
8172
diff
changeset
|
75 public static final int [] SUSP_SEDIMENT = { |
8050
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
76 SedimentLoadData.GF_SUSP_SEDIMENT |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
77 }; |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
78 |
8185
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
79 public static final class LoadSum { |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
80 private String description; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
81 private int [] grainFractions; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
82 |
8185
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
83 public LoadSum(String description, int [] grainFractions) { |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
84 this.description = description; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
85 this.grainFractions = grainFractions; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
86 } |
8185
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
87 public static final LoadSum make(String description, int [] grainFractions) { |
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
88 return new LoadSum(description, grainFractions); |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
89 } |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
90 |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
91 public String getDescription() { |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
92 return description; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
93 } |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
94 |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
95 public int [] getGrainFractions() { |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
96 return grainFractions; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
97 } |
8193
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
98 |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
99 public int getStationType() { |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
100 return SedimentLoadData.measurementStationType( |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
101 SedimentLoadData.grainFractionIndex(this.description)); |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
102 } |
8185
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
103 } // class LoadSum |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
104 |
8185
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
105 public static final LoadSum [] LOAD_SUMS = { |
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
106 // Names are alignt to the grain_fractions table |
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
107 LoadSum.make("total", TOTAL_LOAD), |
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
108 LoadSum.make("bed_load", BED_LOAD), |
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
109 LoadSum.make("bed_load_susp_sand", BED_LOAD_SUSP_SAND), |
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
110 LoadSum.make("coarse", COARSE), |
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
111 LoadSum.make("fine_middle", FINE_MIDDLE), |
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
112 LoadSum.make("sand", SAND) , |
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
113 LoadSum.make("susp_sand", SUSP_SAND), |
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
114 LoadSum.make("susp_sand_bed", SUSP_SAND_BED), |
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
115 LoadSum.make("suspended_sediment", SUSP_SEDIMENT), |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
116 }; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
117 |
8060
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
118 public static class Sum implements Value.Visitor { |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
119 |
8060
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
120 protected int n; |
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
121 protected double sum; |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
122 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
123 public Sum() { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
124 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
125 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
126 public double getSum() { |
8060
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
127 return sum; |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
128 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
129 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
130 public int getN() { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
131 return n; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
132 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
133 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
134 public void reset() { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
135 n = 0; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
136 sum = 0.0; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
137 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
138 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
139 @Override |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
140 public void visit(Value value) { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
141 sum += value.getValue(); |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
142 ++n; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
143 } |
8060
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
144 } // class Sum |
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
145 |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
146 private String river; |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
147 private String yearEpoch; |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
148 private String unit; |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
149 private int [][] epochs; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
150 private int [] years; |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
151 private double from; |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
152 private double to; |
8238
be3c11bef6e8
(issue1448) Finally use the sq time interval as filter in the calculation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8213
diff
changeset
|
153 /* The sq time interval to use. 0 means this is ignored. */ |
be3c11bef6e8
(issue1448) Finally use the sq time interval as filter in the calculation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8213
diff
changeset
|
154 private int sqTiId; |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
155 |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
156 |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
157 public SedimentLoadDataCalculation() { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
158 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
159 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
160 public CalculationResult calculate(SedimentLoadAccess access) { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
161 log.info("SedimentLoadDataCalculation.calculate"); |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
162 |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
163 String river = access.getRiverName(); |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
164 String yearEpoch = access.getYearEpoch(); |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
165 String unit = access.getUnit(); |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
166 |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
167 int [] years = null; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
168 int [][] epochs = null; |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
169 |
8057
555dc5a9b282
Sediment load: More on calculating epoch loads.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8055
diff
changeset
|
170 double from = access.getLowerKM(); |
555dc5a9b282
Sediment load: More on calculating epoch loads.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8055
diff
changeset
|
171 double to = access.getUpperKM(); |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
172 |
8239
b207eeb66edd
(issue1448) Objectify sq_time_interval id.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8238
diff
changeset
|
173 Integer sqTiId = access.getSQTiId(); |
8238
be3c11bef6e8
(issue1448) Finally use the sq time interval as filter in the calculation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8213
diff
changeset
|
174 |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
175 if (yearEpoch.equals("year")) { |
8532
73a4c3c202e5
(issue1051) Use a list of single years in SedimentLoadYear mode
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8258
diff
changeset
|
176 years = access.getYears(); |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
177 } |
8713
6b68777aaeab
(issue1448) Remove obsolete code for OfficalEpoch "Calculation"
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8532
diff
changeset
|
178 else if (yearEpoch.equals("epoch")) { |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
179 epochs = access.getEpochs(); |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
180 } |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
181 else { |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
182 addProblem("minfo.missing.year_epoch"); |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
183 } |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
184 |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
185 if (river == null) { |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
186 // TODO: i18n |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
187 addProblem("minfo.missing.river"); |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
188 } |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
189 |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
190 if (years == null && epochs == null) { |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
191 addProblem("minfo.missing.time"); |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
192 } |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
193 |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
194 if (!hasProblems()) { |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
195 this.river = river; |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
196 this.yearEpoch = yearEpoch; |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
197 this.unit = unit; |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
198 this.years = years; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
199 this.epochs = epochs; |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
200 this.from = from; |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
201 this.to = to; |
8238
be3c11bef6e8
(issue1448) Finally use the sq time interval as filter in the calculation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8213
diff
changeset
|
202 this.sqTiId = sqTiId; |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
203 return internalCalculate(); |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
204 } |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
205 |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
206 return error(null); |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
207 } |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
208 |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
209 private CalculationResult error(String msg) { |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
210 if (msg != null) addProblem(msg); |
8053
72760ca2fc2b
Sediment load: dispatch calculation modes.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8052
diff
changeset
|
211 return new CalculationResult(this); |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
212 } |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
213 |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
214 private CalculationResult internalCalculate() { |
8053
72760ca2fc2b
Sediment load: dispatch calculation modes.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8052
diff
changeset
|
215 if ("year".equals(yearEpoch)) return calculateYears(); |
72760ca2fc2b
Sediment load: dispatch calculation modes.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8052
diff
changeset
|
216 if ("epoch".equals(yearEpoch)) return calculateEpochs(); |
72760ca2fc2b
Sediment load: dispatch calculation modes.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8052
diff
changeset
|
217 |
72760ca2fc2b
Sediment load: dispatch calculation modes.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8052
diff
changeset
|
218 // TODO: i18n |
8213
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
219 return error("minfo.sedimentload.unknown.calc.mode"); |
8053
72760ca2fc2b
Sediment load: dispatch calculation modes.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8052
diff
changeset
|
220 } |
72760ca2fc2b
Sediment load: dispatch calculation modes.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8052
diff
changeset
|
221 |
72760ca2fc2b
Sediment load: dispatch calculation modes.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8052
diff
changeset
|
222 private CalculationResult calculateYears() { |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
223 SedimentLoadData sld = |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
224 SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(river); |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
225 if (sld == null) { |
8213
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
226 return error("minfo.sedimentload.no.data"); |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
227 } |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
228 |
8062
8489565ff563
Sedimen load: Added bundle for fraction results.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8060
diff
changeset
|
229 SedimentLoadDataResult sldr = new SedimentLoadDataResult(); |
8489565ff563
Sedimen load: Added bundle for fraction results.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8060
diff
changeset
|
230 |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
231 Not notEpochs = new Not(IsEpoch.INSTANCE); |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
232 |
8238
be3c11bef6e8
(issue1448) Finally use the sq time interval as filter in the calculation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8213
diff
changeset
|
233 SQTimeInterval sqTiFilter = new SQTimeInterval(sqTiId); |
be3c11bef6e8
(issue1448) Finally use the sq time interval as filter in the calculation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8213
diff
changeset
|
234 |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
235 Sum sum = new Sum(); |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
236 |
8066
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
237 SedimentDensity sd = getSedimentDensity(); |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
238 |
8532
73a4c3c202e5
(issue1051) Use a list of single years in SedimentLoadYear mode
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8258
diff
changeset
|
239 for (int i = 0; i < years.length; i++) { |
73a4c3c202e5
(issue1051) Use a list of single years in SedimentLoadYear mode
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8258
diff
changeset
|
240 int year = years[i]; |
8068
9ecd6267323b
Sediment load: transform units for official epochs, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8067
diff
changeset
|
241 Value.Filter filter = new And(notEpochs) |
8238
be3c11bef6e8
(issue1448) Finally use the sq time interval as filter in the calculation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8213
diff
changeset
|
242 .add(new TimeRangeIntersects(year)).add(sqTiFilter); |
8131
fae48b3c09d1
Add period to sedimentloaddataresult fraction
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8130
diff
changeset
|
243 String period = Integer.toString(year); |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
244 |
8185
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
245 for (LoadSum ls: LOAD_SUMS) { |
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
246 |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
247 double [][] result = sum( |
8193
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
248 sld, ls.getGrainFractions(), ls.getStationType(), |
8213
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
249 filter, sum); |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
250 |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
251 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) { |
8213
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
252 addProblem("sedimentload.missing.fraction." + |
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
253 ls.getDescription(), period); |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
254 continue; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
255 } |
8066
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
256 |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
257 transformT2M3(sd, year, result); |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
258 |
8062
8489565ff563
Sedimen load: Added bundle for fraction results.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8060
diff
changeset
|
259 SedimentLoadDataResult.Fraction sldrf = |
8185
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
260 new SedimentLoadDataResult.Fraction(ls.getDescription(), result, period); |
8066
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
261 |
8062
8489565ff563
Sedimen load: Added bundle for fraction results.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8060
diff
changeset
|
262 sldr.addFraction(sldrf); |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
263 } |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
264 } |
8062
8489565ff563
Sedimen load: Added bundle for fraction results.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8060
diff
changeset
|
265 return new CalculationResult(sldr, this); |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
266 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
267 |
8053
72760ca2fc2b
Sediment load: dispatch calculation modes.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8052
diff
changeset
|
268 private CalculationResult calculateEpochs() { |
8057
555dc5a9b282
Sediment load: More on calculating epoch loads.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8055
diff
changeset
|
269 SedimentLoadData sld = |
555dc5a9b282
Sediment load: More on calculating epoch loads.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8055
diff
changeset
|
270 SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(river); |
555dc5a9b282
Sediment load: More on calculating epoch loads.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8055
diff
changeset
|
271 if (sld == null) { |
8213
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
272 return error("minfo.sedimentload.no.data"); |
8057
555dc5a9b282
Sediment load: More on calculating epoch loads.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8055
diff
changeset
|
273 } |
555dc5a9b282
Sediment load: More on calculating epoch loads.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8055
diff
changeset
|
274 |
8062
8489565ff563
Sedimen load: Added bundle for fraction results.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8060
diff
changeset
|
275 SedimentLoadDataResult sldr = new SedimentLoadDataResult(); |
8489565ff563
Sedimen load: Added bundle for fraction results.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8060
diff
changeset
|
276 |
8176
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
277 Sum sum = new Sum(); |
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
278 |
8067
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
279 SedimentDensity sd = getSedimentDensity(); |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
280 |
8060
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
281 // They are not epochs, they are single years! |
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
282 Not notEpochs = new Not(IsEpoch.INSTANCE); |
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
283 |
8238
be3c11bef6e8
(issue1448) Finally use the sq time interval as filter in the calculation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8213
diff
changeset
|
284 SQTimeInterval sqTiFilter = new SQTimeInterval(sqTiId); |
be3c11bef6e8
(issue1448) Finally use the sq time interval as filter in the calculation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8213
diff
changeset
|
285 |
8057
555dc5a9b282
Sediment load: More on calculating epoch loads.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8055
diff
changeset
|
286 for (int [] epoch: epochs) { |
8067
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
287 int min = Math.min(epoch[0], epoch[1]); |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
288 int max = Math.max(epoch[0], epoch[1]); |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
289 |
8131
fae48b3c09d1
Add period to sedimentloaddataresult fraction
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8130
diff
changeset
|
290 String period = Integer.toString(epoch[0]) + " - " + |
fae48b3c09d1
Add period to sedimentloaddataresult fraction
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8130
diff
changeset
|
291 Integer.toString(epoch[1]); |
8067
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
292 |
8185
76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
Tom Gottfried <tom@intevation.de>
parents:
8176
diff
changeset
|
293 for (LoadSum ls: LOAD_SUMS) { |
8067
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
294 |
8176
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
295 List<double [][]> results = new ArrayList<double [][]>(); |
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
296 |
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
297 for (int year = min; year <= max; ++year) { |
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
298 Value.Filter filter = new And(notEpochs) |
8238
be3c11bef6e8
(issue1448) Finally use the sq time interval as filter in the calculation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8213
diff
changeset
|
299 .add(new TimeRangeIntersects(year)).add(sqTiFilter); |
8176
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
300 |
8067
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
301 double [][] result = sum( |
8193
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
302 sld, ls.getGrainFractions(), ls.getStationType(), |
8213
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
303 filter, sum); |
8067
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
304 |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
305 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) { |
8244
0a03c1921cfe
We well want to average NaNs but want to know the cause of the result being NaN.
Tom Gottfried <tom@intevation.de>
parents:
8239
diff
changeset
|
306 addProblem("sedimentload.missing.fraction." + |
0a03c1921cfe
We well want to average NaNs but want to know the cause of the result being NaN.
Tom Gottfried <tom@intevation.de>
parents:
8239
diff
changeset
|
307 ls.getDescription(), ((Integer)year).toString()); |
8067
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
308 } |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
309 |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
310 transformT2M3(sd, year, result); |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
311 results.add(result); |
8060
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
312 } |
8176
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
313 |
8205
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
314 if (results.size() == 0) { |
8213
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
315 addProblem("sedimentload.missing.fraction." + |
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
316 ls.getDescription(), period); |
8205
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
317 continue; |
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
318 } |
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
319 |
8176
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
320 double [][] result = average(results); |
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
321 |
8205
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
322 if (!DoubleUtil.isNaN(result[1])) { |
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
323 SedimentLoadDataResult.Fraction sldrf = |
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
324 new SedimentLoadDataResult.Fraction( |
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
325 ls.getDescription(), result, period); |
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
326 sldr.addFraction(sldrf); |
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
327 } |
8213
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
328 else { |
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
329 addProblem("sedimentload.missing.fraction." + |
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
330 ls.getDescription(), period); |
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
331 } |
8060
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
332 } |
8067
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
333 |
8060
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
334 } |
8062
8489565ff563
Sedimen load: Added bundle for fraction results.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8060
diff
changeset
|
335 return new CalculationResult(sldr, this); |
8060
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
336 } |
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
337 |
8066
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
338 private final boolean inM3() { |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
339 return unit.equals("m3_per_a"); |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
340 } |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
341 |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
342 private SedimentDensity getSedimentDensity() { |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
343 return inM3() |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
344 ? SedimentDensityFactory.getSedimentDensity(river, from, to) |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
345 : null; |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
346 } |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
347 |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
348 private static void transformT2M3(SedimentDensity sd, int year, double [][] data) { |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
349 if (sd == null) { |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
350 return; |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
351 } |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
352 double [] kms = data[0]; |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
353 double [] values = data[1]; |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
354 for (int i = 0; i < kms.length; ++i) { |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
355 if (Double.isNaN(kms[i]) || Double.isNaN(kms[i])) { |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
356 continue; |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
357 } |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
358 double density = sd.getDensity(kms[i], year); |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
359 values[i] /= density; |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
360 } |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
361 } |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
362 |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
363 public double[][] sum( |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
364 SedimentLoadData sld, |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
365 int [] grainFractions, |
8193
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
366 int lsSType, |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
367 Value.Filter filter, |
8213
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
368 Sum sum |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
369 ) { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
370 List<Station> stations = sld.findStations(from, to); |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
371 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
372 double [] values = new double[grainFractions.length]; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
373 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
374 double [][] result = new double[2][stations.size()]; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
375 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
376 for (int j = 0, S = stations.size(); j < S; ++j) { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
377 Station station = stations.get(j); |
8193
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
378 int sType = station.getType(); |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
379 |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
380 for (int i = 0; i < grainFractions.length; ++i) { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
381 int gf = grainFractions[i]; |
8193
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
382 int gfSType = SedimentLoadData.measurementStationType(gf); |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
383 |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
384 sum.reset(); |
8193
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
385 |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
386 // Add current single fraction at current station |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
387 station.filterGrainFraction(gf, filter, sum); |
8193
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
388 |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
389 if (gfSType == Station.UNKNOWN) { |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
390 log.error("No measurement station type defined for " + |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
391 "fraction-index" + gf); |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
392 } |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
393 else { |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
394 if (lsSType != Station.BED_LOAD && |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
395 lsSType != Station.SUSPENDED && |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
396 (sType == Station.BED_LOAD || |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
397 sType == Station.SUSPENDED) && |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
398 sum.getN() == 0) { |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
399 /* In case the station-type of the load sum is |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
400 a combined type and we are at non-combined station: |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
401 we need to add values from previous station of |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
402 the other type for fractions not given here. */ |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
403 int otherType = sType == Station.BED_LOAD ? |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
404 Station.SUSPENDED : Station.BED_LOAD; |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
405 Station prev = station.prevByType(otherType); |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
406 if (prev != null) { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
407 prev.filterGrainFraction(gf, filter, sum); |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
408 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
409 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
410 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
411 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
412 if (sum.getN() == 0) { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
413 values[i] = Double.NaN; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
414 } else { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
415 values[i] = sum.getSum(); |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
416 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
417 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
418 result[0][j] = station.getStation(); |
8053
72760ca2fc2b
Sediment load: dispatch calculation modes.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8052
diff
changeset
|
419 result[1][j] = DoubleUtil.sum(values); |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
420 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
421 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
422 return result; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
423 } |
8067
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
424 |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
425 private static final class XSum { |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
426 private double sum; |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
427 private int n; |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
428 public XSum() { |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
429 } |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
430 public void add(double v) { |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
431 sum += v; |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
432 ++n; |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
433 } |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
434 public double avg() { |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
435 return sum/n; |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
436 } |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
437 } |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
438 |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
439 private static double [][] average(List<double [][]> data) { |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
440 |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
441 TreeMap<Double, XSum> map = new TreeMap<Double, XSum>(); |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
442 |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
443 for (double [][] pair: data) { |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
444 double [] kms = pair[0]; |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
445 double [] vs = pair[1]; |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
446 for (int i = 0; i < kms.length; ++i) { |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
447 double km = kms[i]; |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
448 double v = vs[i]; |
8176
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
449 if (Double.isNaN(km)) { |
8067
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
450 continue; |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
451 } |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
452 XSum xsum = map.get(km); |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
453 if (xsum == null) { |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
454 map.put(km, xsum = new XSum()); |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
455 } |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
456 xsum.add(v); |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
457 } |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
458 } |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
459 |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
460 double [][] result = new double[2][map.size()]; |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
461 int i = 0; |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
462 for (Map.Entry<Double, XSum> entry: map.entrySet()) { |
8176
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
463 result[0][i] = entry.getKey(); |
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
464 result[1][i] = entry.getValue().avg(); |
8067
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
465 ++i; |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
466 } |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
467 |
8176
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
468 return result; |
8067
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
469 } |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
470 |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
471 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
472 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |