kaijagahm / vultureUtils

Utility functions for working with vulture data
Other
4 stars 0 forks source link

Data downsampling #90

Open kaijagahm opened 1 year ago

kaijagahm commented 1 year ago

Atlastools theoretically does this, but it requires a weird data format and the function is really buggy. (Function atl_thin_data).

For now, implement a quick-and-dirty method inside the cleanData function, with a parameter to turn it on and off. But really need to revisit this later.

kaijagahm commented 1 year ago

ERASE ERASE--I have removed the downsampling (I think? Though I lost track of the PR where this happened, and it would be nice to dig it up). If I didn't get rid of it, let's get rid of it.

Instead, I'd like to formally implement the downsampling code used here, or similar, as a function in the vultureUtils package. Should be fairly straightforward to do, but need to add argument checks etc.

# Downsample the data and save the downsampled data
subsample <- function(df, idCol = "Nili_id", timestampCol = "timestamp", mins = 10){
  sub <- df %>%
    arrange(idCol, timestampCol) %>%
    group_by(.data[[idCol]]) %>%
    mutate(tc = cut(.data[[timestampCol]], 
                    breaks = paste(as.character(mins), "min", sep = " "))) %>%
    group_by(.data[[idCol]], 
             "d" = lubridate::date(.data[[timestampCol]]), tc) %>%
    slice(1) %>%
    ungroup() %>%
    dplyr::select(-c("d", "tc"))
  return(sub)
}
kaijagahm commented 6 months ago

Note to self: might need to update the code in light of changes made to the data prep script.