|
| 1 | +//VERSION=3 |
| 2 | + |
| 3 | +function setup() { |
| 4 | + return { |
| 5 | + input: ["B04", "B08", "dataMask"], |
| 6 | + output: [ |
| 7 | + { id: "default", bands: 4 }, |
| 8 | + { id: "index", bands: 1, sampleType: "FLOAT32" }, |
| 9 | + { id: "eobrowserStats", bands: 1, sampleType: "FLOAT32" }, |
| 10 | + { id: "dataMask", bands: 1 } |
| 11 | + ] |
| 12 | + }; |
| 13 | +} |
| 14 | + |
| 15 | +const ramp = [ |
| 16 | + [-0.5, [0.05, 0.05, 0.05]], |
| 17 | + [-0.2, [0.75, 0.75, 0.75]], |
| 18 | + [-0.1, [0.86, 0.86, 0.86]], |
| 19 | + [0, [0.92, 0.92, 0.92]], |
| 20 | + [0.025, [1, 0.98, 0.8]], |
| 21 | + [0.05, [0.93, 0.91, 0.71]], |
| 22 | + [0.075, [0.87, 0.85, 0.61]], |
| 23 | + [0.1, [0.8, 0.78, 0.51]], |
| 24 | + [0.125, [0.74, 0.72, 0.42]], |
| 25 | + [0.15, [0.69, 0.76, 0.38]], |
| 26 | + [0.175, [0.64, 0.8, 0.35]], |
| 27 | + [0.2, [0.57, 0.75, 0.32]], |
| 28 | + [0.25, [0.5, 0.7, 0.28]], |
| 29 | + [0.3, [0.44, 0.64, 0.25]], |
| 30 | + [0.35, [0.38, 0.59, 0.21]], |
| 31 | + [0.4, [0.31, 0.54, 0.18]], |
| 32 | + [0.45, [0.25, 0.49, 0.14]], |
| 33 | + [0.5, [0.19, 0.43, 0.11]], |
| 34 | + [0.55, [0.13, 0.38, 0.07]], |
| 35 | + [0.6, [0.06, 0.33, 0.04]], |
| 36 | + [1, 0, 0.27, 0], |
| 37 | +]; |
| 38 | + |
| 39 | +const visualizer = new ColorRampVisualizer(ramp); |
| 40 | + |
| 41 | +function evaluatePixel(samples) { |
| 42 | + let val = index(samples.B08, samples.B04); |
| 43 | + const imgVals = visualizer.process(val); |
| 44 | + // The library for tiffs works well only if there is only one channel returned. |
| 45 | + // So we encode the "no data" as NaN here and ignore NaNs on frontend. |
| 46 | + const indexVal = samples.dataMask === 1 ? val : NaN; |
| 47 | + |
| 48 | + return { |
| 49 | + default: imgVals.concat(samples.dataMask), |
| 50 | + index: [indexVal], |
| 51 | + eobrowserStats: [val], |
| 52 | + dataMask: [samples.dataMask] |
| 53 | + }; |
| 54 | +} |
0 commit comments