Last active
July 26, 2021 13:18
-
-
Save willrayeo/59a1ba7413791a2933ba7994cf4bca24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//VERSION=3 | |
function setup() { | |
return { | |
input: ["B02", "B04", "B08", "B11"], | |
output: [{id: "ndvi_t1", bands: 1, sampleType: "FLOAT32"}, | |
{id: "ndvi_t2", bands: 1, sampleType: "FLOAT32"}, | |
{id: "bsi_t2", bands: 1, sampleType: "FLOAT32"}, | |
{id: "harvested", bands: 1, sampleType: "UINT8"}], | |
mosaicking: "ORBIT" | |
}; | |
} | |
function preProcessScenes (collections) { | |
var allowedDates = ["2020-07-12", "2020-08-06"]; | |
collections.scenes.orbits = collections.scenes.orbits.filter(function (orbit) { | |
var orbitDateFrom = orbit.dateFrom.split("T")[0]; | |
return allowedDates.includes(orbitDateFrom); | |
}); | |
return collections; | |
} | |
function evaluatePixel(samples, scenes) { | |
// Compute ndvi for all dates | |
var ndvi = []; | |
for (i=0; i<samples.length; i++){ | |
ndvi.push((samples[i].B08 - samples[i].B04) / (samples[i].B08 + samples[i].B04)); | |
} | |
// Compute bsi for latest date | |
var bsi = ((samples[0].B11 + samples[0].B04) - (samples[0].B08 + samples[0].B02)) / ((samples[0].B11 + samples[0].B04) + (samples[0].B08 + samples[0].B02)); | |
// Compute harvested map | |
var harvested = ((ndvi[1] - ndvi[0] > 0.25 && bsi > 0.15)) ? 1 : 0; | |
return { | |
"ndvi_t1": [ndvi[1]], | |
"ndvi_t2": [ndvi[0]], | |
"bsi_t2": [bsi], | |
"harvested": [harvested] | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment