| Title: | Black Marble Data and Statistics |
|---|---|
| Description: | Geographically referenced data and statistics of nighttime lights from NASA Black Marble <https://blackmarble.gsfc.nasa.gov/>. |
| Authors: | Robert Marty [aut, cre] (ORCID: <https://orcid.org/0000-0002-3164-3813>), Gabriel Stefanini Vicente [aut] (ORCID: <https://orcid.org/0000-0001-6530-3780>) |
| Maintainer: | Robert Marty <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.2 |
| Built: | 2026-10-15 07:16:50 UTC |
| Source: | https://github.com/dar4datascience/blackmarbler |
This function calculates additional pixel information for the extracted data frames.
add_n_pixels(roi_df, bm_r, roi_sf, quiet)add_n_pixels(roi_df, bm_r, roi_sf, quiet)
roi_df |
Data frame containing extracted data. |
bm_r |
The raster data. |
roi_sf |
The spatial features representing the regions of interest. |
quiet |
Logical indicating whether to show progress messages. |
The input data frame with added columns for pixel information.
## Not run: # Adding pixel information to extracted data add_n_pixels(roi_df, bm_r, roi_sf, quiet = FALSE) ## End(Not run)## Not run: # Adding pixel information to extracted data add_n_pixels(roi_df, bm_r, roi_sf, quiet = FALSE) ## End(Not run)
Apply scaling factor to variables according to Black Marble user guide. The scaling factor is 0.1 for specific VIIRS variables.
apply_scaling_factor_to_viirs_data(x, variable, quiet = TRUE)apply_scaling_factor_to_viirs_data(x, variable, quiet = TRUE)
x |
A numeric vector or matrix representing the VIIRS data. |
variable |
A character string specifying the variable name. |
quiet |
Logical, if TRUE, suppresses warnings when the variable is not found in scaling variables. |
This function applies a scaling factor of 0.1 to specific VIIRS variables according to the Black Marble user guide.
The following VIIRS variables are affected:
DNB_At_Sensor_Radiance (VNP46A1)
DNB_BRDF-Corrected_NTL (VNP46A2)
Gap_Filled_DNB_BRDF-Corrected_NTL (VNP46A2)
DNB_Lunar_Irradiance (VNP46A2)
AllAngle_Composite_Snow_Covered (VNP46A3/4)
AllAngle_Composite_Snow_Covered_Std (VNP46A3/4)
AllAngle_Composite_Snow_Free (VNP46A3/4)
AllAngle_Composite_Snow_Free_Std (VNP46A3/4)
NearNadir_Composite_Snow_Covered (VNP46A3/4)
NearNadir_Composite_Snow_Covered_Std (VNP46A3/4)
NearNadir_Composite_Snow_Free (VNP46A3/4)
NearNadir_Composite_Snow_Free_Std (VNP46A3/4)
OffNadir_Composite_Snow_Covered (VNP46A3/4)
OffNadir_Composite_Snow_Covered_Std (VNP46A3/4)
OffNadir_Composite_Snow_Free (VNP46A3/4)
OffNadir_Composite_Snow_Free_Std (VNP46A3/4)
A numeric vector or matrix with the scaling factor applied to the specified variables.
Black Marble User Guide - https://viirsland.gsfc.nasa.gov/PDF/BlackMarbleUserGuide_v1.2_20220916.pdf
This function binds together the extracted data frames or a list of extracted data frames.
bind_extracted_data(extracted_data_list)bind_extracted_data(extracted_data_list)
extracted_data_list |
One or more extracted data frames or a list of extracted data frames. |
A single data frame containing the bound extracted data.
## Not run: # Binding extracted data frames bind_extracted_data(df1, df2) # Binding a list of extracted data frames bind_extracted_data(list_of_dfs) ## End(Not run)## Not run: # Binding extracted data frames bind_extracted_data(df1, df2) # Binding a list of extracted data frames bind_extracted_data(list_of_dfs) ## End(Not run)
Spatial dataset containing black marble tiles obtained from NASA's Black Marble project.
black_marble_tiles_sfblack_marble_tiles_sf
A spatial dataframe (sf) with 648 rows and 2 columns:
Identification of the tile associated with the VIIRS satellites mapping.
Spatial geometry representing the tile boundaries.
https://blackmarble.gsfc.nasa.gov/
The dataset is obtained from the Black Marble project by NASA, specifically the VIIRS (Visible Infrared Imaging Radiometer Suite) satellites. The TileID column represents the identification of the tile associated with the VIIRS satellites mapping. For more details on the dataset and its characteristics, refer to the Black Marble User Guide: https://viirsland.gsfc.nasa.gov/PDF/BlackMarbleUserGuide_v1.2_20220916.pdf
Tan, Bin, et al. "Night-time light imagery analysis for urban population mapping in China." International Journal of Remote Sensing 27.9 (2006): 1943-1950.
Wolfe, Robert E., et al. "Achieving accuracy requirements for forest biomass mapping: A data fusion method for combining the strengths of spaceborne lidar and Landsat TM data." Remote Sensing of Environment 80.2 (2002): 253-267.
https://viirsland.gsfc.nasa.gov/PDF/BlackMarbleUserGuide_v1.2_20220916.pdf
head(black_marble_tiles_sf)head(black_marble_tiles_sf)
This function extracts and processes raster data for individual dates.
bm_extract( roi_sf, product_id, date, bearer, aggregation_fun = c("mean"), add_n_pixels = TRUE, variable = NULL, quality_flags_to_remove = NULL, check_all_tiles_exist = TRUE, interpol_na = FALSE, output_location_type = "memory", file_dir = NULL, file_prefix = NULL, file_skip_if_exists = TRUE, quiet = FALSE, ... )bm_extract( roi_sf, product_id, date, bearer, aggregation_fun = c("mean"), add_n_pixels = TRUE, variable = NULL, quality_flags_to_remove = NULL, check_all_tiles_exist = TRUE, interpol_na = FALSE, output_location_type = "memory", file_dir = NULL, file_prefix = NULL, file_skip_if_exists = TRUE, quiet = FALSE, ... )
roi_sf |
The spatial features representing the regions of interest. |
product_id |
The product ID. |
date |
The date. |
bearer |
The bearer. |
aggregation_fun |
The function to aggregate data. |
add_n_pixels |
Logical indicating whether to compute additional pixel information. |
variable |
The variable. |
quality_flags_to_remove |
The quality flags to remove. |
check_all_tiles_exist |
Logical indicating whether to check if all tiles exist. |
interpol_na |
Logical indicating whether to interpolate missing values. |
output_location_type |
The type of output location. |
file_dir |
The directory to save files. |
file_prefix |
The prefix for file names. |
file_skip_if_exists |
Logical indicating whether to skip saving if files exist. |
quiet |
Logical indicating whether to suppress messages. |
... |
Additional arguments passed to helper functions. |
A data frame containing the extracted and processed raster data.
## Not run: bm_extract(roi_sf = my_roi_sf, product_id = "my_product", date = "2024-04-02", bearer = "my_bearer") ## End(Not run)## Not run: bm_extract(roi_sf = my_roi_sf, product_id = "my_product", date = "2024-04-02", bearer = "my_bearer") ## End(Not run)
Extract and aggregate nighttime lights data from NASA Black Marble data.
bm_raster( roi_sf, product_id, date, bearer, variable = NULL, quality_flags_to_remove = NULL, check_all_tiles_exist = TRUE, interpol_na = FALSE, output_location_type = "memory", file_dir = NULL, file_prefix = NULL, file_skip_if_exists = TRUE, quiet = FALSE, ... )bm_raster( roi_sf, product_id, date, bearer, variable = NULL, quality_flags_to_remove = NULL, check_all_tiles_exist = TRUE, interpol_na = FALSE, output_location_type = "memory", file_dir = NULL, file_prefix = NULL, file_skip_if_exists = TRUE, quiet = FALSE, ... )
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 raster. Entering multiple dates will produce a raster stack.
|
bearer |
NASA bearer token. For instructions on how to create a token, see here. |
variable |
Variable to used to create raster (default: NULL). If NULL, uses the following default variables:
|
quality_flags_to_remove |
Quality flag values to use to set values to NA. Each pixel has a quality flag value, where low quality values can be removed. Values are set to NA for each value in ther quality_flag_rm vector. (Default: NULL). For VNP46A1 and VNP46A2 (daily data):
For VNP46A3 and VNP46A4 (monthly and annual data):
|
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 TRUE, skips cases where not all tiles are available. (Default: TRUE). |
interpol_na |
When data for more than one date is downloaded, whether to interpolate NA values in rasters using the raster::approxNA function. Additional arguments for the raster::approxNA function can also be passed into bm_extract (eg, method, rule, f, ties, z, NA_rule). (Default: FALSE). |
output_location_type |
Where to produce output; either memory or file. If memory, functions returns a dataframe in R. If file, function exports a .csv file and returns NULL. |
file_dir |
(If output_location_type = file). The directory where data should be exported (default: NULL, so the working directory will be used) |
file_prefix |
(If output_location_type = file). Prefix to add to the file to be saved. The file will be saved as the following: file_prefix_tdate.csv |
file_skip_if_exists |
(If output_location_type = file). 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: TRUE). |
quiet |
Suppress output that show downloading progress and other messages. (Default: FALSE). |
... |
Additional arguments for raster::approxNA, if interpol_na = TRUE |
Raster
## 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_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)## 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_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)
This function cleans raster data by removing fill values and applying scaling factors.
clean_raster_data(raster_obj, variable_name)clean_raster_data(raster_obj, variable_name)
raster_obj |
The raster object to be cleaned. |
variable_name |
A character string specifying the variable name. |
This function removes fill values and applies scaling factors to the specified variable in the raster object.
A cleaned raster object.
remove_fill_value_from_satellite_data, apply_scaling_factor_to_viirs_data
Converts an HDF5 file to a raster object.
convert_h5_to_raster( download_path, blackmarble_variable, quality_flags_to_remove = numeric() )convert_h5_to_raster( download_path, blackmarble_variable, quality_flags_to_remove = numeric() )
download_path |
A character string representing the download path to the HDF5 file. |
blackmarble_variable |
A character string specifying the blackmarble_variable name to extract from the HDF5 file. |
quality_flags_to_remove |
A numeric vector containing quality flag values to be removed from the data (optional). |
This function converts an HDF5 file to a raster object. It extracts the specified variable from the HDF5 file and optionally removes specific quality flag values from the data.
A raster object containing the extracted variable data from the HDF5 file.
Black Marble User Guide - https://viirsland.gsfc.nasa.gov/PDF/BlackMarbleUserGuide_v1.2_20220916.pdf
Counts observations for each variable, considering coverage fraction, for use in exact_extract.
count_n_obs(values)count_n_obs(values)
values |
A data frame containing the values. |
This function counts observations for each variable in the provided data frame, considering coverage fraction, for use in exact_extract. It calculates the number of non-NA pixels and total pixels for each variable. The coverage_fraction parameter is included in the function's signature but currently not used in the calculation.
A data frame with the count of non-NA pixels and total pixels for each variable.
Creates a data frame containing Black Marble dataset filenames based on the specified parameters.
create_black_marble_dataset_df( product_id, all = TRUE, years = NULL, months = NULL, days = NULL )create_black_marble_dataset_df( product_id, all = TRUE, years = NULL, months = NULL, days = NULL )
product_id |
The product ID specifying the type of Black Marble data. |
all |
Logical; indicating whether to create filenames for all available data or only for specific years, months, or days (default: TRUE). |
years |
A numeric vector specifying the years for which to create filenames (optional). |
months |
A numeric vector specifying the months for which to create filenames (optional). |
days |
A numeric vector specifying the days for which to create filenames (optional). |
This function generates a data frame with filenames of Black Marble datasets. It allows filtering
by year, month, and day based on the provided parameters. Depending on the product_id, it generates
filenames for daily, monthly, or yearly data. The generated filenames are based on the specified product ID,
year, and day or month. The resulting data frame includes columns for the year and day or month, depending on the
type of data.
A data frame containing the filenames of Black Marble datasets based on the specified parameters.
## Not run: # Generate filenames for all available Black Marble data all_data <- create_black_marble_dataset_df("VNP46A1") # Generate filenames for Black Marble data for specific years and months specific_data <- create_black_marble_dataset_df("VNP46A2", years = c(2018, 2019), months = 1:6) ## End(Not run)## Not run: # Generate filenames for all available Black Marble data all_data <- create_black_marble_dataset_df("VNP46A1") # Generate filenames for Black Marble data for specific years and months specific_data <- create_black_marble_dataset_df("VNP46A2", years = c(2018, 2019), months = 1:6) ## End(Not run)
This function creates a raster object from the provided data and metadata using the terra package.
create_raster_from_data_metadata(data, metadata)create_raster_from_data_metadata(data, metadata)
data |
The data matrix for the raster. |
metadata |
A list containing metadata information including nodata value, bounding box coordinates, and coordinate reference system (CRS). |
This function transposes the input data, assigns nodata values to NA, creates an extent class from bounding box coordinates, and finally creates a raster object with the given data, extent, and CRS.
A raster object created from the input data and metadata.
This function prints an information message if quiet is set to FALSE.
custom_inform(message, quiet = FALSE)custom_inform(message, quiet = FALSE)
message |
The message to be printed. |
quiet |
Logical indicating whether to suppress printing the message. Default is FALSE. |
## Not run: custom_inform("This is an information message.", quiet = FALSE) custom_inform("This message will not be printed.", quiet = TRUE) ## End(Not run)## Not run: custom_inform("This is an information message.", quiet = FALSE) custom_inform("This message will not be printed.", quiet = TRUE) ## End(Not run)
Defines the variable based on the Black Marble product ID if it is NULL.
define_blackmarble_variable(variable, product_id)define_blackmarble_variable(variable, product_id)
variable |
A character string specifying the variable to define. |
product_id |
A character string representing the product ID. |
This function defines the variable based on the provided Black Marble product ID if the variable is NULL. It checks if the product ID is valid and then assigns a default variable based on the product ID if the variable is NULL. The default variables for each product ID are as follows:
VNP46A1: "DNB_At_Sensor_Radiance_500m"
VNP46A2: "Gap_Filled_DNB_BRDF-Corrected_NTL"
VNP46A3 and VNP46A4: "NearNadir_Composite_Snow_Free"
A character string representing the defined variable.
Generates a name for the raster based on the given date and product ID.
define_raster_name(date_string, product_id)define_raster_name(date_string, product_id)
date_string |
A character string representing the date in the format "YYYY-MM-DD". |
product_id |
A character string representing the product ID (e.g., "VNP46A1", "VNP46A2"). |
This function generates a name for the raster based on the provided date and product ID. The raster name format depends on the product ID as follows:
For VNP46A1: The raster name is simply the product ID.
For VNP46A2: The raster name starts with "t" followed by the date string with hyphens replaced by underscores.
For VNP46A3: The raster name starts with "t" followed by the year and month extracted from the date string.
For VNP46A4: The raster name starts with "t" followed by the year extracted from the date string.
A character string representing the generated raster name.
Downloads raster data from NASA's LADSWeb and converts it to a raster object.
download_and_convert_raster( file_name, temp_dir, blackmarble_variable, bearer, quality_flags_to_remove = numeric(), quiet = FALSE )download_and_convert_raster( file_name, temp_dir, blackmarble_variable, bearer, quality_flags_to_remove = numeric(), quiet = FALSE )
file_name |
A character string representing the name of the file to download. |
temp_dir |
A character string specifying the temporary directory where the file will be saved. |
blackmarble_variable |
A character string specifying the variable to extract from the raster data. |
bearer |
A character string containing the authorization token for accessing NASA's LADSWeb. |
quality_flags_to_remove |
A numeric vector containing quality flag values to be removed from the data (optional). |
quiet |
Logical; indicating whether to suppress progress messages (default: FALSE). |
This function downloads raster data from NASA's LADSWeb based on the provided file name. It then converts the downloaded data to a raster object, extracting the specified variable and removing quality flag values if specified. The function also provides an option to suppress progress messages.
A raster object containing the downloaded and processed raster data.
Black Marble User Guide - https://viirsland.gsfc.nasa.gov/PDF/BlackMarbleUserGuide_v1.2_20220916.pdf
Downloads a VIIRS satellite image in HDF5 format from NASA's LADSWeb and saves it to a temporary directory or persistent location.
download_h5_viirs_sat_image( file_name, download_path, bearer, quality_flags_to_remove = numeric(), quiet = FALSE )download_h5_viirs_sat_image( file_name, download_path, bearer, quality_flags_to_remove = numeric(), quiet = FALSE )
file_name |
A character string representing the name of the file to download. |
download_path |
A character string representing the path to save the downloaded file. |
bearer |
A character string containing the authorization token for accessing NASA's LADSWeb. |
quality_flags_to_remove |
A numeric vector containing quality flag values to be removed from the data (optional). |
quiet |
Logical; indicating whether to suppress progress messages (default: FALSE). |
This function downloads a VIIRS satellite image in HDF5 format from NASA's LADSWeb based on the provided file name. It then processes the downloaded data, removing quality flag values if specified. The function also provides an option to suppress progress messages.
Black Marble User Guide - https://viirsland.gsfc.nasa.gov/PDF/BlackMarbleUserGuide_v1.2_20220916.pdf
This function extracts and processes raster data either for a single raster or for multiple rasters.
extract_and_process( bm_r, roi_sf, fun, add_n_pixels = TRUE, quiet = FALSE, is_single = FALSE )extract_and_process( bm_r, roi_sf, fun, add_n_pixels = TRUE, quiet = FALSE, is_single = FALSE )
bm_r |
The raster data. |
roi_sf |
The spatial features representing the regions of interest. |
fun |
The function to apply to the raster data for extraction and processing. |
add_n_pixels |
Logical indicating whether to compute additional pixel information. |
quiet |
Logical indicating whether to show progress messages. |
is_single |
Logical indicating whether a single raster is being processed. Default is |
This function extracts raster data from the specified regions of interest (roi_sf) and processes it using the specified function (fun). It can handle both single raster and multiple raster inputs.
A data frame containing the extracted and processed raster data.
## Not run: # For a single raster extract_and_process(raster = my_raster, roi_sf = my_roi_sf, fun = mean, is_single = TRUE, add_n_pixels = TRUE, quiet = FALSE) # For multiple rasters extract_and_process(raster = my_raster, roi_sf = my_roi_sf, fun = mean) ## End(Not run)## Not run: # For a single raster extract_and_process(raster = my_raster, roi_sf = my_roi_sf, fun = mean, is_single = TRUE, add_n_pixels = TRUE, quiet = FALSE) # For multiple rasters extract_and_process(raster = my_raster, roi_sf = my_roi_sf, fun = mean) ## End(Not run)
This code snippet extracts the bounding box coordinates (minimum longitude, minimum latitude, maximum longitude, maximum latitude)
based on the tile ID extracted from the file path. It uses the file_path to extract the tile ID, then retrieves the corresponding
grid from the black_marble_tiles_sf dataset. Finally, it calculates the bounding box of the grid and rounds the coordinates.
extract_bounding_box(file_path, black_marble_tiles_sf)extract_bounding_box(file_path, black_marble_tiles_sf)
file_path |
A character string specifying the file path. |
black_marble_tiles_sf |
The spatial dataset containing the grid tiles information. |
A list containing the minimum and maximum longitude and latitude coordinates of the bounding box.
This function extracts daily data from an HDF5 file based on the provided file path and variable name.
extract_daily_data( download_file_path, h5_data, blackmarble_variable, quality_flags_to_remove )extract_daily_data( download_file_path, h5_data, blackmarble_variable, quality_flags_to_remove )
download_file_path |
A character string specifying the file path. |
h5_data |
The HDF5 file data. |
blackmarble_variable |
A character string specifying the variable name. |
quality_flags_to_remove |
A numeric vector containing quality flag values to be removed from the data. |
This function extracts daily data from an HDF5 file for the specified variable. It retrieves the data and applies quality flag removal if specified. Additionally, it calculates the bounding box coordinates based on the tile ID extracted from the file path.
A list containing the extracted data and metadata.
Black Marble User Guide - https://viirsland.gsfc.nasa.gov/PDF/BlackMarbleUserGuide_v1.2_20220916.pdf
This function extracts data and metadata from an HDF5 file.
extract_data_and_metadata_from_hdf5( h5_data, download_path, blackmarble_variable, quality_flags_to_remove )extract_data_and_metadata_from_hdf5( h5_data, download_path, blackmarble_variable, quality_flags_to_remove )
h5_data |
The HDF5 file data. |
download_path |
A character string specifying the path to the downloaded file. |
blackmarble_variable |
A character string specifying the variable name. |
quality_flags_to_remove |
A numeric vector containing quality flag values to be removed from the data. |
This function extracts data and metadata from an HDF5 file based on the specified file path and variable name.
Depending on the file path pattern (daily or monthly/annually), it calls different functions to extract the data.
Quality flag values specified in quality_flags_to_remove are removed from the data.
A list containing the extracted data and metadata.
Black Marble User Guide - https://viirsland.gsfc.nasa.gov/PDF/BlackMarbleUserGuide_v1.2_20220916.pdf
This function extracts monthly data from an HDF5 file.
extract_monthly_data( download_file_path, h5_data, blackmarble_variable, quality_flags_to_remove )extract_monthly_data( download_file_path, h5_data, blackmarble_variable, quality_flags_to_remove )
download_file_path |
Path to the downloaded HDF5 file. |
h5_data |
The HDF5 data. |
blackmarble_variable |
The variable to extract from the HDF5 data. |
quality_flags_to_remove |
Quality flag values to set to NA. |
A list containing the extracted data and bounding box coordinates.
## Not run: # Extract monthly data data <- extract_monthly_data(download_file_path, h5_data, blackmarble_variable, quality_flags_to_remove) ## End(Not run)## Not run: # Extract monthly data data <- extract_monthly_data(download_file_path, h5_data, blackmarble_variable, quality_flags_to_remove) ## End(Not run)
This function intersects Black Marble tiles with a region of interest, removing grid along edges to avoid issues with st_intersects.
intersect_bm_tiles(black_marble_tiles_sf, roi_sf)intersect_bm_tiles(black_marble_tiles_sf, roi_sf)
black_marble_tiles_sf |
Spatial object representing Black Marble tiles. |
roi_sf |
Spatial object representing the region of interest. |
Spatial object containing Black Marble tiles intersecting with the region of interest.
## Not run: # Load required libraries library(sf) # Create example data black_marble_tiles_sf <- st_read("path_to_black_marble_tiles_shapefile") roi_sf <- st_read("path_to_roi_shapefile") # Intersect Black Marble tiles with region of interest intersected_tiles <- intersect_bm_tiles(black_marble_tiles_sf, roi_sf) ## End(Not run)## Not run: # Load required libraries library(sf) # Create example data black_marble_tiles_sf <- st_read("path_to_black_marble_tiles_shapefile") roi_sf <- st_read("path_to_roi_shapefile") # Intersect Black Marble tiles with region of interest intersected_tiles <- intersect_bm_tiles(black_marble_tiles_sf, roi_sf) ## End(Not run)
This function translates Julian dates to regular month representations.
julian_to_month(julian_date)julian_to_month(julian_date)
julian_date |
A character string representing the day of the year in Julian format (e.g., "001" for January 1st). |
A number representing the month corresponding to the given Julian date (e.g., 1 for January).
For more information on the Julian day system, see: https://en.wikipedia.org/wiki/Julian_day
## Not run: julian_to_month("001") # [1] 1 julian_to_month("032") # [1] 2 ## End(Not run)## Not run: julian_to_month("001") # [1] 1 julian_to_month("032") # [1] 2 ## End(Not run)
Generate an interactive map displaying black marble tiles using Leaflet.
map_black_marble_tiles()map_black_marble_tiles()
This function requires the leaflet package for generating interactive maps.
This function generates an interactive map displaying black marble tiles obtained from NASA's Black Marble project using the Leaflet library. The map includes black marble tiles overlaid on a base map, with a marker indicating the center coordinates (latitude and longitude).
An interactive Leaflet map object.
## Not run: library(leaflet) # Generate the map map_black_marble_tiles() ## End(Not run)## Not run: library(leaflet) # Generate the map map_black_marble_tiles() ## End(Not run)
Processes satellite imagery tiles based on specified parameters.
process_tiles( bm_files_df, grid_use_sf, check_all_tiles_exist, temp_dir, product_id, blackmarble_variable, bearer, quality_flags_to_remove, quiet )process_tiles( bm_files_df, grid_use_sf, check_all_tiles_exist, temp_dir, product_id, blackmarble_variable, bearer, quality_flags_to_remove, quiet )
bm_files_df |
A data frame containing Black Marble dataset filenames. |
grid_use_sf |
A spatial grid containing TileIDs. |
check_all_tiles_exist |
Logical; indicating whether to check if all tiles exist (default: TRUE). |
temp_dir |
A character string specifying the temporary directory. |
product_id |
A character string representing the product ID. |
blackmarble_variable |
A character string specifying the Black Marble variable. |
bearer |
A character string containing the authorization token for accessing NASA's LADSWeb. |
quality_flags_to_remove |
A numeric vector containing quality flag values to be removed from the data (optional). |
quiet |
Logical; indicating whether to suppress progress messages (default: FALSE). |
A raster object processed from satellite imagery tiles.
Reads Black Marble CSV data for a specific year and day.
read_black_marble_csv(year, day, product_id)read_black_marble_csv(year, day, product_id)
year |
The year of the data. |
day |
The day of the year (1-365 or 1-366 for leap years). |
product_id |
The product ID specifying the type of data to retrieve. |
This function reads Black Marble CSV data from the NASA LADS website for the given year,
day, and product_id. It constructs the URL based on the provided parameters and attempts
to read the CSV file using readr::read_csv. If successful, it adds columns for year and day
to the data frame. If an error occurs during the reading process, it returns an empty data frame and issues a warning.
Additionally, to avoid overloading the server with rapid requests, the function includes a small delay (0.1 seconds) between
consecutive requests using Sys.sleep(0.1).
A data frame containing the Black Marble CSV data for the specified year and day.
## Not run: # Read Black Marble CSV data for the year 2023, day 150, and product ID "VIIRS_SNPP_CorrectedReflectance_BandM3" data <- read_black_marble_csv(2023, 150, "VIIRS_SNPP_CorrectedReflectance_BandM3") ## End(Not run)## Not run: # Read Black Marble CSV data for the year 2023, day 150, and product ID "VIIRS_SNPP_CorrectedReflectance_BandM3" data <- read_black_marble_csv(2023, 150, "VIIRS_SNPP_CorrectedReflectance_BandM3") ## End(Not run)
This function removes artifact values from satellite data, replacing them with NA. Artifact values are commonly used in satellite data to represent fill values, invalid measurements, or missing data.
remove_fill_value_from_satellite_data(data, blackmarble_variable)remove_fill_value_from_satellite_data(data, blackmarble_variable)
data |
A matrix or data frame containing satellite data. |
blackmarble_variable |
A character string specifying the blackmarble_variable for which artifact values should be removed. |
The artifact values and their corresponding blackmarble_variables are based on the data format described in the Black Marble User Guide (https://viirsland.gsfc.nasa.gov/PDF/BlackMarbleUserGuide_v1.2_20220916.pdf).
The input data with artifact values replaced by NA.
Table 6 (page 16)
Table 9 (page 18)
For more information on artifact values in satellite data, refer to the Black Marble User Guide.
## Not run: # Remove artifact values from UTC_Time variable in satellite data cleaned_data <- remove_fill_value_from_satellite_data(satellite_data, "UTC_Time") ## End(Not run)## Not run: # Remove artifact values from UTC_Time variable in satellite data cleaned_data <- remove_fill_value_from_satellite_data(satellite_data, "UTC_Time") ## End(Not run)
Retrieves and processes nighttime light raster data from the Black Marble dataset.
retrieve_and_process_nightlight_data( roi_sf, product_id, date, bearer, blackmarble_variable, quality_flags_to_remove, check_all_tiles_exist = TRUE, quiet = FALSE, temp_dir )retrieve_and_process_nightlight_data( roi_sf, product_id, date, bearer, blackmarble_variable, quality_flags_to_remove, check_all_tiles_exist = TRUE, quiet = FALSE, temp_dir )
roi_sf |
An sf object representing the region of interest. |
product_id |
A character string specifying the product ID. |
date |
A character string representing the date. |
bearer |
A character string representing the authorization bearer token. |
blackmarble_variable |
A character string specifying the blackmarble_variable to extract. |
quality_flags_to_remove |
A numeric vector containing quality flag values to be removed from the data (optional). |
check_all_tiles_exist |
A logical value indicating whether to check if all satellite imagery tiles for the location exist (default is TRUE). |
quiet |
A logical value indicating whether to suppress progress messages (default is FALSE). |
temp_dir |
A character string representing the temporary directory path. |
This function retrieves and processes nighttime light raster data from the Black Marble dataset. It downloads the data for the specified region of interest and date, removes any quality-flagged pixels as specified, and mosaics the tiles together if necessary. It then crops the raster to the region of interest.
A raster object containing the processed nighttime light data.