Skip to content

Commit

Permalink
ntl
Browse files Browse the repository at this point in the history
  • Loading branch information
ramarty committed Jan 25, 2024
1 parent 8f3ec36 commit d2c8266
Show file tree
Hide file tree
Showing 8 changed files with 578 additions and 45 deletions.
507 changes: 507 additions & 0 deletions notebooks/nighttime-lights/analysis-2024/.Rhistory

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ roi_sf <- read_sf(file.path(gadm_dir, "rawdata", paste0("gadm41_MMR_",0,".json")
# Download ---------------------------------------------------------------------
bm_raster(roi_sf = roi_sf,
product_id = "VNP46A4",
date = 2012:2022,
date = 2012:2023,
bearer = bearer,
output_location_type = "file",
file_dir = file.path(ntl_bm_dir, "FinalData", "VNP46A4_rasters"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,28 @@ if(DELETE_DIR){

# Prep SEZ ---------------------------------------------------------------------
sez_sf <- read_sf(file.path(data_dir, "SEZ", "RawData", "industrial__special_economic_zones_sept2019.shp"))
sez_sf <- sez_sf %>% st_buffer(dist = 2.5)
sez_sf <- sez_sf %>% st_buffer(dist = 2500)

border_df <- read_xlsx(file.path(data_dir, "Border Towns", "RawData", "Myanmar's Border Town Coordinates.xlsx"))
border_sf <- border_df %>%
st_as_sf(coords = c("longitude", "latitude"), crs = 4326)

border_1km_sf <- border_sf %>% st_buffer(dist = 1000)
border_2_5km_sf <- border_sf %>% st_buffer(dist = 2500)

# Loop through ROIs ------------------------------------------------------------
for(adm_level in c("bound1", "bound2", "sez", "0", "1", "2", "3")){
for(adm_level in c("bound1", "bound2", "sez", "0", "1", "2", "3", "border_1km", "border_2_5km")){

if(adm_level == "sez"){
roi_sf <- sez_sf
} else if(adm_level == "bound1"){
roi_sf <- read_sf(file.path(data_dir, "Boundaries", "RawData", "mmr_polbnda_adm1_250k_mimu.shp"))
} else if(adm_level == "bound2"){
roi_sf <- read_sf(file.path(data_dir, "Boundaries", "RawData", "mmr_polbnda_adm2_250k_mimu_1.shp"))
} else if(adm_level == "border_1km"){
roi_sf <- border_1km_sf
} else if(adm_level == "border_2_5km"){
roi_sf <- border_2_5km_sf
} else{
roi_sf <- read_sf(file.path(gadm_dir, "rawdata", paste0("gadm41_MMR_",adm_level,".json")))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
roi = "adm2"
product <- "VNP46A3"

for(roi in c("adm0", "adm1", "adm2", "adm3", "admsez", "admbound2", "admbound1")){
for(roi in c("adm0", "adm1", "adm2", "adm3", "admsez", "admbound2", "admbound1",
"admborder_1km", "admborder_2_5km")){
for(product in c("VNP46A3", "VNP46A4")){

df <- file.path(ntl_bm_dir, "FinalData", "aggregated", paste0(roi, "_", product)) %>%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,85 @@

# Load data --------------------------------------------------------------------
adm1_df <- readRDS(file.path(ntl_bm_dir, "FinalData", "aggregated",
paste0("adm1", "_", "VNP46A3", ".Rds")))
paste0("adm1", "_", "VNP46A4", ".Rds")))

adm2_df <- readRDS(file.path(ntl_bm_dir, "FinalData", "aggregated",
paste0("adm2", "_", "VNP46A3", ".Rds")))
paste0("adm2", "_", "VNP46A4", ".Rds")))

adm3_df <- readRDS(file.path(ntl_bm_dir, "FinalData", "aggregated",
paste0("adm3", "_", "VNP46A3", ".Rds")))
paste0("adm3", "_", "VNP46A4", ".Rds")))

sez_df <- readRDS(file.path(ntl_bm_dir, "FinalData", "aggregated",
paste0("admsez", "_", "VNP46A3", ".Rds")))
paste0("admsez", "_", "VNP46A4", ".Rds")))

# Filter -----------------------------------------------------------------------
clean_data <- function(df){
df %>%
mutate(year = date %>% year(),
month = date %>% month()) %>%
filter(month != 12,
year >= 2019)
}

adm1_df <- adm1_df %>%
clean_data() %>%
group_by(year, NAME_1) %>%
dplyr::summarise(across(c(ntl_bm_sum, ntl_bm_mean, ntl_bm_median), mean)) %>%
ungroup()

adm2_df <- adm2_df %>%
clean_data() %>%
group_by(year, NAME_1, NAME_2) %>%
dplyr::summarise(across(c(ntl_bm_sum, ntl_bm_mean, ntl_bm_median), mean)) %>%
ungroup()

adm3_df <- adm3_df %>%
clean_data() %>%
group_by(year, NAME_1, NAME_2, NAME_3) %>%
dplyr::summarise(across(c(ntl_bm_sum, ntl_bm_mean, ntl_bm_median), mean)) %>%
ungroup()
border_df <- readRDS(file.path(ntl_bm_dir, "FinalData", "aggregated",
paste0("admborder_1km", "_", "VNP46A4", ".Rds")))

sez_df <- sez_df %>%
clean_data() %>%
group_by(year, Name) %>%
dplyr::summarise(across(c(ntl_bm_sum, ntl_bm_mean, ntl_bm_median), mean)) %>%
ungroup()
# Filter -----------------------------------------------------------------------
# clean_data <- function(df){
# df %>%
# mutate(year = date %>% year(),
# month = date %>% month()) %>%
# filter(month != 12,
# year >= 2019)
# }
#
# adm1_df <- adm1_df %>%
# clean_data() %>%
# group_by(year, NAME_1) %>%
# dplyr::summarise(across(c(ntl_bm_sum, ntl_bm_mean, ntl_bm_median), mean)) %>%
# ungroup()
#
# adm2_df <- adm2_df %>%
# clean_data() %>%
# group_by(year, NAME_1, NAME_2) %>%
# dplyr::summarise(across(c(ntl_bm_sum, ntl_bm_mean, ntl_bm_median), mean)) %>%
# ungroup()
#
# adm3_df <- adm3_df %>%
# clean_data() %>%
# group_by(year, NAME_1, NAME_2, NAME_3) %>%
# dplyr::summarise(across(c(ntl_bm_sum, ntl_bm_mean, ntl_bm_median), mean)) %>%
# ungroup()
#
# sez_df <- sez_df %>%
# clean_data() %>%
# group_by(year, Name) %>%
# dplyr::summarise(across(c(ntl_bm_sum, ntl_bm_mean, ntl_bm_median), mean)) %>%
# ungroup()
#
# border_df <- border_df %>%
# clean_data() %>%
# group_by(year, Name) %>%
# dplyr::summarise(across(c(ntl_bm_sum, ntl_bm_mean, ntl_bm_median), mean)) %>%
# ungroup()

# Trends -----------------------------------------------------------------------
sez_df %>%
ggplot(aes(x = year, y = ntl_bm_sum)) +
geom_line() +
facet_wrap(~Name)
ggplot(aes(x = date, y = ntl_bm_sum)) +
geom_col() +
facet_wrap(~Name, scales = "free_y")

border_df %>%
ggplot(aes(x = date, y = ntl_bm_sum)) +
geom_col() +
facet_wrap(~border_town, scales = "free_y")

adm1_df %>%
filter(NAME_1 == "Yangon") %>%
ggplot(aes(x = year, y = ntl_bm_sum)) +
ggplot(aes(x = date, y = ntl_bm_sum)) +
geom_col()

adm2_df %>%
filter(NAME_1 == "Yangon") %>%
ggplot(aes(x = year, y = ntl_bm_sum)) +
ggplot(aes(x = date, y = ntl_bm_sum)) +
geom_col() +
facet_wrap(~NAME_2)

adm3_df %>%
mutate(NAME_3_clean = paste(NAME_2, NAME_3)) %>%
filter(NAME_1 == "Yangon") %>%
ggplot(aes(x = year, y = ntl_bm_sum)) +
ggplot(aes(x = date, y = ntl_bm_sum)) +
geom_col() +
facet_wrap(~NAME_3_clean,
scales = "free_y")
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit d2c8266

Please sign in to comment.