Skip to content

Speed up autoplot.epi_archive #668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
brookslogan opened this issue May 15, 2025 · 0 comments
Open

Speed up autoplot.epi_archive #668

brookslogan opened this issue May 15, 2025 · 0 comments

Comments

@brookslogan
Copy link
Contributor

brookslogan commented May 15, 2025

With daily-time daily-version data and multiple locations, the wait time can be an annoyance, or it can brick some machines (maybe from memory usage expanding quadratically). Here's some progress toward a faster approach, at least if there aren't a bunch of revisions:

tibble(
  current = s05_smoothed_phrru_archive$DT %>%
    as.data.frame() %>%
    as_tibble(),
  preceding =
    s05_smoothed_phrru_archive$DT[
      unique(s05_smoothed_phrru_archive$DT[, key_colnames(s05_smoothed_phrru_archive), with = FALSE])[
      , time_value := epiprocess:::time_minus_n_steps(time_value, 1L,  s05_smoothed_phrru_archive$time_type)
      ],
      on = key_colnames(s05_smoothed_phrru_archive),
      roll = TRUE
    ] %>%
    as.data.frame() %>%
    as_tibble(),
  subsequent =
    copy(s05_smoothed_phrru_archive$DT)[
    , .version := version
    ][
      unique(s05_smoothed_phrru_archive$DT[, key_colnames(s05_smoothed_phrru_archive), with = FALSE])[
      , time_value := epiprocess:::time_plus_n_steps(time_value, 1L,  s05_smoothed_phrru_archive$time_type)
      ],
      on = key_colnames(s05_smoothed_phrru_archive),
      roll = TRUE
    ] %>%
    as.data.frame() %>%
    as_tibble()
) %>%
  filter(current$geo_value == "103") %>%
  mutate(current_lag = current$version - current$time_value) %>%
  # ggplot(aes(colour = current$version)) %>%
  ggplot(aes(colour = current_lag)) %>%
  `+`(geom_segment(aes(x = preceding$time_value, xend = current$time_value,
                       y = preceding$s05_smoothed, yend = current$s05_smoothed),
                   function(tbl) {
                     tbl %>% filter(!is.na(preceding$s05_smoothed))
                   })) %>%
  `+`(geom_segment(aes(x = current$time_value, xend = subsequent$time_value,
                       y = current$s05_smoothed, yend = subsequent$s05_smoothed),
                   function(tbl) {
                     tbl %>% filter(!is.na(subsequent$s05_smoothed), current$version != subsequent$.version)
                   })) %>%
  # `+`(scale_colour_viridis_c(trans = "date")) %>%
  `+`(scale_colour_viridis_c()) %>%
  {}

todo: faceting, isolated points

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant