Mercurial > dive4elements > river
changeset 395:aae8f327425e
'berechnete Abflusskurve': generate ws from qs
flys-artifacts/trunk@1822 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 04 May 2011 13:51:25 +0000 |
parents | b9175ddea49b |
children | 5d0e973f203e |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java |
diffstat | 2 files changed, 54 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Wed May 04 10:10:11 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed May 04 13:51:25 2011 +0000 @@ -1,3 +1,9 @@ +2011-05-03 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java: + To make diagram generation possible ws are now generated from qs + because they are many ws having different qs. + 2011-05-04 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/exports/ComputedDischargeCurveExporter.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java Wed May 04 10:10:11 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java Wed May 04 13:51:25 2011 +0000 @@ -46,7 +46,7 @@ " FROM wst_value_table" + " WHERE wst_id = :wst_id"; - public static final double DEFAULT_STEP_WIDTH = 0.01; + public static final int DEFAULT_Q_STEPS = 500; public static class Column implements Serializable @@ -212,12 +212,9 @@ (double [])qs.clone() }; } - public double [][] interpolateWQ(Row other, double km, double stepWidth) { + public double [][] interpolateWQ(Row other, double km, int steps) { - int W1 = ascendingWs(); - int W2 = other.ascendingWs(); - - int W = Math.min(W1, W2); + int W = Math.min(ws.length, other.ws.length); if (W < 1) { return new double[2][0]; @@ -225,34 +222,34 @@ double factor = factor(km, this.km, other.km); - double minW = weight(factor, ws[0], other.ws[0]); - double maxW = weight(factor, ws[W-1], other.ws[W-1]); + double [] splineQ = new double[W]; + double [] splineW = new double[W]; - if (minW > maxW) { - double t = minW; - minW = maxW; - maxW = t; - } - double [] x = new double[W]; - double [] y = new double[W]; + double minQ = Double.MAX_VALUE; + double maxQ = -Double.MAX_VALUE; for (int i = 0; i < W; ++i) { - x[i] = weight(factor, ws[i], other.ws[i]); - y[i] = weight(factor, qs[i], other.qs[i]); + double wws = weight(factor, ws[i], other.ws[i]); + double wqs = weight(factor, qs[i], other.qs[i]); + splineW[i] = wws; + splineQ[i] = wqs; + if (wqs < minQ) minQ = wqs; + if (wqs > maxQ) maxQ = wqs; } + double stepWidth = (maxQ - minQ)/steps; + SplineInterpolator interpolator = new SplineInterpolator(); - PolynomialSplineFunction spline = interpolator.interpolate(x, y); + PolynomialSplineFunction spline = + interpolator.interpolate(splineQ, splineW); - double [] outWs = - new double[(int)Math.ceil((maxW - minW)/stepWidth)]; - double [] outQs = - new double[outWs.length]; + double [] outWs = new double[steps]; + double [] outQs = new double[steps]; try { - double w = minW; - for (int i = 0; i < outWs.length; ++i, w += stepWidth) { - outQs[i] = spline.value(outWs[i] = w); + double q = minQ; + for (int i = 0; i < outWs.length; ++i, q += stepWidth) { + outWs[i] = spline.value(outQs[i] = q); } } catch (ArgumentOutsideDomainException aode) { @@ -260,40 +257,43 @@ } return new double [][] { outWs, outQs }; - } - public double [][] interpolateWQ(double stepWidth) { - int W = ascendingWs(); // ignore back jumps + public double [][] interpolateWQ(int steps) { + + int W = ws.length; if (W < 1) { return new double[2][0]; } - double [] x = new double[W]; - double [] y = new double[W]; + double [] splineW = new double[W]; + double [] splineQ = new double[W]; + + double minQ = Double.MAX_VALUE; + double maxQ = -Double.MAX_VALUE; for (int i = 0; i < W; ++i) { - x[i] = ws[i]; - y[i] = qs[i]; + splineW[i] = ws[i]; + splineQ[i] = qs[i]; + if (qs[i] < minQ) minQ = qs[i]; + if (qs[i] > maxQ) maxQ = qs[i]; } + double stepWidth = (maxQ - minQ)/steps; + SplineInterpolator interpolator = new SplineInterpolator(); - PolynomialSplineFunction spline = interpolator.interpolate(x, y); + PolynomialSplineFunction spline = + interpolator.interpolate(splineQ, splineW); - double minW = ws[0]; - double maxW = ws[W-1]; - - double [] outWs = - new double[(int)Math.ceil((maxW - minW)/stepWidth)]; - double [] outQs = - new double[outWs.length]; + double [] outWs = new double[steps]; + double [] outQs = new double[steps]; try { - double w = minW; - for (int i = 0; i < outWs.length; ++i, w += stepWidth) { - outQs[i] = spline.value(outWs[i] = w); + double q = minQ; + for (int i = 0; i < outWs.length; ++i, q += stepWidth) { + outWs[i] = spline.value(outQs[i] = q); } } catch (ArgumentOutsideDomainException aode) { @@ -382,21 +382,16 @@ public double [][] interpolateWQ(double km) { - return interpolateWQ(km, DEFAULT_STEP_WIDTH, true); + return interpolateWQ(km, DEFAULT_Q_STEPS); } - public double [][] interpolateWQ( - double km, - double stepWidth, - boolean checkAscending - ) { + public double [][] interpolateWQ(double km, int steps) { + int rowIndex = Collections.binarySearch(rows, new Row(km)); if (rowIndex >= 0) { // direct row match Row row = rows.get(rowIndex); - return checkAscending - ? row.interpolateWQ(stepWidth) - : row.cloneWQs(); + return row.interpolateWQ(steps); } rowIndex = -rowIndex -1; @@ -409,9 +404,7 @@ Row r1 = rows.get(rowIndex-1); Row r2 = rows.get(rowIndex); - return checkAscending - ? r1.interpolateWQ(r2, km, stepWidth) - : r1.weightWQs(r2, km); + return r1.interpolateWQ(r2, km, steps); } public static WstValueTable getTable(River river) {