3
3
//Basic initialization setup function
4
4
function setup ( ) {
5
5
return {
6
- //List of all bands, that will be used in the script, either for visualization or for choosing best pixel
6
+ //List of all bands, that will be used in the script, either for visualization or for choosing best pixel
7
7
input : [ {
8
8
bands : [
9
- "Red" ,
10
- "NIR"
9
+ "Red" ,
10
+ "NIR"
11
11
]
12
12
} ] ,
13
- //This can always be the same if one is doing RGB images
14
- output : { bands : 3 } ,
13
+ //This can always be the same if one is doing RGB images
14
+ output : { bands : 4 } ,
15
15
mosaicking : "ORBIT"
16
16
}
17
17
}
@@ -26,44 +26,47 @@ The more scenes there are, longer it will take to process the data.
26
26
After 60 seconds of processing, there will be a timeout.
27
27
*/
28
28
29
- function preProcessScenes ( collections ) {
30
- collections . scenes . orbits = collections . scenes . orbits . filter ( function ( orbit ) {
31
- var orbitDateFrom = new Date ( orbit . dateFrom )
32
- return orbitDateFrom . getTime ( ) >= ( collections . to . getTime ( ) - 3 * 31 * 24 * 3600 * 1000 ) ;
33
- } )
34
- return collections
29
+ function preProcessScenes ( collections ) {
30
+ collections . scenes . orbits = collections . scenes . orbits . filter ( function ( orbit ) {
31
+ var orbitDateFrom = new Date ( orbit . dateFrom )
32
+ return orbitDateFrom . getTime ( ) >= ( collections . to . getTime ( ) - 3 * 31 * 24 * 3600 * 1000 ) ;
33
+ } )
34
+ return collections
35
35
}
36
36
37
37
function calcNDVI ( sample ) {
38
38
var denom = sample . Red + sample . NIR ;
39
39
return ( ( denom != 0 ) ? ( sample . NIR - sample . Red ) / denom : NaN ) ;
40
40
}
41
- function evaluatePixel ( samples ) {
42
- var max = 0 ;
43
- for ( var i = 0 ; i < samples . length ; i ++ ) {
44
- var ndvi = calcNDVI ( samples [ i ] ) ;
45
- max = ndvi > max ? ndvi : max ;
41
+ function evaluatePixel ( samples ) {
42
+ var max = Number . NEGATIVE_INFINITY ;
43
+ for ( let i = 0 ; i < samples . length ; i ++ ) {
44
+ var ndvi = calcNDVI ( samples [ i ] ) ;
45
+ max = ndvi > max ? ndvi : max ;
46
46
}
47
- if ( max < - 1.1 ) return [ 0 , 0 , 0 ] ;
48
- else if ( max < - 0.2 ) return [ 0.75 , 0.75 , 0.75 ] ;
49
- else if ( max < - 0.1 ) return [ 0.86 , 0.86 , 0.86 ] ;
50
- else if ( max < 0 ) return [ 1 , 1 , 0.88 ] ;
51
- else if ( max < 0.025 ) return [ 1 , 0.98 , 0.8 ] ;
52
- else if ( max < 0.05 ) return [ 0.93 , 0.91 , 0.71 ] ;
53
- else if ( max < 0.075 ) return [ 0.87 , 0.85 , 0.61 ] ;
54
- else if ( max < 0.1 ) return [ 0.8 , 0.78 , 0.51 ] ;
55
- else if ( max < 0.125 ) return [ 0.74 , 0.72 , 0.42 ] ;
56
- else if ( max < 0.15 ) return [ 0.69 , 0.76 , 0.38 ] ;
57
- else if ( max < 0.175 ) return [ 0.64 , 0.8 , 0.35 ] ;
58
- else if ( max < 0.2 ) return [ 0.57 , 0.75 , 0.32 ] ;
59
- else if ( max < 0.25 ) return [ 0.5 , 0.7 , 0.28 ] ;
60
- else if ( max < 0.3 ) return [ 0.44 , 0.64 , 0.25 ] ;
61
- else if ( max < 0.35 ) return [ 0.38 , 0.59 , 0.21 ] ;
62
- else if ( max < 0.4 ) return [ 0.31 , 0.54 , 0.18 ] ;
63
- else if ( max < 0.45 ) return [ 0.25 , 0.49 , 0.14 ] ;
64
- else if ( max < 0.5 ) return [ 0.19 , 0.43 , 0.11 ] ;
65
- else if ( max < 0.55 ) return [ 0.13 , 0.38 , 0.07 ] ;
66
- else if ( max < 0.6 ) return [ 0.06 , 0.33 , 0.04 ] ;
67
- else return [ 0 , 0.27 , 0 ] ;
68
-
47
+ let max_exists = 0 ;
48
+ if ( isFinite ( max ) ) {
49
+ max_exists = 1 ;
50
+ }
51
+ if ( max < - 1.1 ) { return [ 0 , 0 , 0 , max_exists ] ; }
52
+ else if ( max < - 0.2 ) { return [ 0.75 , 0.75 , 0.75 , max_exists ] ; }
53
+ else if ( max < - 0.1 ) { return [ 0.86 , 0.86 , 0.86 , max_exists ] ; }
54
+ else if ( max < 0 ) { return [ 1 , 1 , 0.88 , max_exists ] ; }
55
+ else if ( max < 0.025 ) { return [ 1 , 0.98 , 0.8 , max_exists ] ; }
56
+ else if ( max < 0.05 ) { return [ 0.93 , 0.91 , 0.71 , max_exists ] ; }
57
+ else if ( max < 0.075 ) { return [ 0.87 , 0.85 , 0.61 , max_exists ] ; }
58
+ else if ( max < 0.1 ) { return [ 0.8 , 0.78 , 0.51 , max_exists ] ; }
59
+ else if ( max < 0.125 ) { return [ 0.74 , 0.72 , 0.42 , max_exists ] ; }
60
+ else if ( max < 0.15 ) { return [ 0.69 , 0.76 , 0.38 , max_exists ] ; }
61
+ else if ( max < 0.175 ) { return [ 0.64 , 0.8 , 0.35 , max_exists ] ; }
62
+ else if ( max < 0.2 ) { return [ 0.57 , 0.75 , 0.32 , max_exists ] ; }
63
+ else if ( max < 0.25 ) { return [ 0.5 , 0.7 , 0.28 , max_exists ] ; }
64
+ else if ( max < 0.3 ) { return [ 0.44 , 0.64 , 0.25 , max_exists ] ; }
65
+ else if ( max < 0.35 ) { return [ 0.38 , 0.59 , 0.21 , max_exists ] ; }
66
+ else if ( max < 0.4 ) { return [ 0.31 , 0.54 , 0.18 , max_exists ] ; }
67
+ else if ( max < 0.45 ) { return [ 0.25 , 0.49 , 0.14 , max_exists ] ; }
68
+ else if ( max < 0.5 ) { return [ 0.19 , 0.43 , 0.11 , max_exists ] ; }
69
+ else if ( max < 0.55 ) { return [ 0.13 , 0.38 , 0.07 , max_exists ] ; }
70
+ else if ( max < 0.6 ) { return [ 0.06 , 0.33 , 0.04 , max_exists ] ; }
71
+ else { return [ 0 , 0.27 , 0 , max_exists ] ; }
69
72
}
0 commit comments