# NOT RUN {
#Example 1: process VIIRS nightlights for all countries and all periods available e.g. to create
#a local cache or repo
#Recommend running nlInit() to improve performance. It stores some global variables
#so that they do not have to be re-evaluated multiply
nlInit()
processNlData() #process VIIRS nightlights for all countries and all periods
#Example 2: process nightlights for all countries in 2012 only
nlInit() #for performance. See Example 1
nlPeriods <- getAllNlYears("VIIRS") #get a list of all nightlight periods to present-day
nlPeriods <- nlPeriods[grep("^2012", nlPeriods)] #filter only periods in 2012
processNlData(nlPeriods=nlPeriods)
#Example 3: process VIIRS nightlights for countries KEN & RWA in 2014 Jan to 2014 May only
nlInit()
cCodes <- c("KEN", "RWA")
nlPeriods <- getAllNlPeriods("VIIRS")
nlPeriods <- nlPeriods[grep("^20120[1-5]", nlPeriods)]
processNlData(ctryCodes=cCodes, nlPeriods=nlPeriods)
#Example 4: process VIIRS nightlights for countries KEN & RWA in 2014 Oct to 2014 Dec only
processNlData(ctryCodes=c("KEN", "RWA"), nlPeriods=c("201410", "201411", "201412"))
#Example 5: process all nightlights, all countries, all stats in one thread
processNlData()
#Example 6: process all nightlights, all countries, all stats with each
# year in a separate thread. Create a separate R script for each year as follows:
library(Rnightlights)
nlInit()
nlPeriods <- getAllNlYears("VIIRS")
nlPeriods_2012 <- nlPeriods[grep("^2012", nlPeriods)]
processNlData(nlPeriods=nlPeriods_2012)
#Run the script from the command line as:
#R CMD BATCH script_name_2012.R
# }
Run the code above in your browser using DataLab