Skip to content

Commit

Permalink
Merge branch 'master' into webpage
Browse files Browse the repository at this point in the history
  • Loading branch information
Azahramirez committed Nov 7, 2024
2 parents c39408f + 5eee292 commit 2202f7c
Show file tree
Hide file tree
Showing 121 changed files with 2,636 additions and 1,118 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.httr-oauth
.DS_Store
.quarto
.Rprofile
16 changes: 11 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
Package: SoundEcology2
Title: Soundscape Ecology
Version: 0.0.0.9000
Version: 0.0.9
Authors@R: c(
person(
"Francisco", "Rivas",
email = "frivasfu@purdue.edu",
role = c("cre","aut"),
comment = c(ORCID = "0000-0002-1256-2225")),
person("Luis", "Villanueva-Rivera", role = "aut"),
person("Bryan", "Pijanowski", email = "bpijanow@purdue.edu", role = "aut"))
person("Bryan", "Pijanowski", email = "bpijanow@purdue.edu", role = "aut"),
person("Angel", "Ramirez", email = "azahramirez@gmail.com", role = "ctb"))
Description: Computes acoustic indices on audio recordings.
License: CC BY-NC 4.0
Encoding: UTF-8
Expand All @@ -21,7 +22,6 @@ Imports:
data.table,
seewave,
tuneR,
magrittr,
ineq,
plotly,
parallel,
Expand All @@ -34,9 +34,15 @@ Imports:
tibble,
tidyr,
tidyverse,
vegan,
viridis,
stats,
utils,
writexl
writexl,
grid,
future,
future.apply
VignetteBuilder: knitr
URL: https://github.com/panchorivasf/SoundEcology2
BugReports: https://github.com/panchorivasf/SoundEcology2/issues
Config/testthat/edition: 3

15 changes: 15 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export(aci)
export(aci_folder)
export(aci_list)
export(add_replicate_id)
export(adi)
export(adi_folder)
export(adi_heatmap)
Expand All @@ -22,25 +23,33 @@ export(fadi_list)
export(fci)
export(fci_folder)
export(fci_list)
export(first_recording_hour)
export(get_fft_params)
export(harmonize_index)
export(import_indices)
export(import_kaleidoscope)
export(import_kaleidoscope_batch)
export(import_stereo_mix)
export(indices_summary)
export(list_csvs)
export(list_waves)
export(merge_index_results)
export(merge_se2_indices)
export(nbai)
export(nbai_folder)
export(nbai_list)
export(ndsi)
export(ndsi_folder)
export(ndsi_list)
export(plot_diel_indices)
export(print_list)
export(spectral_dynamics)
export(spectrogram)
export(spectrogram_3d)
export(spectrogram_binary)
export(spectrogram_cutoff)
export(spectrogram_plotly)
export(summary_spectrograms)
export(tai)
export(tai_folder)
export(tai_list)
Expand Down Expand Up @@ -78,7 +87,11 @@ importFrom(dplyr,summarize)
importFrom(dplyr,ungroup)
importFrom(foreach,"%dopar%")
importFrom(foreach,foreach)
importFrom(future,multisession)
importFrom(future,plan)
importFrom(future.apply,future_lapply)
importFrom(ggplot2,aes)
importFrom(ggplot2,annotation_custom)
importFrom(ggplot2,element_text)
importFrom(ggplot2,geom_bar)
importFrom(ggplot2,geom_line)
Expand All @@ -88,6 +101,8 @@ importFrom(ggplot2,ggsave)
importFrom(ggplot2,labs)
importFrom(ggplot2,scale_x_date)
importFrom(ggplot2,theme)
importFrom(grid,gpar)
importFrom(grid,textGrob)
importFrom(lubridate,seconds)
importFrom(magrittr,"%>%")
importFrom(parallel,detectCores)
Expand Down
92 changes: 8 additions & 84 deletions R/aci.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
#' @import seewave
#' @import tibble
#'
#' @examples aci(tropicalsound)
#' @examples
#' \dontrun{
#' aci(tropicalsound)}
aci <- function(wave,
freq.res = 50,
w.fun = "hanning",
Expand All @@ -46,12 +48,10 @@ aci <- function(wave,
#test arguments
if (is.na(max.freq)){
max.freq <- wave@samp.rate / 2
# cat(paste("\n max.freq not set, using value of:", max.freq, "\n\n"))
}

if (is.na(min.freq)){
min.freq <- 0
# cat(paste("\n min.freq not set, using value of:", min.freq, "\n\n"))
}

if (is.numeric(as.numeric(min.freq))){
Expand All @@ -74,14 +74,10 @@ aci <- function(wave,
stop(" freq.res is not a number.")
}



#Some general values
#Get sampling rate
# Extract general values
samplingrate <- wave@samp.rate
duration <- length(wave@left)/samplingrate


if(is.na(j)){
j <- duration
}
Expand Down Expand Up @@ -188,11 +184,6 @@ aci <- function(wave,
which_max.freq = dim(specA_left)[1]-1
}

# cat(which_min.freq)
# cat(",")
# cat(which_max.freq)
# cat(",")
# cat(dim(specA_left))
specA_left <- spec_left$amp[which_min.freq:which_max.freq,]
rm(spec_left)

Expand All @@ -214,24 +205,13 @@ aci <- function(wave,

rm(left,right)

# specA_rows <- dim(specA_left)[1]
# specA_cols <- dim(specA_left)[2]
#
# freq_per_row <- specA_rows/nyquist_freq
#
# max_row <- round(max.freq * freq_per_row)
#
# specA_left <- specA_left[1:max_row,]
# specA_right <- specA_right[1:max_row,]
specA_rows <- dim(specA_left)[1]
specA_cols <- dim(specA_left)[2]

fl <- rep(NA, specA_rows)
delta_fl <- ( max.freq - min.freq ) / specA_rows
delta_tk <- (length(wave@left)/wave@samp.rate) / specA_cols

#m <- floor(duration / j)
#q <- specA_rows
no_j <- floor(duration / j)

#Number of values, in each row, for each j period (no. of columns)
Expand Down Expand Up @@ -264,7 +244,6 @@ aci <- function(wave,
}

ACI_tot_left <- sum(ACI_fl_left_vector)
# ACI_tot_left <- as.numeric(ACI_tot_left)

#Right channel
#For each frequency bin fl
Expand All @@ -285,31 +264,9 @@ aci <- function(wave,
}

ACI_tot_right <- sum(ACI_fl_right_vector)
# ACI_tot_right <- as.numeric(ACI_tot_right)

ACI_tot_left_by_min <- round((ACI_tot_left/duration) * 60)#, 2)
ACI_tot_right_by_min <- round((ACI_tot_right/duration) * 60)#, 2)

# cat(paste(" Acoustic Complexity Index (total):\n", " Left channel: ", sep=""))
# cat(ACI_tot_left)
# cat(paste("\n", " Right channel: ", sep=""))
# cat(ACI_tot_right)
# cat("\n\n")
# if (duration > 60){
# cat(paste(" Acoustic Complexity Index (by minute):\n", " Left channel: ", sep=""))
# cat(ACI_tot_left_by_min)
# cat(paste("\n", " Right channel: ", sep=""))
# cat(ACI_tot_right_by_min)
# cat("\n\n")
# }

# if(noise.red == 1){
# noise <- "rows"
# } else if(noise.red == 2){
# noise <- "columns"
# } else {
# noise <- "none"
# }

ACI_tot_left_by_min <- round((ACI_tot_left/duration) * 60)
ACI_tot_right_by_min <- round((ACI_tot_right/duration) * 60)


aciOutputStereo <- tibble(value_l = ACI_tot_left,
Expand Down Expand Up @@ -362,7 +319,6 @@ aci <- function(wave,


#matrix of values
# cat("\n Calculating index. Please wait... \n\n")
if(noise.red == 1 || noise.red == 2) {
spec_left <- spectro(left, f = samplingrate, wl = w.len, plot = FALSE,
norm = TRUE, dB = NULL, scale = FALSE, wn = w.fun,
Expand All @@ -372,7 +328,6 @@ aci <- function(wave,
norm = TRUE, dB = NULL, scale = FALSE, wn = w.fun)
}

# spec_left <- spectro(left, f = samplingrate, wl = w.len, plot = FALSE, norm = TRUE, dB = NULL, scale = FALSE, wn = w.fun)

specA_left <- spec_left$amp

Expand All @@ -391,20 +346,13 @@ aci <- function(wave,
specA_rows <- dim(specA_left)[1]
specA_cols <- dim(specA_left)[2]

# freq_per_row <- specA_rows/nyquist_freq
#
# max_row <- round(max.freq * freq_per_row)
#
# specA_left <- specA_left[1:max_row,]
# specA_rows <- dim(specA_left)[1]

fl <- rep(NA, specA_rows)
delta_fl <- ( max.freq - min.freq ) / specA_rows
delta_tk <- (length(wave@left)/wave@samp.rate) / specA_cols

no_j <- floor(duration / j)
#q <- specA_rows
#m <- floor(duration / j)


#Number of values, in each row, for each j period (no. of columns)
I_per_j <- floor(j/delta_tk)
Expand Down Expand Up @@ -441,24 +389,6 @@ aci <- function(wave,
ACI_tot_right <- NA
ACI_tot_right_by_min <- NA

# cat(" Acoustic Complexity Index (total): ")
# cat(ACI_tot_left)
# cat("\n\n")
# if (duration > 60){
# cat(" Acoustic Complexity Index (by minute): ")
# cat(ACI_tot_left_by_min)
# cat("\n\n")
# }

# if(noise.red == 1){
# noise <- "rows"
# } else if(noise.red == 2){
# noise <- "columns"
# } else {
# noise <- "none"
# }


aciOutputMono <- tibble(value = ACI_tot_left)

# Add metadata columns
Expand All @@ -485,10 +415,4 @@ aci <- function(wave,

}

# invisible(list(AciTotAll_left = ACI_tot_left, AciTotAll_right = ACI_tot_right,
# AciTotAll_left_bymin = ACI_tot_left_by_min, AciTotAll_right_bymin = ACI_tot_right_by_min,
# #AciIfTotAll_left=ACIif_tot_left, AciIfTotAll_right=ACIif_tot_right,
# aci_fl_left_vals = ACI_fl_left_vector, aci_fl_right_vals = ACI_fl_right_vector,
# #aci_if_left_vals=ACI_if_left_vector, aci_if_right_vals=ACI_if_right_vector,
# aci_left_matrix = ACI_left_matrix, aci_right_matrix = ACI_right_matrix))
}
7 changes: 4 additions & 3 deletions R/aci_folder.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#' @examples
#' aci_folder(path/to/folder)

aci_folder <- function (folder,
aci_folder <- function (folder = NULL,
save.csv = TRUE,
csv.name = "aci_results.csv",
freq.res = 50,
Expand Down Expand Up @@ -91,7 +91,7 @@ aci_folder <- function (folder,
args_list$noise.red,
args_list$rm.offset))

tibble(file_name = "filename") %>% bind_cols(aci1)
tibble(file_name = "filename") |> bind_cols(aci1)

# Assess how long it takes to parse 1 file
timePerFile <- Sys.time() - startTime
Expand Down Expand Up @@ -158,7 +158,7 @@ aci_folder <- function (folder,
args_list$rm.offset)

# Combine the results for each file into a single row
tibble(file_name = file) %>%
tibble(file_name = file) |>
bind_cols(aci)


Expand All @@ -172,6 +172,7 @@ aci_folder <- function (folder,
stopCluster(cl)

if(save.csv == TRUE){
resultsWithMetadata$datetime <- format(resultsWithMetadata$datetime, "%Y-%m-%d %H:%M:%S")
write.csv(resultsWithMetadata, csv.name, row.names = FALSE)
}

Expand Down
15 changes: 15 additions & 0 deletions R/add_replicate_id.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#' Add replicate id for a dataset with severall treatments
#'
#' @param data a data frame
#' @param treatment the name of the column containing the treatment identifiers
#'
#' @return a data frame with treatment_id column
#' @export
#'
#' @examples add_replicate_id(my_dataset, treatment = 'zone')
add_replicate_id <- function(data, treatment = "treatment") {
data %>%
group_by(treatment) %>%
mutate(replicate = dense_rank(sensor_id)) %>%
ungroup()
}
Loading

0 comments on commit 2202f7c

Please sign in to comment.