comparison artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BezugswstCalculation.java @ 9451:fd6621f47a72

Bundu bzws density calculation completed
author mschaefer
date Thu, 23 Aug 2018 10:57:40 +0200
parents 7e1fb8d0cb0d
children be9bd06a1e3f
comparison
equal deleted inserted replaced
9450:7e1fb8d0cb0d 9451:fd6621f47a72
36 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; 36 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
37 import org.dive4elements.river.artifacts.sinfo.util.WstInfo; 37 import org.dive4elements.river.artifacts.sinfo.util.WstInfo;
38 import org.dive4elements.river.exports.WaterlevelDescriptionBuilder; 38 import org.dive4elements.river.exports.WaterlevelDescriptionBuilder;
39 import org.dive4elements.river.model.BedHeightValueType; 39 import org.dive4elements.river.model.BedHeightValueType;
40 import org.dive4elements.river.model.River; 40 import org.dive4elements.river.model.River;
41 import org.dive4elements.river.utils.DoubleUtil;
41 import org.dive4elements.river.utils.Formatter; 42 import org.dive4elements.river.utils.Formatter;
42 43
43 class BezugswstCalculation { 44 class BezugswstCalculation {
44 45
45 // private static Logger log = Logger.getLogger(BezugswstCalculation.class); 46 // private static Logger log = Logger.getLogger(BezugswstCalculation.class);
118 } 119 }
119 120
120 // Compute the missing volumes 121 // Compute the missing volumes
121 if (access.isCalculateMissingValue()) { 122 if (access.isCalculateMissingValue()) {
122 computeMissingVolumes(problems); 123 computeMissingVolumes(problems);
123 final BedQualityCalculator bqCalculator = new BedQualityCalculator(this.context, bunduartifact); 124 final BedQualityCalculator bqCalculator = computeDensities(problems, bunduartifact, access, river);
124 final double[] kms = new double[] { this.missKmFrom.doubleValue(), this.missKmTo.doubleValue() }; 125 computeMissingMasses(problems, bqCalculator);
125 final Calendar endDay = Calendar.getInstance();
126 endDay.set(access.getBezugsJahr().intValue(), 11, 31);
127 final Calendar startDay = Calendar.getInstance();
128 startDay.set(endDay.get(Calendar.YEAR) - 20, 0, 1);
129 // TODO final double[][] kmDensities = bqCalculator.execute(problems, river, kms, startDay.getTime(), endDay.getTime());
130 computeMissingMasses(problems);
131 } 126 }
132 127
133 // Add the result to the results collection 128 // Add the result to the results collection
134 final WaterlevelDescriptionBuilder descBuilder = new WaterlevelDescriptionBuilder(winfo, this.context); 129 final WaterlevelDescriptionBuilder descBuilder = new WaterlevelDescriptionBuilder(winfo, this.context);
135 final String qtext = descBuilder.getMetadataQ(); 130 final String qtext = descBuilder.getMetadataQ();
386 return this.rows.get(rowIndex).getDoubleValue(GeneralResultType.station); 381 return this.rows.get(rowIndex).getDoubleValue(GeneralResultType.station);
387 return Double.NaN; 382 return Double.NaN;
388 } 383 }
389 384
390 /** 385 /**
386 * Create a density calculator and compute the densities of the missing volume km range and time period according to the
387 * reference year
388 */
389 private BedQualityCalculator computeDensities(final Calculation problems, final BUNDUArtifact bunduartifact, final BunduAccess access, final River river) {
390 final BedQualityCalculator bqCalculator = new BedQualityCalculator(this.context, bunduartifact);
391 // REMARK 10km tolerance at start and end to enable interpolation there
392 final double[] kms = DoubleUtil.explode(access.getMissingVolFrom().doubleValue() - 10.0, access.getMissingVolTo().doubleValue() + 10.0,
393 access.getStep().doubleValue() / 1000);
394 final Calendar endDay = Calendar.getInstance();
395 endDay.set(access.getBezugsJahr().intValue(), 11, 31);
396 final Calendar startDay = Calendar.getInstance();
397 // TODO Spezialregelung für den Rhein (bis 1999, 2000 bis 2009, ab 2010)
398 startDay.set(endDay.get(Calendar.YEAR) - 20, 0, 1);
399 bqCalculator.execute(problems, river, kms, startDay.getTime(), endDay.getTime());
400 return bqCalculator;
401 }
402
403 /**
391 * Computes the missing masses 404 * Computes the missing masses
392 */ 405 */
393 private void computeMissingMasses(final Calculation problems) { 406 private void computeMissingMasses(final Calculation problems, final BedQualityCalculator densityFinder) {
394 for (final ResultRow row : this.rows) { 407 for (final ResultRow row : this.rows) {
395 @SuppressWarnings("unchecked") 408 @SuppressWarnings("unchecked")
396 final List<Double> volumes = (List<Double>) row.getValue(BunduResultType.missVolumeFields); 409 final List<Double> volumes = (List<Double>) row.getValue(BunduResultType.missVolumeFields);
397 if ((volumes == null) || Double.isNaN(volumes.get(0))) 410 if ((volumes == null) || Double.isNaN(volumes.get(0)))
398 continue; 411 continue;
399 final double density = getDensity(row.getDoubleValue(GeneralResultType.station)); 412 final double density = getDensity(row.getDoubleValue(GeneralResultType.station), densityFinder);
400 final List<Double> masses = new ArrayList<>(); 413 final List<Double> masses = new ArrayList<>();
401 double kmTotal = 0.0; 414 double kmTotal = 0.0;
402 for (int j = BedHeightValueType.FIELD_FIRST_INDEX; j <= BedHeightValueType.FIELD_LAST_INDEX; j++) { 415 for (int j = BedHeightValueType.FIELD_FIRST_INDEX; j <= BedHeightValueType.FIELD_LAST_INDEX; j++) {
403 final double m = volumes.get(j - 1) * density; 416 final double m = volumes.get(j - 1) * density;
404 masses.add(m); 417 masses.add(m);
468 missRows.add(row); 481 missRows.add(row);
469 } 482 }
470 return missRows; 483 return missRows;
471 } 484 }
472 485
473 private double getDensity(final double km) { 486 /**
474 return 1.73; // TODO 487 * Gets the density of a km from the densities calculation
488 */
489 private double getDensity(final double km, final BedQualityCalculator densityFinder) {
490 return densityFinder.getDensity(km);
475 } 491 }
476 492
477 /** 493 /**
478 * Checks whether a km lies in the missing volume calculation range 494 * Checks whether a km lies in the missing volume calculation range
479 */ 495 */

http://dive4elements.wald.intevation.org