Title: | Black Marble Data and Statistics |
Version: | 0.2.4 |
Description: | Geographically referenced data and statistics of nighttime lights from NASA Black Marble https://blackmarble.gsfc.nasa.gov/. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.1 |
URL: | https://worldbank.github.io/blackmarbler/ |
BugReports: | https://github.com/worldbank/blackmarbler/issues |
Imports: | readr, dplyr, purrr, lubridate, tidyr, terra, sf, exactextractr, stringr, httr2 |
Suggests: | geodata, ggplot2, knitr, tidyterra, testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
NeedsCompilation: | no |
Packaged: | 2025-01-07 15:21:49 UTC; robmarty |
Author: | Robert Marty |
Maintainer: | Robert Marty <rmarty@worldbank.org> |
Repository: | CRAN |
Date/Publication: | 2025-01-07 15:50:05 UTC |
Extract and Aggregate Black Marble Data
Description
Extract and aggregate nighttime lights data from NASA Black Marble data
Usage
bm_extract(
roi_sf,
product_id,
date,
bearer,
aggregation_fun = c("mean"),
add_n_pixels = TRUE,
variable = NULL,
quality_flag_rm = NULL,
check_all_tiles_exist = TRUE,
interpol_na = FALSE,
output_location_type = "memory",
file_dir = NULL,
file_prefix = NULL,
file_skip_if_exists = TRUE,
file_return_null = FALSE,
h5_dir = NULL,
quiet = FALSE,
...
)
Arguments
roi_sf |
Region of interest; sf polygon. Must be in the WGS 84 (epsg:4326) coordinate reference system. |
product_id |
One of the following:
|
date |
Date of raster data. Entering one date will produce a
|
bearer |
NASA bearer token. For instructions on how to create a token, see here. |
aggregation_fun |
Function used to aggregate nighttime lights data to polygons; this values is passed to the |
add_n_pixels |
Whether to add a variable indicating the number of nighttime light pixels used to compute nighttime lights statistics (eg, number of pixels used to compute average of nighttime lights). When |
variable |
Variable to used to create raster (default:
|
quality_flag_rm |
Quality flag values to use to set values to For
For
|
check_all_tiles_exist |
Check whether all Black Marble nighttime light tiles exist for the region of interest. Sometimes not all tiles are available, so the full region of interest may not be covered. If |
interpol_na |
When data for more than one date is downloaded, whether to interpolate |
output_location_type |
Where to produce output; either |
file_dir |
(If |
file_prefix |
(If |
file_skip_if_exists |
(If |
file_return_null |
Whether to return |
h5_dir |
Black Marble data are originally downloaded as |
quiet |
Suppress output that show downloading progress and other messages. (Default: |
... |
Additional arguments for |
Value
Raster
Author(s)
Robert Marty rmarty@worldbank.org
Examples
## Not run:
# Define bearer token
bearer <- "BEARER-TOKEN-HERE"
# sf polygon of Ghana
library(geodata)
roi_sf <- gadm(country = "GHA", level=1, path = tempdir()) %>% st_as_sf()
# Daily data: raster for October 3, 2021
ken_20210205_r <- bm_extract(roi_sf = roi_sf,
product_id = "VNP46A2",
date = "2021-10-03",
bearer = bearer)
# Monthly data: raster for March 2021
ken_202103_r <- bm_extract(roi_sf = roi_sf,
product_id = "VNP46A3",
date = "2021-03-01",
bearer = bearer)
# Annual data: raster for 2021
ken_2021_r <- bm_extract(roi_sf = roi_sf,
product_id = "VNP46A4",
date = 2021,
bearer = bearer)
## End(Not run)
Make Black Marble Raster
Description
Make a raster of nighttime lights from NASA Black Marble data
Usage
bm_raster(
roi_sf,
product_id,
date,
bearer,
variable = NULL,
quality_flag_rm = NULL,
check_all_tiles_exist = TRUE,
interpol_na = FALSE,
output_location_type = "memory",
file_dir = NULL,
file_prefix = NULL,
file_skip_if_exists = TRUE,
file_return_null = FALSE,
h5_dir = NULL,
quiet = FALSE,
...
)
Arguments
roi_sf |
Region of interest; sf polygon. Must be in the WGS 84 (epsg:4326) coordinate reference system. |
product_id |
One of the following:
|
date |
Date of raster data. Entering one date will produce a
|
bearer |
NASA bearer token. For instructions on how to create a token, see here. |
variable |
Variable to used to create raster (default:
|
quality_flag_rm |
Quality flag values to use to set values to For
For
|
check_all_tiles_exist |
Check whether all Black Marble nighttime light tiles exist for the region of interest. Sometimes not all tiles are available, so the full region of interest may not be covered. If |
interpol_na |
When data for more than one date is downloaded, whether to interpolate |
output_location_type |
Where to produce output; either |
file_dir |
The directory where data should be exported (default: |
file_prefix |
Prefix to add to the file to be saved. The file will be saved as the following: |
file_skip_if_exists |
Whether the function should first check wither the file already exists, and to skip downloading or extracting data if the data for that date if the file already exists (default: |
file_return_null |
Whether to return |
h5_dir |
Black Marble data are originally downloaded as |
quiet |
Suppress output that show downloading progress and other messages. (Default: |
... |
Additional arguments for |
Value
Raster
Author(s)
Robert Marty rmarty@worldbank.org
Examples
## Not run:
# Define bearer token
bearer <- "BEARER-TOKEN-HERE"
# sf polygon of Ghana
library(geodata)
roi_sf <- gadm(country = "GHA", level=0, path = tempdir()) %>% st_as_sf()
# Daily data: raster for October 3, 2021
ken_20210205_r <- bm_raster(roi_sf = roi_sf,
product_id = "VNP46A2",
date = "2021-10-03",
bearer = bearer)
# Monthly data: raster for March 2021
ken_202103_r <- bm_raster(roi_sf = roi_sf,
product_id = "VNP46A3",
date = "2021-03-01",
bearer = bearer)
# Annual data: raster for 2021
ken_2021_r <- bm_raster(roi_sf = roi_sf,
product_id = "VNP46A4",
date = 2021,
bearer = bearer)
## End(Not run)
Get a NASA Earthdata bearer token
Description
Fetch a NASA Earthdata bearer token from using the Earthdata API. If none exist, this will create one, or if one already exists it will fetch that one instead.
Usage
get_nasa_token(username, password)
Arguments
username |
character. NASA Earthdata username |
password |
character. NASA Earthdata password |
Value
character
Author(s)
Simon E. H. Smart simon.smart@cantab.net