-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNDVI_Pajaro
More file actions
38 lines (26 loc) · 955 Bytes
/
Copy pathNDVI_Pajaro
File metadata and controls
38 lines (26 loc) · 955 Bytes
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
Map.setCenter(-121.7617, 36.8984, 12);
var aoi = geometry;
var sentinel = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED');
function maskS2clouds(image) {
var qa = image.select('QA60');
var cloudBitMask = 1 << 10;
var cirrusBitMask = 1 << 11;
var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask).divide(10000);
}
var cloudless = sentinel
.filterBounds(aoi)
.filterDate('2020-01-01', '2023-05-01')
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 15))
.map(maskS2clouds);
var addNDVI = function(image) {
var ndvi = image.normalizedDifference(['B8', 'B4']).rename('NDVI');
return image.addBands(ndvi);
};
var withNDVI = cloudless.map(addNDVI);
var firstImage = ee.Image(withNDVI.first());
Map.addLayer(firstImage.select('NDVI'), {
min: -1,
max: 1,
palette: ['blue', 'white', 'green']
}, 'NDVI');