[Dive4elements-commits] [PATCH 3 of 3] Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'
Wald Commits
scm-commit at wald.intevation.org
Mon Jan 21 14:03:47 CET 2013
# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1358773402 -3600
# Node ID bcf25d8c183e6b8910c83d8ff972d76d0c1ae6b2
# Parent 26c849cf54e7a5e8d69249fbbe00481f76195b2c
Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
diff -r 26c849cf54e7 -r bcf25d8c183e flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation4.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation4.java Mon Jan 21 12:49:44 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation4.java Mon Jan 21 14:03:22 2013 +0100
@@ -1,18 +1,21 @@
package de.intevation.flys.artifacts.model;
+import de.intevation.flys.artifacts.access.Calculation4Access;
+
import de.intevation.flys.artifacts.math.BackJumpCorrector;
import de.intevation.flys.artifacts.math.Function;
import de.intevation.flys.artifacts.math.Identity;
import de.intevation.flys.artifacts.math.Linear;
import de.intevation.flys.artifacts.model.RiverFactory;
+
import de.intevation.flys.artifacts.model.WstValueTable.QPosition;
import de.intevation.flys.model.River;
import de.intevation.flys.utils.DoubleUtil;
-import de.intevation.flys.artifacts.access.Calculation4Access;
+import gnu.trove.TDoubleArrayList;
import java.util.ArrayList;
import java.util.Arrays;
@@ -273,12 +276,14 @@
}
// Generate the "Umhuellende".
- results = generateInfolding(table, results, from, to, step);
+ QKms [] qkms = generateInfolding(table, results, from, to, step);
+
+ // TODO: Use qkms in a new result type.
return new CalculationResult(results, this);
}
- protected WQKms [] generateInfolding(
+ protected QKms [] generateInfolding(
WstValueTable wst,
WQKms [] results,
double from,
@@ -290,43 +295,43 @@
InfoldingColumns ic = new InfoldingColumns(columns);
ic.markInfoldingColumns(results);
- List<WQKms> infoldings = new ArrayList<WQKms>();
+ List<QKms> infoldings = new ArrayList<QKms>();
boolean [] infoldingColumns = ic.getInfoldingColumns();
+
+ double [] kms = null;
+
for (int i = 0; i < infoldingColumns.length; ++i) {
if (!infoldingColumns[i]) {
continue;
}
- double q = columns[i].getQRangeTree().findQ(from);
- if (Double.isNaN(q)) {
- addProblem(from, "cannot.find.q");
- continue;
+
+ kms = kms == null
+ ? DoubleUtil.explode(from, to, step)
+ : (double [])kms.clone();
+
+ QRangeTree.QuickQFinder qf =
+ columns[i].getQRangeTree().new QuickQFinder();
+
+ int numProblemsBefore = numProblems();
+ double [] qs = qf.findQs(kms, this);
+
+ // TODO: i18n
+ String name = "Umh\u00fcllende " + columns[i].getName();
+
+ QKmsImpl qkms = new QKmsImpl(
+ new TDoubleArrayList(kms),
+ new TDoubleArrayList(qs),
+ name);
+
+ if (numProblems() > numProblemsBefore) {
+ qkms.removeNaNs();
}
- double [] kms = DoubleUtil.explode(from, to, step);
- double [] oqs = new double[kms.length];
- double [] ows = new double[kms.length];
- boolean success =
- wst.interpolate(q, from, kms, ows, oqs, this) != null;
- if (success) {
- // TODO: generate a better name. I18N.
- String name = "Umh\u00fcllende " + columns[i].getName();
- WQKms wqkms = new WQKms(kms, oqs, ows, name);
- infoldings.add(wqkms);
- }
+ infoldings.add(qkms);
}
- int N = infoldings.size();
- if (N > 0) {
- WQKms [] newResults = new WQKms[results.length + N];
- System.arraycopy(results, 0, newResults, 0, results.length);
- for (int i = 0; i < N; ++i) {
- newResults[i+results.length] = infoldings.get(i);
- }
- results = newResults;
- }
-
- return results;
+ return infoldings.toArray(new QKms[infoldings.size()]);
}
protected String createName(int index) {
diff -r 26c849cf54e7 -r bcf25d8c183e flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java Mon Jan 21 12:49:44 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java Mon Jan 21 14:03:22 2013 +0100
@@ -2,6 +2,8 @@
import de.intevation.flys.artifacts.math.Linear;
+import de.intevation.flys.utils.DoubleUtil;
+
import gnu.trove.TDoubleArrayList;
import java.io.Serializable;
@@ -124,7 +126,7 @@
}
public void removeNaNs() {
- W.removeNaNs(columns);
+ DoubleUtil.removeNaNs(columns);
}
public int [] columnIndices(String [] columns) {
diff -r 26c849cf54e7 -r bcf25d8c183e flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QKmsImpl.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QKmsImpl.java Mon Jan 21 12:49:44 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QKmsImpl.java Mon Jan 21 14:03:22 2013 +0100
@@ -2,6 +2,8 @@
import gnu.trove.TDoubleArrayList;
+import de.intevation.flys.utils.DoubleUtil;
+
public class QKmsImpl
extends NamedObjectImpl
implements QKms
@@ -73,4 +75,8 @@
public TDoubleArrayList allQs() {
return qs;
}
+
+ public void removeNaNs() {
+ DoubleUtil.removeNaNs(new TDoubleArrayList [] { kms, qs });
+ }
}
diff -r 26c849cf54e7 -r bcf25d8c183e flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java Mon Jan 21 12:49:44 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java Mon Jan 21 14:03:22 2013 +0100
@@ -145,6 +145,23 @@
last = QRangeTree.this.findNode(pos);
return last != null ? last.q : Double.NaN;
}
+
+ public double [] findQs(double [] kms, Calculation report) {
+ return findQs(kms, new double[kms.length], report);
+ }
+
+ public double [] findQs(
+ double [] kms,
+ double [] qs,
+ Calculation report
+ ) {
+ for (int i = 0; i < kms.length; ++i) {
+ if (Double.isNaN(qs[i] = findQ(kms[i]))) {
+ report.addProblem(kms[i], "cannot.find.q");
+ }
+ }
+ return qs;
+ }
} // class QuickQFinder
protected Node root;
diff -r 26c849cf54e7 -r bcf25d8c183e flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/W.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/W.java Mon Jan 21 12:49:44 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/W.java Mon Jan 21 14:03:22 2013 +0100
@@ -1,6 +1,7 @@
package de.intevation.flys.artifacts.model;
import de.intevation.flys.utils.DataUtil;
+import de.intevation.flys.utils.DoubleUtil;
import gnu.trove.TDoubleArrayList;
@@ -60,34 +61,8 @@
return ws.min();
}
- 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 [] { ws });
+ DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws });
}
public boolean guessWaterIncreasing() {
diff -r 26c849cf54e7 -r bcf25d8c183e flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java Mon Jan 21 12:49:44 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java Mon Jan 21 14:03:22 2013 +0100
@@ -1,10 +1,12 @@
package de.intevation.flys.artifacts.model;
+import de.intevation.flys.utils.DoubleUtil;
+
+import gnu.trove.TDoubleArrayList;
+
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import gnu.trove.TDoubleArrayList;
-
import org.apache.log4j.Logger;
public class WQ
@@ -96,7 +98,7 @@
@Override
public void removeNaNs() {
- removeNaNs(new TDoubleArrayList [] { ws, qs });
+ DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws, qs });
}
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 26c849cf54e7 -r bcf25d8c183e flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQCKms.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQCKms.java Mon Jan 21 12:49:44 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQCKms.java Mon Jan 21 14:03:22 2013 +0100
@@ -1,5 +1,7 @@
package de.intevation.flys.artifacts.model;
+import de.intevation.flys.utils.DoubleUtil;
+
import gnu.trove.TDoubleArrayList;
/**
@@ -32,7 +34,7 @@
@Override
public void removeNaNs() {
- removeNaNs(new TDoubleArrayList [] { ws, qs, cws, kms });
+ DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws, qs, cws, kms });
}
/**
diff -r 26c849cf54e7 -r bcf25d8c183e flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java Mon Jan 21 12:49:44 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java Mon Jan 21 14:03:22 2013 +0100
@@ -1,5 +1,7 @@
package de.intevation.flys.artifacts.model;
+import de.intevation.flys.utils.DoubleUtil;
+
import gnu.trove.TDoubleArrayList;
import org.apache.log4j.Logger;
@@ -54,7 +56,7 @@
@Override
public void removeNaNs() {
- removeNaNs(new TDoubleArrayList [] { ws, qs, kms });
+ DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws, qs, kms });
}
/**
diff -r 26c849cf54e7 -r bcf25d8c183e flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WW.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WW.java Mon Jan 21 12:49:44 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WW.java Mon Jan 21 14:03:22 2013 +0100
@@ -3,6 +3,8 @@
import de.intevation.flys.artifacts.math.Function;
import de.intevation.flys.artifacts.math.Identity;
+import de.intevation.flys.utils.DoubleUtil;
+
import gnu.trove.TDoubleArrayList;
public class WW
@@ -175,7 +177,7 @@
@Override
public void removeNaNs() {
- removeNaNs(new TDoubleArrayList [] { ws, ws2 });
+ DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws, ws2 });
}
public double minWs2() {
diff -r 26c849cf54e7 -r bcf25d8c183e flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WWQQ.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WWQQ.java Mon Jan 21 12:49:44 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WWQQ.java Mon Jan 21 14:03:22 2013 +0100
@@ -2,6 +2,8 @@
import de.intevation.flys.artifacts.math.Identity;
+import de.intevation.flys.utils.DoubleUtil;
+
import gnu.trove.TDoubleArrayList;
public class WWQQ
@@ -91,7 +93,7 @@
@Override
public void removeNaNs() {
- removeNaNs(new TDoubleArrayList [] { ws, ws2, qs1, qs2 });
+ DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws, ws2, qs1, qs2 });
}
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 26c849cf54e7 -r bcf25d8c183e flys-artifacts/src/main/java/de/intevation/flys/utils/DoubleUtil.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/DoubleUtil.java Mon Jan 21 12:49:44 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/DoubleUtil.java Mon Jan 21 14:03:22 2013 +0100
@@ -209,5 +209,31 @@
}
return max;
}
+
+ 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);
+ }
+ }
+ }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
More information about the Dive4elements-commits
mailing list