Mercurial > dive4elements > river
changeset 675:8b0152363bdb
Added methods to remove NaN values.
flys-artifacts/trunk@2099 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 10 Jun 2011 10:10:04 +0000 (2011-06-10) |
parents | d5f9ba1d055f |
children | c501f27c1f71 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQCKms.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQDay.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java |
diffstat | 4 files changed, 75 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Fri Jun 10 09:19:27 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Jun 10 10:10:04 2011 +0000 @@ -1,3 +1,10 @@ +2011-06-10 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/model/WQKms.java, + src/main/java/de/intevation/flys/artifacts/model/WQCKms.java, + src/main/java/de/intevation/flys/artifacts/model/WQDay.java: + Added methods to remove NaN values. + 2011-06-10 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/artifacts/model/Calculation.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQCKms.java Fri Jun 10 09:19:27 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQCKms.java Fri Jun 10 10:10:04 2011 +0000 @@ -30,6 +30,11 @@ this.cw = new TDoubleArrayList(cws); } + @Override + public void removeNaNs() { + removeNaNs(new TDoubleArrayList [] { w, q, cw, kms }); + } + /** * Adds a new row to this data pool with corrected W.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQDay.java Fri Jun 10 09:19:27 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQDay.java Fri Jun 10 10:10:04 2011 +0000 @@ -48,17 +48,43 @@ public int getDay(int idx) { - return days.get(idx); + return days.getQuick(idx); } public double getW(int idx) { - return ws.get(idx); + return ws.getQuick(idx); } public double getQ(int idx) { - return qs.get(idx); + return qs.getQuick(idx); + } + + public void removeNaNs() { + + int dest = 0; + int N = ws.size(); + + for (int i = 0; i < N; ++i) { + double w = ws.getQuick(i); + double q = qs.getQuick(i); + + if (Double.isNaN(w) || Double.isNaN(q)) { + continue; + } + + days.setQuick(dest, days.getQuick(i)); + ws.setQuick(dest, w); + qs.setQuick(dest, q); + ++dest; + } + + if (dest < N) { + days.remove(dest, N-dest); + ws .remove(dest, N-dest); + qs .remove(dest, N-dest); + } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java Fri Jun 10 09:19:27 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java Fri Jun 10 10:10:04 2011 +0000 @@ -53,6 +53,36 @@ this.kms = new TDoubleArrayList(capacity); } + public static void removeNaNs(TDoubleArrayList [] arrays) { + + int dest = 0; + + int A = arrays.length; + int N = arrays[0].size(); + + OUTER: for (int i = 0; i < N; ++i) { + for (int j = 0; j < A; ++j) { + TDoubleArrayList a = arrays[j]; + double v = a.getQuick(i); + if (Double.isNaN(v)) { + continue OUTER; + } + a.setQuick(dest, v); + } + ++dest; + } + + if (dest < N) { + for (int i = 0; i < A; ++i) { + arrays[i].remove(dest, N-dest); + } + } + } + + public void removeNaNs() { + removeNaNs(new TDoubleArrayList [] { w, q, kms }); + } + public WQKms(double[] kms, double[] qs, double[] ws) { this(kms, qs, ws, ""); @@ -107,15 +137,15 @@ * @return a triple of [W, Q, Kms] in dst. */ public double[] get(int idx, double [] dst) { - dst[0] = w .get(idx); - dst[1] = q .get(idx); - dst[2] = kms.get(idx); + dst[0] = w .getQuick(idx); + dst[1] = q .getQuick(idx); + dst[2] = kms.getQuick(idx); return dst; } public double getKms(int idx) { - return kms.get(idx); + return kms.getQuick(idx); }