comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/Parameters.java @ 7299:cde863b2dae3

(issue1529) Only interpolate within a step limit in WQ diagram Created together with Sascha Teichmann
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 11 Oct 2013 17:11:15 +0200
parents af13ceeba52a
children 5e38e2924c07
comparison
equal deleted inserted replaced
7298:5b2126d21c2e 7299:cde863b2dae3
312 } 312 }
313 313
314 return values; 314 return values;
315 } 315 }
316 316
317 public double [] interpolateWithLimit(
318 String keyName,
319 double key,
320 String [] columnNames,
321 double limit
322 ) {
323 int keyIndex = columnIndex(keyName);
324 return keyIndex < 0
325 ? null
326 : interpolateWithLimit(keyIndex, key, columnNames, limit);
327 }
328
329 /* Only interpolate if the difference between the two key's
330 * is less then limit */
331 public double [] interpolateWithLimit(
332 int keyIndex,
333 double key,
334 String [] columnNames,
335 double limit
336 ) {
337 int row = binarySearch(keyIndex, key, EPSILON);
338
339 if (row >= 0) { // direct match
340 double [] values = new double[columnNames.length];
341 for (int i = 0; i < values.length; ++i) {
342 int ci = columnIndex(columnNames[i]);
343 values[i] = ci < 0
344 ? Double.NaN
345 : columns[ci].getQuick(row);
346 }
347 return values;
348 }
349
350 row = -row - 1;
351 if (row < 1 || row >= size()) {
352 log.debug("interpolate: row is out of bounds");
353 return null;
354 }
355
356 double v1 = columns[keyIndex].getQuick(row-1);
357 double v2 = columns[keyIndex].getQuick(row);
358 if (Math.abs(v1-v2) > limit) {
359 return null;
360 }
361 double factor = Linear.factor(key, v1, v2);
362
363 double [] values = new double[columnNames.length];
364
365 for (int i = 0; i < values.length; ++i) {
366 int ci = columnIndex(columnNames[i]);
367 values[i] = ci < 0
368 ? Double.NaN
369 : Linear.weight(
370 factor,
371 columns[ci].getQuick(row-1),
372 columns[ci].getQuick(row));
373 }
374
375 return values;
376 }
377
317 public boolean isSorted(String columnName) { 378 public boolean isSorted(String columnName) {
318 return isSorted(columnIndex(columnName)); 379 return isSorted(columnIndex(columnName));
319 } 380 }
320 381
321 public boolean isSorted(int columnIndex) { 382 public boolean isSorted(int columnIndex) {

http://dive4elements.wald.intevation.org