-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathelectrification_estimation.R
58 lines (44 loc) · 1.67 KB
/
electrification_estimation.R
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
#####################
# Population and electrification calculation
#####################
gaul_code <-countrycode(countryiso3, "iso3c", "gaul")
gaul = ee$FeatureCollection("FAO/GAUL/2015/level0")$filter(ee$Filter$eq('ADM0_CODE', gaul_code))
imageCollection = ee$ImageCollection("NOAA/VIIRS/DNB/MONTHLY_V1/VCMSLCFG");
nl20 = imageCollection$filterDate('2019-01-01', '2020-01-01')$select('avg_rad')$median()
zero = ee$Image(0)
Sys.sleep(1)
nl20 = nl20$where(nl20$lt(0.37), zero)$clip(gaul)
pop = ee$Image('users/giacomofalchetta/hrsl_images')$clip(gaul)
popnoaccess = pop$mask(nl20$eq(0))$clip(gaul)
popnoaccess <- ee_as_raster(
image = popnoaccess,
region = gaul$geometry(),
via = "drive",
scale = 1000
)
clusters$noacc <- exactextractr::exact_extract(popnoaccess, clusters, fun="sum")
pop <- ee_as_raster(
image = pop,
region = gaul$geometry(),
via = "drive",
scale = 1000
)
clusters$pop <- exactextractr::exact_extract(pop, clusters, fun="sum")
# estimate electrification rate of each cluster
clusters$elrate <- 1- (clusters$noacc/clusters$pop)
# adjust
somma = sum(clusters$pop)
spread = ((national_official_population-somma)/somma)
clusters$pop <- clusters$pop * (1+spread)
somma = sum(clusters$noacc)
spread = (((national_official_population*(1-national_official_elrate))-somma)/somma)
clusters$noacc <- clusters$noacc * (1+spread)
elrate_plot <- ggplot(data=clusters)+
geom_sf(aes(fill=elrate))+
scale_fill_viridis_c(trans="log", name="Electr. acc. rate (2019 estimate)")
pop_plot <- ggplot(data=clusters)+
geom_sf(aes(fill=pop))+
scale_fill_viridis_c(trans="log")
noacc_plot <- ggplot(data=clusters)+
geom_sf(aes(fill=noacc))+
scale_fill_viridis_c(trans="log")