diff --git a/DESCRIPTION b/DESCRIPTION index 5b61eb1..91d9311 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: crawlUtils Type: Package Title: Enhance And Integrate the {crawl} Package For Spatial Analysis Of Telemetry Output -Version: 0.1.47 -Date: 2023-10-07 +Version: 0.1.50 +Date: 2024-03-01 Authors@R: c( person("Devin S.", "Johnson", email = "devin.johnson@noaa.gov",role = c("aut", "cre")), person("Josh", "London", email = "josh.london@noaa.gov", role = c("aut")) @@ -15,12 +15,12 @@ Description: Utility functions to augment the the {crawl} package and integrate License: CC0 Encoding: UTF-8 LazyData: true -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Roxygen: list(markdown = TRUE) Imports: fuzzyjoin, dplyr, lubridate, magrittr, purrr, sf, crawl, foreach, rmapshaper, nngeo, units, janitor, readr, ggplot2, mgcv, - smoothr, sfheaders, GPSeqClus, rlang, mclust + smoothr, sfheaders, rlang, mclust Suggests: pathroutr, ctmm Remotes: - jmlondon/pathroutr, dsjohnson/GPSeqClus@fixes + jmlondon/pathroutr LinkingTo: Rcpp diff --git a/NAMESPACE b/NAMESPACE index 65273d3..a3bd40b 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -48,7 +48,6 @@ import(mgcv, except = mvn) import(sf) import(smoothr) import(units) -importFrom(GPSeqClus,GPSeq_clus) importFrom(dplyr,group_by) importFrom(dplyr,summarize) importFrom(fuzzyjoin,fuzzy_left_join) diff --git a/R/crawlUtils-package.R b/R/crawlUtils-package.R index ea9cf0d..5781f8a 100755 --- a/R/crawlUtils-package.R +++ b/R/crawlUtils-package.R @@ -7,8 +7,8 @@ #' \tabular{ll}{ #' Package: \tab crawlUtils\cr #' Type: \tab Package\cr -#' Version: \tab 0.1.47\cr -#' Date: \tab October 7, 2023\cr +#' Version: \tab 0.1.50\cr +#' Date: \tab March 1, 2024\cr #' License: \tab CC0 \cr #' LazyLoad: \tab yes\cr #' } diff --git a/R/cu_GPSeq_clus.R b/R/cu_GPSeq_clus.R index d56e4f0..09c865b 100755 --- a/R/cu_GPSeq_clus.R +++ b/R/cu_GPSeq_clus.R @@ -22,7 +22,6 @@ #' building, model application and field site investigations. Methods in Ecology #' and Evolution, 12(5), 787-793. #' @import sf dplyr -#' @importFrom GPSeqClus GPSeq_clus #' @importFrom sfheaders sf_to_df #' @importFrom rlang .data #' @author Devin S. Johnson @@ -31,70 +30,70 @@ cu_GPSeq_clus <- function(dat, search_radius_m, window_days, clus_min_locs = 2, centroid_calc = "mean", show_plots = c(FALSE, "mean"), scale_plot_clus = TRUE, store_plots = FALSE, season_breaks_jul = NA, daylight_hrs = NA){ - - data <- AID <- TelemDate <- datetime <- y <- point_id <- sfg_id <- . <- .data <- x <- NULL - - ## Function to convert crw objects to GPSeqClus objects - crw_to_GPSeq <- function(dat){ - if("x" %in% colnames(dat)) dat <- dplyr::rename(dat, x..1=.data[["x"]]) - if("y" %in% colnames(dat)) dat <- dplyr::rename(dat, y..1=.data[["y"]]) - dat <- st_transform(dat, 4326) |> sfheaders::sf_to_df(fill=TRUE) |> dplyr::select(-sfg_id, -point_id) |> - dplyr::rename(Long=x, Lat=y, TelemDate=datetime) - if("x..1" %in% colnames(dat)) dat <- dplyr::rename(dat, x=.data[["x..1"]]) - if("y..1" %in% colnames(dat)) dat <- dplyr::rename(dat, y=.data[["y..1"]]) - dat$AID <- 1 - return(dat) - } - - ## function to execute clustering - ex_GPSeq_clus <- function(dat,search_radius_m=search_radius_m, window_days=window_days, clus_min_locs=clus_min_locs, - centroid_calc=centroid_calc, show_plots=show_plots, scale_plot_clus=scale_plot_clus, - store_plots=store_plots, season_breaks_jul=season_breaks_jul, daylight_hrs=daylight_hrs){ - x_type <- attr(dat, "crw_type") - x_crs <- st_crs(dat) - dat <- crw_to_GPSeq(dat) - clus <- try(suppressWarnings( - GPSeqClus::GPSeq_clus(dat=dat,search_radius_m=search_radius_m, window_days=window_days, clus_min_locs=clus_min_locs, - centroid_calc=centroid_calc, show_plots=show_plots, scale_plot_clus=scale_plot_clus, - store_plots=store_plots, - season_breaks_jul=season_breaks_jul, daylight_hrs=daylight_hrs) - ), silent=TRUE) - if(!inherits(clus,"try-error")){ - clus <- clus[[1]] |> rename(datetime=TelemDate) |> st_as_sf(coords=c("Long","Lat"), crs=4326) |> - st_transform(x_crs) - } else { - clus <- dat - clus <- clus |> rename(datetime=TelemDate) |> st_as_sf(coords=c("Long","Lat"), crs=4326) |> - st_transform(x_crs) - warning("Clustering failed, returning original data. Try different 'search_radius_m' values") - } - clus <- select(clus, -AID) - attr(clus, "crw_type") <- x_type - return(clus) - } - - ## Main portion of function - x_type <- attr(dat, "crw_type") - if(inherits(dat, "list")){ - if(!all(sapply(dat, attr, "crw_type")=="crwIS_sf")) stop("The 'dat' argument is not the correct form!") - x_type <- "crwIS_sf_list" - } - if(! x_type %in% c("crwIS_sf_list","crwIS_sf","crwPredict_sf")) stop("The 'dat' argument is not the correct form!") - if(x_type %in% c("crwIS_sf","crwPredict_sf")){ - dat <- ex_GPSeq_clus(dat, search_radius_m=search_radius_m, window_days=window_days, - clus_min_locs=clus_min_locs,centroid_calc=centroid_calc, - show_plots=show_plots, scale_plot_clus=scale_plot_clus, - store_plots=store_plots, season_breaks_jul=season_breaks_jul, - daylight_hrs=daylight_hrs) - } else{ - for(i in 1:length(dat)){ - dat[[i]] <- ex_GPSeq_clus(dat[[i]], search_radius_m=search_radius_m, window_days=window_days, - clus_min_locs=clus_min_locs,centroid_calc=centroid_calc, - show_plots=show_plots, scale_plot_clus=scale_plot_clus, - store_plots=store_plots, season_breaks_jul=season_breaks_jul, - daylight_hrs=daylight_hrs) - } - attr(dat, "crw_type") <- "crwIS_sf_list" - } - return(dat) +return("This function has been removed") + # data <- AID <- TelemDate <- datetime <- y <- point_id <- sfg_id <- . <- .data <- x <- NULL + # + # ## Function to convert crw objects to GPSeqClus objects + # crw_to_GPSeq <- function(dat){ + # if("x" %in% colnames(dat)) dat <- dplyr::rename(dat, x..1=.data[["x"]]) + # if("y" %in% colnames(dat)) dat <- dplyr::rename(dat, y..1=.data[["y"]]) + # dat <- st_transform(dat, 4326) |> sfheaders::sf_to_df(fill=TRUE) |> dplyr::select(-sfg_id, -point_id) |> + # dplyr::rename(Long=x, Lat=y, TelemDate=datetime) + # if("x..1" %in% colnames(dat)) dat <- dplyr::rename(dat, x=.data[["x..1"]]) + # if("y..1" %in% colnames(dat)) dat <- dplyr::rename(dat, y=.data[["y..1"]]) + # dat$AID <- 1 + # return(dat) + # } + # + # ## function to execute clustering + # ex_GPSeq_clus <- function(dat,search_radius_m=search_radius_m, window_days=window_days, clus_min_locs=clus_min_locs, + # centroid_calc=centroid_calc, show_plots=show_plots, scale_plot_clus=scale_plot_clus, + # store_plots=store_plots, season_breaks_jul=season_breaks_jul, daylight_hrs=daylight_hrs){ + # x_type <- attr(dat, "crw_type") + # x_crs <- st_crs(dat) + # dat <- crw_to_GPSeq(dat) + # clus <- try(suppressWarnings( + # GPSeqClus::GPSeq_clus(dat=dat,search_radius_m=search_radius_m, window_days=window_days, clus_min_locs=clus_min_locs, + # centroid_calc=centroid_calc, show_plots=show_plots, scale_plot_clus=scale_plot_clus, + # store_plots=store_plots, + # season_breaks_jul=season_breaks_jul, daylight_hrs=daylight_hrs) + # ), silent=TRUE) + # if(!inherits(clus,"try-error")){ + # clus <- clus[[1]] |> rename(datetime=TelemDate) |> st_as_sf(coords=c("Long","Lat"), crs=4326) |> + # st_transform(x_crs) + # } else { + # clus <- dat + # clus <- clus |> rename(datetime=TelemDate) |> st_as_sf(coords=c("Long","Lat"), crs=4326) |> + # st_transform(x_crs) + # warning("Clustering failed, returning original data. Try different 'search_radius_m' values") + # } + # clus <- select(clus, -AID) + # attr(clus, "crw_type") <- x_type + # return(clus) + # } + # + # ## Main portion of function + # x_type <- attr(dat, "crw_type") + # if(inherits(dat, "list")){ + # if(!all(sapply(dat, attr, "crw_type")=="crwIS_sf")) stop("The 'dat' argument is not the correct form!") + # x_type <- "crwIS_sf_list" + # } + # if(! x_type %in% c("crwIS_sf_list","crwIS_sf","crwPredict_sf")) stop("The 'dat' argument is not the correct form!") + # if(x_type %in% c("crwIS_sf","crwPredict_sf")){ + # dat <- ex_GPSeq_clus(dat, search_radius_m=search_radius_m, window_days=window_days, + # clus_min_locs=clus_min_locs,centroid_calc=centroid_calc, + # show_plots=show_plots, scale_plot_clus=scale_plot_clus, + # store_plots=store_plots, season_breaks_jul=season_breaks_jul, + # daylight_hrs=daylight_hrs) + # } else{ + # for(i in 1:length(dat)){ + # dat[[i]] <- ex_GPSeq_clus(dat[[i]], search_radius_m=search_radius_m, window_days=window_days, + # clus_min_locs=clus_min_locs,centroid_calc=centroid_calc, + # show_plots=show_plots, scale_plot_clus=scale_plot_clus, + # store_plots=store_plots, season_breaks_jul=season_breaks_jul, + # daylight_hrs=daylight_hrs) + # } + # attr(dat, "crw_type") <- "crwIS_sf_list" + # } + # return(dat) } diff --git a/R/cu_read_wc_dirs.R b/R/cu_read_wc_dirs.R index 3453416..282bb87 100755 --- a/R/cu_read_wc_dirs.R +++ b/R/cu_read_wc_dirs.R @@ -16,16 +16,27 @@ cu_read_wc_dirs <- function(x, remove_duplicates=TRUE){ # Determine which file to load for each animal: dirs <- list.dirs(x)[-1] nms1 <- paste0(list.dirs(x, full.names=FALSE)[-1], - "-1-Locations.csv" + "-2-Locations.csv" ) loc_file1 <- paste(dirs, nms1, sep="/") nms2 <- paste0(list.dirs(x, full.names=FALSE)[-1], - "-Locations.csv" + "-1-Locations.csv" ) loc_file2 <- paste(dirs, nms2, sep="/") + nms3 <- paste0(list.dirs(x, full.names=FALSE)[-1], + "-Locations.csv" + ) + loc_file3 <- paste(dirs, nms3, sep="/") + # Container for file names - loc_file <- ifelse(file.exists(loc_file1), loc_file1, loc_file2) + if(file.exists(loc_file1)){ + loc_file <- loc_file1 + } else if(file.exists(loc_file2)){ + loc_file <- loc_file2 + } else{ + loc_file <- loc_file3 + } # Read in data and combine into single table # There are 2 animals with no location data diff --git a/man/crawlUtils-package.Rd b/man/crawlUtils-package.Rd index 9cc9b09..5a52f49 100755 --- a/man/crawlUtils-package.Rd +++ b/man/crawlUtils-package.Rd @@ -13,8 +13,8 @@ for ease of model fitting and track prediction, notably in marine environments. \tabular{ll}{ Package: \tab crawlUtils\cr Type: \tab Package\cr -Version: \tab 0.1.46\cr -Date: \tab July 11, 2023\cr +Version: \tab 0.1.50\cr +Date: \tab March 1, 2024\cr License: \tab CC0 \cr LazyLoad: \tab yes\cr }