-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchart.js
More file actions
54 lines (44 loc) · 1.4 KB
/
chart.js
File metadata and controls
54 lines (44 loc) · 1.4 KB
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
var s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED');
Map.addLayer(geometry, {color: 'red'}, 'Farm');
Map.centerObject(geometry);
var filtered = s2
.filter(ee.Filter.date('2017-01-01', '2018-01-01'))
.filter(ee.Filter.bounds(geometry));
var csPlus = ee.ImageCollection('GOOGLE/CLOUD_SCORE_PLUS/V1/S2_HARMONIZED');
var csPlusBands = csPlus.first().bandNames();
var filteredS2WithCs = filtered.linkCollection(csPlus, csPlusBands);
var maskLowQA = function(image) {
var qaBand = 'cs';
var clearThreshold = 0.5;
var mask = image.select(qaBand).gte(clearThreshold);
return image.updateMask(mask);
};
var filteredMasked = filteredS2WithCs
.map(maskLowQA)
.select('B.*');
var scaleValues = function(image) {
var scaledImage = image.multiply(0.0001);
return scaledImage
.copyProperties(image, ['system:time_start']);
};
var addNDVI = function(image) {
var ndvi = image.normalizedDifference(['B8', 'B4']).rename('ndvi');
return image.addBands(ndvi);
};
var withNdvi = filteredMasked
.map(scaleValues)
.map(addNDVI);
var chart = ui.Chart.image.series({
imageCollection: withNdvi.select('ndvi'),
region: geometry,
reducer: ee.Reducer.mean(),
scale: 10
}).setOptions({
lineWidth: 1,
pointSize: 2,
title: 'NDVI Time Series',
interpolateNulls: true,
vAxis: {title: 'NDVI'},
hAxis: {title: '', format: 'YYYY-MMM'}
});
print(chart);