Given a countryCode
, yearMonth
and preferred processing
methods cropMaskMethod
and extractMethod
, this function
will first check if the data already exists in the cache. First it
will check if the data file exists and if it does not it will create
a dataframe of the country data containing only the administrative
properties and move to processing. If the data file exists it will
check to see if the particular year month already exists. If it
exists, it will exit with a message. If it does not exist, it will
load the country data file and move on to processing.
processNLCountry(ctryCode, admLevel, nlType,
configName = pkgOptions(paste0("configName_", nlType)),
multiTileStrategy = pkgOptions("multiTileStrategy"),
multiTileMergeFun = pkgOptions("multiTileMergeFun"),
removeGasFlares = pkgOptions("removeGasFlares"), nlPeriod,
nlStats = pkgOptions("nlStats"),
downloadMethod = pkgOptions("downloadMethod"),
cropMaskMethod = pkgOptions("cropMaskMethod"),
extractMethod = pkgOptions("extractMethod"),
gadmVersion = pkgOptions("gadmVersion"),
gadmPolyType = pkgOptions("gadmPolyType"), custPolyPath = NULL)
character
The ctryCode of interest
character
The country admin level in the given
ctryCode at which to calculate stats
character
The nlType of interest
character the type of raster being processed
character How to handle multiple tiles per nlPeriod
character The function to use to merge tiles
logical Whether to perform gas flare removal pre-processing
character
The nlPeriod of interest
the statistics to calculate. If not provided will calculate
the stats specified in pkgOptions("nlStats")
The method used to download polygons and rasters
character
Whether to use rasterize or
gdal-based functions to crop and mask the country rasters
("rast" or "gdal") Whether to use rasterize or gdal-based functions to crop and mask the country rasters
The GADM version to use
The format of polygons to download from GADM
Alternative to GADM. A path to a custom shapefile zip
None
Processing consists of:
Reading in the country polygon in ESRI Shapefile format
Reading in the tiles that the particular country intersects with and then clipping the tile(s) to the country boundary
Extract the data from the clipped raster and compute various statistics at the lowest admin level in the country.
Finally, these stats are appended to the data frame and written to the data file.
NOTE: processNLCountry()
assumes that all inputs are available
and will not attempt to download them. It should ideally be called
from the function processNlData()
which does all the
preparation for processing. processNlData()
which can process
multiple countries and time periods will download all the required
tiles and polygons prior to calling processNlCountry
.
getCtryNlData
can also be used with the option
ignoreMissing=FALSE
which will call processNlData
in the background.
# NOT RUN {
#calculate only the sum of monthly VIIRS radiances for Dec 2014 using gdal
#for both cropMask and extraction for KEN
# }
# NOT RUN {
Rnightlights:::processNLCountry("KEN", "KEN_adm2", "VIIRS.M", "201412", "gdal", "gdal", "sum")
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab