Giter VIP home page Giter VIP logo

nightlights's Introduction

nightlights

An R package to extract NOAA night lights data for regions within shapefiles (a SpatialPolygons or SpatialPolygonsDataFrame). The night lights data can be downloaded from here or using the function downloadNightLights() in the package. Alternatively, a download script is provided to download and extract all the data (see below).

Data

Installation

if (!require(devtools)) install.packages("devtools")
devtools::install_github("walshc/nightlights")

Usage

require(nightlights)

# Download, extract and load and example shapefile to work with (US counties):
download.file("ftp://ftp2.census.gov/geo/tiger/TIGER2015/COUSUB/tl_2015_25_cousub.zip",
              destfile = "tl_2015_25_cousub.zip")
unzip("tl_2015_25_cousub.zip")
shp <- rgdal::readOGR(".", "tl_2015_25_cousub")

# Download and extract some night lights data to a directory "night-lights":
downloadNightLights(years = 1999:2000, directory = "night-lights")

# By default, the function gets the sum of night lights within the regions:
nl.sums <- extractNightLights(directory = "night-lights", shp)

# You can specificy other statistics to get, e.g. the mean & standard deviation:
nl.mean.sd <- extractNightLights(directory = "night-lights", shp,
                                 stats = c("mean", "sd"))

Example output

If the night lights directory contains the data for years 1999 and 2000 and stats = "sum":

           GEOID       NAME night.lights.1999.sum night.lights.2000.sum
    0 2502328285    Hanover                3613.0                3587.0
    1 2502338855 Marshfield                5726.5                5253.5
    2 2502350145    Norwell                4494.0                4268.5
    3 2502372985    Wareham                5625.5                5338.0
    4 2500300975     Alford                 324.5                 409.0
    5 2500334970      Lenox                2339.5                2661.0

Script to download and extract all the data

Instead of downloading all the data using the downloadNightLights() function, I also provide a script (download-and-extract-lights-data.sh) which should work in the terminal on OS X and Linux. The script will ask which directory you want to save the night lights data to. Keep in mind the full data set is very large so you will need about 50GB of space to do this. You can choose to save it to an external drive if you wish. Paste the following command into the terminal to get it started:

curl https://raw.githubusercontent.com/walshc/nightlights/master/download-and-extract-lights-data.sh | bash

nightlights's People

Contributors

walshc avatar

Watchers

Priyanka deSouza avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.