iccsa-21-wind

Wind Simulation Using High-Frequency Velocity Component Measurements
git clone https://git.igankevich.com/iccsa-21-wind.git
Log | Files | Refs

direction-min-max.R (1534B)


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