knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
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].
You can install the development version of eventstream from github with:
#install.packages("devtools") devtools::install_github("sevvandi/eventstream")
This is an example of a data stream you can generate with eventstream.
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()
The extracted events are plotted for the first 2 windows using a window size of 200 and a step size of 50.
zz2 <- zz[1:250,] ftrs <- extract_event_ftrs(zz2, rolling=FALSE, win_size=200, step_size = 50, vis=TRUE)
To extract 3D events we use the NO2 data from NASA's NEO website.
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.
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")
Next we extract 3D events from March - June 2019. Then we visualize 2D cross sections of these 3D events for March 2019.
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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.