Skip to content

Commit

Permalink
Merge pull request #15 from IDEELResearch/feature/covars
Browse files Browse the repository at this point in the history
Feature/covars
  • Loading branch information
cecile-meier-scherling authored Sep 25, 2024
2 parents a1f5afa + a2fd37e commit b9455d6
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 3 deletions.
4 changes: 1 addition & 3 deletions analysis/02_covariate_maps.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# Load pkgs ---------------------------------------------------------------

library(sf)
library(raster)
library(tidyverse)

# Read data ---------------------------------------------------------------

covars <- readRDS("analysis/data_raw/final_covariates.rds")
covars <- readRDS(url("https://github.com/IDEELResearch/scrape/raw/refs/heads/main/analysis/data-derived/final_covariates.rds"))
sf_adm0 <- readRDS("analysis/data_derived/sf_admin0_africa.rds") # adm0 map data


# Unlist and combine dfs in long format with map --------------------------

# Use the custom (but very specific) get_map_covar_data() fxn
Expand Down
38 changes: 38 additions & 0 deletions analysis/03_get_data_for_grff.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
library(sf)

# variables needed for dataframe: lat, lon, time, num, denom, covar1

# find lat lon from stave -> merge with shp -> convert to df (remove geometries)

covars <- readRDS(url("https://github.com/IDEELResearch/scrape/raw/refs/heads/main/analysis/data-derived/final_covariates.rds"))
stave <- readRDS(url("https://github.com/IDEELResearch/stitch/raw/refs/heads/main/analysis/data_derived/mock_stave_prevalence.rds"))

map_data <- get_map_covar_data(covars)

stave %>% st_as_sf(coords = c("lon", "lat"), crs = 4326) %>% # EPSG:4326 for WGS84
ggplot() +
geom_sf() +
coord_sf()

get_grff_input <- function(stave_obj, covar_obj){

covar_processed <- get_map_covar_data(covar_obj)
covar_names <- covar_processed %>% select(-c(iso3c:year)) %>% st_drop_geometry() %>% names()

sf_use_s2(FALSE)

stave_obj %>%
st_as_sf(coords = c("lon", "lat"), crs = 4326, remove = F) %>% # EPSG:4326 for WGS84 same as MAP shp files
st_join(covar_processed, left = TRUE) %>%
as.data.frame() %>%
select(lat, lon, collection_day, numerator, denominator, year, all_of(covar_names)) %>%
mutate(collection_year = year(as.Date(collection_day))) %>%
filter(collection_year == year) %>%
relocate(collection_year, .after = collection_day) %>%
select(-year)

}

input_df <- get_grff_input(stave, covars)

saveRDS(input_df, "analysis/data_derived/input_for_grff.rds")
Binary file added analysis/data_derived/input_for_grff.rds
Binary file not shown.
Binary file modified analysis/plots/map_AL.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 analysis/plots/map_ASAQ.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 added analysis/plots/map_ASMQ.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 analysis/plots/map_ASPY.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 added analysis/plots/map_ASSP.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 added analysis/plots/map_DHAPPQ.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 analysis/plots/map_ft.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 added analysis/plots/map_pfpr210.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b9455d6

Please sign in to comment.