Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BedQualityCalculator.java @ 9451:fd6621f47a72
Bundu bzws density calculation completed
author | mschaefer |
---|---|
date | Thu, 23 Aug 2018 10:57:40 +0200 |
parents | 7e1fb8d0cb0d |
children |
rev | line source |
---|---|
9450
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
2 * Software engineering by |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
3 * Björnsen Beratende Ingenieure GmbH |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
5 * |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
6 * This file is Free Software under the GNU AGPL (>=v3) |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
8 * documentation coming with Dive4Elements River for details. |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
9 */ |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
10 |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
11 package org.dive4elements.river.artifacts.bundu.bezugswst; |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
12 |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
13 import java.util.Date; |
9451 | 14 import java.util.Map.Entry; |
15 import java.util.NavigableMap; | |
16 import java.util.TreeMap; | |
9450
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
17 |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
18 import org.dive4elements.artifacts.CallContext; |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
19 import org.dive4elements.river.artifacts.access.BedQualityAccess; |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
20 import org.dive4elements.river.artifacts.bundu.BUNDUArtifact; |
9451 | 21 import org.dive4elements.river.artifacts.math.Linear; |
9450
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
22 import org.dive4elements.river.artifacts.model.Calculation; |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
23 import org.dive4elements.river.artifacts.model.Calculation.Problem; |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
24 import org.dive4elements.river.artifacts.model.CalculationResult; |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
25 import org.dive4elements.river.artifacts.model.minfo.BedQualityCalculation; |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
26 import org.dive4elements.river.artifacts.model.minfo.BedQualityResult; |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
27 import org.dive4elements.river.artifacts.model.minfo.BedQualityResultValue; |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
28 import org.dive4elements.river.model.River; |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
29 |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
30 /** |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
31 * Calculator for bed quality parameters in a km range and time period, wrapping the minfo BedQualityCalculation |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
32 * |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
33 * @author Matthias Schäfer |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
34 * |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
35 */ |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
36 public class BedQualityCalculator { |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
37 |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
38 private final CallContext context; |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
39 |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
40 private final BUNDUArtifact bundu; |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
41 |
9451 | 42 private final NavigableMap<Double, Double> densities; |
9450
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
43 |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
44 public BedQualityCalculator(final CallContext context, final BUNDUArtifact bundu) { |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
45 this.context = context; |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
46 this.bundu = bundu; |
9451 | 47 this.densities = new TreeMap<>(); |
9450
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
48 } |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
49 |
9451 | 50 |
9450
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
51 /** |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
52 * Calculates the river bed sublayer densities for an array of kms and a time period of measurements |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
53 */ |
9451 | 54 public void execute(final Calculation problems, final River river, final double[] kms, final Date startDay, final Date endDay) { |
9450
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
55 final BedQualityCalculation bqCalc = new BedQualityCalculation(); |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
56 final BedQualityAccess access = createBqAccess(kms[0], kms[kms.length - 1], startDay, endDay); |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
57 final CalculationResult bqCalcResult = bqCalc.calculate(access); |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
58 if (bqCalcResult.getReport().getProblems() != null) { |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
59 for (final Problem problem : bqCalcResult.getReport().getProblems()) |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
60 problems.addProblem(problem); |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
61 } |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
62 final BedQualityResult[] results = (BedQualityResult[]) bqCalcResult.getData(); |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
63 final BedQualityResult result = results[0]; |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
64 final BedQualityResultValue bqResValue = result.getValue("density", "sublayer"); |
9451 | 65 final double[][] kmdensities = bqResValue.getDataInterpolated(kms); |
66 this.densities.clear(); | |
67 for (int i = 0; i <= kmdensities[0].length - 1; i++) | |
68 this.densities.put(Double.valueOf(kmdensities[0][i]), Double.valueOf(kmdensities[1][i])); | |
69 } | |
70 | |
71 /** | |
72 * Searches the density of a station in the active calculation result | |
73 */ | |
74 public double getDensity(final double station) { | |
75 return interpolateDensity(station); | |
76 } | |
77 | |
78 /** | |
79 * Searches and interpolates a density value for a km | |
80 */ | |
81 private double interpolateDensity(final double km) { | |
82 | |
83 if (this.densities.containsKey(km)) { | |
84 final Double value = this.densities.get(km); | |
85 return (value == null) ? Double.NaN : value.doubleValue(); | |
86 } | |
87 | |
88 final Entry<Double, Double> floorEntry = this.densities.floorEntry(km); | |
89 final Entry<Double, Double> ceilingEntry = this.densities.ceilingEntry(km); | |
90 | |
91 if ((floorEntry == null) || (ceilingEntry == null)) | |
92 return Double.NaN; | |
93 | |
94 final double floorKm = floorEntry.getKey().doubleValue(); | |
95 final double ceilKm = ceilingEntry.getKey().doubleValue(); | |
96 | |
97 // report once if the interpolation distance exceeds 1000m | |
98 // if ((Math.abs(floorKm - ceilKm) > MAX_DISTANCE_KM) && (this.problems != null)) { | |
99 // this.problems.addProblem(km, "linearInterpolator.maxdistance", MAX_DISTANCE_KM * 1000); | |
100 // this.problems = null; | |
101 // return Double.NaN; | |
102 // } | |
103 | |
104 final Double floorHeight = floorEntry.getValue(); | |
105 final Double ceilingHeight = ceilingEntry.getValue(); | |
106 | |
107 if (floorHeight == null || ceilingHeight == null) | |
108 return Double.NaN; | |
109 | |
110 return Linear.linear(km, floorKm, ceilKm, floorHeight, ceilingHeight); | |
9450
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
111 } |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
112 |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
113 /** |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
114 * Creates an access object for the bed quality calculation |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
115 */ |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
116 private BedQualityAccess createBqAccess(final double fromKm, final double toKm, final Date startDay, final Date endDay) { |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
117 final BunduMinfoArtifactWrapper minfo = new BunduMinfoArtifactWrapper(this.bundu, startDay, endDay); |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
118 return new BedQualityAccess(minfo, this.context); |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
119 } |
7e1fb8d0cb0d
Bundu bzws calculation nearly completed, some corrections with csv output, started with linking the minfo density calculation
mschaefer
parents:
diff
changeset
|
120 } |