|
10 | 10 |
|
11 | 11 | var Lib = require('../../lib'); |
12 | 12 |
|
13 | | -var INTERPTHRESHOLD = 1e-2, |
14 | | - NEIGHBORSHIFTS = [[-1, 0], [1, 0], [0, -1], [0, 1]]; |
| 13 | +var INTERPTHRESHOLD = 1e-2; |
| 14 | +var NEIGHBORSHIFTS = [[-1, 0], [1, 0], [0, -1], [0, 1]]; |
15 | 15 |
|
16 | 16 | function correctionOvershoot(maxFractionalChange) { |
17 | 17 | // start with less overshoot, until we know it's converging, |
18 | 18 | // then ramp up the overshoot for faster convergence |
19 | 19 | return 0.5 - 0.25 * Math.min(1, maxFractionalChange * 0.5); |
20 | 20 | } |
21 | 21 |
|
22 | | -module.exports = function interp2d(z, emptyPoints, savedInterpZ) { |
23 | | - // fill in any missing data in 2D array z using an iterative |
24 | | - // poisson equation solver with zero-derivative BC at edges |
25 | | - // amazingly, this just amounts to repeatedly averaging all the existing |
26 | | - // nearest neighbors (at least if we don't take x/y scaling into account) |
27 | | - var maxFractionalChange = 1, |
28 | | - i, |
29 | | - thisPt; |
30 | | - |
31 | | - if(Array.isArray(savedInterpZ)) { |
32 | | - for(i = 0; i < emptyPoints.length; i++) { |
33 | | - thisPt = emptyPoints[i]; |
34 | | - z[thisPt[0]][thisPt[1]] = savedInterpZ[thisPt[0]][thisPt[1]]; |
35 | | - } |
36 | | - } |
37 | | - else { |
38 | | - // one pass to fill in a starting value for all the empties |
39 | | - iterateInterp2d(z, emptyPoints); |
40 | | - } |
| 22 | +/* |
| 23 | + * interp2d: Fill in missing data from a 2D array using an iterative |
| 24 | + * poisson equation solver with zero-derivative BC at edges. |
| 25 | + * Amazingly, this just amounts to repeatedly averaging all the existing |
| 26 | + * nearest neighbors, at least if we don't take x/y scaling into account, |
| 27 | + * which is the right approach here where x and y may not even have the |
| 28 | + * same units. |
| 29 | + * |
| 30 | + * @param {array of arrays} z |
| 31 | + * The 2D array to fill in. Will be mutated here. Assumed to already be |
| 32 | + * cleaned, so all entries are numbers except gaps, which are `undefined`. |
| 33 | + * @param {array of arrays} emptyPoints |
| 34 | + * Each entry [i, j, neighborCount] for empty points z[i][j] and the number |
| 35 | + * of neighbors that are *not* missing. Assumed to be sorted from most to |
| 36 | + * least neighbors, as produced by heatmap/find_empties. |
| 37 | + */ |
| 38 | +module.exports = function interp2d(z, emptyPoints) { |
| 39 | + var maxFractionalChange = 1; |
| 40 | + var i; |
| 41 | + |
| 42 | + // one pass to fill in a starting value for all the empties |
| 43 | + iterateInterp2d(z, emptyPoints); |
41 | 44 |
|
42 | 45 | // we're don't need to iterate lone empties - remove them |
43 | 46 | for(i = 0; i < emptyPoints.length; i++) { |
|
0 commit comments