-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wray
committed
Jun 25, 2024
1 parent
b6bf3d4
commit 372168e
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//VERSION=3 | ||
|
||
//Basic initialization setup function | ||
function setup() { | ||
return { | ||
//List of all bands, that will be used in the script, either for visualization or for choosing best pixel | ||
input: [{ | ||
bands: [ | ||
"Red", | ||
"NIR" | ||
] | ||
}], | ||
//This can always be the same if one is doing RGB images | ||
output: { bands: 3 }, | ||
mosaicking: "ORBIT" | ||
} | ||
} | ||
|
||
/* | ||
In this function we limit the scenes, which are used for processing. | ||
These are based also on input variables. | ||
E.g. if one sets date "2017-03-01" ("TO date") and cloud coverage filter 30%, | ||
all scenes older than 2017-03-01 with cloud coverage 30% will be checked against | ||
further conditions in this function (in this function it is currently limited to 3 months). | ||
The more scenes there are, longer it will take to process the data. | ||
After 60 seconds of processing, there will be a timeout. | ||
*/ | ||
|
||
function preProcessScenes (collections) { | ||
collections.scenes.orbits = collections.scenes.orbits.filter(function (orbit) { | ||
var orbitDateFrom = new Date(orbit.dateFrom) | ||
return orbitDateFrom.getTime() >= (collections.to.getTime()-3*31*24*3600*1000); | ||
}) | ||
return collections | ||
} | ||
|
||
function calcNDVI(sample) { | ||
var denom = sample.Red + sample.NIR; | ||
return ((denom != 0) ? (sample.NIR - sample.Red) / denom : NaN); | ||
} | ||
function evaluatePixel(samples) { | ||
var max = 0; | ||
for (var i= 0; i<samples.length;i++) { | ||
var ndvi = calcNDVI(samples[i]); | ||
max = ndvi > max ? ndvi:max; | ||
return [max]; | ||
} | ||
} |