Mercurial > dive4elements > river
changeset 1937:f07d64d5cbe1
'W auf freier Strecke' calculation. Fetch corresponding Qs for given Ws from the WST model
flys-artifacts/trunk@3318 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 25 Nov 2011 15:50:31 +0000 |
parents | 0ad05cb691fc |
children | 1d991c91285b |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WQKmsInterpolArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java |
diffstat | 5 files changed, 141 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Fri Nov 25 12:55:53 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Nov 25 15:50:31 2011 +0000 @@ -1,3 +1,17 @@ +2011-11-25 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java(findQsForW): + Added method findQsForW(w, km) to retrieve the Qs that correspond + for the given w and km. + + This is to be called when doing a "W auf freier Strecke" calculation + to find out the Qs belonging to the user given W. + + * src/main/java/de/intevation/flys/artifacts/WQKmsInterpolArtifact.java, + src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java, + src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java: + Removed superfluous imports. + 2011-11-25 Felix Wolfsteller <felix.wolfsteller@intevation.de> Fix bug when adding Q data in LongitudinalSectionGenerator.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WQKmsInterpolArtifact.java Fri Nov 25 12:55:53 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WQKmsInterpolArtifact.java Fri Nov 25 15:50:31 2011 +0000 @@ -16,7 +16,6 @@ import de.intevation.artifacts.ArtifactNamespaceContext; import de.intevation.artifacts.CallMeta; -import de.intevation.flys.artifacts.model.Calculation; import de.intevation.flys.artifacts.model.FacetTypes; import de.intevation.flys.artifacts.model.WQKms; import de.intevation.flys.artifacts.model.WQFacet; @@ -28,7 +27,6 @@ import de.intevation.flys.artifacts.states.StaticState; import de.intevation.flys.artifacts.resources.Resources; -import de.intevation.flys.utils.FLYSUtils; import de.intevation.artifacts.common.utils.XMLUtils; /**
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java Fri Nov 25 12:55:53 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java Fri Nov 25 15:50:31 2011 +0000 @@ -20,6 +20,8 @@ import org.apache.commons.math.exception.MathIllegalArgumentException; +import gnu.trove.TDoubleArrayList; + /** * W, Q and km data from database 'wsts' spiced with interpolation algorithms. */ @@ -362,6 +364,105 @@ return Linear.weight(kmWeight, tw, ow); } + + public double [] findQsForW(double w, WstValueTable table) { + + TDoubleArrayList qs = new TDoubleArrayList(); + + if (ws.length > 0 && Math.abs(ws[0]-w) < 0.000001) { + double q = table.getQIndex(0, km); + if (!Double.isNaN(q)) { + qs.add(q); + } + } + + for (int i = 1; i < ws.length; ++i) { + double w2 = ws[i]; + if (Double.isNaN(w2)) { + continue; + } + if (Math.abs(w2-w) < 0.000001) { + double q = table.getQIndex(i, km); + if (!Double.isNaN(q)) { + qs.add(q); + } + continue; + } + double w1 = ws[i-1]; + if (Double.isNaN(w1)) { + continue; + } + + if (w < Math.min(w1, w2) || w > Math.max(w1, w2)) { + continue; + } + + double q1 = table.getQIndex(i-1, km); + double q2 = table.getQIndex(i, km); + if (Double.isNaN(q1) || Double.isNaN(q2)) { + continue; + } + + double q = Linear.linear(w, w1, w2, q1, q2); + qs.add(q); + } + + return qs.toNativeArray(); + } + + public double [] findQsForW( + Row other, + double w, + double km, + WstValueTable table + ) { + TDoubleArrayList qs = new TDoubleArrayList(); + + double factor = Linear.factor(km, this.km, other.km); + + if (ws.length > 0) { + double wt = Linear.weight(factor, ws[0], other.ws[0]); + if (!Double.isNaN(wt)) { + double q = table.getQIndex(0, km); + if (!Double.isNaN(q)) { + qs.add(q); + } + } + } + + for (int i = 1; i < ws.length; ++i) { + double w2 = Linear.weight(factor, ws[i], other.ws[i]); + if (Double.isNaN(w2)) { + continue; + } + if (Math.abs(w2-w) < 0.000001) { + double q = table.getQIndex(i, km); + if (!Double.isNaN(q)) { + qs.add(q); + } + continue; + } + double w1 = Linear.weight(factor, ws[i-1], other.ws[i-1]); + if (Double.isNaN(w1)) { + continue; + } + + if (w < Math.min(w1, w2) || w > Math.max(w1, w2)) { + continue; + } + + double q1 = table.getQIndex(i-1, km); + double q2 = table.getQIndex(i, km); + if (Double.isNaN(q1) || Double.isNaN(q2)) { + continue; + } + + double q = Linear.linear(w, w1, w2, q1, q2); + qs.add(q); + } + + return qs.toNativeArray(); + } } // class Row /** Rows in table. */ @@ -668,8 +769,9 @@ if (rowIndex < 0) { rowIndex = -rowIndex -1; } - if (rowIndex >= rows.size()) + if (rowIndex >= rows.size()) { rowIndex = rows.size() -1; + } Row startRow = rows.get(rowIndex); @@ -703,6 +805,30 @@ return new double [][] {qs, ws}; } + public double [] findQsForW(double km, double w) { + + + int rowIndex = Collections.binarySearch(rows, new Row(km)); + + if (rowIndex >= 0) { + return rows.get(rowIndex).findQsForW(w, this); + } + + rowIndex = -rowIndex - 1; + + if (rowIndex < 1 || rowIndex >= rows.size()) { + // do not extrapolate + return new double[0]; + } + + + // Needs bilinear interpolation + Row r1 = rows.get(rowIndex-1); + Row r2 = rows.get(rowIndex); + + return r1.findQsForW(r2, w, km, this); + } + public QPosition getQPosition(double km, double q) { return getQPosition(km, q, new QPosition()); }
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java Fri Nov 25 12:55:53 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java Fri Nov 25 15:50:31 2011 +0000 @@ -5,14 +5,11 @@ import org.apache.log4j.Logger; -import java.awt.Font; - import org.w3c.dom.Document; import org.jfree.chart.annotations.XYTextAnnotation; import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.title.TextTitle; import org.jfree.data.xy.XYSeries;
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java Fri Nov 25 12:55:53 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java Fri Nov 25 15:50:31 2011 +0000 @@ -2,8 +2,6 @@ import org.apache.log4j.Logger; -import java.awt.Font; - import org.jfree.chart.title.TextTitle; import org.jfree.chart.JFreeChart;