nightlight time lapse movie

with a timestamp

copy and paste the code below, hit run to export the movie to your google drive.

// import library from Gena
var text = require('users/gena/packages:text');

// import country layers
var countries = ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017");
// select Cambodia
var kh = countries.filter(ee.Filter.eq("country_na", "Cambodia"));
// add cambodia to the map
Map.addLayer(kh.draw("red"),{},"Cambodia");

// data was uploaded from this dataset: https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/YGIVCD
// article for the data can be found here: https://essd.copernicus.org/articles/13/889/2021/
var nightlights = ee.ImageCollection("projects/servir-mekong/nightlight");

//make the data 8-bit which is necessary for making a video
var nightlight_video =  nightlights.map(function(image){
  var date = ee.Date(image.get('system:time_start'));
  var label = date.format('YYYY');
  
  image = image.clip(kh).unmask(-1)
  
  return image.visualize({
    forceRgbOutput: true,
    palette: ['c0c0c0','000000','700000','808080','FFFF00','ffffff','ffffff','ffffff','ffffff','ffffff','ffffff','ffffff'],
    min: -1,
    max: 10
  }).set({label: label});
});

// annotate
var annotations = [
  {
    position: 'left', offset: '1%', margin: '1%', property: 'label', scale: Map.getScale() * 2
  }
];

Map.centerObject(kh, 8);

nightlight_video = nightlight_video.map(function(image) {
  return text.annotateImage(image, {}, kh.geometry().bounds(), annotations);
});


//Export NDVI from whole study area to video
Export.video.toDrive({
  collection: nightlight_video,
  description: "nightlightKH",    // Filename, no spaces allowed
  framesPerSecond: 1,             // I.e., 1 year / second
  region: kh.geometry().bounds(),
  scale: 500,                     // Scale in m
  });
  

Leave a Reply