Skip to content

Commit

Permalink
new processFile function for updated innovasea format (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomflavio committed Jul 1, 2024
1 parent 5834e3e commit 0f376ef
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: actel
Title: Acoustic Telemetry Data Analysis
Version: 1.3.0.9005
Version: 1.3.0.9006
Authors@R: person("Hugo", "Flávio", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0002-5174-1197"))
Description: Designed for studies where animals tagged with acoustic tags are expected
to move through receiver arrays. This package combines the advantages of automatic sorting and checking
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Fixes:
Enhancements:
* Improve timestamp handling when importing data through `preload()` (issue [#94](https://github.com/hugomflavio/actel/issues/94)).
* Improve column name checks to avoid accidentally matching anything to the dot wildcard.
* Add new "first to first" method to speed calculations (issue [#94](https://github.com/hugomflavio/actel/issues/96))
* Add new "first to first" method to speed calculations (issue [#96](https://github.com/hugomflavio/actel/issues/96))
* New `processInnovaseaFile()` function to handle updated innovasea detection file format (issue [#97](https://github.com/hugomflavio/actel/issues/97)).

## actel 1.3.0

Expand Down
44 changes: 44 additions & 0 deletions R/load.R
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,13 @@ compileDetections <- function(path = "detections", start.time = NULL, stop.time
})
unknown.file <- FALSE
}
if (unknown.file && all(!is.na(match(c("Device Time (UTC)", "Full ID", "Serial Number"), colnames(aux))))) {
appendTo("debug", paste0("File '", i, "' matches an Innovasea log."))
output <- tryCatch(processInnovaseaFile(input = aux), error = function(e) {
stopAndReport("Something went wrong when processing file '", i, "'. If you are absolutely sure this file is ok, contact the developer.\nOriginal error:", sub("^Error:", "", e))
})
unknown.file <- FALSE
}
if (unknown.file) {
appendTo(c("Screen", "Report", "Warning"),
paste0("File '", i, "' does not match to any of the supported hydrophone file formats!\n If your file corresponds to a hydrophone log and actel did not recognize it, please get in contact through www.github.com/hugomflavio/actel/issues/new"))
Expand Down Expand Up @@ -1549,6 +1556,43 @@ processVemcoFile <- function(input) {
return(input)
}

#' Innovasea files
#'
#' Processes Innovasea ALS files
#'
#' @param input the detections data frame.
#'
#' @return A data frame of standardized detections from the input file.
#'
#' @keywords internal
#'
processInnovaseaFile <- function(input) {
appendTo("Debug", "Running processInnovaseaFile.")

colnames(input) <- gsub(" ", ".", colnames(input))

transmitter_aux <- strsplit(input$Full.ID, "-", fixed = TRUE)
input$CodeSpace <- unlist(lapply(transmitter_aux, function(x) paste(x[1:2], collapse = "-"))) # Rejoin code space
input$Signal <- unlist(lapply(transmitter_aux, function(x) x[3])) # extract only signal
input$Receiver <- input$Serial.Number
input$Timestamp <- input$`Device.Time.(UTC)`
input$Sensor.Value <- input$Raw.Data
input$Sensor.Unit <- rep(NA_character_, nrow(input))

input <- input[, c("Timestamp", "Receiver", "CodeSpace", "Signal", "Sensor.Value", "Sensor.Unit")]
input$Timestamp <- fasttime::fastPOSIXct(as.character(input$Timestamp), tz = "UTC")

if (any(is.na(input$Timestamp)))
stop("Importing timestamps failed", call. = FALSE)
if (any(is.na(input$Receiver)))
stop("Importing receivers failed", call. = FALSE)
if (any(is.na(input$Signal)))
stop("Importing code space failed", call. = FALSE)
if (any(is.na(input$Receiver)))
stop("Importing signals failed", call. = FALSE)
return(input)
}

#' Convert code spaces
#'
#' Unifies CodeSpace names, to avoid having different names depending on ALS vendor.
Expand Down
18 changes: 18 additions & 0 deletions man/processInnovaseaFile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0f376ef

Please sign in to comment.