comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataCalculation.java @ 8176:7b0b3b1a2ee8

Let epochs be averages over their years.
author Tom Gottfried <tom@intevation.de>
date Tue, 02 Sep 2014 17:47:03 +0200
parents d2673ca68e70
children 76e1e9d81ce2
comparison
equal deleted inserted replaced
8175:d2673ca68e70 8176:7b0b3b1a2ee8
103 return grainFractions; 103 return grainFractions;
104 } 104 }
105 } // class GrainFraction 105 } // class GrainFraction
106 106
107 public static final GrainFraction [] GRAIN_FRACTIONS = { 107 public static final GrainFraction [] GRAIN_FRACTIONS = {
108 // TODO: i18n for bfg parts
109 // Grain fraction names are alignt to the grain_fractions table 108 // Grain fraction names are alignt to the grain_fractions table
110 GrainFraction.make("total", TOTAL_LOAD), 109 GrainFraction.make("total", TOTAL_LOAD),
111 GrainFraction.make("bed_load", BED_LOAD), 110 GrainFraction.make("bed_load", BED_LOAD),
112 GrainFraction.make("bed_load_susp_sand", BED_LOAD_SUSP_SAND), 111 GrainFraction.make("bed_load_susp_sand", BED_LOAD_SUSP_SAND),
113 GrainFraction.make("coarse", COARSE), 112 GrainFraction.make("coarse", COARSE),
283 SedimentLoadDataResult sldr = new SedimentLoadDataResult(); 282 SedimentLoadDataResult sldr = new SedimentLoadDataResult();
284 283
285 boolean isKmUp = isKmUp(); 284 boolean isKmUp = isKmUp();
286 Set<Integer> missingFractions = new TreeSet<Integer>(); 285 Set<Integer> missingFractions = new TreeSet<Integer>();
287 286
287 Sum sum = new Sum();
288
288 SedimentDensity sd = getSedimentDensity(); 289 SedimentDensity sd = getSedimentDensity();
289 290
290 // They are not epochs, they are single years! 291 // They are not epochs, they are single years!
291 Not notEpochs = new Not(IsEpoch.INSTANCE); 292 Not notEpochs = new Not(IsEpoch.INSTANCE);
292 293
293 for (int [] epoch: epochs) { 294 for (int [] epoch: epochs) {
294 List<double [][]> results = new ArrayList<double [][]>();
295
296 int min = Math.min(epoch[0], epoch[1]); 295 int min = Math.min(epoch[0], epoch[1]);
297 int max = Math.max(epoch[0], epoch[1]); 296 int max = Math.max(epoch[0], epoch[1]);
298 297
299 String period = Integer.toString(epoch[0]) + " - " + 298 String period = Integer.toString(epoch[0]) + " - " +
300 Integer.toString(epoch[1]); 299 Integer.toString(epoch[1]);
301 for (int year = min; year <= max; ++year) { 300
302 Value.Filter filter = new And(notEpochs) 301 for (GrainFraction gf: GRAIN_FRACTIONS) {
303 .add(new TimeRangeIntersects(year)); 302
304 303 List<double [][]> results = new ArrayList<double [][]>();
305 Sum sum = new Sum(); 304
306 305 for (int year = min; year <= max; ++year) {
307 for (GrainFraction gf: GRAIN_FRACTIONS) { 306 Value.Filter filter = new And(notEpochs)
307 .add(new TimeRangeIntersects(year));
308
308 double [][] result = sum( 309 double [][] result = sum(
309 sld, gf.getGrainFractions(), filter, sum, isKmUp, 310 sld, gf.getGrainFractions(), filter, sum, isKmUp,
310 missingFractions); 311 missingFractions);
311 312
312 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) { 313 if (result[0].length == 0 || DoubleUtil.isNaN(result[1])) {
317 } 318 }
318 319
319 transformT2M3(sd, year, result); 320 transformT2M3(sd, year, result);
320 results.add(result); 321 results.add(result);
321 } 322 }
323
324 double [][] result = average(results);
325
326 SedimentLoadDataResult.Fraction sldrf =
327 new SedimentLoadDataResult.Fraction(gf.getDescription(),
328 result, period);
329 sldr.addFraction(sldrf);
322 } 330 }
323 331
324 double [][] result = average(results);
325 // TODO: Optionally transform units.
326 SedimentLoadDataResult.Fraction sldrf =
327 new SedimentLoadDataResult.Fraction("TODO: nice description", result, period);
328 sldr.addFraction(sldrf);
329 } 332 }
330 // TODO: Generate messages for missing fractions. 333 // TODO: Generate messages for missing fractions.
331 return new CalculationResult(sldr, this); 334 return new CalculationResult(sldr, this);
332 } 335 }
333 336
482 double [] kms = pair[0]; 485 double [] kms = pair[0];
483 double [] vs = pair[1]; 486 double [] vs = pair[1];
484 for (int i = 0; i < kms.length; ++i) { 487 for (int i = 0; i < kms.length; ++i) {
485 double km = kms[i]; 488 double km = kms[i];
486 double v = vs[i]; 489 double v = vs[i];
487 if (Double.isNaN(km) || Double.isNaN(v)) { 490 if (Double.isNaN(km)) {
488 continue; 491 continue;
489 } 492 }
490 XSum xsum = map.get(km); 493 XSum xsum = map.get(km);
491 if (xsum == null) { 494 if (xsum == null) {
492 map.put(km, xsum = new XSum()); 495 map.put(km, xsum = new XSum());
496 } 499 }
497 500
498 double [][] result = new double[2][map.size()]; 501 double [][] result = new double[2][map.size()];
499 int i = 0; 502 int i = 0;
500 for (Map.Entry<Double, XSum> entry: map.entrySet()) { 503 for (Map.Entry<Double, XSum> entry: map.entrySet()) {
501 result[i][0] = entry.getKey(); 504 result[0][i] = entry.getKey();
502 result[i][1] = entry.getValue().avg(); 505 result[1][i] = entry.getValue().avg();
503 ++i; 506 ++i;
504 } 507 }
505 508
506 return null; 509 return result;
507 } 510 }
508 511
509 } 512 }
510 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : 513 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org