Learn R Programming

Rnightlights (version 0.2.4)

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

48

Version

0.2.4

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Christopher Njuguna

Last Published

August 29th, 2019

Functions in Rnightlights (0.2.4)

addREADME

Add README file to the root data path
allExistsCtryNlData

Checks if all data is available
allValidNlPeriods

Check if all nlPeriods are valid for given nlTypes
ZonalPipe

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

Checks if all given character strings are valid nlTypes
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 admin level data read from the polygon
addCtryPolyIdx

Add an index column to all layers of a polygon
allValidCtryCodes

Check if all ctryCodes are valid
dnldCtryPoly

createNlTilesSpPolysDF

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

ctryShpLyrName2Num

Get the integer number of the layer.
ctryNameToCode

Convert country names to ISO3 codes
deleteCtryPoly

existsPolyFnamePath

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

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

Check if the decompressed country polygon has been stored as RDS
downloadNlTiles

Download the listed tiles for a given nlType in a given nlPeriod
.RnightlightsEnv

A package-wide hidden environment
dnldGADMCtrySpRds

existsPolyFnameZip

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

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

Calculate the RAM to provide to the package for gdal calculations
getCtryNlDataFnamePath

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

Calculate zonal statistics using GDAL
exploreData

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

Construct the name of the country data file.
getAllNlConfigNames

Generate a list of all possible configNames for a given nlType
getAllNlCtryCodes

Get all known valid ISO3 country codes
downloadNlTilesOLS

Download OLS nightlight tile
allValidCtryAdmLvls

Checks if all ctry admLevels are valid
getCRS

Specify the wgs84 CRS globally
getAllGadmVersions

Return a vector of GADM versions
getCtryNlDataColName

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

Return a vector of GADM polyTypes
getCtryNlData

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

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

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

Get the paths to the various data locations
getNlTileZipLclNameOLS

The name with which to save the OLS tile locally
getNlDataPath

Gets the root path to the file directory"
getNlTileTifLclNameOLS

Constructs the filename of the decompressed OLS .tif file
getCtryShpLowestLyrNames

Get the name of the lowest ctry admin level
getCtryShpAllAdmLvls

Get all the admLevels in a country
orderCustPolyLayers

Order polygon shapefile layers in custom polygons
newNlType

Convert pre-0.2.0 nlType names to their new names
myfun

Function to test the use of rowcols and lonlats in getCtryNlData
ctryCodeToName

Convert a country ISO3 code to the full name
getNlUrlVIIRS

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

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

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

Calculate zonal statistics. Used internally
pkgDefaults

Retrieve default global options for the Rnightlights package
validCtryAdmLvls

Checks if ctry admLevels are valid
removeDataPath

Deletes a root data path all sub-directories
upgradeRnightlights

Perform upgrade functions to new package versions as required
saveCtryNlData

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

Check whether GADM versions are valid
validGadmPolyTypes

Check whether GADM polyTypes are valid
processNlData

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

Processes nightlights for an individual country in a particular nlPeriod
getPolyFnameZip

mapCtryPolyToTilesVIIRS

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

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

Extract raster pixel values within the boundaries of a polygon
downloadNlTilesVIIRS

Download VIIRS nightlight tile
existsCtryNlData

Check if VIIRS nightlight stats exist locally
createCtryStruct

Save ctry admin structure to text file for faster access
getCtryStructFnamePath

Construct the full path to the country struct file
getCtryPolyAdmLevelNames

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

Lists supported nightlight types
getAllNlPeriods

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

Construct the name for the country struct file
getCtryPolyUrl

Get the GADM url from which to download country polygons
getNlTileTifLclNamePathVIIRS

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

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

Format credits to print to the console
listNlTiles

List locally cached tiles
getPolyFnamePath

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

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

Create a range of nlPeriods
getPolyFnameRDS

getNlTileTifLclNameVIIRS

Constructs the filename of the decompressed VIIRS .tif file
nlCleanup

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

Sets the root path to the package data directory
setDataVersion

Add data version file to the root data path
readCtryPolyAdmLayer

Read a country admLevel polygon
validNlTileNumVIIRS

Check valid tile number for a given VIIRS nightlight type
validNlConfigName

Check if a configName is valid for a given nlType
validNlPeriods

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

Checks if a given character string is a valid nlType
readCtryStruct

Reads the ctry admin structure from struct text file
validCtryCodes

Check if country codes are valid
createNlDataDirs

Create required data subdirectories in the root data path
getCtryStructAdmLevelNames

Get the list of admin level names from a ctryStruct file
existsCtryPoly

Checks if a country polygon exists
getCtryRasterOutputFnamePath

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

Constructs the name of the output raster
existsCtryNlDataFile

Check if a country admin level data file exists
getCtryShpLyrNames

Get the standard names of polygon layers in a country
getNlTileZipLclNameVIIRS

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

Create mapping of nightlight tiles
getWorldMap

Make the rworldmap available for other functions
getCtryTileList

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

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

Detect the amount of available RAM on the computer
listCtryNlRasters

List available cropped country rasters
insertNlDataCol

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

List available data
setupDataPath

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

Get the index of a tile given its name
tileIdx2Name

Get the name of a tile given its index
tilesPolygonIntersectVIIRS

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

Function to return the url of the tile to download
getNlTileTifLclNamePathOLS

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

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

Reset global options for the Rnightlights package
pkgOptions

Set or get options for the Rnightlights package
searchAdmLevel

Search for the admLevel by official name
searchCountry

Search for a country by name or code
validCtryNlDataDF

Check if a country dataframe is valid
validNlTileNameVIIRS

Check valid VIIRS nightlight tile name
validNlStats

Check if given statistics are valid