comparison artifacts/src/main/java/org/dive4elements/river/utils/DoubleUtil.java @ 8596:b486812f4f14

(issue1755) Filter out NaN values before creating the interplation function
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 19 Mar 2015 15:15:55 +0100
parents 07c9ac22f611
children 5e38e2924c07
comparison
equal deleted inserted replaced
8595:cc1c644ed30f 8596:b486812f4f14
315 315
316 /** Convieniance function for results to get an interpolator. 316 /** Convieniance function for results to get an interpolator.
317 * This is basically a static wrapper to for LinearInterpolator.interpolate 317 * This is basically a static wrapper to for LinearInterpolator.interpolate
318 * with error handling. Returns null on error.*/ 318 * with error handling. Returns null on error.*/
319 public static PolynomialSplineFunction getLinearInterpolator(double[] x, double[] y) { 319 public static PolynomialSplineFunction getLinearInterpolator(double[] x, double[] y) {
320 /* We want copies here to remove NaNs but don't change the original data. */
321 TDoubleArrayList tX = new TDoubleArrayList();
322 TDoubleArrayList tY = new TDoubleArrayList();
323 for (int i = 0; i < x.length; i++) {
324 if (!Double.isNaN(y[i])) {
325 tX.add(x[i]);
326 tY.add(y[i]);
327 }
328 }
320 LinearInterpolator lpol = new LinearInterpolator(); 329 LinearInterpolator lpol = new LinearInterpolator();
321 try { 330 try {
322 return lpol.interpolate(x, y); 331 return lpol.interpolate(tX.toNativeArray(), tY.toNativeArray());
323 } catch (DimensionMismatchException e) { 332 } catch (DimensionMismatchException e) {
324 log.error("KMs and Result values have different sizes. Failed to interpolate: " + 333 log.error("KMs and Result values have different sizes. Failed to interpolate: " +
325 e.getMessage()); 334 e.getMessage());
326 } catch (NonMonotonousSequenceException e) { 335 } catch (NonMonotonousSequenceException e) {
327 log.error("KMs are not monotonous. Failed to interpolate: " + e.getMessage()); 336 log.error("KMs are not monotonous. Failed to interpolate: " + e.getMessage());

http://dive4elements.wald.intevation.org