Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxCalculation.java @ 8964:45f1ad66560e
Code cleanup concerning calculations: improved error handling; improved interpolation; bed heights are now always used for spatial discretisation
author | gernotbelger |
---|---|
date | Thu, 29 Mar 2018 15:48:17 +0200 |
parents | 322b0e6298ea |
children | b5600453bb8f |
comparison
equal
deleted
inserted
replaced
8963:b98fbd91f64a | 8964:45f1ad66560e |
---|---|
85 private FlowDepthMinMaxCalculationResult calculateResult(final DoubleRange calcRange, final MinMaxIdPair minMaxPair, final Calculation problems, | 85 private FlowDepthMinMaxCalculationResult calculateResult(final DoubleRange calcRange, final MinMaxIdPair minMaxPair, final Calculation problems, |
86 final RiverInfoProvider infoProvider) { | 86 final RiverInfoProvider infoProvider) { |
87 | 87 |
88 /* access real input data from database */ | 88 /* access real input data from database */ |
89 final String wstId = minMaxPair.getWstId(); | 89 final String wstId = minMaxPair.getWstId(); |
90 | |
91 // FIXME: bfg überzeugen dass man immer nur pärchen auswählen kann --> min/max id ist gleich! | |
92 | |
90 final String minSoundingId = minMaxPair.getMinSoundingId(); | 93 final String minSoundingId = minMaxPair.getMinSoundingId(); |
91 final String maxSoundingId = minMaxPair.getMaxSoundingId(); | 94 final String maxSoundingId = minMaxPair.getMaxSoundingId(); |
92 | 95 |
93 final BedHeightsFinder minBedHeight = minSoundingId == null ? null : BedHeightsFinder.forId(this.context, minSoundingId, calcRange, problems); | 96 final BedHeightsFinder minBedHeight = minSoundingId == null ? null : BedHeightsFinder.forId(this.context, minSoundingId, calcRange, problems); |
94 final BedHeightsFinder maxBedHeight = maxSoundingId == null ? null : BedHeightsFinder.forId(this.context, maxSoundingId, calcRange, problems); | 97 final BedHeightsFinder maxBedHeight = maxSoundingId == null ? null : BedHeightsFinder.forId(this.context, maxSoundingId, calcRange, problems); |
95 if (minBedHeight == null && maxBedHeight == null) | 98 if (minBedHeight == null && maxBedHeight == null) |
96 return null; | 99 return null; |
97 | 100 |
98 /* REMARK: fetch ALL wst kms, because we want to determine the original reference gauge */ | 101 /* REMARK: fetch ALL wst kms, because we want to determine the original reference gauge */ |
99 final WaterlevelData waterlevel = new WaterlevelFetcher().findWaterlevel(this.context, wstId, Double.NaN, Double.NaN, problems); | 102 final WaterlevelData waterlevel = new WaterlevelFetcher().findWaterlevel(this.context, wstId, calcRange, problems); |
100 if (waterlevel == null) | 103 if (waterlevel == null) |
101 return null; | 104 return null; |
102 | 105 |
103 final String label = createLabel(waterlevel, minBedHeight, maxBedHeight); | 106 final String label = createLabel(waterlevel, minBedHeight, maxBedHeight); |
104 | 107 |
105 final WKms wstKms = waterlevel.getWkms(); | 108 final WKms wstKms = waterlevel.getWkms(); |
106 | 109 |
107 final int soundingYear = checkSoundingYear(minBedHeight, maxBedHeight, problems); | 110 final int soundingYear = checkSoundingYear(minBedHeight, maxBedHeight, problems); |
108 FlowDepthUtils.checkYearDifference(label, waterlevel.getYear(), soundingYear, problems); | 111 FlowDepthUtils.checkYearDifference(label, waterlevel.getYear(), soundingYear, problems); |
109 // FIXME | |
110 // checkWaterlevelDiscretisation(wstKms, calcRange, problems); | |
111 // TODO: prüfen, ob sohlhöhen die calcRange abdecken/überschneiden | |
112 | 112 |
113 /* re-determine the reference gauge, in the same way as the WaterlevelArtifact would do it */ | 113 /* re-determine the reference gauge, in the same way as the WaterlevelArtifact would do it */ |
114 final RiverInfoProvider riverInfoProvider = infoProvider.forWaterlevel(waterlevel); | 114 final RiverInfoProvider riverInfoProvider = infoProvider.forWaterlevel(waterlevel); |
115 | 115 |
116 final int wspYear = waterlevel.getYear(); | 116 final int wspYear = waterlevel.getYear(); |
117 final WstInfo wstInfo = new WstInfo(waterlevel.getName(), wspYear, riverInfoProvider.getReferenceGauge()); | 117 final WstInfo wstInfo = new WstInfo(waterlevel.getName(), wspYear, riverInfoProvider.getReferenceGauge()); |
118 | 118 |
119 final WaterlevelValuesFinder waterlevelProvider = WaterlevelValuesFinder.fromKms(wstKms); | 119 final WaterlevelValuesFinder waterlevelProvider = WaterlevelValuesFinder.fromKms(problems, wstKms); |
120 final DischargeValuesFinder dischargeProvider = DischargeValuesFinder.fromKms(wstKms); | 120 final DischargeValuesFinder dischargeProvider = DischargeValuesFinder.fromKms(wstKms); |
121 | 121 |
122 final String waterlevelLabel = waterlevel.getName(); | 122 final String waterlevelLabel = waterlevel.getName(); |
123 final String soundingLabel = buildSoundingLabel(minBedHeight, maxBedHeight); | 123 final String soundingLabel = buildSoundingLabel(minBedHeight, maxBedHeight); |
124 | 124 |
125 /* real calculation loop */ | 125 /* real calculation loop */ |
126 final Collection<SInfoResultRow> rows = new ArrayList<>(); | 126 final Collection<SInfoResultRow> rows = new ArrayList<>(); |
127 | 127 |
128 // FIXME: determine what is the spatial discretisation that we will use... | 128 // FIXME: we use the stations of one of the bed heights atm, because we probably will later use only data from one bed heights datasets! |
129 final double[] allKms = wstKms.allKms().toNativeArray(); | 129 final Collection<Double> stations = minBedHeight == null ? maxBedHeight.getStations() : minBedHeight.getStations(); |
130 for (final double station : allKms) { | 130 for (final double station : stations) { |
131 if (calcRange.containsDouble(station)) { | 131 if (calcRange.containsDouble(station)) { |
132 | 132 |
133 final double wst = waterlevelProvider.getWaterlevel(station); | 133 final double wst = waterlevelProvider.getWaterlevel(station); |
134 final double discharge = dischargeProvider.getDischarge(station); | 134 final double discharge = dischargeProvider.getDischarge(station); |
135 | 135 |
138 | 138 |
139 final double minFlowDepth = wst - minBedHeightValue; | 139 final double minFlowDepth = wst - minBedHeightValue; |
140 final double maxFlowDepth = wst - maxBedHeightValue; | 140 final double maxFlowDepth = wst - maxBedHeightValue; |
141 | 141 |
142 // FIXME: unclear what is meant here... | 142 // FIXME: unclear what is meant here... |
143 // FIXME: this will simply the bed height of 'the' bed height if we reduce this to simply using one sounding dataset | |
143 final double meanBedHeight = Double.NaN; | 144 final double meanBedHeight = Double.NaN; |
144 | 145 |
145 // REMARK: access the location once only during calculation | 146 // REMARK: access the location once only during calculation |
146 final String location = riverInfoProvider.getLocation(station); | 147 final String location = riverInfoProvider.getLocation(station); |
147 | 148 |