|
| 1 | +//VERSION=3 |
| 2 | + |
| 3 | +const bits_to_check = [8, 9, 11, 13, 14, 15]; // Bits to check if they are set |
| 4 | +const sensing_time = "0130"; // "0130" or "1330" or "" |
| 5 | + |
| 6 | +function setup() { |
| 7 | + return { |
| 8 | + input: ["QF", "dataMask"], |
| 9 | + output: { id: "default", bands: 4 }, |
| 10 | + mosaicking: "TILE", |
| 11 | + }; |
| 12 | +} |
| 13 | + |
| 14 | +//Select files based on sensing time (0130 or 1330) |
| 15 | +function preProcessScenes(collections) { |
| 16 | + collections.scenes.tiles = collections.scenes.tiles.filter(function (tile) { |
| 17 | + return tile.dataPath.includes("T" + sensing_time); |
| 18 | + }); |
| 19 | + collections.scenes.tiles.sort((a, b) => new Date(b.date) - new Date(a.date)); |
| 20 | + return collections; |
| 21 | +} |
| 22 | + |
| 23 | +function areBitsSet(qf) { |
| 24 | + // Check if the bits are set |
| 25 | + for (let idx in bits_to_check) { |
| 26 | + const bit = 1 << (bits_to_check[idx] - 1); |
| 27 | + if ((qf & bit) !== 0) { |
| 28 | + return true; |
| 29 | + } |
| 30 | + } |
| 31 | + return false; |
| 32 | +} |
| 33 | + |
| 34 | +function evaluatePixel(sample) { |
| 35 | + // When there are no dates, return no data |
| 36 | + if (sample.length == 0) return [NaN, NaN, NaN, 0]; |
| 37 | + |
| 38 | + // Return NaN for no data pixels |
| 39 | + if (sample[0].dataMask == 0) { |
| 40 | + return [NaN, NaN, NaN, 0]; |
| 41 | + } |
| 42 | + |
| 43 | + // Check if the bits are set |
| 44 | + const bit_set = areBitsSet(sample[0].QF); |
| 45 | + |
| 46 | + // Ensure only flagged pixels are displayed |
| 47 | + let opacity = 0; |
| 48 | + let imgVals = [1, 0, 0]; |
| 49 | + if (bit_set) { |
| 50 | + opacity = 0.5; |
| 51 | + } |
| 52 | + |
| 53 | + return [...imgVals, opacity]; |
| 54 | +} |
0 commit comments