comparison artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java @ 9130:f61bc0c63188

WQSelect can now handle distance-only data
author gernotbelger
date Wed, 06 Jun 2018 14:16:28 +0200
parents e3519c3e7a0a
children 3f49835a00c3
comparison
equal deleted inserted replaced
9129:28eec75415d8 9130:f61bc0c63188
18 18
19 import org.dive4elements.artifacts.common.utils.StringUtils; 19 import org.dive4elements.artifacts.common.utils.StringUtils;
20 20
21 import org.dive4elements.river.artifacts.access.Calculation4Access; 21 import org.dive4elements.river.artifacts.access.Calculation4Access;
22 import org.dive4elements.river.artifacts.access.RangeAccess; 22 import org.dive4elements.river.artifacts.access.RangeAccess;
23 import org.dive4elements.river.artifacts.access.RiverAccess;
23 import org.dive4elements.river.artifacts.access.ComputationRangeAccess; 24 import org.dive4elements.river.artifacts.access.ComputationRangeAccess;
24 import org.dive4elements.river.artifacts.geom.Lines; 25 import org.dive4elements.river.artifacts.geom.Lines;
25 26
26 import org.dive4elements.river.artifacts.model.Calculation1; 27 import org.dive4elements.river.artifacts.model.Calculation1;
27 import org.dive4elements.river.artifacts.model.Calculation2; 28 import org.dive4elements.river.artifacts.model.Calculation2;
39 import org.dive4elements.river.artifacts.model.WstValueTableFactory; 40 import org.dive4elements.river.artifacts.model.WstValueTableFactory;
40 41
41 import org.dive4elements.river.artifacts.model.extreme.ExtremeResult; 42 import org.dive4elements.river.artifacts.model.extreme.ExtremeResult;
42 43
43 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; 44 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
44
45 import org.dive4elements.river.artifacts.states.LocationDistanceSelect;
46 45
47 import org.dive4elements.river.model.DischargeTable; 46 import org.dive4elements.river.model.DischargeTable;
48 import org.dive4elements.river.model.FastCrossSectionLine; 47 import org.dive4elements.river.model.FastCrossSectionLine;
49 import org.dive4elements.river.model.Gauge; 48 import org.dive4elements.river.model.Gauge;
50 import org.dive4elements.river.model.River; 49 import org.dive4elements.river.model.River;
172 */ 171 */
173 public CalculationResult getWaterlevelData() { 172 public CalculationResult getWaterlevelData() {
174 return this.getWaterlevelData(null); 173 return this.getWaterlevelData(null);
175 } 174 }
176 175
177 protected CalculationResult getDischargeLongitudinalSectionData() { 176 private CalculationResult getDischargeLongitudinalSectionData() {
178 // TODO: This caluclation should be cached as it is quite expensive. 177 // TODO: This caluclation should be cached as it is quite expensive.
179 return new Calculation4(new Calculation4Access(this)).calculate(); 178 return new Calculation4(new Calculation4Access(this)).calculate();
180 } 179 }
181 180
182 /** 181 /**
189 log.debug("WINFOArtifact.getWaterlevelData"); 188 log.debug("WINFOArtifact.getWaterlevelData");
190 189
191 String calculationMode = getDataAsString("calculation_mode"); 190 String calculationMode = getDataAsString("calculation_mode");
192 191
193 // If this WINFO-Artifact has a calculation trait. 192 // If this WINFO-Artifact has a calculation trait.
194 if (calculationMode != null) { 193 if (calculationMode != null)
195 if (calculationMode.equals("calc.discharge.longitudinal.section") 194 {
196 ) { 195 if (calculationMode.equals("calc.discharge.longitudinal.section"))
197 return getDischargeLongitudinalSectionData(); 196 return getDischargeLongitudinalSectionData();
198 } 197
199 else if (calculationMode.equals("calc.extreme.curve")) { 198 if (calculationMode.equals("calc.extreme.curve"))
200 return (CalculationResult) 199 return (CalculationResult)this.compute(context, ComputeType.ADVANCE, false);
201 this.compute(context, ComputeType.ADVANCE, false); 200
202 } 201 if (calculationMode.equals("calc.w.differences"))
203 else if (calculationMode.equals("calc.w.differences")) { 202 return (CalculationResult)this.compute(context, ComputeType.ADVANCE, true);
204 return (CalculationResult) 203
205 this.compute(context, ComputeType.ADVANCE, true); 204 log.warn("Unhandled calculation_mode " + calculationMode);
206 } 205 }
207 else { 206
208 log.warn("Unhandled calculation_mode " + calculationMode);
209 }
210 }
211
212 // Otherwise get it from parameterization. 207 // Otherwise get it from parameterization.
213 River river = RiverUtils.getRiver(this); 208 // TODO: wrong comment: now always a waterlevle computation is executed; actually there is a calc_mode for that, why dont check?
214 if (river == null) { 209 return computeWaterlevelData();
210 }
211
212 /** Execu5tes the calculation of 'waterlevel', fetches all input data from this artifact */
213 private CalculationResult computeWaterlevelData() {
214 final double[] kms = new ComputationRangeAccess(this).getKms();
215 if (kms == null)
216 return error(new WQKms[0], "no.kms.selected");
217
218 return computeWaterlevelData(kms);
219 }
220
221 /**
222 * Execu5tes the calculation of 'waterlevel'.
223 * Allows to override the stations for which the calculation is done. All other inputs are fetched from this artifact.
224 */
225 public final CalculationResult computeWaterlevelData(final double kms[]) {
226
227 final River river = new RiverAccess(this).getRiver();
228 if (river == null)
215 return error(new WQKms[0], "no.river.selected"); 229 return error(new WQKms[0], "no.river.selected");
216 }
217
218 double[] kms = getKms();
219 if (kms == null) {
220 return error(new WQKms[0], "no.kms.selected");
221 }
222 230
223 double[] qs = getQs(); 231 double[] qs = getQs();
224 double[] ws = null; 232 double[] ws = null;
225 boolean qSel = true;
226 233
227 Calculation report = new Calculation(); 234 Calculation report = new Calculation();
228 235
229 if (qs == null) { 236 if (qs == null) {
230 log.debug("Determine Q values based on a set of W values."); 237 log.debug("Determine Q values based on a set of W values.");
231 qSel = false;
232 ws = getWs(); 238 ws = getWs();
233 double [][] qws = getQsForWs(ws, report); 239 double [][] qws = getQsForWs(ws, report);
234 if (qws == null || qws.length == 0) { 240 if (qws == null || qws.length == 0) {
235 return error(new WQKms[0], "converting.ws.to.qs.failed"); 241 return error(new WQKms[0], "converting.ws.to.qs.failed");
236 } 242 }
271 277
272 log.debug( 278 log.debug(
273 "reference gauge: " + gauge.getName() + " (km " + refKm + ")"); 279 "reference gauge: " + gauge.getName() + " (km " + refKm + ")");
274 } 280 }
275 281
276 return computeWaterlevelData(kms, qs, ws, wst, refKm, report); 282 return computeWaterlevelData(kms, qs, ws, wst, refKm, report);
277 } 283 }
278
279 284
280 /** 285 /**
281 * Computes the data of a waterlevel computation based on the interpolation 286 * Computes the data of a waterlevel computation based on the interpolation
282 * in WstValueTable. 287 * in WstValueTable.
283 * 288 *
285 * @param qs The discharge values. 290 * @param qs The discharge values.
286 * @param wst The WstValueTable used for the interpolation. 291 * @param wst The WstValueTable used for the interpolation.
287 * 292 *
288 * @return an array of data triples that consist of W, Q and Kms. 293 * @return an array of data triples that consist of W, Q and Kms.
289 */ 294 */
290 public static CalculationResult computeWaterlevelData( 295 private static CalculationResult computeWaterlevelData(
291 double [] kms, 296 double [] kms,
292 double [] qs, 297 double [] qs,
293 double [] ws, 298 double [] ws,
294 WstValueTable wst, 299 WstValueTable wst,
295 double refKm, 300 double refKm,
347 * @param gauge The selected gauge. 352 * @param gauge The selected gauge.
348 * @param location The selected location. 353 * @param location The selected location.
349 * 354 *
350 * @return the computed data. 355 * @return the computed data.
351 */ 356 */
352 public static CalculationResult computeDurationCurveData( 357 private static CalculationResult computeDurationCurveData(
353 Gauge gauge, 358 Gauge gauge,
354 WstValueTable wst, 359 WstValueTable wst,
355 double location) 360 double location)
356 { 361 {
357 log.info("WINFOArtifact.computeDurationCurveData"); 362 log.info("WINFOArtifact.computeDurationCurveData");
407 * @param location The location where the computation should be based on. 412 * @param location The location where the computation should be based on.
408 * 413 *
409 * @return an object that contains tuples of W/Q values at the specified 414 * @return an object that contains tuples of W/Q values at the specified
410 * location. 415 * location.
411 */ 416 */
412 public static CalculationResult computeDischargeCurveData( 417 private static CalculationResult computeDischargeCurveData(
413 WstValueTable wst, 418 WstValueTable wst,
414 double location) 419 double location)
415 { 420 {
416 log.info("WINFOArtifact.computeDischargeCurveData"); 421 log.info("WINFOArtifact.computeDischargeCurveData");
417 422
542 547
543 548
544 /** 549 /**
545 * Get corrected waterline against surface/profile. 550 * Get corrected waterline against surface/profile.
546 */ 551 */
547 public Lines.LineData waterLineC(int idx, FastCrossSectionLine csl) { 552 private Lines.LineData waterLineC(int idx, FastCrossSectionLine csl) {
548 List<Point2D> points = csl.getPoints(); 553 List<Point2D> points = csl.getPoints();
549 554
550 WQKms[] wqckms = (WQKms[]) 555 WQKms[] wqckms = (WQKms[])
551 getDischargeLongitudinalSectionData().getData(); 556 getDischargeLongitudinalSectionData().getData();
552 557
663 * 668 *
664 * @param ws An array of W values. 669 * @param ws An array of W values.
665 * 670 *
666 * @return an array of Q values. 671 * @return an array of Q values.
667 */ 672 */
668 public double [][] getQsForWs(double[] ws, Calculation report) { 673 private double [][] getQsForWs(double[] ws, Calculation report) {
669 674
670 if (ws == null) { 675 if (ws == null) {
671 log.error("getQsForWs: ws == null"); 676 log.error("getQsForWs: ws == null");
672 return null; 677 return null;
673 } 678 }
801 return new double[] { from, to }; 806 return new double[] { from, to };
802 } 807 }
803 808
804 809
805 /** 810 /**
806 * Returns the selected Kms.
807 *
808 * @return the selected kms.
809 */
810 public double[] getKms() {
811 return new ComputationRangeAccess(this).getKms();
812 }
813
814 public double [] getFromToStep() {
815 return new ComputationRangeAccess(this).getFromToStep();
816 }
817
818 /**
819 * This method returns the Q values. 811 * This method returns the Q values.
820 * 812 *
821 * @return the selected Q values or null, if no Q values are selected. 813 * @return the selected Q values or null, if no Q values are selected.
822 */ 814 */
823 public double[] getQs() { 815 public double[] getQs() {

http://dive4elements.wald.intevation.org