-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExamine fully crossed structures.Rmd
More file actions
143 lines (110 loc) · 3.97 KB
/
Copy pathExamine fully crossed structures.Rmd
File metadata and controls
143 lines (110 loc) · 3.97 KB
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
---
title: "Reclassify 10% structures"
author: "Xiao Yang"
date: "4/13/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
require(sf)
require(tidyverse)
```
## export the fully crossed structures (dll) reclassify in GEE
```{r}
grod = st_read("outputs/GROD_reclassified_uncertain_20200211.shp")
grod = grod %>%
mutate(grod_id = 1:nrow(grod))
st_write(grod, dsn = "outputs/GROD_v1_6classes_withID_20200530.shp")
subGrod = grod %>%
filter(class %in% c("Dam", "Low_Permeable_Dams", "Locks"))
print("how many structures in total?")
subGrod %>% nrow()
subGrod %>% st_drop_geometry() %>% group_by(class) %>% count() %>% ungroup
## add index just for this step
subGrod = subGrod %>%
mutate(index = 1:nrow(.))
subGrod %>%
ggplot() +
geom_bar(aes(x = class)) +
theme(axis.text.x.bottom = element_text(hjust = 1, angle = 45)) +
labs(x = "", y = "Count")
st_write(subGrod, dsn = "outputs/subGrod_fully_crossed_classes_20200530.shp")
```
## latest results
```{r}
range_index = tibble(name = c("Galit", "Riley", "Mike"), initIndex = c(1, 16874, 8437), maxIndex = c(8436, 25307, 16873))
require(foreach)
fileInfo = tibble(
filePath = dir(path = "data/fully_crossed_structures", full.names = T),
filename = dir(path = "data/fully_crossed_structures")
) %>%
separate(filename, into = c("name", NA), sep = "_")
dat = foreach(i = 1:nrow(fileInfo), .combine = "rbind") %do% {
read_csv(fileInfo$filePath[i]) %>%
mutate(name = fileInfo$name[i])
} %>%
select(-`system:index`, -`.geo`) %>%
mutate(class = as.factor(class), name = as.factor(name)) %>%
rename(class_new = class) %>%
st_as_sf(coords = c("lon", "lat"), crs = 4326)
dat = dat %>% mutate(row.id = 1:nrow(dat))
ref = st_read("outputs/subGrod_fully_crossed_classes_20200530.shp")
ref = ref %>% mutate(col.id = 1:nrow(ref))
test = st_is_within_distance(dat, ref, dist = 500)
test = test %>% as_tibble()
merged = dat %>% left_join(test, by = "row.id") %>% left_join(ref %>% as_tibble(), by = "col.id") %>%
group_by(row.id, col.id) %>%
mutate(dist = st_distance(geometry.x, geometry.y)[1, 1]) %>%
ungroup()
## for structures with multiple matches, choose the one with minimal distance
merged_final = merged %>%
group_by(row.id) %>%
slice_min(order_by = dist) %>%
ungroup()
## no. of structures finished mapping and some stats
progress = merged_final %>%
left_join(range_index, by = "name") %>%
filter(index >= initIndex, index <= maxIndex) %>%
st_drop_geometry() %>%
group_by(name) %>%
summarise(currentIndex = max(index),
NoMapped = currentIndex - first(initIndex),
initIndex = first(initIndex),
nUncertain = sum(class_new == "Uncertain"),
nChanged = n()) %>%
ungroup()
progress %>%
mutate(rateOfChange = nChanged / NoMapped,
rateOfUncertain = nUncertain / NoMapped) %>%
select(-currentIndex)
# now need to filled in the structures are left unchanged
merged_unchanged = ref %>%
filter(
(index >= progress[1, ]$initIndex & index <= progress[1, ]$currentIndex) |
(index >= progress[2, ]$initIndex & index <= progress[2, ]$currentIndex) |
(index >= progress[3, ]$initIndex & index <= progress[3, ]$currentIndex)) %>%
filter(!(index %in% merged_final$index)) %>%
mutate(class_new = class,
geometry.x = geometry) %>%
select(index, grod_id, class_new, geometry.x, class)
currentDll = merged_final %>%
select(index, grod_id, class_new, geometry.x, class) %>%
as_tibble() %>%
rbind(merged_unchanged %>% st_drop_geometry())
save(currentDll, file = "outputs/currentDll_7_16_2020.RData")
```
## flow diagram
```{r}
library(flipPlots)
stats = currentDll %>%
group_by(class, class_new) %>%
count() %>%
ungroup()
SankeyDiagram(stats[, 1:2],
link.color = "Source",
variables.share.values = T,
label.show.varname = F,
label.show.percentages = T,
weights = stats$n,
font.size = 18)
```