Skip to content

Commit

Permalink
ntl
Browse files Browse the repository at this point in the history
  • Loading branch information
ramarty committed Jun 25, 2024
1 parent aa7e873 commit 3291464
Show file tree
Hide file tree
Showing 21 changed files with 804 additions and 796 deletions.
16 changes: 8 additions & 8 deletions notebooks/nighttime-lights/01_download_ntl.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ month_r <- bm_raster(roi_sf = roi_sf,
"individual_rasters",
"monthly"))

day_r <- bm_raster(roi_sf = roi_sf,
product_id = "VNP46A2",
date = seq.Date(from = ymd("2023-01-01"), to = Sys.Date(), by = "day"),
bearer = bearer,
output_location_type = "file",
file_dir = file.path(ntl_dir,
"individual_rasters",
"daily"))
# day_r <- bm_raster(roi_sf = roi_sf,
# product_id = "VNP46A2",
# date = seq.Date(from = ymd("2023-01-01"), to = Sys.Date(), by = "day"),
# bearer = bearer,
# output_location_type = "file",
# file_dir = file.path(ntl_dir,
# "individual_rasters",
# "daily"))

20 changes: 18 additions & 2 deletions notebooks/nighttime-lights/02_extract_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,28 @@ for(unit in c("adm0", "adm1", "adm2", "adm3", "city")){
list.files(full.names = T) %>%
map_df(readRDS)

# Add moving average for monthly data
if(time_period == "monthly"){

if(unit == "adm0") ntl_df$name <- ntl_df$ADM0_FR
if(unit == "adm1") ntl_df$name <- ntl_df$ADM1_PCODE
if(unit == "adm2") ntl_df$name <- ntl_df$ADM2_PCODE
if(unit == "adm3") ntl_df$name <- ntl_df$ADM3_PCODE

ntl_df <- ntl_df %>%
arrange(date) %>%
group_by(name) %>%
mutate(ntl_mean_3m_ma = slider::slide_dbl(ntl_mean, mean, .before = 3, .after = 3),
ntl_sum_3m_ma = slider::slide_dbl(ntl_sum, mean, .before = 3, .after = 3)) %>%
ungroup()
}

saveRDS(ntl_df, file.path(ntl_dir, "aggregated_appended",
paste0(unit, "_", time_period, ".Rds")))

write_dta(ntl_df, file.path(ntl_dir, "aggregated_appended",
paste0(unit, "_", time_period, ".dta")))

paste0(unit, "_", time_period, ".dta")))
}
}

1 change: 1 addition & 0 deletions notebooks/nighttime-lights/_main.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ library(exactextractr)
library(blackmarbler)
library(sparkline)
library(sparklyr)
library(slider)
938 changes: 476 additions & 462 deletions notebooks/nighttime-lights/ntl_analysis.html

Large diffs are not rendered by default.

Loading

0 comments on commit 3291464

Please sign in to comment.