Learn R Programming

⚠️There's a newer version (0.2.4) of this package.Take me there.

Rnightlights

Nightlights for R

The Rnightlights package extracts raster and zonal statistics from satellite nightlight rasters downloaded from the United States National Oceanic and Atmospheric Administration (http://www.noaa.gov) free data repositories.

Both the DMSP-OLS annual and SNPP-VIIRS monthly nightlight raster data are supported. Satellite nightlight raster tiles are downloaded and cropped to the country boundaries using shapefiles from the GADM database of Global Administrative Areas (http://gadm.org). Zonal statistics are then calculated at the lowest administrative boundary for the selected country and cached locally for future retrieval. Finally, a simple data explorer/browser is included that allows one to visualize the cached data e.g. graphing, mapping and clustering regional data.

Installation

R package Rnightlights is available on CRAN and can be installed in R as:

install.packages('Rnightlights')

Copy Link

Version

Install

install.packages('Rnightlights')

Monthly Downloads

44

Version

0.1.2

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Christopher Njuguna

Last Published

September 9th, 2017

Functions in Rnightlights (0.1.2)

allValid

Check if a vector/list of values given is valid as per the given validation function
createCtryNlDataDF

Initiates the country nightlight dataframe with the country data read from the polygon
downloadNlTilesVIIRS

Download VIIRS nightlight tile
existsCtryNlData

Check if VIIRS nightlight stats exist locally
getCtryNlDataFname

Check if a month number is valid for a given nightlight type
getCtryNlDataFnamePath

Get the full path to the file containing the country data
getNlDataPath

Gets the root path to the file directory"
getNlDir

Get the paths to the various data locations
getPolyFname

Returns the directory name of the unzipped shapefile downloaded from GADM.ORG without the path
getPolyFnamePath

Get the path of the unzipped polygon directory downloaded from GADM.ORG
myZonal

Calculate zonal statistics. Used internally
nlCleanup

Clean up the environment after processing (Not yet implemented)
createNlDataDirs

Create required data subdirectories in the root data path
createNlTilesSpPolysDF

Creates a tile Spatial Polygons DataFrame from the "nlTiles" dataframe
existsPolyFnameZip

Check if the compressed country polygon has been downloaded and stored in the polygon folder
exploreData

Run a web application to explore the processed nightlight data cached locally
saveCtryNlData

Save a data frame of a country's data to the appropriate location
setNlDataPath

Sets the root path to the package data directory
tileName2Idx

Get the index of a tile given its name
tilesPolygonIntersectVIIRS

Get the list of VIIRS tiles that a polygon intersects with
ZonalPipe

Create a zonal file if it does not exist and calculate the zonal stats
addREADME

Add README file to the root data path
fnAggRadGdal

Calculate zonal statistics using GDAL. Faster than fnAggRadRast for large polygons.
ctryCodeToName

Convert a country ISO3 code to the full name
ctryNameToCode

Convert a country name to its ISO3 code
downloadNlTiles

Download the listed tiles for a given nlType in a given nlPeriod
getCtryPolyAdmLevelNames

Get the list of admin level names in a polygon shapefile
getCtryPolyUrl

Get the GADM url from which to download country polygons
getNlTifLclNameOLS

Constructs the filename used to save/access the decompressed OLS .tif file
getNlTileTifLclNameOLS

Constructs the filename of the decompressed OLS .tif file
getNlUrlOLS

Function to return the url of the OLS tile to download
getNlUrlVIIRS

Function to return the url of the VIIRS tile to download
mapAllCtryPolyToTilesVIIRS

Create a mapping of all countries and the tiles they intersect
mapCtryPolyToTilesVIIRS

Create a mapping of all countries and the tiles they intersect
nlInit

Initialize some important variables and create directory structure
nlRange

Create a range of nlPeriods
fnAggRadRast

Calculate statistics on a nightlight raster that fall within a polygon
getCtryRasterOutputFname

Get the full path to the file where the cropped VIIRS country raster is stored.
getCtryShpLowestLyrName

Get the name of the lowest ctry admin level
getCtryShpLyrName

Get the standard name of a polygon layer for a country
getCtryTileList

Returns a list of VIIRS nightlight tiles that a country or countries intersects with
validNlPeriodOLS

Check if an OLS nlYear is valid
validNlPeriodVIIRS

Check if a VIIRS nlYearMonth is valid
getNlTileZipLclNameOLS

The name with which to save the OLS tile locally
getNlTileZipLclNamePath

Constructs the full path used to save/access the compressed downloaded tile
masqOLS

Extract raster pixel values within the boundaries of a polygon
masqVIIRS

extract data from a raster using one polygon in a multipolygon
downloadNlTilesOLS

Download OLS nightlight tile
getAllNlCtryCodes

Check if a month number is valid for a given nightlight type
getAllNlPeriods

Generate a list of all possible nlPeriods for a given nlType
getNlTileTifLclNamePath

Constructs the full path used to save/access the downloaded tile .tgz file
getNlTileTifLclNamePathOLS

Constructs the full path used to save/access the decompressed OLS .tif file
getPolyFnameZip

getTilesCtryIntersectVIIRS

Get a list of tiles that a country polygon intersects with
insertNlDataCol

Insert an aggregate nightlight data column in a country nightlights dataframe
listCtryNlData

List available data
pkgOptions

Set or get options for the Rnightlights package
pkgReset

Reset global options for the Rnightlights package
validCtryCode

Check if a month number is valid for a given nightlight type
validCtryNlDataDF

Check if a country dataframe is valid
plotCtryWithTilesVIIRS

Plot a country polygon against a background of the VIIRS tiles and world map
processNLCountry

Processes nightlights for an individual country in a particular nlPeriod
setupDataPath

Interactively allows the user to set up the default root path
tileIdx2Name

Get the name of a tile given its index
validNlTileNameVIIRS

Check if a tile index name is valid for a given nightlight type
validNlTileNumVIIRS

Check if a tile index number is valid for a given nightlight type
ctryShpLyrName2Num

Get the integer number of the layer. topmost country layer=0
dnldCtryPoly

existsCtryNlDataFile

Check if a country's data file exists
existsPolyFnamePath

Check if the decompressed country polygon has been downloaded and stored in the polygon folder
getCtryNlData

Returns nightlight statistics for the given ctryCode and nlType in the given nPeriods
getCtryNlDataColName

Construct the name of a nightlight data column given the nightlight type and nlPeriod
getNlTileTifLclNamePathVIIRS

Constructs the full path used to save/access the decompressed VIIRS .tif file
getNlTileTifLclNameVIIRS

Constructs the filename of the decompressed VIIRS .tif file
getNlTileZipLclNameVIIRS

Constructs the filename used to save/access the downloaded VIIRS tile .tgz file
getNlTiles

Create mapping of nightlight tiles
listCtryNlRasters

List available cropped country rasters
listNlTiles

List locally cached tiles
processNlData

Downloads nightlight tiles and country polygons and calls the function to process them
removeDataPath

Deletes a root data path all sub-directories
validNlMonthNum

Check if a month number is valid for a given nightlight type
validNlPeriod

Check if an nlPeriod is valid for a given nightlight type
validNlYearNum

Check if a year is valid for a given nightlight type
validStat

Check if a statistic given is valid