-
Notifications
You must be signed in to change notification settings - Fork 0
/
Indice_NDVI_Cabuyaro_Sentinel.js
405 lines (350 loc) · 17.3 KB
/
Indice_NDVI_Cabuyaro_Sentinel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
var geometry =
/* color: #d63000 */
/* shown: false */
ee.Geometry.Polygon(
[[[-72.83131382235845, 4.3909269466189915],
[-72.82947920310157, 4.395339576565946],
[-72.82788059648794, 4.3998377796179415],
[-72.82684525090103, 4.402322217207816],
[-72.82645632167021, 4.403286308636893],
[-72.82636914490611, 4.40385393144579],
[-72.82617467940769, 4.404828045400769],
[-72.82717246098731, 4.404560617948143],
[-72.82818633551793, 4.404277143386955],
[-72.82896417582074, 4.405191748151025],
[-72.8284170065776, 4.406389826009799],
[-72.82744068162918, 4.407545114612819],
[-72.82658237504066, 4.407395354442528],
[-72.8266682050641, 4.408047877252472],
[-72.82649654366232, 4.4086736573306835],
[-72.8274406816318, 4.409598955616436],
[-72.8281487840952, 4.410433327067396],
[-72.82889980284097, 4.411374667804088],
[-72.82937187110115, 4.412134157754776],
[-72.83012288974743, 4.4130220113788425],
[-72.83047694074644, 4.413535468820054],
[-72.83093291623949, 4.413770803262261],
[-72.83190387589408, 4.41370662058319],
[-72.83276218337936, 4.413214557685144],
[-72.83339518444994, 4.4127117975196],
[-72.83381360808244, 4.4121234607427136],
[-72.83465045697379, 4.411481638208421],
[-72.83533710224302, 4.40959895560892],
[-72.8356804254634, 4.40857203593713],
[-72.83591645951968, 4.407908816276492],
[-72.8365065449833, 4.407940907543027],
[-72.83733266509861, 4.407759056584899],
[-72.83791738619655, 4.407593251955651],
[-72.83850210740411, 4.407898119351777],
[-72.83907073591227, 4.408336699808889],
[-72.83937114290694, 4.408818068541337],
[-72.8396286348106, 4.409235254815417],
[-72.84001487294715, 4.409588258357028],
[-72.84022944967647, 4.410117763342956],
[-72.8401650768333, 4.410775632862449],
[-72.8404225687879, 4.412316007389793],
[-72.84090536677846, 4.412326703943655],
[-72.84155446171545, 4.412460416807013],
[-72.84134256780996, 4.413404429801177],
[-72.84072163620176, 4.413940618149834],
[-72.84059423018029, 4.414754927330519],
[-72.84054058666916, 4.415728354043344],
[-72.84052985725533, 4.41650923317814],
[-72.84063714627932, 4.417161748420583],
[-72.8409482824643, 4.417594975703258],
[-72.84063178166822, 4.418025528602496],
[-72.8406237346674, 4.418583107088922],
[-72.84040111124183, 4.419012320957021],
[-72.84048694175213, 4.419525773764666],
[-72.84104484107503, 4.4200606200918795],
[-72.84171002716568, 4.4206061618620485],
[-72.84204262122911, 4.4213923844844585],
[-72.84210163026002, 4.42219197794941],
[-72.84254687759966, 4.423226902519223],
[-72.855764799035, 4.4012337969015904],
[-72.85578625681555, 4.399928736911972],
[-72.85574334137084, 4.398559493518869],
[-72.85580771437299, 4.396034942369099],
[-72.85585063027946, 4.394751268576372],
[-72.85617249513176, 4.394195009726963],
[-72.85626905438222, 4.39370293408197],
[-72.85668747863112, 4.393531777220826],
[-72.85742776846914, 4.393221555163498],
[-72.85780327723577, 4.392141126372383],
[-72.858119778001, 4.391616956672743],
[-72.85826461706985, 4.39096441889961],
[-72.85836654081696, 4.390311881036699],
[-72.85846846487279, 4.3899802636721565],
[-72.8584899228438, 4.389445395327595],
[-72.85846846507566, 4.388974710986999],
[-72.85844700719929, 4.388504026710804],
[-72.85838263417926, 4.387904973780211],
[-72.85827534556641, 4.387027787295628],
[-72.85827534587776, 4.3862361798027],
[-72.85793202320578, 4.383925535835018],
[-72.85772817526339, 4.38340136043434],
[-72.85763161565973, 4.382877185033602],
[-72.85730975093037, 4.381828834192973],
[-72.85726683560341, 4.379475386571453],
[-72.85782473488877, 4.377934944119561],
[-72.85788910761931, 4.376822400024019],
[-72.85752432758404, 4.376223337675301],
[-72.85703080079736, 4.375560089143086],
[-72.85630124069398, 4.374918235130912],
[-72.85588281594225, 4.374447542039634],
[-72.85503523847359, 4.374233590263058],
[-72.85398381285363, 4.3738163852837735],
[-72.85318987930437, 4.373591735130669],
[-72.85243886087811, 4.373773594615669],
[-72.85147326612332, 4.373313597735325],
[-72.85082953618134, 4.371601980728763],
[-72.85097973926695, 4.370489427522611],
[-72.8507544338784, 4.3700615220474734],
[-72.85022872156878, 4.369719197506667],
[-72.84928458345215, 4.36912013001256],
[-72.84879105716949, 4.368339200650602],
[-72.84782546311486, 4.368242920990585],
[-72.84746068330169, 4.369002455781846],
[-72.84676330885986, 4.369275246177067],
[-72.84607129873852, 4.369047920614247],
[-72.84555095064877, 4.368392688305174],
[-72.84254687758076, 4.372800113041608],
[-72.8392853125377, 4.377079141379587],
[-72.83306258976528, 4.386514312395148]]]);
/*El siguiente script crea visualizaciones en video con los cambios en el terreno y enl indice NDVI,
que se presentan en una coleccion de imagenes multiespectrales Sentinel en un poligono
creado por geometria que es un area de cultivo en Cabuyaro Meta*/
/*Traer la coleccion de imagenes Sentinel_2_SR_HARMONIZED con un filtro de fechas del 2021-09-01 al 2023-10-30,
teniendo dos años del ciclo del año cacaotero para Colombia que inicia en el mes de octubre y
finaliza en el mes de septiembre. Se aplica un filtro con los parametros de
visualizacion en RGB y recortadas al area del poligono para cada una de las imagenes de la coleccion
al final se imprime la coleccion para saber cuantas imagnes tiene y se visualiza en el mapa*/
var coleccion = ee.ImageCollection('COPERNICUS/S2_HARMONIZED')
.filterBounds(geometry)
.filterDate('2018-09-01','2023-10-30')
.filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 5)
.map(function(i){return i.select(['B2','B3','B4','B5','B8','B11']).clip(geometry)
})
print('coleccion', coleccion)
var resampleBands = function(image) {
var projection = image.select('B8').projection()
var scale = image.select('B8').projection().nominalScale()
var band5_resampled = image.select('B5').resample('bicubic').reproject({
crs: projection,
scale: scale
})
var band11_resampled = image.select('B11').resample('bicubic').reproject({
crs: projection,
scale: scale
})
return image.select(['B2', 'B3', 'B4', 'B8'])
.addBands(band5_resampled)
.addBands(band11_resampled)
.clip(geometry)
}
var resampledCollection = coleccion.map(resampleBands)
// print('Resampled Collection:', resampledCollection)
var visparam = {bands:['B4','B3','B2'], min: 513, max: 1385, gamma: 1.7}
Map.addLayer(resampledCollection, visparam, "RGB_coleccion")
/*Se define la variable gif para generar el video de visualizacion de la coleccion de imagenes en RGB
y se imprime donde se crea un enlace del video con la coleccion*/
// var gif = resampledCollection.getVideoThumbURL(visparam)
// print('video coleccion cabuyaro', gif)
/*Se define la variable de parametros para la generacion del indice NDVI para cada imagen de la
coleccion y se crea la funcion de normalizacion diferenciada para el NDVI de cada imagen
recortada al area del poligono de la geometria dada, de igual forma se define una mascara para los
valores de NDVI superiores a 0.5*/
var parametrosndvi = {min:-0.5, max:0.9, palette: ['blue', 'black', 'white', 'yellow', 'green', 'red']}
var ndvi = resampledCollection.map(function (c){return c.normalizedDifference(['B8','B4']).clip(geometry)})
var vis = ndvi.map(function (f){return f.visualize(parametrosndvi)})
var mask = ndvi.map(function (c){return c.visualize(parametrosndvi).mask(c.gte(0.3))})
/*Se realiza el mismo procedimiento para los otros indices SAVI, ARVI, EVI, NDMI, NDRE,GCI*/
// var parametrosavi = {min:-0.5, max:0.9, palette: ['blue', 'black', 'white', 'yellow', 'green', 'red']}
// var savi = resampledCollection.map(function (a){return a.expression('(1+L)*((nir-red)/(nir+red+L))',
// {
// nir : a.select('B8').divide(10000),
// red : a.select('B4').divide(10000),
// L : 0.5
// }).clip(geometry)})
// var visavi = savi.map(function (a){return a.visualize(parametrosavi)})
// var parametrosarvi = {min:-0.5, max:0.9, palette: ['blue', 'black', 'white', 'yellow', 'green', 'red']}
// var arvi = resampledCollection.map(function (b){return b.expression('(nir-(2*red)+blue)/(nir+(2*red)+blue)',
// {
// nir : b.select('B8').divide(10000),
// red : b.select('B4').divide(10000),
// blue : b.select('B2').divide(10000),
// }).clip(geometry)})
// var visarvi = arvi.map(function (b){return b.visualize(parametrosarvi)})
// var parametroevi = {min:-0.5, max:0.9, palette: ['blue', 'black', 'white', 'yellow', 'green', 'red']}
// var evi = resampledCollection.map(function (g){return g.expression('(2.5)*((nir-red)/(nir+(red*C)-(B*blue)+L))',
// {
// nir : g.select('B8').divide(10000),
// red : g.select('B4').divide(10000),
// blue : g.select('B2').divide(10000),
// C : 6,
// B : 7.5,
// L : 1
// }).clip(geometry)})
// var visevi = evi.map(function (g){return g.visualize(parametroevi)})
// var parametrosndmi = {min:-1, max:0.9, palette: ['blue', 'black', 'white', 'yellow', 'green', 'red']}
// var ndmi = resampledCollection.map(function (j){return j.expression('((nir-swir)/(nir+swir))',
// {
// nir : j.select('B8').divide(10000),
// swir : j.select('B11').divide(10000),
// }).clip(geometry)})
// var visndmi = ndmi.map(function (j){return j.visualize(parametrosndmi)})
// var parametrosndre = {min:-1, max:0.9, palette: ['blue', 'black', 'white', 'yellow', 'green', 'red']}
// var ndre = resampledCollection.map(function (k){return k.expression('((nir-rededge)/(nir+rededge))',
// {
// nir : k.select('B8').divide(10000),
// rededge : k.select('B5').divide(10000),
// }).clip(geometry)})
// var visndre = ndre.map(function (k){return k.visualize(parametrosndre)})
// var parametrosgci = {min:-0.5, max:10, palette: ['blue', 'black', 'white', 'yellow', 'green', 'red']}
// var gci = resampledCollection.map(function (h){return h.expression('((nir)/(green))-(N)',
// {
// nir : h.select('B8').divide(10000),
// green : h.select('B3').divide(10000),
// N : 1,
// }).clip(geometry)})
// var visgci = gci.map(function (h){return h.visualize(parametrosgci)})
/*Se establece la variable de visualizacion por imagenes por segundo y se crea la visualizacion del
video en la consola con la funcion ui.Thumbnail para los diferentes indices y se imprime para
ver los videos en consola*/
var viscontrol = {framesPerSecond: 2}
var timeserie1 = ui.Thumbnail(vis, viscontrol)
var timeserie2 = ui.Thumbnail(mask, viscontrol)
// var timeserie3 = ui.Thumbnail(visavi, viscontrol)
// var timeserie4 = ui.Thumbnail(visarvi, viscontrol)
// var timeserie5 = ui.Thumbnail(visevi, viscontrol)
// var timeserie6 = ui.Thumbnail(visndmi, viscontrol)
// var timeserie7 = ui.Thumbnail(visndre, viscontrol)
// var timeserie8 = ui.Thumbnail(visgci, viscontrol)
print('ndvi', timeserie1)
print('maskndvi', timeserie2)
// print('savi', timeserie3)
// print('arvi', timeserie4)
// print('evi', timeserie5)
// print('ndmi', timeserie6)
// print('ndre', timeserie7)
// print('gci', timeserie8)
// throw('stop')
/*Se adiciona a la coleccion de imagenes las bandas de los indices recortadas a la geometria,
se definen los parametros de visualizacion y se visualizan en el mapa que se
genera de la coleccion de imagenes*/
var app = function (image){
var ndvi = image.normalizedDifference(["B8", "B4"])
// var savi = image.expression('(1+L)*((nir-red)/(nir+red+L))',
// {
// nir : image.select('B8').divide(10000),
// red : image.select('B4').divide(10000),
// L : 0.5
// })
// var arvi = image.expression('(nir-(2*red)+blue)/(nir+(2*red)+blue)',
// {
// nir : image.select('B8').divide(10000),
// red : image.select('B4').divide(10000),
// blue : image.select('B2').divide(10000),
// })
// var evi = image.expression('(2.5)*((nir-red)/(nir+(red*C)-(B*blue)+L))',
// {
// nir : image.select('B8').divide(10000),
// red : image.select('B4').divide(10000),
// blue : image.select('B2').divide(10000),
// C : 6,
// B : 7.5,
// L : 1
// })
// var ndmi = image.expression('((nir-swir)/(nir-swir))',
// {
// nir : image.select('B8').divide(10000),
// swir : image.select('B11').divide(10000),
// })
// var ndre = image.expression('((nir-rededge)/(nir-rededge))',
// {
// nir : image.select('B8').divide(10000),
// rededge : image.select('B5').divide(10000),
// })
// var gci = image.expression('((nir)/(green))-(N)',
// {
// nir : image.select('B8').divide(10000),
// green : image.select('B3').divide(10000),
// N : 1
// })
image = image.addBands(ndvi.rename("NDVI"))
// image = image.addBands(savi.rename("SAVI"))
// image = image.addBands(arvi.rename("ARVI"))
// image = image.addBands(evi.rename("EVI"))
// image = image.addBands(ndmi.rename("NDMI"))
// image = image.addBands(ndre.rename("NDRE"))
// image = image.addBands(gci.rename("GCI"))
return image.clip(geometry)}
var coleccion1 = resampledCollection.map(app)
print('coleccion1', coleccion1)
var visParams = {bands:["NDVI"], min: -0.5, max:0.9, palette: ["blue", "black", "white", "yellow", "green", "red"]}
Map.addLayer(coleccion1, visParams, "NDVI_coleccion")
// var visParams1 = {bands:["SAVI"], min: -0.5, max:0.9, palette: ["blue", "black", "white", "yellow", "green", "red"]}
// Map.addLayer(coleccion1, visParams1, "SAVI_coleccion")
// var visParams2 = {bands:["ARVI"], min: -0.5, max:0.9, palette: ["blue", "black", "white", "yellow", "green", "red"]}
// Map.addLayer(coleccion1, visParams2, "ARVI_coleccion")
// var visParams3 = {bands:["EVI"], min: -0.5, max:0.9, palette: ["blue", "black", "white", "yellow", "green", "red"]}
// Map.addLayer(coleccion1, visParams3, "EVI_coleccion")
// var visParams4 = {bands:["NDMI"], min: -0.5, max:0.9, palette: ["blue", "black", "white", "yellow", "green", "red"]}
// Map.addLayer(coleccion1, visParams4, "NDMI_coleccion")
// var visParams5 = {bands:["NDRE"], min: -0.5, max:0.9, palette: ["blue", "black", "white", "yellow", "green", "red"]}
// Map.addLayer(coleccion1, visParams5, "NDRE_coleccion")
// var visParams6 = {bands:["GCI"], min: -0.5, max:10, palette: ["blue", "black", "white", "yellow", "green", "red"]}
// Map.addLayer(coleccion1, visParams6, "GCI_coleccion")
Map.centerObject(geometry,14)
/*Se imprime la coleccion con las bandas adicionadas de los indices y se genera un video de
visualizacion de los cambios de cada indice en la coleccion de imagenes mediante un enlace*/
// var gif1 = coleccion1.getVideoThumbURL(visParams)
// print('video coleccion ndvi cabuyaro', gif1)
// var gif2 = coleccion1.getVideoThumbURL(visParams1)
// print('video coleccion savi cabuyaro', gif2)
// var gif3 = coleccion1.getVideoThumbURL(visParams2)
// print('video coleccion arvi cabuyaro', gif3)
// var gif4 = coleccion1.getVideoThumbURL(visParams3)
// print('video coleccion evi cabuyaro', gif4)
// var gif5 = coleccion1.getVideoThumbURL(visParams4)
// print('video coleccion ndmi cabuyaro', gif5)
// var gif6 = coleccion1.getVideoThumbURL(visParams5)
// print('video coleccion ndre cabuyaro', gif6)
// var gif7 = coleccion1.getVideoThumbURL(visParams6)
// print('video coleccion gci cabuyaro', gif7)
/*Se crea una etiqueta a partir de un punto que se defina mediante un click en el mapa
la cual va a presentar la grafica de los indices de vegetacion para el sitio que se define en el click*/
var lon = ui.Label()
var lat = ui.Label()
Map.onClick(function(click){
lon.setValue('Longitud: '+ click.lon.toFixed(2))
lat.setValue('Latitud: '+ click.lat.toFixed(2))
var punto = ee.Geometry.Point(click.lon, click.lat)
var dibujo = ui.Map.Layer(punto)
Map.layers().set(1, ui.Map.Layer(punto, {color: 'white', pointSize: 10}))
Map.centerObject(punto, 16)
var grafico = ui.Chart.image
.series({
imageCollection: coleccion1.select("NDVI"),
// imageCollection: coleccion1.select("NDVI","SAVI","ARVI","EVI","NDMI","NDRE","GCI"),
region: punto,
reducer: ee.Reducer.mean(),
scale: 10,
xProperty: 'system:time_start'
})
.setSeriesNames(["NDVI"])
// .setSeriesNames(["NDVI","SAVI","ARVI","EVI","NDMI","NDRE","GCI"])
.setOptions({
title: 'Distribución de valores índice de vegetación',
vAxis: {title: 'Valores índices de vegetación'},
hAxis: {title: 'Mes/Año'},
lineWidth: 2,
colors: ['red'],
// colors: ['red', 'green', 'blue', 'yellow', 'purple', 'black', 'orange'],
curveType: 'function'
})
var panel = ui.Panel({widgets: grafico, layout: ui.Panel.Layout.Flow('vertical'),
style:{width: '500px', position: 'bottom-left'}
})
Map.widgets().set(2, panel)
})