acf-min-max.R (1444B)
1 library(gplots) # hist2d 2 3 source("R/common.R") 4 5 time_delta = 60*60*2 6 for (timestamp in c(1614920400, 1615388400, 1614135600, 1616058000, 1614430800, 1614452400)) { 7 velocity <- select_samples(timestamp, time_delta) 8 path <- file.path('build', 'acf') 9 make_directory(path) 10 filename <- file.path(path, sprintf("%d-hist-xy", timestamp)) 11 print(filename) 12 # add corner points with mean speed 13 ## v1 14 #x_max = max(abs(velocity$x)) 15 #y_max = max(abs(velocity$y)) 16 #s = mean(velocity$speed) 17 #r = sqrt(x_max**2 + y_max**2) 18 #tmp <- data.frame(x=c(velocity$x/r,r,-r,-r,r), 19 # y=c(velocity$y/r,r,r,-r,-r), 20 # r=c(velocity$speed,s,s,s,s)) 21 #tmp <- tmp[order(tmp$r),] # order by speed for gnuplot 22 #write.table(tmp, filename, row.names=FALSE, quote=FALSE) 23 24 # write.table(data.frame(x=velocity$x, 25 # y=velocity$y, 26 # r=velocity$speed), 27 # filename, row.names=FALSE, quote=FALSE) 28 29 # v2 30 hist_xy <- hist2d(velocity$x, velocity$y, same.scale=TRUE, show=TRUE, nbins=400) 31 grid_xy <- expand.grid(x=-hist_xy$x,y=-hist_xy$y) 32 x_max = max(abs(grid_xy$x)) 33 y_max = max(abs(grid_xy$y)) 34 r = sqrt(x_max**2 + y_max**2) 35 write.table(data.frame(x=c(grid_xy$x/r,r,-r,-r,r), 36 y=c(grid_xy$y/r,r,r,-r,-r), 37 r=c(as.vector(t(hist_xy$counts)),0,0,0,0)), 38 filename, row.names=FALSE, quote=FALSE) 39 } 40