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, nlPeriod, nlType,
cropMaskMethod = pkgOptions("cropMaskMethod"),
extractMethod = pkgOptions("extractMethod"),
fnStats = pkgOptions("stats"))character string The ctryCode of interest
character string The nlPeriod of interest
character string The nlType of interest
("rast" or "gdal") 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 statistics to calculate. If not provided will calculate the stats specified
in pkgOptions("stats")
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 VIIRS radiances for Dec 2012 using gdal
#for both cropMask and extraction for KEN
# }
# NOT RUN {
processNLCountry("KEN", "201212", "VIIRS", "gdal", "gdal", "sum")
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab