comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculation.java @ 8911:37ff7f435912

SINFO Flowdepth: more error checks, d50 interpolation, avoid negative tkh
author mschaefer
date Fri, 23 Feb 2018 09:30:24 +0100
parents 0a900d605d52
children e3519c3e7a0a
comparison
equal deleted inserted replaced
8910:d9c89651bd67 8911:37ff7f435912
152 problems.addProblem(message); 152 problems.addProblem(message);
153 doCalcTkh = false; 153 doCalcTkh = false;
154 } 154 }
155 155
156 BedQualityD50KmValueFinder bedMeasurementsFinder = null; 156 BedQualityD50KmValueFinder bedMeasurementsFinder = null;
157 if (doCalcTkh) 157 if (doCalcTkh) {
158 bedMeasurementsFinder = loadBedMeasurements(river, calcRange, sounding.getYear().intValue()); 158 bedMeasurementsFinder = loadBedMeasurements(river, calcRange, sounding.getYear().intValue());
159 if (bedMeasurementsFinder == null) {
160 final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingSoilKind", null, label);
161 problems.addProblem(message);
162 doCalcTkh = false;
163 }
164 }
159 165
160 final String bedHeightLabel = bedHeight.getDescription(); 166 final String bedHeightLabel = bedHeight.getDescription();
161 final String wstLabel = wstKms.getName(); 167 final String wstLabel = wstKms.getName();
162 168
163 final UnivariateRealFunction wstInterpolator = DoubleUtil.getLinearInterpolator(wstKms.allKms(), wstKms.allWs()); 169 final UnivariateRealFunction wstInterpolator = DoubleUtil.getLinearInterpolator(wstKms.allKms(), wstKms.allWs());
164 UnivariateRealFunction qInterpolator = null; 170 UnivariateRealFunction qInterpolator = null;
165 DoubleRange qRange = null; 171 DoubleRange qRange = null;
166 if (doCalcTkh) { 172 if (doCalcTkh) {
167 qInterpolator = DoubleUtil.getLinearInterpolator(((QKms) wstKms).allKms(), ((QKms) wstKms).allQs()); 173 qInterpolator = DoubleUtil.getLinearInterpolator(((QKms) wstKms).allKms(), ((QKms) wstKms).allQs());
168 qRange = new DoubleRange( ((QKms) wstKms).allQs().min(), ((QKms) wstKms).allQs().max()); 174 if (qInterpolator != null)
175 qRange = new DoubleRange( ((QKms) wstKms).allQs().min(), ((QKms) wstKms).allQs().max());
176 else {
177 final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingQ", null, label);
178 problems.addProblem(message);
179 doCalcTkh = false;
180 }
169 } 181 }
170 182
171 // FIXME: sort by station first, but in what direction? 183 // FIXME: sort by station first, but in what direction?
172 // FIXME: using river.getKmUp()? 184 // FIXME: using river.getKmUp()?
173 final List<BedHeightValue> values = bedHeight.getValues(); 185 final List<BedHeightValue> values = bedHeight.getValues();
178 // FIXME: wie wird ggf. interpoliert? prüfung ob werte vorhanden? 190 // FIXME: wie wird ggf. interpoliert? prüfung ob werte vorhanden?
179 /* SoilKind lastKind = SoilKind.mobil; */ 191 /* SoilKind lastKind = SoilKind.mobil; */
180 SoilKindKmValueFinder soilKindFinder = null; 192 SoilKindKmValueFinder soilKindFinder = null;
181 if (doCalcTkh) { 193 if (doCalcTkh) {
182 soilKindFinder = new SoilKindKmValueFinder(); 194 soilKindFinder = new SoilKindKmValueFinder();
183 soilKindFinder.loadValues(river, calcRange); 195 if (!soilKindFinder.loadValues(river, calcRange)) {
196 doCalcTkh = false;
197 final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingSoilKind", null, label);
198 problems.addProblem(message);
199 }
184 } 200 }
185 201
186 FlowVelocityModelKmValueFinder flowVelocitiesFinder = null; 202 FlowVelocityModelKmValueFinder flowVelocitiesFinder = null;
187 if (doCalcTkh) { 203 if (doCalcTkh) {
188 flowVelocitiesFinder = new FlowVelocityModelKmValueFinder(); 204 flowVelocitiesFinder = new FlowVelocityModelKmValueFinder();
189 flowVelocitiesFinder.loadValues(river, calcRange, qRange); 205 if (!flowVelocitiesFinder.loadValues(river, calcRange, qRange)) {
206 doCalcTkh = false;
207 final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingVelocity", null, label);
208 problems.addProblem(message);
209 }
190 } 210 }
191 211
192 for (final BedHeightValue bedHeightValue : sortedValues) { 212 for (final BedHeightValue bedHeightValue : sortedValues) {
193 213
194 final Double station = bedHeightValue.getStation(); 214 final Double station = bedHeightValue.getStation();
217 if (qInterpolator != null) 237 if (qInterpolator != null)
218 discharge = qInterpolator.value(km); 238 discharge = qInterpolator.value(km);
219 else 239 else
220 discharge = Double.NaN; 240 discharge = Double.NaN;
221 241
222 // FIXME: calculate tkh 242 // Calculate tkh
223 double tkh = 0; 243 double tkh = 0;
224 if (doCalcTkh) { 244 if (doCalcTkh) {
225 double d50 = bedMeasurementsFinder.findD50(km); 245 double d50 = Double.NaN;
226 if (Double.isNaN(d50)) { 246 try {
247 d50 = bedMeasurementsFinder.findD50(km);
248 } catch (Exception e) {
227 final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingD50", null, label); 249 final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingD50", null, label);
228 problems.addProblem(km, message); 250 problems.addProblem(km, message);
229 //FIXME: cumulate problems to one message? 251 //FIXME: cumulate problems to one message?
230 } 252 }
231 if (!Double.isNaN(d50)) { 253 if (!Double.isNaN(d50)) {
232 if (flowVelocitiesFinder.findKmQValues(km, discharge)) { 254 if (flowVelocitiesFinder.findKmQValues(km, discharge)) {
233 tkh = calculateTkh(wst - meanBedHeight, flowVelocitiesFinder.getFindVmainFound(), d50, flowVelocitiesFinder.getFindTauFound()); 255 tkh = calculateTkh(wst - meanBedHeight, flowVelocitiesFinder.getFindVmainFound(), d50, flowVelocitiesFinder.getFindTauFound());
256 if (!Double.isNaN(tkh) && (tkh < 0))
257 tkh = 0;
234 /* log.debug(String.format("calculateTkh km %.3f q %.0f w %.2f mbh %.2f vm %.1f tau %.1f d50(mm) %.1f tkh(cm) %.1f", 258 /* log.debug(String.format("calculateTkh km %.3f q %.0f w %.2f mbh %.2f vm %.1f tau %.1f d50(mm) %.1f tkh(cm) %.1f",
235 km, discharge, wst, meanBedHeight, flowVelocitiesFinder.getFindVmainFound(), flowVelocitiesFinder.getFindTauFound(), d50*1000, tkh)); */ 259 km, discharge, wst, meanBedHeight, flowVelocitiesFinder.getFindVmainFound(), flowVelocitiesFinder.getFindTauFound(), d50*1000, tkh)); */
236 } 260 }
237 else { 261 else {
238 final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingQ", null, label); 262 final String message = Resources.getMsg(this.context.getMeta(), "sinfo_calc_flow_depth.warning.missingQ", null, label);

http://dive4elements.wald.intevation.org