Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java @ 8185:76e1e9d81ce2
Removed obsolete average and renamed some symbols to make the difference between single fractions and sums of them clearer in the calculation.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 04 Sep 2014 12:03:02 +0200 |
parents | 7b0b3b1a2ee8 |
children | 8d447516b7dd |
comparison
equal
deleted
inserted
replaced
8184:143b24546b26 | 8185:76e1e9d81ce2 |
---|---|
77 | 77 |
78 public static final int [] SUSP_SEDIMENT = { | 78 public static final int [] SUSP_SEDIMENT = { |
79 SedimentLoadData.GF_SUSP_SEDIMENT | 79 SedimentLoadData.GF_SUSP_SEDIMENT |
80 }; | 80 }; |
81 | 81 |
82 public static final int [] AVERAGE = { | 82 public static final class LoadSum { |
83 SedimentLoadData.GF_AVERAGE | |
84 }; | |
85 | |
86 public static final class GrainFraction { | |
87 private String description; | 83 private String description; |
88 private int [] grainFractions; | 84 private int [] grainFractions; |
89 | 85 |
90 public GrainFraction(String description, int [] grainFractions) { | 86 public LoadSum(String description, int [] grainFractions) { |
91 this.description = description; | 87 this.description = description; |
92 this.grainFractions = grainFractions; | 88 this.grainFractions = grainFractions; |
93 } | 89 } |
94 public static final GrainFraction make(String description, int [] grainFractions) { | 90 public static final LoadSum make(String description, int [] grainFractions) { |
95 return new GrainFraction(description, grainFractions); | 91 return new LoadSum(description, grainFractions); |
96 } | 92 } |
97 | 93 |
98 public String getDescription() { | 94 public String getDescription() { |
99 return description; | 95 return description; |
100 } | 96 } |
101 | 97 |
102 public int [] getGrainFractions() { | 98 public int [] getGrainFractions() { |
103 return grainFractions; | 99 return grainFractions; |
104 } | 100 } |
105 } // class GrainFraction | 101 } // class LoadSum |
106 | 102 |
107 public static final GrainFraction [] GRAIN_FRACTIONS = { | 103 public static final LoadSum [] LOAD_SUMS = { |
108 // Grain fraction names are alignt to the grain_fractions table | 104 // Names are alignt to the grain_fractions table |
109 GrainFraction.make("total", TOTAL_LOAD), | 105 LoadSum.make("total", TOTAL_LOAD), |
110 GrainFraction.make("bed_load", BED_LOAD), | 106 LoadSum.make("bed_load", BED_LOAD), |
111 GrainFraction.make("bed_load_susp_sand", BED_LOAD_SUSP_SAND), | 107 LoadSum.make("bed_load_susp_sand", BED_LOAD_SUSP_SAND), |
112 GrainFraction.make("coarse", COARSE), | 108 LoadSum.make("coarse", COARSE), |
113 GrainFraction.make("fine_middle", FINE_MIDDLE), | 109 LoadSum.make("fine_middle", FINE_MIDDLE), |
114 GrainFraction.make("sand", SAND) , | 110 LoadSum.make("sand", SAND) , |
115 GrainFraction.make("susp_sand", SUSP_SAND), | 111 LoadSum.make("susp_sand", SUSP_SAND), |
116 GrainFraction.make("susp_sand_bed", SUSP_SAND_BED), | 112 LoadSum.make("susp_sand_bed", SUSP_SAND_BED), |
117 GrainFraction.make("suspended_sediment", SUSP_SEDIMENT), | 113 LoadSum.make("suspended_sediment", SUSP_SEDIMENT), |
118 GrainFraction.make("average", AVERAGE), | |
119 }; | 114 }; |
120 | 115 |
121 public static class Sum implements Value.Visitor { | 116 public static class Sum implements Value.Visitor { |
122 | 117 |
123 protected int n; | 118 protected int n; |
243 for (int year = min; year <= max; ++year) { | 238 for (int year = min; year <= max; ++year) { |
244 Value.Filter filter = new And(notEpochs) | 239 Value.Filter filter = new And(notEpochs) |
245 .add(new TimeRangeIntersects(year)); | 240 .add(new TimeRangeIntersects(year)); |
246 String period = Integer.toString(year); | 241 String period = Integer.toString(year); |
247 | 242 |
248 for (GrainFraction gf: GRAIN_FRACTIONS) { | 243 for (LoadSum ls: LOAD_SUMS) { |
244 | |
249 double [][] result = sum( | 245 double [][] result = sum( |
250 sld, gf.getGrainFractions(), filter, sum, isKmUp, | 246 sld, ls.getGrainFractions(), filter, sum, isKmUp, |
251 missingFractions); | 247 missingFractions); |
252 | 248 |
253 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) { | 249 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) { |
254 // TODO: resolve i18n | 250 // TODO: resolve i18n |
255 addProblem("minfo.sediment.load.no.fractions", | 251 addProblem("minfo.sediment.load.no.fractions", |
256 gf.getDescription()); | 252 ls.getDescription()); |
257 continue; | 253 continue; |
258 } | 254 } |
259 | 255 |
260 transformT2M3(sd, year, result); | 256 transformT2M3(sd, year, result); |
261 | 257 |
262 SedimentLoadDataResult.Fraction sldrf = | 258 SedimentLoadDataResult.Fraction sldrf = |
263 new SedimentLoadDataResult.Fraction(gf.getDescription(), result, period); | 259 new SedimentLoadDataResult.Fraction(ls.getDescription(), result, period); |
264 | 260 |
265 sldr.addFraction(sldrf); | 261 sldr.addFraction(sldrf); |
266 } | 262 } |
267 | 263 |
268 } | 264 } |
296 int max = Math.max(epoch[0], epoch[1]); | 292 int max = Math.max(epoch[0], epoch[1]); |
297 | 293 |
298 String period = Integer.toString(epoch[0]) + " - " + | 294 String period = Integer.toString(epoch[0]) + " - " + |
299 Integer.toString(epoch[1]); | 295 Integer.toString(epoch[1]); |
300 | 296 |
301 for (GrainFraction gf: GRAIN_FRACTIONS) { | 297 for (LoadSum ls: LOAD_SUMS) { |
302 | 298 |
303 List<double [][]> results = new ArrayList<double [][]>(); | 299 List<double [][]> results = new ArrayList<double [][]>(); |
304 | 300 |
305 for (int year = min; year <= max; ++year) { | 301 for (int year = min; year <= max; ++year) { |
306 Value.Filter filter = new And(notEpochs) | 302 Value.Filter filter = new And(notEpochs) |
307 .add(new TimeRangeIntersects(year)); | 303 .add(new TimeRangeIntersects(year)); |
308 | 304 |
309 double [][] result = sum( | 305 double [][] result = sum( |
310 sld, gf.getGrainFractions(), filter, sum, isKmUp, | 306 sld, ls.getGrainFractions(), filter, sum, isKmUp, |
311 missingFractions); | 307 missingFractions); |
312 | 308 |
313 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) { | 309 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) { |
314 // TODO: resolve i18n | 310 // TODO: resolve i18n |
315 addProblem("minfo.sediment.load.no.fractions", | 311 addProblem("minfo.sediment.load.no.fractions", |
316 gf.getDescription()); | 312 ls.getDescription()); |
317 continue; | 313 continue; |
318 } | 314 } |
319 | 315 |
320 transformT2M3(sd, year, result); | 316 transformT2M3(sd, year, result); |
321 results.add(result); | 317 results.add(result); |
322 } | 318 } |
323 | 319 |
324 double [][] result = average(results); | 320 double [][] result = average(results); |
325 | 321 |
326 SedimentLoadDataResult.Fraction sldrf = | 322 SedimentLoadDataResult.Fraction sldrf = |
327 new SedimentLoadDataResult.Fraction(gf.getDescription(), | 323 new SedimentLoadDataResult.Fraction(ls.getDescription(), |
328 result, period); | 324 result, period); |
329 sldr.addFraction(sldrf); | 325 sldr.addFraction(sldrf); |
330 } | 326 } |
331 | 327 |
332 } | 328 } |
358 String period = Integer.toString(epoch[0]) + " - " + | 354 String period = Integer.toString(epoch[0]) + " - " + |
359 Integer.toString(epoch[1]); | 355 Integer.toString(epoch[1]); |
360 | 356 |
361 Sum sum = new Sum(); | 357 Sum sum = new Sum(); |
362 | 358 |
363 for (GrainFraction gf: GRAIN_FRACTIONS) { | 359 for (LoadSum ls: LOAD_SUMS) { |
364 double [][] result = sum( | 360 double [][] result = sum( |
365 sld, gf.getGrainFractions(), filter, sum, isKmUp, | 361 sld, ls.getGrainFractions(), filter, sum, isKmUp, |
366 missingFractions); | 362 missingFractions); |
367 | 363 |
368 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) { | 364 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) { |
369 // TODO: resolve i18n | 365 // TODO: resolve i18n |
370 addProblem("minfo.sediment.load.no.fractions", | 366 addProblem("minfo.sediment.load.no.fractions", |
371 gf.getDescription()); | 367 ls.getDescription()); |
372 continue; | 368 continue; |
373 } | 369 } |
374 transformT2M3(sd, year, result); | 370 transformT2M3(sd, year, result); |
375 SedimentLoadDataResult.Fraction sldrf = | 371 SedimentLoadDataResult.Fraction sldrf = |
376 new SedimentLoadDataResult.Fraction(gf.getDescription(), result, period); | 372 new SedimentLoadDataResult.Fraction(ls.getDescription(), result, period); |
377 sldr.addFraction(sldrf); | 373 sldr.addFraction(sldrf); |
378 } | 374 } |
379 } | 375 } |
380 // TODO: Generate messages for missing fractions. | 376 // TODO: Generate messages for missing fractions. |
381 return new CalculationResult(sldr, this); | 377 return new CalculationResult(sldr, this); |