README.md

nightlightstats

This package was built using the code of the paper "The Elusive Banker. Using Hurricanes to Uncover (Non-)Activity in Offshore Financial Centers" by Jakob Miethe but while that paper only focuses on small island economies, this package allows constructing nighttime light statistics for most geospatial units on the planet, which is hopefully useful for researchers in other areas. Calculations using nighttime lights can be performed via the function nightlight_calculate. Plots of nighttime lights can be created with nightlight_plot.

To install the package, run devtools::install_github("JakobMie/nightlightstats").

You can either work with yearly DMSP data ranging from 1992 to 2013 (https://www.ngdc.noaa.gov/eog/dmsp/downloadV4composites.html - Image and data processing by NOAA's National Geophysical Data Center, DMSP data collected by US Air Force Weather Agency) or monthly VIIRS data beginning in April 2012 (https://eogdata.mines.edu/products/vnl/ - Earth Observation Group, Payne Institute for Public Policy, Elvidge et al., 2013). Yearly VIIRS data are available at https://eogdata.mines.edu/nighttime_light/annual/v20/. At the moment, the package does not process these data. The package uses administrative boundary shapefiles from GADM (https://gadm.org/data.html).

If you experience trouble with the calculation capacities of your computer because a region you want to investigate is too large, you can take a look at the auxiliary function slice_shapefile which cuts a region into smaller pieces.

nightlight_calculate

This function allows to perform calculations using nighttime lights of a set of areas in a given time span. The output will be an aggregated dataframe in your environment, or if desired an additional dataframe for each area provided in area_names. To get these single dataframes, you can set the argument single_dataframes to TRUE.

For example, if you would like to get a dataframe for the DMSP nighttime lights in adm 1 regions of Luxembourg between 1992 and 1995, you can input:

nightlight_calculate(
area_names = "Luxembourg",
time = c("1992", "1995"),
shapefile_location = "D:/shapefiles",
light_location = "D:/nightlights",
admlevel = 1)

which will give you this dataframe called "lights" in the R environment:

The area in square kilometers will automatically be calculated based on your shapefiles or coordinates. NAME_1 indicates the names of the adm 1 regions of Luxembourg. "mean_obs" refers to the average number of observations per pixel that went into the aggregated image for a time period in a given area.

Default calculations are the sum of the light values and their average. Outliers can be identfied with the minimum and maximum light values. You can use any desired function for the calculations via the argument functions_calculate. The function has to accept an na.rm argument. In case it does not, you have to wrap the function accordingly. If encountering problems, check the documentation of raster::extract.

Other arguments in nightlight_calculate, for which you can consult the helpfiles for further details are:

nightlight_plot

This function allows to plot a shapefile with its nighttime lights for a given time span. Note: even though it is possible to produce multiple plots by using multiple inputs for area_names and a time span for time, you should pay attention to the number of plots that will be produced this way. All plots will be loaded into your global environment as ggplot objects. As an example, if you input:

nightlight_plot(
area_names = "Germany",
time = "1992",
shapefile_location = "D:/shapefiles",
light_location = "D:/nightlights",
admlevel = 1)

you get the following image:

In case you want to plot a region that is not available on GADM (i.e., a region that is not a country), you must have the downloaded shapefile in your shapefile_location, so the function can detect it according to the name you give in area_names. If this fails, there is always the option to use the shapefiles argument and provide the filenames of the shapefiles instead. This applies to nightlight_calculate as well.

In case you input a set of coordinates, you will get an image with a rectangular shapefile constructed from your coordinates.

nightlight_download

You can download DMSP nighttime light data with this function. As the Colorado School of Mines has changed the access to their VIIRS nighttime light data to require a free user account, you have to download the VIIRS data manually via their website.

The DMSP data are of lower resolution than the VIIRS data and take up less space (1 global DMSP image = 1/16 space of a global VIIRS image). Quality files (recognizable by the ending cf_cvg) show how many observations went into the value of a pixel in the aggregated nighttime light image in a given period.

Limitations, additional notes, and alternative data sources

References



JakobMie/nightlightstats documentation built on April 11, 2025, 11:04 p.m.