Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 385:478940d06876
Enabled the WINFO artifact to create duration curves - new OutGenerator, added methods for data computation.
flys-artifacts/trunk@1802 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 03 May 2011 12:05:32 +0000 |
parents | 5f55047a17e8 |
children | befedd7629d5 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Tue May 03 09:23:17 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Tue May 03 12:05:32 2011 +0000 @@ -20,10 +20,13 @@ import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.flys.model.Gauge; import de.intevation.flys.model.River; import de.intevation.flys.artifacts.states.DefaultState; import de.intevation.flys.artifacts.context.FLYSContext; +import de.intevation.flys.artifacts.model.MainValuesFactory; +import de.intevation.flys.artifacts.model.WQDay; import de.intevation.flys.artifacts.model.WQKms; import de.intevation.flys.artifacts.model.WstValueTable; @@ -301,5 +304,77 @@ return wqkms; } + + + /** + * Returns the data that is computed by a duration curve computation. + * + * @return the data computed by a duration curve computation. + */ + public WQDay getDurationCurveData() + throws NullPointerException + { + logger.debug("WINFOArtifact.getDurationCurveData"); + + River r = getRiver(); + + if (r == null) { + throw new NullPointerException("Cannot determine river."); + } + + Gauge g = getGauge(); + + if (g == null) { + throw new NullPointerException("Cannot determine gauge."); + } + + double[] locations = getLocations(); + + if (locations == null) { + throw new NullPointerException("Cannot determine location."); + } + + WstValueTable wst = WstValueTable.getTable(r); + if (wst == null) { + throw new NullPointerException("No Wst found for selected river."); + } + + // TODO Introduce a caching mechanism here! + + return computeDurationCurveData(g, wst, locations[0]); + } + + + /** + * Computes the data used to create duration curves. + * + * @param gauge The selected gauge. + * @param location The selected location. + * + * @return the computed data. + */ + public static WQDay computeDurationCurveData( + Gauge gauge, + WstValueTable wst, + double location) + { + logger.info("WINFOArtifact.computeDurationCurveData"); + + Object[] obj = MainValuesFactory.getDurationCurveData(gauge); + + int[] days = (int[]) obj[0]; + double[] qs = (double[]) obj[1]; + + double[] interpolatedW = new double[qs.length]; + interpolatedW = wst.interpolateW(location, qs, interpolatedW); + + WQDay wqday = new WQDay(qs.length); + + for (int i = 0; i < days.length; i++) { + wqday.add(days[i], interpolatedW[i], qs[i]); + } + + return wqday; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :