Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed May 13, 2024
1 parent f0ee3b5 commit 74a4efb
Show file tree
Hide file tree
Showing 16 changed files with 264 additions and 233 deletions.
339 changes: 186 additions & 153 deletions notebooks/mobility/mobility.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ for(adm_level in c("bound1", "bound2", "sez", "0", "1", "2", "3",
"0_rm_border_2_5km",
"0_rm_border_5km",
"0_rm_border_10km")){

if(adm_level == "sez"){
roi_sf <- sez_sf
} else if(adm_level == "bound1"){
Expand All @@ -56,12 +56,12 @@ for(adm_level in c("bound1", "bound2", "sez", "0", "1", "2", "3",
} else if(adm_level == "border_10km"){
roi_sf <- border_10km_sf
} else if(adm_level == "rwi"){

source("https://raw.githubusercontent.com/ramarty/fast-functions/master/R/functions_in_chunks.R")
rwi_df <- read_csv(file.path(data_dir, "Relative Wealth", "MMR_relative_wealth_index.csv"))
rwi_sf <- st_as_sf(x = rwi_df, coords = c("longitude", "latitude"), crs = 4326)
rwi_buff_sf <- rwi_sf %>% st_buffer_chunks(dist = 1200, chunk_size = 500)

roi_sf <- rwi_buff_sf
} else if(adm_level == "0_rm_sez"){
roi_sf <- adm0_rm_sez_sf
Expand All @@ -76,41 +76,41 @@ for(adm_level in c("bound1", "bound2", "sez", "0", "1", "2", "3",
} else{
roi_sf <- read_sf(file.path(gadm_dir, "rawdata", paste0("gadm41_MMR_",adm_level,".json")))
}

# Loop through product -------------------------------------------------------
# VNP46A2 = daily
# VNP46A3 = monthly
# VNP46A4 = annually

for(product in c("VNP46A4", "VNP46A3")){

## Make directory to export files - organized by ROI and prduct
OUT_DIR <- file.path(ntl_bm_dir, "FinalData", "aggregated", paste0("adm", adm_level, "_", product))
dir.create(OUT_DIR)

# Loop through rasters -----------------------------------------------------
r_name_vec <- file.path(ntl_bm_dir, "FinalData", paste0(product, "_rasters")) %>% list.files()

for(r_name_i in r_name_vec){

OUT_FILE <- file.path(OUT_DIR, r_name_i %>% str_replace_all(".tif", ".Rds"))

## Check if file exists
if(!file.exists(OUT_FILE)){

## Load raster and create rasters for just gas flaring and non gas flaring locations
r <- raster(file.path(ntl_bm_dir, "FinalData", paste0(product, "_rasters"), r_name_i))

## Extract data
ntl_df <- exact_extract(r, roi_sf, fun = c("mean", "median", "sum"))
roi_sf$ntl_bm_mean <- ntl_df$mean
roi_sf$ntl_bm_median <- ntl_df$median
roi_sf$ntl_bm_sum <- ntl_df$sum

## Prep for export
roi_df <- roi_sf %>%
st_drop_geometry()

## Add date
if(product == "VNP46A2"){
year <- r_name_i %>% substring(12,15) %>% as.numeric()
Expand All @@ -122,7 +122,7 @@ for(adm_level in c("bound1", "bound2", "sez", "0", "1", "2", "3",
paste0("-01") %>%
ymd()
}

if(product == "VNP46A3"){
date_r <- r_name_i %>%
str_replace_all("VNP46A3_t", "") %>%
Expand All @@ -131,17 +131,17 @@ for(adm_level in c("bound1", "bound2", "sez", "0", "1", "2", "3",
paste0("-01") %>%
ymd()
}

if(product == "VNP46A4"){
# Just grab year
date_r <- r_name_i %>%
str_replace_all("VNP46A4_t", "") %>%
str_replace_all(".tif", "") %>%
as.numeric()
}

roi_df$date <- date_r

## Export
saveRDS(roi_df, OUT_FILE)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}
/* CSS for syntax highlighting */
Expand Down Expand Up @@ -90,7 +90,7 @@
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
<nav id="TOC" role="doc-toc" class="toc-active">
<h2 id="toc-title">Table of contents</h2>

<ul>
<li><a href="#data" id="toc-data" class="nav-link active" data-scroll-target="#data">Data</a></li>
<li><a href="#methodology" id="toc-methodology" class="nav-link" data-scroll-target="#methodology">Methodology</a></li>
Expand Down Expand Up @@ -137,17 +137,17 @@ <h1 class="title">Nighttime Lights Analysis</h1>
<p>Data Lab </p>
</div>
</div>

<div>
<div class="quarto-title-meta-heading">Published</div>
<div class="quarto-title-meta-contents">
<p class="date">April 18, 2024</p>
</div>
</div>


</div>


</header>

Expand Down Expand Up @@ -982,7 +982,7 @@ <h1>Limitations</h1>
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
Expand All @@ -992,7 +992,7 @@ <h1>Limitations</h1>
anchorJS.add('.anchored');
const isCodeAnnotation = (el) => {
for (const clz of el.classList) {
if (clz.startsWith('code-annotation-')) {
if (clz.startsWith('code-annotation-')) {
return true;
}
}
Expand Down Expand Up @@ -1023,11 +1023,11 @@ <h1>Limitations</h1>
button.setAttribute("data-bs-toggle", "tooltip");
button.setAttribute("data-bs-placement", "left");
button.setAttribute("data-bs-title", "Copied!");
tooltip = new bootstrap.Tooltip(button,
{ trigger: "manual",
tooltip = new bootstrap.Tooltip(button,
{ trigger: "manual",
customClass: "code-copy-button-tooltip",
offset: [0, -8]});
tooltip.show();
tooltip.show();
}
setTimeout(function() {
if (tooltip) {
Expand Down Expand Up @@ -1057,7 +1057,7 @@ <h1>Limitations</h1>
theme: 'quarto',
placement: 'bottom-start'
};
window.tippy(el, config);
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
Expand Down Expand Up @@ -1102,7 +1102,7 @@ <h1>Limitations</h1>
height = bottom - top;
}
if (top !== null && height !== null && parent !== null) {
// cook up a div (if necessary) and position it
// cook up a div (if necessary) and position it
let div = window.document.getElementById("code-annotation-line-highlight");
if (div === null) {
div = window.document.createElement("div");
Expand Down Expand Up @@ -1200,4 +1200,4 @@ <h1>Limitations</h1>



</body></html>
</body></html>
Loading

0 comments on commit 74a4efb

Please sign in to comment.