Learn R Programming

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

Rnightlights (version 0.2.3)

Satellite Nightlight Data Extraction

Description

Extracts raster and zonal statistics from satellite nightlight rasters downloaded from the United States National Oceanic and Atmospheric Administration () 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 (). 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.

Copy Link

Version

Install

install.packages('Rnightlights')

Monthly Downloads

44

Version

0.2.3

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Christopher Njuguna

Last Published

October 13th, 2018

Functions in Rnightlights (0.2.3)

createCtryNlDataDF

Initiates the country nightlight dataframe with the country admin level data read from the polygon
ctryNameToCode

Convert country names to ISO3 codes
ctryShpLyrName2Num

Get the integer number of the layer.
ZonalPipe

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

Add an index column to all layers of a polygon
addREADME

Add README file to the root data path
allValid

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

Download OLS nightlight tile
downloadNlTilesVIIRS

Download VIIRS nightlight tile
existsCtryNlData

Check if VIIRS nightlight stats exist locally
getAllGadmVersions

Return a vector of GADM versions
existsCtryPoly

Checks if a country polygon exists
createNlTilesSpPolysDF

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

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

Constructs the name of the output raster
existsCtryNlDataFile

Check if a country admin level data file exists
getAllNlCtryCodes

Get all known valid ISO3 country codes
getCtryRasterOutputFnamePath

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

Check if all nlPeriods are valid for given nlTypes
allValidNlTypes

Checks if all given character strings are valid nlTypes
getCtryTileList

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

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

Get the standard names of polygon layers in a country
getNlTileTifLclNamePathOLS

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

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

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

List available cropped country rasters
getAllNlTypes

Lists supported nightlight types
getNlDataPath

Gets the root path to the file directory"
getCtryStructFname

Construct the name for the country struct file
getCtryStructFnamePath

Construct the full path to the country struct file
allValidCtryAdmLvls

Checks if all ctry admLevels are valid
deleteNlDataCol

Delete an aggregate nightlight data column in a country nightlights dataframe
getNlTileZipLclNamePath

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

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

Check if all ctryCodes are valid
getNlTiles

Create mapping of nightlight tiles
listNlTiles

List locally cached tiles
nlCleanup

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

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

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

Calculate zonal statistics using GDAL
dnldCtryPoly

nlInit

Initialize some important variables and create directory structure
getCtryNlDataColName

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

Get the paths to the various data locations
nlRange

Create a range of nlPeriods
orderCustPolyLayers

Order polygon shapefile layers in custom polygons
processNlData

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

Read a country admLevel polygon
fnAggRadRast

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

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

Check if country codes are valid
insertNlDataCol

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

Construct the name of the country data file.
getNlTileTifLclNameOLS

Constructs the filename of the decompressed OLS .tif file
myZonal

Calculate zonal statistics. Used internally
listCtryNlData

List available data
getNlTileTifLclNamePath

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

Construct the full path to save the file containing the country data
tileName2Idx

Get the index of a tile given its name
getCtryShpAllAdmLvls

Get all the admLevels in a country
getPolyFnameZip

newNlType

Convert pre-0.2.0 nlType names to their new names
getTilesCtryIntersectVIIRS

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

Set or get options for the Rnightlights package
downloadNlTiles

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

Reset global options for the Rnightlights package
masqOLS

Extract raster pixel values within the boundaries of a polygon
getCtryShpLowestLyrNames

Get the name of the lowest ctry admin level
tilesPolygonIntersectVIIRS

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

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

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

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

Check if a country dataframe is valid
saveCtryNlData

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

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

Search for the admLevel by official name
setupDataPath

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

Get the name of a tile given its index
getNlTileTifLclNameVIIRS

Constructs the filename of the decompressed VIIRS .tif file
getNlTileZipLclNameOLS

The name with which to save the OLS tile locally
validNlStats

Check if given statistics are valid
getNlUrlVIIRS

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

Check valid tile number for a given VIIRS nightlight type
validNlTypes

Checks if a given character string is a valid nlType
getPolyFname

Returns the directory name of the unzipped shapefile downloaded from http://gadm.org without the path
readCtryStruct

Reads the ctry admin structure from struct text file
validNlTileNameVIIRS

Check valid VIIRS nightlight tile name
validCtryAdmLvls

Checks if ctry admLevels are valid
upgradeRnightlights

Perform upgrade functions to new package versions as required
removeDataPath

Deletes a root data path all sub-directories
validGadmVersions

Check whether GADM versions are valid
validNlPeriods

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

Get the GADM url from which to download country polygons
getPolyFnamePath

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

mapAllCtryPolyToTilesVIIRS

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

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

Plot a country boundary with the VIIRS tiles and world map
processNLCountry

Processes nightlights for an individual country in a particular nlPeriod
searchCountry

Search for a country by name or code
setNlDataPath

Sets the root path to the package data directory
createCtryStruct

Save ctry admin structure to text file for faster access
createNlDataDirs

Create required data subdirectories in the root data path
ctryCodeToName

Convert a country ISO3 code to the full name