knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 7, 
  fig.height = 4
)
theme_radar <- function(...) {
    theme_bw() +
        theme(panel.border = element_blank(), panel.grid.major = element_blank(),
              panel.grid.minor = element_blank(),
              panel.background = element_rect(fill = "white", colour = NA),
              legend.position = 'none',
              axis.line = element_line(size = 0.5, linetype = "solid", colour = "black"))
}

Creating vessel trajectories

We can start by creating the radar bearing vessel trajectory:

library(vesselett)
library(dplyr)
library(ggplot2)
library(tidyr)
library(forcats)
set.seed(1)
x<- create_tracking_history(n = 15, nscans = 60, clutter_intensity = 5, scan_range = 1e3, delta_time = 5, turning_rate = 0.0001)

full_x <- full_join(x$obs_target, x$obs_radar, by = "time")
full_x <- dplyr::mutate(full_x, dist = sqrt((east - radar_east)^2 + (north - radar_north)^2), 
           radar_range = 1e3, isObserved = dist < radar_range) %>% arrange(time)

ggplot(data = full_x) + 
    geom_point(aes(x = radar_east, y = radar_north), size = 4) + 
    geom_point(aes(x = radar_east, y = radar_north), col = "white", size = 3) + 
    geom_text(aes(x = radar_east, y = radar_north, label = time), col = "black", size = 2) +
    geom_point(aes(x = east, y = north, col = target_id), size = 4) + 
    geom_path(data = full_x %>% dplyr::filter(target_id != "0"), 
              aes(x = east, y = north, col = target_id)) + 
    geom_point(aes(x = east, y = north), col = "white", size = 3) +
    geom_text(aes(x = east, y = north, label = time), col = "black", size = 1.5) +
    theme_radar()

Now, some targets are observed, while some are too far away. We limit to the one observed:

obs_x <- dplyr::filter(full_x, .data$isObserved == TRUE)
obs_x <- dplyr::arrange(obs_x, time)


ggplot(obs_x) + 
    geom_point(aes(x = radar_east, y = radar_north), size = 4) + 
    geom_path(aes(x = radar_east, y = radar_north)) + 
    geom_point(aes(x = radar_east, y = radar_north), col = "white", size = 3) + 
    geom_text(aes(x = radar_east, y = radar_north, label = time), size = 2) + 
    geom_point(data = obs_x %>% dplyr::filter(.data$target_id != "0"), 
               aes(x = east, y = north, col = target_id), size = 4) + 
    geom_path(data = obs_x %>% dplyr::filter(.data$target_id != "0"), 
              aes(x = east, y = north, col = target_id))  + 
    geom_point(data = obs_x %>% dplyr::filter(.data$target_id != "0"), 
               aes(x = east, y = north), col = "white", size = 3) + 
    geom_text(data = obs_x %>% dplyr::filter(.data$target_id != "0"), 
              aes(x = east, y = north, label = time), size=2) +
    geom_point(data = obs_x %>% dplyr::filter(.data$target_id == "0"), 
               aes(x = east, y = north), col = "grey", size = 4) + 
    geom_point(data = obs_x %>% dplyr::filter(.data$target_id == "0"), 
               aes(x = east, y = north), col = "white", size = 3) + 
    geom_text(data = obs_x %>% dplyr::filter(.data$target_id == "0"), 
              aes(x = east, y = north, label = time), size=2) +
    xlab("")+ ylab("") + theme_radar()
obs_x_long <-  pivot_longer(obs_x, c(north, east))
obs_x_long <-  mutate(obs_x_long,  name = fct_relevel(as.factor(name), c("north", "east")))

plot_obs(obs_x, varnames = c("north", "east"))

Tracking the observed vessels

mI = unlist(obs_x[obs_x$time == min(obs_x$time),c("north", "east", "v_north", "v_east")])
init_field = list(list(m = mI, P = diag(10, nrow = 4), w = 1, l = "1"))

res = gm_cphd_tracker(obs_x,  init_field = init_field,
                     tau = 1e-5, kappa=1e-15, P_B = 0.05, P_S = 0.6,P_D = 0.9, wt = .5, T_s = 5,U = 10,
                     sigma2_measure = 1e-1, sigma2_process = 1e-1, cutDist = 10)

Tracks = res$Tracks

plot(res, varnames = c("north", "east"))
 ggplot() + geom_point(data = obs_x %>% group_by(time, target_id) %>%
 summarize(n = n()) %>%
 ungroup() %>% group_by(time) %>% summarise(n =n()), aes(x = time, y = n)) +
 geom_path(aes(x = unique(Tracks$time), y = as.matrix(res$Cardinality) %*% t(t(c(0:20)))),
 col = "blue")


ick003/vesselett documentation built on July 20, 2020, 9:08 p.m.