-
Notifications
You must be signed in to change notification settings - Fork 1
/
07_acc_access_to_healthcare.Rmd
151 lines (114 loc) · 6.05 KB
/
07_acc_access_to_healthcare.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
---
title: "Data analysis: Access to healthcare"
author: "Linda Petutschnig"
date: "13 6 2023"
output:
html_document:
theme: paper
highlight: default
---
Two indicators are calculated that are both related to healthcare accessibility:
1: Average walking time to nearest healthcare facility
2: Number of people served by the same healthcare facility
This script performs the following tasks:
- Accesses the Malaria Atlas Project database and downloads the "Walking-only travel time to healthcare map without access to motorized transport" data.
- Plots the Accessibility raster to visualize the data
- For indicator 1, the hexagonify function is used to calculate the average walking time in minutes per hexagon.
- For indicator 2, the population per service area is calculated and mapped. To this end, the "worldpop_2020_constrained_100m" data is loaded from hard drive which has been prepared in another script. The service areas were calculated using the SAGA GIS algorithm "Accumulate costs" with the "Walking-only travel time to healthcare map without access to motorized transport" data as input. The service areas are now overlaid with the population data. In a last step the population per service area is disaggregated into the hexagon layer.
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(ft.shadow = FALSE)
```
## Load libraries
```{r prepare, message = FALSE, warning = FALSE}
# Loads necessary packages
library(here) # to access data via relative paths
library(malariaAtlas) # to access data provided by the Malaria Atlas Project
library(sf) # to manipultate vector features
library(raster) # to work with raster files
library(httr)
library(jsonlite) # is this package really needed?
```
## Define extent and download data
```{r accessibility get data, message = FALSE, warning = FALSE}
# Loads hexagon layer from database
aoi_shape = st_read(here("data/geopackages", "AOI_hex5.gpkg"))
# Converts AOI to SpatialPolygons object because this is required by the next function getRaster
aoi_spatial <- as(aoi_shape, "Spatial")
# Accesses the accessibility data via the malariaAtlas function "getRaster"
accessibility_raster <- getRaster(surface = "Walking-only travel time to healthcare map without access to motorized transport", shp = aoi_spatial)
# Plots the raw accessibility data
plot(accessibility_raster)
# Gets the metadata associated with the layer
meta <- metadata(accessibility_raster)
# Saves raster layer to disk
writeRaster(accessibility_raster, here("data/rasters", "AOI_traveltime_foot_hf.tif"), overwrite = TRUE)
```
## Get population data
```{r population get data, message = FALSE, warning = FALSE}
# API path look up is in the following exemplified based on COD.
# Define the URL
url <- "https://hub.worldpop.org/rest/data/pop/wpicuadj1km?iso3=COD"
# Send the GET request
response <- GET(url)
# Parse the response data
data <- content(response, "text")
parsed_data <- fromJSON(data) # Look into the parsed_data object for more information
#-----------------------------------
# Download country data
download_pop <- function(url, filename) {
# Send GET request to the URL
response <- GET(url)
# Check if the request was successful (status code 200)
if (status_code(response) == 200) {
# File path where to save the downloaded .tif file
file_path <- here("data/rasters", filename)
# Save the content of the response to a file
writeBin(content(response, "raw"), file_path)
return(TRUE)
} else {
return(FALSE)
}
}
cod_pop <- download_pop("https://data.worldpop.org/GIS/Population/Global_2000_2020_1km_UNadj/2020/COD/cod_ppp_2020_1km_Aggregated_UNadj.tif","COD_ppp_2020_unconst_1km_UNadj.tif")
bdi_pop <- download_pop("https://data.worldpop.org/GIS/Population/Global_2000_2020_1km_UNadj/2020/BDI/bdi_ppp_2020_1km_Aggregated_UNadj.tif","BDI_ppp_2020_unconst_1km_UNadj.tif")
rwa_pop <- download_pop("https://data.worldpop.org/GIS/Population/Global_2000_2020_1km_UNadj/2020/RWA/rwa_ppp_2020_1km_Aggregated_UNadj.tif","RWA_ppp_2020_unconst_1km_UNadj.tif")
uga_pop <- download_pop("https://data.worldpop.org/GIS/Population/Global_2000_2020_1km_UNadj/2020/UGA/uga_ppp_2020_1km_Aggregated_UNadj.tif","UGA_ppp_2020_unconst_1km_UNadj.tif")
#-----------------------------------
# Loads the just downloaded rasters.
pop_cod <- raster(here("data/rasters","COD_ppp_2020_unconst_1km_UNadj.tif"))
pop_bdi <- raster(here("data/rasters","BDI_ppp_2020_unconst_1km_UNadj.tif"))
pop_rwa <- raster(here("data/rasters","RWA_ppp_2020_unconst_1km_UNadj.tif"))
pop_uga <- raster(here("data/rasters","UGA_ppp_2020_unconst_1km_UNadj.tif"))
# To preserve the shape of the AOI, we first crop and then mask
AOI <- sf::read_sf(here("data/geopackages", "AOI.gpkg"))
crop_aoi <- function(country){
pop_cod_aoi <- crop(country, extent(AOI)) %>%
mask(AOI)
}
# Crop and mask all population datasets to the boundary of the AOI
pop_cod_aoi <- crop_aoi(pop_cod)
pop_bdi_aoi <- crop_aoi(pop_bdi)
pop_rwa_aoi <- crop_aoi(pop_rwa)
pop_uga_aoi <- crop_aoi(pop_uga)
# Mosaic countries together and save
aoi_population <- mosaic(pop_cod_aoi, pop_bdi_aoi, pop_rwa_aoi, pop_uga_aoi, fun = "mean")
writeRaster(aoi_population, here("data/rasters","AOI_ppp_2020_unconst_UNadj.tif"))
## THINGS I TRIED THAT DID NOT WORK----
# wopr-------
# Tried data access using wopr on 31.07.23. So far the catalog can only access Social Distancing and Building data for a few selected countries. Therefore, the package is not (yet)
# useful for accessing WorldPop data in general.
# library(wopr)
# catalogue <- getCatalogue()
#
# wpgpDownloadR-------
# When using wpgpListCountryDatasets(), there is ppp_2020_UNadj_constrained in all four country lists. However, calling it receives an error, stating that the co-variate is not present in WP (?). Same goes for ppp_2020_UNadj.
# library(wpgpDownloadR)
# wpgpListCountries()
# wpgpListCountryDatasets(ISO3="COD")
#
# wpgpGetCountryDataset(ISO3 = "COD",
# covariate = "Unconstrained individual countries 2000-2020 UN adjusted ( 1km resolution )",
# destDir = here("data/rasters"))
#
```