forked from seanyx/lake-ice-classification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0. Set up training dataset.Rmd
56 lines (43 loc) · 1.33 KB
/
0. Set up training dataset.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
---
title: "0. Set up training dataset"
author: "Xiao Yang"
date: "8/10/2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
require(tidyverse)
require(sf)
```
merge manually classified areas and assign image id to each polygon
```{r}
dat1 = st_read("data/lake_ice_training_data1.shp")
dat2 = st_read("data/lake_ice_training_data2.shp")
dat = rbind(dat1, dat2)
save(dat, file = "outputs/training_polygons_20190808.RData")
summary(dat)
class_count_raw = dat %>%
ggplot() +
geom_bar(aes(x = class)) +
theme(axis.text.x.bottom = element_text(angle = 45, hjust = 1)) +
labs(
x = "Class",
y = "Count"
)
class_count_raw
class_count_raw %>%
ggsave(filename = "figs/class_count_raw.png",
width = 5,
height = 4)
hl = st_read("data/HydroLAKES_polys_v10_shp/HydroLAKES_polys_v10.shp")
imgIds = read_csv("outputs/subsamples_training_lakes_20190802.csv")
dat = dat %>%
mutate(polygonId = 1:nrow(dat))
dat_ids = dat %>%
st_join(hl %>% dplyr::select(Hylak_id, Elevation), left = T) %>%
left_join(imgIds %>% dplyr::select(LANDSAT_SCENE_ID, Hylak_id, lif, temp), by = "Hylak_id")
dat_ids = dat_ids %>%
filter(!is.na(LANDSAT_SCENE_ID)) %>%
mutate(area = as.numeric(st_area(geometry)) / 1000000)
st_write(dat_ids, dsn = "outputs/training_polygons_ids_20190810.shp")
```