Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java @ 8049:d49846f05108
Sediment load: (incomplete) new sediment load calculation.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 17 Jul 2014 16:51:18 +0200 |
parents | |
children | 9e79e384aa8b |
comparison
equal
deleted
inserted
replaced
8048:cde6d2a9ec32 | 8049:d49846f05108 |
---|---|
1 /* Copyright (C) 2014 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 package org.dive4elements.river.artifacts.model.minfo; | |
9 | |
10 import java.util.List; | |
11 import java.util.Set; | |
12 | |
13 import org.dive4elements.river.artifacts.access.SedimentLoadAccess; | |
14 import org.dive4elements.river.artifacts.model.Calculation; | |
15 import org.dive4elements.river.artifacts.model.CalculationResult; | |
16 import org.apache.log4j.Logger; | |
17 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData; | |
18 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData.Value; | |
19 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData.Station; | |
20 | |
21 public class SedimentLoadDataCalculation | |
22 extends Calculation | |
23 { | |
24 private static final Logger log = Logger | |
25 .getLogger(SedimentLoadDataCalculation.class); | |
26 | |
27 public static final int [] TOTAL_LOAD_FLYS = { | |
28 SedimentLoadData.GF_COARSE, | |
29 SedimentLoadData.GF_FINE_MIDDLE, | |
30 SedimentLoadData.GF_SAND, | |
31 SedimentLoadData.GF_SUSP_SEDIMENT | |
32 }; | |
33 | |
34 public static final int [] BED_LOAD_FLYS = { | |
35 SedimentLoadData.GF_COARSE, | |
36 SedimentLoadData.GF_FINE_MIDDLE, | |
37 SedimentLoadData.GF_SAND | |
38 }; | |
39 | |
40 public static final int [] BED_LOAD_SUSP_SAND_FLYS = { | |
41 SedimentLoadData.GF_COARSE, | |
42 SedimentLoadData.GF_FINE_MIDDLE, | |
43 SedimentLoadData.GF_SAND, | |
44 SedimentLoadData.GF_SUSP_SAND | |
45 }; | |
46 | |
47 public static final class Sum implements Value.Visitor { | |
48 | |
49 private int n; | |
50 private double sum; | |
51 private double scale; | |
52 | |
53 public Sum() { | |
54 } | |
55 | |
56 public Sum(double scale) { | |
57 this.scale = scale; | |
58 } | |
59 | |
60 public double getSum() { | |
61 return sum * scale; | |
62 } | |
63 | |
64 public int getN() { | |
65 return n; | |
66 } | |
67 | |
68 public double getScale() { | |
69 return scale; | |
70 } | |
71 | |
72 public void reset() { | |
73 n = 0; | |
74 sum = 0.0; | |
75 } | |
76 | |
77 @Override | |
78 public void visit(Value value) { | |
79 sum += value.getValue(); | |
80 ++n; | |
81 } | |
82 } // class Aggregate | |
83 | |
84 | |
85 public SedimentLoadDataCalculation() { | |
86 } | |
87 | |
88 public CalculationResult calculate(SedimentLoadAccess access) { | |
89 log.info("SedimentLoadDataCalculation.calculate"); | |
90 // TODO: Implement me! | |
91 | |
92 return null; | |
93 } | |
94 | |
95 private static double sum(double [] values) { | |
96 double sum = 0.0; | |
97 for (double value: values) { | |
98 sum += value; | |
99 } | |
100 return sum; | |
101 } | |
102 | |
103 public double[][] sum( | |
104 SedimentLoadData sld, | |
105 double from, | |
106 double to, | |
107 int [] grainFractions, | |
108 Value.Filter filter, | |
109 Sum sum, | |
110 boolean isKMUp, | |
111 Set<Integer> missingFractions | |
112 ) { | |
113 List<Station> stations = sld.findStations(from, to); | |
114 | |
115 double [] values = new double[grainFractions.length]; | |
116 | |
117 double [][] result = new double[2][stations.size()]; | |
118 | |
119 for (int j = 0, S = stations.size(); j < S; ++j) { | |
120 Station station = stations.get(j); | |
121 for (int i = 0; i < grainFractions.length; ++i) { | |
122 int gf = grainFractions[i]; | |
123 sum.reset(); | |
124 station.filterGrainFraction(gf, filter, sum); | |
125 if (sum.getN() == 0) { // No values found | |
126 int msType = SedimentLoadData.measurementStationType(gf); | |
127 // Station of right fraction type already? No: take previous. | |
128 if (!station.isType(msType)) { | |
129 Station prev = station.prevByType(msType, isKMUp); | |
130 if (prev != null) { | |
131 prev.filterGrainFraction(gf, filter, sum); | |
132 } | |
133 } | |
134 } | |
135 | |
136 if (sum.getN() == 0) { | |
137 missingFractions.add(gf); | |
138 values[i] = Double.NaN; | |
139 } else { | |
140 values[i] = sum.getSum(); | |
141 } | |
142 } | |
143 result[0][j] = station.getStation(); | |
144 result[1][j] = sum(values); | |
145 } | |
146 | |
147 // TODO: Handle 'virtual' measument stations 'from' and 'to'. | |
148 | |
149 return result; | |
150 } | |
151 } | |
152 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |