-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNDVIGIF.js
74 lines (61 loc) · 2.23 KB
/
NDVIGIF.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
// Fetch a MODIS NDVI collection and select NDVI.
var col = ee.ImageCollection('MODIS/006/MOD13A2').select('NDVI');
// Define a mask to clip the NDVI data by.
var mask = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017')
.filter(ee.Filter.eq('wld_rgn', 'South America'));
// Define the regional bounds of animation frames.
var region = ee.Geometry.Polygon(
[[[-93.79974690382801,11.116671638933818],
[-30.34271565382801,13.901437356557262],
[-90.76721928371984,-57.9083458714126],
[-31.00159428371984,-58.09463734857874]]],
null, false
);
// Add day-of-year (DOY) property to each image.
col = col.map(function(img) {
var doy = ee.Date(img.get('system:time_start')).getRelative('day', 'year');
return img.set('doy', doy);
});
// Get a collection of distinct images by 'doy'.
var distinctDOY = col.filterDate('2017-01-01', '2018-01-01');
// Define a filter that identifies which images from the complete
// collection match the DOY from the distinct DOY collection.
var filter = ee.Filter.equals({leftField: 'doy', rightField: 'doy'});
// Define a join.
var join = ee.Join.saveAll('doy_matches');
// Apply the join and convert the resulting FeatureCollection to an
// ImageCollection.
var joinCol = ee.ImageCollection(join.apply(distinctDOY, col, filter));
// Apply median reduction among matching DOY collections.
var comp = joinCol.map(function(img) {
var doyCol = ee.ImageCollection.fromImages(
img.get('doy_matches')
);
return doyCol.reduce(ee.Reducer.median());
});
// Define RGB visualization parameters.
var visParams = {
min: 0.0,
max: 9000.0,
palette: [
'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
'66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
'012E01', '011D01', '011301'
],
};
// Create RGB visualization images for use as animation frames.
var rgbVis = comp.map(function(img) {
return img.visualize(visParams).clip(mask);
});
// Define GIF visualization arguments.
var gifParams = {
'region': region,
'dimensions': 600,
'crs': 'EPSG:3857',
'framesPerSecond': 10,
'format': 'gif'
};
// Print the GIF URL to the console.
print(rgbVis.getVideoThumbURL(gifParams));
// Render the GIF animation in the console.
print(ui.Thumbnail(rgbVis, gifParams));