Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java @ 9801:1d7a72a50183 3.2.x tip
Assume Compose V2, consistently
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 23 Nov 2023 10:14:13 +0100 |
parents | 0a5239a1e46e |
children |
rev | line source |
---|---|
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; |
9726 | 18 import org.apache.logging.log4j.Logger; |
19 import org.apache.logging.log4j.LogManager; | |
8049
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.Value; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
21 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
|
22 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
|
23 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
|
24 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
|
25 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
|
26 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
|
27 import org.dive4elements.river.utils.DoubleUtil; |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
28 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
29 public class SedimentLoadDataCalculation |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
30 extends Calculation |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
31 { |
9726 | 32 private static final Logger log = LogManager |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
33 .getLogger(SedimentLoadDataCalculation.class); |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
34 |
8175
d2673ca68e70
Precalculated sums from the database will come through recommendations.
Tom Gottfried <tom@intevation.de>
parents:
8172
diff
changeset
|
35 public static final int [] TOTAL_LOAD = { |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
36 SedimentLoadData.GF_COARSE, |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
37 SedimentLoadData.GF_FINE_MIDDLE, |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
38 SedimentLoadData.GF_SAND, |
8258
155a886ab19b
Suspended sand is part of total load.
Tom Gottfried <tom@intevation.de>
parents:
8244
diff
changeset
|
39 SedimentLoadData.GF_SUSP_SAND, |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
40 SedimentLoadData.GF_SUSP_SEDIMENT |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
41 }; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
42 |
8175
d2673ca68e70
Precalculated sums from the database will come through recommendations.
Tom Gottfried <tom@intevation.de>
parents:
8172
diff
changeset
|
43 public static final int [] BED_LOAD = { |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
44 SedimentLoadData.GF_COARSE, |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
45 SedimentLoadData.GF_FINE_MIDDLE, |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
46 SedimentLoadData.GF_SAND |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
47 }; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
48 |
8175
d2673ca68e70
Precalculated sums from the database will come through recommendations.
Tom Gottfried <tom@intevation.de>
parents:
8172
diff
changeset
|
49 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
|
50 SedimentLoadData.GF_COARSE, |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
51 SedimentLoadData.GF_FINE_MIDDLE, |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
52 SedimentLoadData.GF_SAND, |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
53 SedimentLoadData.GF_SUSP_SAND |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
54 }; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
55 |
8175
d2673ca68e70
Precalculated sums from the database will come through recommendations.
Tom Gottfried <tom@intevation.de>
parents:
8172
diff
changeset
|
56 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
|
57 SedimentLoadData.GF_COARSE |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
58 }; |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
59 |
8175
d2673ca68e70
Precalculated sums from the database will come through recommendations.
Tom Gottfried <tom@intevation.de>
parents:
8172
diff
changeset
|
60 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
|
61 SedimentLoadData.GF_FINE_MIDDLE |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
62 }; |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
63 |
8175
d2673ca68e70
Precalculated sums from the database will come through recommendations.
Tom Gottfried <tom@intevation.de>
parents:
8172
diff
changeset
|
64 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
|
65 SedimentLoadData.GF_SAND |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
66 }; |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
67 |
8175
d2673ca68e70
Precalculated sums from the database will come through recommendations.
Tom Gottfried <tom@intevation.de>
parents:
8172
diff
changeset
|
68 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
|
69 SedimentLoadData.GF_SUSP_SAND |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
70 }; |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
71 |
8175
d2673ca68e70
Precalculated sums from the database will come through recommendations.
Tom Gottfried <tom@intevation.de>
parents:
8172
diff
changeset
|
72 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
|
73 SedimentLoadData.GF_SUSP_SAND_BED |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
74 }; |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
75 |
8175
d2673ca68e70
Precalculated sums from the database will come through recommendations.
Tom Gottfried <tom@intevation.de>
parents:
8172
diff
changeset
|
76 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
|
77 SedimentLoadData.GF_SUSP_SEDIMENT |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
78 }; |
9e79e384aa8b
Sediment load: Added more 'sums' to be calculated.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8049
diff
changeset
|
79 |
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
|
80 public static final class LoadSum { |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
81 private String description; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
82 private int [] grainFractions; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
83 |
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
|
84 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
|
85 this.description = description; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
86 this.grainFractions = grainFractions; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
87 } |
8856 | 88 public static final LoadSum make( |
89 String description, | |
90 int [] grainFractions | |
91 ) { | |
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
|
92 return new LoadSum(description, grainFractions); |
8055
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 String getDescription() { |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
96 return description; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
97 } |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
98 |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
99 public int [] getGrainFractions() { |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
100 return grainFractions; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
101 } |
8193
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
102 |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
103 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
|
104 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
|
105 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
|
106 } |
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
|
107 } // class LoadSum |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
108 |
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
|
109 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
|
110 // 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 }; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
121 |
8060
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
122 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
|
123 |
8060
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
124 protected int n; |
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
125 protected double sum; |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
126 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
127 public Sum() { |
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 double getSum() { |
8060
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
131 return sum; |
8049
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 int getN() { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
135 return n; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
136 } |
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 public void reset() { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
139 n = 0; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
140 sum = 0.0; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
141 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
142 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
143 @Override |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
144 public void visit(Value value) { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
145 sum += value.getValue(); |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
146 ++n; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
147 } |
8060
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
148 } // class Sum |
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
149 |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
150 private String river; |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
151 private String yearEpoch; |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
152 private String unit; |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
153 private int [][] epochs; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
154 private int [] years; |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
155 private double from; |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
156 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
|
157 /* 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
|
158 private int sqTiId; |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
159 |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
160 |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
161 public SedimentLoadDataCalculation() { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
162 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
163 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
164 public CalculationResult calculate(SedimentLoadAccess access) { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
165 log.info("SedimentLoadDataCalculation.calculate"); |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
166 |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
167 String river = access.getRiverName(); |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
168 String yearEpoch = access.getYearEpoch(); |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
169 String unit = access.getUnit(); |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
170 |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
171 int [] years = null; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
172 int [][] epochs = null; |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
173 |
8057
555dc5a9b282
Sediment load: More on calculating epoch loads.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8055
diff
changeset
|
174 double from = access.getLowerKM(); |
555dc5a9b282
Sediment load: More on calculating epoch loads.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8055
diff
changeset
|
175 double to = access.getUpperKM(); |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
176 |
8239
b207eeb66edd
(issue1448) Objectify sq_time_interval id.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8238
diff
changeset
|
177 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
|
178 |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
179 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
|
180 years = access.getYears(); |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
181 } |
8713
6b68777aaeab
(issue1448) Remove obsolete code for OfficalEpoch "Calculation"
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8532
diff
changeset
|
182 else if (yearEpoch.equals("epoch")) { |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
183 epochs = access.getEpochs(); |
8052
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 else { |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
186 addProblem("minfo.missing.year_epoch"); |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
187 } |
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 if (river == null) { |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
190 // TODO: i18n |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
191 addProblem("minfo.missing.river"); |
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 |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
194 if (years == null && epochs == null) { |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
195 addProblem("minfo.missing.time"); |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
196 } |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
197 |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
198 if (!hasProblems()) { |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
199 this.river = river; |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
200 this.yearEpoch = yearEpoch; |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
201 this.unit = unit; |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
202 this.years = years; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
203 this.epochs = epochs; |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
204 this.from = from; |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
205 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
|
206 this.sqTiId = sqTiId; |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
207 return internalCalculate(); |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
208 } |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
209 |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
210 return error(null); |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
211 } |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
212 |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
213 private CalculationResult error(String msg) { |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
214 if (msg != null) addProblem(msg); |
8053
72760ca2fc2b
Sediment load: dispatch calculation modes.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8052
diff
changeset
|
215 return new CalculationResult(this); |
8052
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
216 } |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
217 |
1dae69eff79d
Sediment load: take arguments from sediment access.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8050
diff
changeset
|
218 private CalculationResult internalCalculate() { |
8053
72760ca2fc2b
Sediment load: dispatch calculation modes.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8052
diff
changeset
|
219 if ("year".equals(yearEpoch)) return calculateYears(); |
72760ca2fc2b
Sediment load: dispatch calculation modes.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8052
diff
changeset
|
220 if ("epoch".equals(yearEpoch)) return calculateEpochs(); |
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 // TODO: i18n |
8213
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
223 return error("minfo.sedimentload.unknown.calc.mode"); |
8053
72760ca2fc2b
Sediment load: dispatch calculation modes.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8052
diff
changeset
|
224 } |
72760ca2fc2b
Sediment load: dispatch calculation modes.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8052
diff
changeset
|
225 |
72760ca2fc2b
Sediment load: dispatch calculation modes.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8052
diff
changeset
|
226 private CalculationResult calculateYears() { |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
227 SedimentLoadData sld = |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
228 SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(river); |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
229 if (sld == null) { |
8213
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
230 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
|
231 } |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
232 |
8062
8489565ff563
Sedimen load: Added bundle for fraction results.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8060
diff
changeset
|
233 SedimentLoadDataResult sldr = new SedimentLoadDataResult(); |
8489565ff563
Sedimen load: Added bundle for fraction results.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8060
diff
changeset
|
234 |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
235 Not notEpochs = new Not(IsEpoch.INSTANCE); |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
236 |
8238
be3c11bef6e8
(issue1448) Finally use the sq time interval as filter in the calculation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8213
diff
changeset
|
237 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
|
238 |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
239 Sum sum = new Sum(); |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
240 |
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
|
241 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
|
242 |
8532
73a4c3c202e5
(issue1051) Use a list of single years in SedimentLoadYear mode
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8258
diff
changeset
|
243 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
|
244 int year = years[i]; |
8068
9ecd6267323b
Sediment load: transform units for official epochs, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8067
diff
changeset
|
245 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
|
246 .add(new TimeRangeIntersects(year)).add(sqTiFilter); |
8131
fae48b3c09d1
Add period to sedimentloaddataresult fraction
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8130
diff
changeset
|
247 String period = Integer.toString(year); |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
248 |
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
|
249 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
|
250 |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
251 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
|
252 sld, ls.getGrainFractions(), ls.getStationType(), |
8213
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
253 filter, sum); |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
254 |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
255 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
|
256 addProblem("sedimentload.missing.fraction." + |
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
257 ls.getDescription(), period); |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
258 continue; |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
259 } |
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
|
260 |
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 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
|
262 |
8062
8489565ff563
Sedimen load: Added bundle for fraction results.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8060
diff
changeset
|
263 SedimentLoadDataResult.Fraction sldrf = |
8856 | 264 new SedimentLoadDataResult.Fraction( |
265 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
|
266 |
8062
8489565ff563
Sedimen load: Added bundle for fraction results.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8060
diff
changeset
|
267 sldr.addFraction(sldrf); |
8055
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
268 } |
cd35b76f1ef8
Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8053
diff
changeset
|
269 } |
8062
8489565ff563
Sedimen load: Added bundle for fraction results.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8060
diff
changeset
|
270 return new CalculationResult(sldr, this); |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
271 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
272 |
8053
72760ca2fc2b
Sediment load: dispatch calculation modes.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8052
diff
changeset
|
273 private CalculationResult calculateEpochs() { |
8057
555dc5a9b282
Sediment load: More on calculating epoch loads.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8055
diff
changeset
|
274 SedimentLoadData sld = |
555dc5a9b282
Sediment load: More on calculating epoch loads.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8055
diff
changeset
|
275 SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(river); |
555dc5a9b282
Sediment load: More on calculating epoch loads.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8055
diff
changeset
|
276 if (sld == null) { |
8213
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
277 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
|
278 } |
555dc5a9b282
Sediment load: More on calculating epoch loads.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8055
diff
changeset
|
279 |
8062
8489565ff563
Sedimen load: Added bundle for fraction results.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8060
diff
changeset
|
280 SedimentLoadDataResult sldr = new SedimentLoadDataResult(); |
8489565ff563
Sedimen load: Added bundle for fraction results.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8060
diff
changeset
|
281 |
8176
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
282 Sum sum = new Sum(); |
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
283 |
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
|
284 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
|
285 |
8060
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
286 // 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
|
287 Not notEpochs = new Not(IsEpoch.INSTANCE); |
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
288 |
8238
be3c11bef6e8
(issue1448) Finally use the sq time interval as filter in the calculation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8213
diff
changeset
|
289 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
|
290 |
8057
555dc5a9b282
Sediment load: More on calculating epoch loads.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8055
diff
changeset
|
291 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
|
292 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
|
293 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
|
294 |
8131
fae48b3c09d1
Add period to sedimentloaddataresult fraction
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8130
diff
changeset
|
295 String period = Integer.toString(epoch[0]) + " - " + |
fae48b3c09d1
Add period to sedimentloaddataresult fraction
Andre Heinecke <andre.heinecke@intevation.de>
parents:
8130
diff
changeset
|
296 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
|
297 |
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
|
298 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
|
299 |
8176
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
300 List<double [][]> results = new ArrayList<double [][]>(); |
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
301 |
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
302 for (int year = min; year <= max; ++year) { |
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
303 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
|
304 .add(new TimeRangeIntersects(year)).add(sqTiFilter); |
8176
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
305 |
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
|
306 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
|
307 sld, ls.getGrainFractions(), ls.getStationType(), |
8213
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
308 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
|
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 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
|
311 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
|
312 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
|
313 } |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
314 |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
315 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
|
316 results.add(result); |
8060
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
317 } |
8176
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
318 |
8205
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
319 if (results.size() == 0) { |
8213
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
320 addProblem("sedimentload.missing.fraction." + |
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
321 ls.getDescription(), period); |
8205
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
322 continue; |
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
323 } |
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
324 |
8176
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
325 double [][] result = average(results); |
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
326 |
8205
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
327 if (!DoubleUtil.isNaN(result[1])) { |
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
328 SedimentLoadDataResult.Fraction sldrf = |
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
329 new SedimentLoadDataResult.Fraction( |
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
330 ls.getDescription(), result, period); |
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
331 sldr.addFraction(sldrf); |
04d1d56d896b
Do not return pure NaN data.
Tom Gottfried <tom@intevation.de>
parents:
8194
diff
changeset
|
332 } |
8213
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
333 else { |
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
334 addProblem("sedimentload.missing.fraction." + |
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
335 ls.getDescription(), period); |
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
336 } |
8060
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
337 } |
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
|
338 |
8060
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
339 } |
8062
8489565ff563
Sedimen load: Added bundle for fraction results.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8060
diff
changeset
|
340 return new CalculationResult(sldr, this); |
8060
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
341 } |
25feef564d09
Sediment load: More of official epochs.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8057
diff
changeset
|
342 |
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
|
343 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
|
344 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
|
345 } |
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 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
|
348 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
|
349 ? 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
|
350 : 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
|
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 |
8856 | 353 private static void transformT2M3( |
354 SedimentDensity sd, | |
355 int year, | |
356 double [][] data | |
357 ) { | |
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
|
358 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
|
359 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
|
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 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
|
362 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
|
363 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
|
364 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
|
365 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
|
366 } |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
367 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
|
368 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
|
369 } |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
370 } |
fe5ef780f8b1
Sediment load: fetch sediment density for transforming t/a to m^3/a.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8062
diff
changeset
|
371 |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
372 public double[][] sum( |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
373 SedimentLoadData sld, |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
374 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
|
375 int lsSType, |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
376 Value.Filter filter, |
8213
ebdf34cae14d
Error reports for sediment load calculation.
Tom Gottfried <tom@intevation.de>
parents:
8205
diff
changeset
|
377 Sum sum |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
378 ) { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
379 List<Station> stations = sld.findStations(from, to); |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
380 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
381 double [] values = new double[grainFractions.length]; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
382 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
383 double [][] result = new double[2][stations.size()]; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
384 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
385 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
|
386 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
|
387 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
|
388 |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
389 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
|
390 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
|
391 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
|
392 |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
393 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
|
394 |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
395 // 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
|
396 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
|
397 |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
398 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
|
399 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
|
400 "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
|
401 } |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
402 else { |
8d447516b7dd
Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents:
8185
diff
changeset
|
403 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
|
404 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
|
405 (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
|
406 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
|
407 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
|
408 /* 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
|
409 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
|
410 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
|
411 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
|
412 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
|
413 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
|
414 Station prev = station.prevByType(otherType); |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
415 if (prev != null) { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
416 prev.filterGrainFraction(gf, filter, sum); |
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 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
419 } |
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 if (sum.getN() == 0) { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
422 values[i] = Double.NaN; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
423 } else { |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
424 values[i] = sum.getSum(); |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
425 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
426 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
427 result[0][j] = station.getStation(); |
8053
72760ca2fc2b
Sediment load: dispatch calculation modes.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8052
diff
changeset
|
428 result[1][j] = DoubleUtil.sum(values); |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
429 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
430 |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
431 return result; |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
432 } |
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
|
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 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
|
435 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
|
436 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
|
437 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
|
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 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
|
440 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
|
441 ++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
|
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 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
|
444 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
|
445 } |
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 } |
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 |
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 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
|
449 |
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 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
|
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 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
|
453 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
|
454 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
|
455 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
|
456 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
|
457 double v = vs[i]; |
8176
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
458 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
|
459 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
|
460 } |
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 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
|
462 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
|
463 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
|
464 } |
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 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
|
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 } |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
468 |
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 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
|
470 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
|
471 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
|
472 result[0][i] = entry.getKey(); |
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
473 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
|
474 ++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
|
475 } |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
476 |
8176
7b0b3b1a2ee8
Let epochs be averages over their years.
Tom Gottfried <tom@intevation.de>
parents:
8175
diff
changeset
|
477 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
|
478 } |
6d24ba2ac964
Sediment load: refactored epoch calculation to not average over all but per year.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8066
diff
changeset
|
479 |
8049
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
480 } |
d49846f05108
Sediment load: (incomplete) new sediment load calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
481 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |