|
| 1 | +if (simulated){ |
| 2 | +# Creating vector for duration |
| 3 | +durs <- rep(c(0.3, 1), 5) |
| 4 | +# Creating simulated song |
| 5 | +set.seed(12) |
| 6 | +simulated_1 <- warbleR::simulate_songs(n = 10, durs = durs, freqs = 5, sig2 = 0.01, gaps = 0.5, harms = 1, bgn = 0.1, path = tempdir(), file.name = "simulated_1", selec.table = TRUE, shape = "cos", fin = 0.3, fout = 0.35, samp.rate = 18) |
| 7 | +sim_2 <- sim_songs(n = 10, durs = durs, freqs = 5, sig2 = 0.01, gaps = 0.5, harms = 1, bgn = 0.1, path = tempdir(), file.name = "simulated_2", selec.table = TRUE, shape = "cos", fin = 0.3, fout = 0.35, samp.rate = 18, am.amps = c(1, 2, 3, 2, 0.1, 2, 3, 3, 2, 1)) |
| 8 | +sel_tab2 <- sel_tab1 <- simulated_1$selec.table |
| 9 | +sel_tab2$sound.files <- gsub("_1", "_2", sel_tab2$sound.files) |
| 10 | +sel_tab <- rbind(sel_tab1, sel_tab2) |
| 11 | +return(sel_tab) |
| 12 | +} |
| 13 | +# if (other.formats){ |
| 14 | +# file.copy(from = system.file("extdata", "recording_20170716_230503.wac", package = "bioacoustics"), to = file.path(tempdir(), "recording_20170716_230503.wac")) |
| 15 | +# |
| 16 | +# file.copy(from = "../Phae.long4.mp3", to = file.path(tempdir(), "Phae.long4.mp3")) |
| 17 | +# |
| 18 | +# file.copy(from = file.path(tempdir(), "Phae.long1.wav"), to = file.path(tempdir(), "Phae.long5.wav")) |
| 19 | +# |
| 20 | +# wav2flac(file.path(tempdir(), "Phae.long5.wav")) |
| 21 | +# |
| 22 | +# if (selection.table){ |
| 23 | +# |
| 24 | +# lbh_selec_table$sound.files <- as.character(lbh_selec_table$sound.files) |
| 25 | +# |
| 26 | +# sub_tab <- lbh_selec_table[lbh_selec_table$sound.files %in% c("Phae.long1.wav", "Phae.long4.wav"), 1:7] |
| 27 | +# |
| 28 | +# sub_tab$sound.files[sub_tab$sound.files == "Phae.long1.wav"] <- "Phae.long5.flac" |
| 29 | +# |
| 30 | +# sub_tab$sound.files[sub_tab$sound.files == "Phae.long4.wav"] <- "Phae.long4.mp3" |
| 31 | +# |
| 32 | +# # fix times |
| 33 | +# sub_tab$start[sub_tab$sound.files == "Phae.long4.mp3"] <- c(0.2085945, 1.5950019, 2.3057996) |
| 34 | +# |
| 35 | +# sub_tab$end[sub_tab$sound.files == "Phae.long4.mp3"] <- c(0.3528653, 1.7287163, 2.4289576) |
| 36 | +# |
| 37 | +# |
| 38 | +# sub_tab <- rbind(sub_tab, data.frame(sound.files = "recording_20170716_230503.wac", channel = 1, selec = 1, start = 0.1, end = 0.3, bottom.freq = 2, top.freq = 10)) |
| 39 | +# |
| 40 | +# sub_tab <- rbind(sub_tab, lbh_selec_table[, 1:7]) |
| 41 | +# |
| 42 | +# sub_tab$format <-ifelse(grepl("flac$", sub_tab$sound.files), "flac", ifelse(grepl("mp3$", sub_tab$sound.files), "mp3", "wav")) |
| 43 | +# |
| 44 | +# |
| 45 | +# return(sub_tab) |
| 46 | +# } else return(NULL) |
| 47 | +# } |
| 48 | +} |
| 49 | +# run all warbleR fuctions |
| 50 | +run.all <- function() invisible(lapply(list.files(pattern = "\\.R", path = "./R", full.names = T, all.files = T), function(x) source(x))) |
| 51 | +# run.all() |
| 52 | +list.selection.table <- function(lbh_selec_table, path = tempdir()) |
| 53 | +{ |
| 54 | +crr.dr <- getwd() |
| 55 | +on.exit(setwd(crr.dr)) |
| 56 | +if(!is.null(path)) setwd(path) |
| 57 | +Xlist <- list() |
| 58 | +Xlist$Xdf <- lbh_selec_table |
| 59 | +Xlist$Xst <- selection_table(lbh_selec_table) |
| 60 | +Xlist$Xest <- selection_table(lbh_selec_table, extended = T, confirm.extended = F) |
| 61 | +lbh_selec_table$song <- as.numeric(lbh_selec_table$sound.files) |
| 62 | +Xlist$Xestbs <- selection_table(X = lbh_selec_table, extended = T, by.song = "song", confirm.extended = F) |
| 63 | +names(Xlist) <- c("DATA.FRAME", "SELECTION_TABLE", "EXTENDED_SELECTION_TABLE", "by.song.EXTENDED_SELECTION_TABLE") |
| 64 | +return(Xlist) |
| 65 | +} |
| 66 | +bi_mats <- function(X, labels) { |
| 67 | +# create empty matrix to store memebership matrix |
| 68 | +mat <- matrix(nrow = ncol(X), ncol = ncol(X)) |
| 69 | +# add labels to row and col names |
| 70 | +rownames(mat) <- colnames(mat) <- labels |
| 71 | +# add 0 if same lek and 1 if else |
| 72 | +out <- lapply(1:(length(labels) - 1), function(i){ |
| 73 | +sapply((i + 1):length(labels), function(j) |
| 74 | +if (labels[i] == labels[j]) 0 else 1) |
| 75 | +}) |
| 76 | +# add to mat |
| 77 | +mat[lower.tri(mat)] <- unlist(out) |
| 78 | +# retunr as distance matrix |
| 79 | +return(as.dist(mat)) |
| 80 | +} |
| 81 | +plot_detection <- function(reference, detection, lwd = 90, sep = 1, labels = detection$selec){ |
| 82 | +if (!is.null(detection$detection.class)){ |
| 83 | +labels <- ifelse(detection$detection.class == "true.positive", "\nTP", ifelse(detection$detection.class == "false.positive", "\nFP", ifelse(detection$detection.class == "false.negative", "\nFN", ifelse(detection$detection.class == "true.positive (split)", "\nTPs", ifelse(detection$detection.class == "true.positive (merged)", "\nTPm", ifelse(detection$detection.class == "negative (split)", "\nNs", ifelse(detection$detection.class == "negative (merged)", "\nNm", ifelse(detection$detection.class == "negative (split/merged)", "\nNsm", "\nTPsm")))))))) |
| 84 | +detection$labels <- paste0(detection$selec, labels) |
| 85 | +} else detection$labels <- detection$selec |
| 86 | +old_par <- par() |
| 87 | +old_par <- old_par[!names(old_par) %in% c("cin", "cra", "csi", "cxy", "din", "page")] |
| 88 | +on.exit(par(old_par)) |
| 89 | +par(mar = rep(0, 4)) |
| 90 | +n_sound.files <- length(unique(c(reference$sound.files, detection$sound.files))) |
| 91 | +if (n_sound.files > 1) |
| 92 | +par(mfrow = c(n_sound.files, 1)) |
| 93 | +for (e in unique(c(detection$sound.files, reference$sound.files))){ |
| 94 | +sub_detec <- detection[detection$sound.files == e, ] |
| 95 | +sub_ref <- reference[reference$sound.files == e, ] |
| 96 | +plot(x = range(c(sub_detec$start, sub_detec$end, sub_ref$start, sub_ref$end)), y = c(-1, 1), col = "white", pch = 21, yaxt = "n", ylab = "", xaxt = "n", xlab = "") |
| 97 | +# plot references first |
| 98 | +if (nrow(sub_ref) > 0) |
| 99 | +for (i in 1:nrow(sub_ref)){ |
| 100 | +segments( |
| 101 | +x0 = sub_ref$start[i], |
| 102 | +x1 = sub_ref$end[i], |
| 103 | +y0 = sep / -2, |
| 104 | +y1 = sep / -2, |
| 105 | +lwd = lwd, |
| 106 | +col = viridis::magma(10, alpha = 0.4)[3], |
| 107 | +lend = 1 |
| 108 | +) |
1 | 109 | text(x = (sub_ref$end[i] + sub_ref$start[i]) / 2, y = sep / -2, labels = i, col = "white") |
2 | 110 | } |
3 | 111 | # add detections |
@@ -31,134 +139,50 @@ return(sim_ref) |
31 | 139 | sims <- do.call(rbind, sims_l) |
32 | 140 | return(sims) |
33 | 141 | } |
34 | | -# set XC key |
35 | | -if (!nzchar(Sys.getenv("xc_api_key"))) |
36 | | -Sys.setenv(xc_api_key = getPass::getPass()) |
37 | | -# update citation |
38 | | -source("~/Dropbox/R_package_testing/suwo/testing/update_citation.R") |
39 | | -lintr::lint_package(linters = list(lintr::line_length_linter())) |
40 | | -lintr::lint_package(linters = list(lintr::line_length_linter())) |
41 | | -devtools::document(".") |
42 | | -devtools::check(document = TRUE, run_dont_test = TRUE, vignettes = TRUE, manual = TRUE) |
43 | | -up_amanitas_list <- |
44 | | -lapply(split(sub_amanitas, sub_amanitas$repository), update_metadata) |
45 | | -# merge updated metadata |
46 | | -up_amanitas <- do.call(merge_metadata, up_amanitas_list) |
47 | | -# check number of rows is the same (e.g. it has been updated) |
48 | | -nrow(amanitas) == nrow(a_gioiosa) + nrow(a_orientigemmata) |
49 | | -devtools::document(".") |
50 | | -devtools::check(document = TRUE, run_dont_test = TRUE, vignettes = TRUE, manual = TRUE) |
51 | | -beepr::beep(3) |
52 | | -devtools::document(".") |
53 | | -devtools::check(document = TRUE, run_dont_test = TRUE, vignettes = TRUE, manual = TRUE) |
54 | | -source("~/Dropbox/R_package_testing/suwo/R/map_locations.R") |
55 | | -source("~/Dropbox/R_package_testing/suwo/R/internal_functions.R") |
56 | | -source("~/Dropbox/R_package_testing/suwo/R/map_locations.R") |
57 | | -source("~/Dropbox/R_package_testing/suwo/R/map_locations.R") |
58 | | -merged_data <- read.csv("map_location_vignette_data.csv") |
59 | | -merged_data <- read.csv("./vignettes/map_location_vignette_data.csv") |
60 | | -op_sound <- merged_data[ |
61 | | -merged_data$format == "sound" & merged_data$species == "Oophaga pumilio", |
62 | | -] |
63 | | -op_image_ca_sample <- merged_data[merged_data$format == "image", ] |
64 | | -cm_video_display <- merged_data[merged_data$format == "video", ] |
65 | | -alouatta_sound <- merged_data[grep("Alouatta", merged_data$species), ] |
66 | | -# get metadata |
67 | | -op_image <- query_inaturalist( |
68 | | -species = "Oophaga pumilio", |
| 142 | +run.all() |
| 143 | +df1 <- query_gbif( |
| 144 | +species = 'Phaethornis anthophilus', |
| 145 | +all_data = FALSE, |
69 | 146 | format = "image" |
70 | 147 | ) |
71 | | -# restrict only to those in its natural range (Central America) |
72 | | -op_image_ca <- op_image[ |
73 | | -op_image$latitude >= 7 & |
74 | | -op_image$latitude <= 15 & |
75 | | -op_image$longitude >= -90 & |
76 | | -op_image$longitude <= -80 & |
77 | | -!is.na(op_image$latitude), |
78 | | -] |
79 | | -# restrict only to those in its natural range (Central America) |
80 | | -op_image_ca <- op_image[ |
81 | | -op_image$latitude >= 7 & |
82 | | -op_image$latitude <= 15 & |
83 | | -op_image$longitude >= -90 & |
84 | | -op_image$longitude <= -80 & |
85 | | -!is.na(op_image$latitude), |
86 | | -] |
87 | | -# make map |
88 | | -map_locations( |
89 | | -metadata = op_image_ca_sample |
90 | | -) |
91 | | -source("~/Dropbox/R_package_testing/suwo/R/map_locations.R") |
92 | | -# make map |
93 | | -map_locations( |
94 | | -metadata = op_image_ca_sample |
95 | | -) |
96 | | -source("~/Dropbox/R_package_testing/suwo/R/map_locations.R") |
97 | | -# make map |
98 | | -map_locations( |
99 | | -metadata = op_image_ca_sample |
100 | | -) |
101 | | -source("~/Dropbox/R_package_testing/suwo/R/map_locations.R") |
102 | | -source("~/Dropbox/R_package_testing/suwo/R/map_locations.R") |
103 | | -# make map |
104 | | -map_locations( |
105 | | -metadata = op_image_ca_sample |
106 | | -) |
107 | | -source("~/Dropbox/R_package_testing/suwo/R/map_locations.R") |
108 | | -# make map |
109 | | -map_locations( |
110 | | -metadata = op_image_ca_sample |
111 | | -) |
112 | | -source("~/Dropbox/R_package_testing/suwo/R/map_locations.R") |
113 | | -# make map |
114 | | -map_locations( |
115 | | -metadata = op_image_ca_sample |
116 | | -) |
117 | | -source("~/Dropbox/R_package_testing/suwo/R/map_locations.R") |
118 | | -source("~/Dropbox/R_package_testing/suwo/R/map_locations.R") |
119 | | -# make map |
120 | | -map_locations( |
121 | | -metadata = op_image_ca_sample |
122 | | -) |
123 | | -# make map |
124 | | -map_locations( |
125 | | -alouatta_sound, |
126 | | -by = "species", |
127 | | -show_media = FALSE, |
128 | | -palette = grDevices::hcl.colors # viridis palette |
129 | | -) |
130 | | -devtools::reload() |
131 | | -devtools::document() |
132 | | -devtools::document() |
133 | | -devtools::reload() |
134 | | -devtools::reload() |
| 148 | +df2 <- df1[df1$key %in% c("5063794756", "5077057045"), ] |
| 149 | +sxc1 <- df2[!duplicated(df2$key), ][1:2, ] |
| 150 | +a <- download_media(metadata = sxc1, path = tempdir()) |
| 151 | +fls <- list.files(path = tempdir(), pattern = "jpeg$") |
| 152 | +a |
| 153 | +fls <- list.files(path = tempdir(), pattern = "jpeg$") |
| 154 | +library(warbleR) |
| 155 | +open_wd(tempdir()) |
| 156 | +a |
135 | 157 | devtools::document() |
136 | | -devtools::reload() |
137 | | -lintr::lint_packag(linters = list(lintr::line_length_linter())) |
138 | | -lintr::lint_package(linters = list(lintr::line_length_linter())) |
| 158 | +help("download_media") |
| 159 | +all( |
| 160 | +c("download_status", "downloaded_file_name", "file_size") %in% names(a) |
| 161 | +) |
| 162 | +# remove filess |
| 163 | +unlink(file.path(tempdir(), a$downloaded_file_name)) |
| 164 | +a <- download_media(metadata = sxc1, path = tempdir(), folder_by = "country") |
| 165 | +a |
| 166 | +source("~/Dropbox/R_package_testing/suwo/testing/update_citation.R") |
139 | 167 | if (!nzchar(Sys.getenv("xc_api_key"))) |
140 | 168 | Sys.setenv(xc_api_key = getPass::getPass()) |
141 | | -# update vignette (Need XC key) |
142 | | -# if (nzchar(Sys.getenv("xc_api_key"))) |
143 | | -# source("~/Dropbox/R_package_testing/suwo/vignettes/precompile.R") |
144 | 169 | devtools::document(".") |
145 | 170 | devtools::check(document = TRUE, run_dont_test = TRUE, vignettes = TRUE, manual = TRUE) |
146 | 171 | beepr::beep(3) |
147 | | -if (!nzchar(Sys.getenv("xc_api_key"))) |
148 | | -Sys.setenv(xc_api_key = getPass::getPass()) |
149 | | -# update vignette (Need XC key) |
150 | | -# if (nzchar(Sys.getenv("xc_api_key"))) |
151 | | -# source("~/Dropbox/R_package_testing/suwo/vignettes/precompile.R") |
152 | 172 | devtools::document(".") |
153 | 173 | devtools::check(document = TRUE, run_dont_test = TRUE, vignettes = TRUE, manual = TRUE) |
154 | 174 | beepr::beep(3) |
155 | | -# update citation |
156 | | -source("~/Dropbox/R_package_testing/suwo/testing/update_citation.R") |
157 | | -# update citation |
158 | | -source("~/Dropbox/R_package_testing/suwo/testing/update_citation.R") |
159 | | -source("~/Dropbox/R_package_testing/suwo/testing/update_citation.R") |
160 | | -source("~/Dropbox/R_package_testing/suwo/R/download_media.R") |
161 | | -source("~/Dropbox/R_package_testing/suwo/R/download_media.R") |
| 175 | +system("air format . --check") |
| 176 | +system("air format ./R --check") |
| 177 | +system("air format ./R --check") |
| 178 | +system("air format ./R --check") |
| 179 | +system("air format . --check") |
| 180 | +system("air format .") |
| 181 | +system("air format . --check") |
| 182 | +citation("suwo") |
| 183 | +devtools::install() |
| 184 | +citation("suwo") |
| 185 | +cat(format(citation("suwo"), style = "text")) |
162 | 186 | # devtools::install() |
163 | 187 | remotes::install_github("ropensci-review-tools/pkgcheck") |
164 | 188 | pkgs <- c("remotes", "curl", "RCurl", "jsonlite", "crayon", "devtools", "leaflet", "maps", "pkgcheck", "pkgstats", "testthat", "styler", "cli", "beepr", "RecordLinkage", "getPass") |
@@ -467,46 +491,22 @@ sims <- do.call(rbind, sims_l) |
467 | 491 | return(sims) |
468 | 492 | } |
469 | 493 | run.all() |
470 | | -df1 <- query_gbif( |
471 | | -species = 'Phaethornis anthophilus', |
472 | | -all_data = FALSE, |
473 | | -format = "image" |
| 494 | +df1 <- query_macaulay( |
| 495 | +species = 'Glaucis dohrnii', |
| 496 | +format = "sound", |
| 497 | +path = tempdir() |
474 | 498 | ) |
475 | | -df2 <- df1[df1$key %in% c("5063794756", "5077057045"), ] |
476 | | -sxc1 <- df2[!duplicated(df2$key), ][1:2, ] |
477 | | -a <- download_media(metadata = sxc1, path = tempdir()) |
478 | | -fls <- list.files(path = tempdir(), pattern = "jpeg$") |
479 | | -a |
480 | | -fls <- list.files(path = tempdir(), pattern = "jpeg$") |
481 | | -library(warbleR) |
482 | | -open_wd(tempdir()) |
483 | | -a |
484 | | -devtools::document() |
485 | | -help("download_media") |
486 | | -all( |
487 | | -c("download_status", "downloaded_file_name", "file_size") %in% names(a) |
| 499 | +load("~/Dropbox/R_package_testing/suwo/R/sysdata.rda") |
| 500 | +df1 <- query_macaulay( |
| 501 | +species = 'Glaucis dohrnii', |
| 502 | +format = "sound", |
| 503 | +path = tempdir() |
| 504 | +) |
| 505 | +source("~/Dropbox/R_package_testing/suwo/R/internal_functions.R") |
| 506 | +source("~/Dropbox/R_package_testing/suwo/R/internal_functions.R") |
| 507 | +source("~/Dropbox/R_package_testing/suwo/R/query_macaulay.R") |
| 508 | +df1 <- query_macaulay( |
| 509 | +species = 'Glaucis dohrnii', |
| 510 | +format = "sound", |
| 511 | +path = tempdir() |
488 | 512 | ) |
489 | | -# remove filess |
490 | | -unlink(file.path(tempdir(), a$downloaded_file_name)) |
491 | | -a <- download_media(metadata = sxc1, path = tempdir(), folder_by = "country") |
492 | | -a |
493 | | -source("~/Dropbox/R_package_testing/suwo/testing/update_citation.R") |
494 | | -if (!nzchar(Sys.getenv("xc_api_key"))) |
495 | | -Sys.setenv(xc_api_key = getPass::getPass()) |
496 | | -devtools::document(".") |
497 | | -devtools::check(document = TRUE, run_dont_test = TRUE, vignettes = TRUE, manual = TRUE) |
498 | | -beepr::beep(3) |
499 | | -devtools::document(".") |
500 | | -devtools::check(document = TRUE, run_dont_test = TRUE, vignettes = TRUE, manual = TRUE) |
501 | | -beepr::beep(3) |
502 | | -system("air format . --check") |
503 | | -system("air format ./R --check") |
504 | | -system("air format ./R --check") |
505 | | -system("air format ./R --check") |
506 | | -system("air format . --check") |
507 | | -system("air format .") |
508 | | -system("air format . --check") |
509 | | -citation("suwo") |
510 | | -devtools::install() |
511 | | -citation("suwo") |
512 | | -cat(format(citation("suwo"), style = "text")) |
0 commit comments