Skip to content

Commit

Permalink
dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ramarty committed Dec 13, 2023
1 parent a5180d2 commit 97c316f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 27 deletions.
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: blackmarbler
Title: Black Marble Data and Statistics
Version: 0.1.0
Version: 0.1.1
Authors@R:
c(person("Robert", "Marty", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-3164-3813")),
Expand All @@ -27,5 +27,4 @@ Imports:
Suggests:
geodata,
ggplot2,
tidyr,
knitr
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ import(raster, except = c(union, select, intersect, origin, tail, head, values))
import(readr)
import(sf)
import(stringr)
import(tidyr)
import(tidyr, except = c(extract))
28 changes: 14 additions & 14 deletions R/blackmarbler.R
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,18 @@ define_date_name <- function(date_i, product_id){
return(date_name_i)
}


count_n_obs <- function(values, coverage_fraction) {
## Function to count observations, for exact_extract

orig_vars <- names(values)

values %>%
dplyr::mutate(across(orig_vars, ~ as.numeric(!is.na(.)) )) %>%
dplyr::summarise(across(orig_vars, sum, .names = "n_non_na_pixels.{.col}"),
across(orig_vars, ~length(.), .names = "n_pixels.{.col}"))
}

#' Extract and Aggregate Black Marble Data
#'
#' Extract and aggregate nighttime lights data from [NASA Black Marble data](https://blackmarble.gsfc.nasa.gov/)
Expand Down Expand Up @@ -547,18 +559,6 @@ bm_extract <- function(roi_sf,
NArule = NArule)

#### Extract

## Function to count observations
count_n_obs <- function(values, coverage_fraction) {

orig_vars <- names(values)

values %>%
dplyr::mutate(across(orig_vars, ~ as.numeric(!is.na(.)) )) %>%
dplyr::summarise(across(orig_vars, sum, .names = "n_non_na_pixels.{.col}"),
across(orig_vars, ~length(.), .names = "n_pixels.{.col}"))
}

roi_df <- roi_sf %>% st_drop_geometry()
roi_df$date <- NULL

Expand All @@ -567,7 +567,7 @@ bm_extract <- function(roi_sf,
tidyr::pivot_longer(cols = -c(names(roi_df)),
names_to = c(".value", "date"),
names_sep = "\\.t") %>%
dplyr::mutate(prop_non_na_pixels = n_non_na_pixels / n_pixels)
dplyr::mutate(prop_non_na_pixels = .data$n_non_na_pixels / .data$n_pixels)

ntl_df <- exact_extract(bm_r, roi_sf, aggregation_fun) %>%
tidyr::pivot_longer(cols = everything(),
Expand Down Expand Up @@ -804,7 +804,7 @@ bm_extract <- function(roi_sf,
#' @import stringr
#' @import httr
#' @import lubridate
#' @import tidyr
#' @rawNamespace import(tidyr, except = c(extract))
#' @rawNamespace import(purrr, except = c(flatten_df, values))
#' @rawNamespace import(raster, except = c(union, select, intersect, origin, tail, head, values))
#'
Expand Down
Binary file modified man/figures/ntl_gha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/ntl_trends_gha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions readme_figures/figures_for_readme.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ if(F){
library(ggplot2)
library(dplyr)
library(sf)
library(raster)

# Setup ------------------------------------------------------------------------
bearer <- read_csv("~/Desktop/bearer_bm.csv") %>%
Expand All @@ -32,8 +33,6 @@ if(F){
names(r_df) <- c("value", "x", "y")

## Transform NTL
r_df$value[r_df$value <= 1] <- 0

r_df$value_adj <- log(r_df$value+1)

##### Map
Expand All @@ -44,7 +43,7 @@ if(F){
scale_fill_gradient2(low = "black",
mid = "yellow",
high = "red",
midpoint = 4.5) +
midpoint = 3.1) +
labs(title = "Nighttime Lights: October 2021") +
coord_quickmap() +
theme_void() +
Expand All @@ -58,7 +57,7 @@ if(F){
# Extract timeseries -----------------------------------------------------------
ntl_df <- bm_extract(roi_sf = roi_sf,
product_id = "VNP46A4",
date = 2012:2021,
date = 2012:2022,
bearer = bearer,
aggregation_fun = c("mean"))

Expand Down
10 changes: 4 additions & 6 deletions vignettes/assess-quality.html

Large diffs are not rendered by default.

0 comments on commit 97c316f

Please sign in to comment.