annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/river/MainWstValuesCalculator.java @ 9506:8b7bf26b8782

Predefined artifact for standard vegetation zones. Some minor adaptions.
author gernotbelger
date Fri, 28 Sep 2018 13:44:12 +0200
parents 853f2dafc16e
children
rev   line source
9499
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
2 * Software engineering by
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
5 *
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
9 */
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
10 package org.dive4elements.river.artifacts.model.river;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
11
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
12 import java.util.HashMap;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
13 import java.util.Map;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
14
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
15 import org.apache.commons.lang.math.DoubleRange;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
16 import org.dive4elements.artifacts.CallContext;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
17 import org.dive4elements.river.artifacts.model.WstValueTable;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
18 import org.dive4elements.river.artifacts.model.WstValueTable.QPosition;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
19 import org.dive4elements.river.artifacts.model.WstValueTableFactory;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
20 import org.dive4elements.river.model.Gauge;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
21 import org.dive4elements.river.model.MainValue;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
22 import org.dive4elements.river.model.MainValueType.MainValueTypeKey;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
23 import org.dive4elements.river.model.River;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
24
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
25 /**
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
26 * @author Domenico Nardi Tironi
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
27 */
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
28 public final class MainWstValuesCalculator {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
29
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
30 private final WstValueTable wst;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
31
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
32 private final Map<String, MainValueQPosition> positions;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
33
9506
8b7bf26b8782 Predefined artifact for standard vegetation zones.
gernotbelger
parents: 9499
diff changeset
34 static class MainValueQPosition {
9499
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
35
9506
8b7bf26b8782 Predefined artifact for standard vegetation zones.
gernotbelger
parents: 9499
diff changeset
36 public final Map<Gauge, QPosition> gaugePositions = new HashMap<>();
8b7bf26b8782 Predefined artifact for standard vegetation zones.
gernotbelger
parents: 9499
diff changeset
37
8b7bf26b8782 Predefined artifact for standard vegetation zones.
gernotbelger
parents: 9499
diff changeset
38 public QPosition refGaugePositions = null;
9499
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
39 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
40
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
41 public static MainWstValuesCalculator forRiver(final CallContext context, final River river, final DoubleRange calcRange, final String... mainValueNames) {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
42
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
43 final RiverInfoProvider info = RiverInfoProvider.forRange(context, river, calcRange);
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
44
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
45 return forRiverInfo(info, mainValueNames);
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
46 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
47
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
48 public static MainWstValuesCalculator forRiverInfo(final RiverInfoProvider info, final String... mainValueNames) {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
49
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
50 final WstValueTable wst = WstValueTableFactory.getTable(info.getRiver());
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
51
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
52 final Map<String, MainValueQPosition> positions = calculatePositions(info, wst, mainValueNames);
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
53
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
54 return new MainWstValuesCalculator(wst, positions);
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
55 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
56
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
57 private static Map<String, MainValueQPosition> calculatePositions(final RiverInfoProvider info, final WstValueTable wst, final String[] mainValueNames) {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
58
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
59 boolean isFirstGauge = true;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
60
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
61 final Map<String, MainValueQPosition> positions = new HashMap<>();
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
62
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
63 for (final String mainValue : mainValueNames)
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
64 positions.put(mainValue.toUpperCase(), new MainValueQPosition());
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
65
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
66 for (final Gauge gauge : info.getGauges()) {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
67
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
68 for (final MainValueQPosition position : positions.values())
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
69 position.gaugePositions.put(gauge, null);
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
70
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
71 final double gaugeKm = gauge.getStation().doubleValue();
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
72 for (final MainValue mv : MainValue.getValuesOfGaugeAndType(gauge, MainValueTypeKey.Q)) {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
73
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
74 final MainValueQPosition position = positions.get(mv.getMainValue().getName().toUpperCase());
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
75 if (position != null) {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
76 final QPosition qPosition = wst.getQPosition(gaugeKm, mv.getValue().doubleValue());
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
77 position.gaugePositions.put(gauge, qPosition);
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
78
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
79 if (isFirstGauge)
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
80 position.refGaugePositions = qPosition;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
81 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
82 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
83
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
84 isFirstGauge = false;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
85 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
86
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
87 return positions;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
88 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
89
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
90 private MainWstValuesCalculator(final WstValueTable wst, final Map<String, MainValueQPosition> positions) {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
91 this.wst = wst;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
92 this.positions = positions;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
93 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
94
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
95 public boolean hasPosition(final String mainValueName) {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
96
9506
8b7bf26b8782 Predefined artifact for standard vegetation zones.
gernotbelger
parents: 9499
diff changeset
97 final MainValueQPosition position = this.positions.get(mainValueName.toUpperCase());
9499
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
98 if (position == null)
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
99 throw new IllegalArgumentException();
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
100
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
101 return position.refGaugePositions != null;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
102 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
103
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
104 /**
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
105 * Interpolates the W for a station with a fixed (virtual) wst column position
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
106 */
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
107 public double interpolateW(final double station, final String mainValueName) {
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
108
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
109 final MainValueQPosition mainValuePosition = this.positions.get(mainValueName.toUpperCase());
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
110
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
111 if (mainValuePosition.refGaugePositions == null)
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
112 return Double.NaN;
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
113
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
114 return this.wst.interpolateW(station, mainValuePosition.refGaugePositions);
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
115 }
853f2dafc16e VegetationZones in CrossSectionsDiagram
gernotbelger
parents:
diff changeset
116 }

http://dive4elements.wald.intevation.org