This repository provides an R tutorial for querying and processing NASA's Black Marble data, designed to be generalizable and intuitive. The tutorial demonstrates how to download, process, and visualize nighttime light data using various R packages.
Black Marble data represents the Earth's surface and atmosphere visible light emissions at night, captured by the Visible Infrared Imaging Radiometer Suite (VIIRS) Day/Night Band (DNB). This data is valuable for applications in urbanization studies, disaster response, and socioeconomic research.
Ensure that you have R and RStudio installed on your system.
You need a NASA Earthdata account to access Black Marble data. Follow these steps to obtain your bearer token:
- Create an Earthdata Account: Register at NASA Earthdata if you don't have an account.
- Generate a Bearer Token:
- Log in to your Earthdata account.
- Navigate to LAADS DAAC.
- Click on "Create App Token" and follow the instructions.
- Copy the generated bearer token.
Install the following R packages:
install.packages(c("sf", "terra", "tmap", "blackmarbler", "raster", "exactextractr", "lubridate", "geodata", "tidyverse"))
- Clone this repository:
git clone https://github.com/yourusername/black-marble-r-tutorial.git
- Open the R script in RStudio.
- Replace the bearer token placeholder with your actual token.
- Run the script step by step or source it entirely.
The script includes the following main steps:
- Clearing the workspace
- Setting the bearer token
- Defining the Region of Interest (ROI)
- Downloading Black Marble Data
- Data Processing
- Imputing Missing Values
- Transforming the ROI
- Extracting and Summarizing Data
- Visualization
For detailed code explanations, please refer to the comments in the R script.
- The script uses Sydney, Australia as an example ROI. You can modify this to suit your research needs.
- Data quality flags are used to remove bad quality observations.
- Linear interpolation is applied to handle missing values in the raster data.
Yohan Iddawela
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
If you encounter any problems or have suggestions, please open an issue in this repository.