|
| 1 | +//VERSION=3 |
| 2 | +// ADVANCED multitemporal data fusion example |
| 3 | + |
| 4 | +// NOTE: values and dates in this example are NOT CORRECT - they ARE MADE UP |
| 5 | + |
| 6 | +var setup = () => ({ |
| 7 | + input: [ |
| 8 | + {datasource: "s2l1c", bands:["B02", "B03", "B04", "B08", "B11"], units: "REFLECTANCE", mosaicking: "ORBIT"}, |
| 9 | + {datasource: "s1grd", bands:["VV", "VH"], units: "REFLECTANCE", mosaicking: "ORBIT"}, |
| 10 | + {datasource: "s2l2a", bands:["B02", "B03", "B04"], units: "REFLECTANCE", mosaicking: "ORBIT"} |
| 11 | + ], |
| 12 | + output: [ |
| 13 | + { id: "default", bands: 3, sampleType: SampleType.AUTO } |
| 14 | + ], |
| 15 | +}) |
| 16 | + |
| 17 | + |
| 18 | +function evaluatePixel(samples, inputData, inputMetadata, customData, outputMetadata) { |
| 19 | + /* |
| 20 | + For each processed pixel (each time the evaluatePixel is run), the parameters have the following structure |
| 21 | + |
| 22 | + Structure of samples: |
| 23 | + samples:{ |
| 24 | + "s2l2a":[ |
| 25 | + {"B02": 123, "B03": 123, "B04": 123, ...}, // has index 0 (from inputData: date = 2020-01-01) |
| 26 | + {"B02": 123, "B03": 123, "B04": 123, ...}, // has index 1 (from inputData: date = 2020-01-03) |
| 27 | + // one for each date |
| 28 | + ], |
| 29 | + "s2l1c":[ |
| 30 | + {"B02": 123, "B03": 123, "B04": 123, ...}, // has index 0 (from inputData: date = 2020-01-01) |
| 31 | + {"B02": 123, "B03": 123, "B04": 123, ...}, // has index 1 (from inputData: date = 2020-01-03) |
| 32 | + // one for each date |
| 33 | + ], |
| 34 | + "s1grd":[ |
| 35 | + {"VV":123,"VH":123}, // has index 0 (from inputData: date = 2020-01-02) |
| 36 | + {"VV":123,"VH":123}, // has index 1 (from inputData: date = 2020-01-05) |
| 37 | + // one for each date |
| 38 | + ] |
| 39 | + }, |
| 40 | + |
| 41 | + // CAUTION: THE DATES IN THE SCENES CAN DIFFER BETWEEN DATASETS |
| 42 | + // idx-es in the scenes of the dataset correspond to the indexes of the samples of that dataset (but not the other datasets) |
| 43 | + |
| 44 | + Structure of inputData: |
| 45 | + inputData:{ |
| 46 | + "s2l2a":{ |
| 47 | + "scenes":[ |
| 48 | + {"date": "2020-01-01", "idx": 0, ...} |
| 49 | + {"date": "2020-01-03", "idx": 1, ...} |
| 50 | + // for each date one |
| 51 | + ], |
| 52 | + "normalizationFactor": 0.0001 |
| 53 | + }, |
| 54 | + "s2l1c":{ |
| 55 | + "scenes":[ |
| 56 | + {"date": "2020-01-01", "idx": 0, ...} |
| 57 | + {"date": "2020-01-03", "idx": 1, ...} |
| 58 | + // for each date one |
| 59 | + ], |
| 60 | + "normalizationFactor": 0.0001 |
| 61 | + }, |
| 62 | + "s1grd":{ |
| 63 | + "scenes":[ |
| 64 | + {"date": "2020-01-02", "idx": 0, ...} |
| 65 | + {"date": "2020-01-05", "idx": 1, ...} |
| 66 | + // for each date one |
| 67 | + ], |
| 68 | + "normalizationFactor": 0.0001 |
| 69 | + }, |
| 70 | + } |
| 71 | + |
| 72 | + Structure of inputMetadata, customData, outputMetadata: NOT IMPORTANT; NOT USED IN THIS EXAMPLE |
| 73 | + |
| 74 | + */ |
| 75 | + |
| 76 | + // IF YOU NEED THE DATA (SAMPLES) FROM ALL DATASETS, HERE IS HOW TO ONLY USE THE DATA ON THE SAME DATES |
| 77 | + // Not all dates from one dataset are in the other, so we need to filter the scenes and samples |
| 78 | + // plan: go through all the scenes of one dataset (since scenes have the dates and the indexes of the elements in the samples) |
| 79 | + // and find the scenes from other datasets on the same dates as for the selected dataset |
| 80 | + // we also need to fix the arrays of samples |
| 81 | + |
| 82 | + // something like |
| 83 | + |
| 84 | + var S2L1CSamples = samples.s2l1c; // has value [{"B02": 123, "B03": 123, "B04": 123, ...}, {one for each date}], |
| 85 | + var S2L2ASamples = samples.s2l2a; // has value [{"B02": 123, "B03": 123, "B04": 123, ...}, {one for each date}], |
| 86 | + var S1Samples = samples.s1grd; // has value [{"VV": 123, "VH": 123, ...}, {one for each date}], |
| 87 | + |
| 88 | + var S2L1CScenes = scenes.s2l1c.scenes; // has value [{"date": "2020-01-01", "idx": 0, ...}, {one for each date}] |
| 89 | + var S2L2AScenes = scenes.s2l2a.scenes; // has value [{"date": "2020-01-01", "idx": 0, ...}, {one for each date}] |
| 90 | + var S1Scenes = scenes.s1.scenes; // has value [{"date": "2020-01-02", "idx": 0, ...}, {one for each date}] |
| 91 | + |
| 92 | + var usableDates = []; // we can use one variable that holds the dates that are common to all the datasets |
| 93 | + var usableS2L1CSamples = []; // holds S2 L1C samples on the common dates |
| 94 | + var usableS2L2ASamples = []; // holds S2 L2A samples on the common dates |
| 95 | + var usableS1Samples = []; // holds S1 samples on the common dates |
| 96 | + |
| 97 | + for(S2L1Cscene of S2L1CScenes){ |
| 98 | + const date = S2L1Cscene.date; |
| 99 | + const S2L2Ascene = S2L2AScenes.find(scene => scene.date === date); |
| 100 | + const S1scene = S1Scenes.find(scene => scene.date === date); |
| 101 | + |
| 102 | + if(S2L2Ascene !== undefined && S1scene != undefined){ |
| 103 | + usableDates.push(date); |
| 104 | + usableS2L1CSamples.push(S2L1CSamples[S2L1Cscene.idx]); |
| 105 | + usableS2L2ASamples.push(S2L2ASamples[S2L2Ascene.idx]); |
| 106 | + usableS1Samples.push(S1Samples[S1scene.idx]); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + // work with usableDates, usableS2L1CSamples, usableS2L2ASamples, usableS1Samples from here on |
| 111 | + |
| 112 | + // ... your code ... |
| 113 | + |
| 114 | + |
| 115 | +} |
0 commit comments