-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
115 lines (90 loc) · 3.69 KB
/
README.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
---
output: github_document
bibliography: man/figures/README-references.bib
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# eventstream
<!-- badges: start -->
[![R-CMD-check](https://github.com/sevvandi/eventstream/workflows/R-CMD-check/badge.svg)](https://github.com/sevvandi/eventstream/actions)
<!-- badges: end -->
The goal of *eventstream* is to extract and classify events in contiguous spatio-temporal data streams of 2 or 3 dimensions. For details see [@eventstream].
## Installation
You can install the development version of *eventstream* from github with:
``` r
#install.packages("devtools")
devtools::install_github("sevvandi/eventstream")
```
## Generate data - 2D
This is an example of a data stream you can generate with *eventstream*.
```{r getdat}
library("eventstream")
library("ggplot2")
library("raster")
library("maps")
str <- gen_stream(3, sd=1)
zz <- str$data
dat <- as.data.frame(t(zz))
dat.x <- 1:dim(dat)[2]
dat.y <- 1:dim(dat)[1]
mesh.xy <- eventstream:::meshgrid(dat.x,dat.y)
xyz.dat <- cbind(as.vector(mesh.xy$x), as.vector(mesh.xy$y), as.vector(as.matrix(dat)) )
xyz.dat <- as.data.frame(xyz.dat)
colnames(xyz.dat) <- c("Time", "Location", "Value")
ggplot(xyz.dat, aes(Time, Location)) + geom_raster(aes(fill=Value)) + scale_fill_gradientn(colours=topo.colors(12)) + theme_bw()
```
## Extract events - 2D
The extracted events are plotted for the first 2 windows using a window size of 200 and a step size of 50.
```{r extract}
zz2 <- zz[1:250,]
ftrs <- extract_event_ftrs(zz2, rolling=FALSE, win_size=200, step_size = 50, vis=TRUE)
```
## Extract events - 3D
To extract 3D events we use the NO2 data from NASA's [NEO website](https://neo.gsfc.nasa.gov/).
```{r extract3D}
data(NO2_2019)
dim(NO2_2019)
ftrs_2019 <- extract_event_ftrs(NO2_2019, thres=0.97, epsilon = 2, miniPts = 20, win_size=4, step_size=1, rolling=TRUE, tt=1, vis=FALSE)
dim(ftrs_2019)
ftrs_2019[1, , ]
```
The features contain `r dim(ftrs_2019)[1]` events, `r dim(ftrs_2019)[2]` features, and `r dim(ftrs_2019)[3]` age brackets for the events.
First, let us visualize NO2 data for March 2019.
```{r vis2D1}
data(NO2_2019)
r <- raster(NO2_2019[1, ,],xmn=-179.5,xmx=179.5,ymn=-89.5,ymx=89.5,crs="+proj=longlat +datum=WGS84")
plot(r, legend=F, main="2019 March NO2 levels")
map("world",add=T, fill=FALSE, col="darkgrey")
```
## Visualize 2D cross sections of 3D events
Next we extract 3D events from March - June 2019. Then we visualize 2D cross sections of these 3D events for March 2019.
```{r vis2D2}
data(NO2_2019)
output <- get_clusters_3d(NO2_2019, thres=0.97, epsilon = 2, miniPts = 20)
cluster.all <- output$clusters
xyz.high <- output$data
all_no2_clusters_march <- xyz.high[xyz.high[,1]==1,-1]
all_cluster_ids_march <- cluster.all$cluster[xyz.high[,1]==1]
cluster_ids_march <- all_cluster_ids_march[all_cluster_ids_march!=0]
no2_clusters_march <- all_no2_clusters_march[all_cluster_ids_march!=0,]
march_map <- matrix(0, nrow=180, ncol=360)
set.seed(123)
new_ids <- sample( length(unique(cluster_ids_march)),length(unique(cluster_ids_march)) )
new_cluster_ids <- cluster_ids_march
for(i in 1:length(unique(cluster_ids_march)) ) {
new_cluster_ids[ cluster_ids_march== unique(cluster_ids_march)[i]] <- new_ids[i]
}
march_map[no2_clusters_march[,1:2]] <- new_cluster_ids
r <- raster(march_map,xmn=-179.5,xmx=179.5,ymn=-89.5,ymx=89.5,crs="+proj=longlat +datum=WGS84")
plot(r, legend=F)
map("world",add=T, fill=FALSE, col="darkgrey")
```
We see NO2 clusters extracted for March 2019 in the above figure. Each colour represents a single cluster.
## References