From 0f376efcbff637618ccb631f4489bf14f7e6b476 Mon Sep 17 00:00:00 2001 From: hugomflavio Date: Mon, 1 Jul 2024 19:21:00 -0400 Subject: [PATCH] new processFile function for updated innovasea format (#97) --- DESCRIPTION | 2 +- NEWS.md | 3 ++- R/load.R | 44 +++++++++++++++++++++++++++++++++++++ man/processInnovaseaFile.Rd | 18 +++++++++++++++ 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 man/processInnovaseaFile.Rd diff --git a/DESCRIPTION b/DESCRIPTION index ed1a568..1d0312b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 = "hflavio@wlu.ca", 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 diff --git a/NEWS.md b/NEWS.md index fd2314c..515cfd6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/load.R b/R/load.R index faa2e8e..ba58d83 100644 --- a/R/load.R +++ b/R/load.R @@ -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")) @@ -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. diff --git a/man/processInnovaseaFile.Rd b/man/processInnovaseaFile.Rd new file mode 100644 index 0000000..eaae781 --- /dev/null +++ b/man/processInnovaseaFile.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/load.R +\name{processInnovaseaFile} +\alias{processInnovaseaFile} +\title{Innovasea files} +\usage{ +processInnovaseaFile(input) +} +\arguments{ +\item{input}{the detections data frame.} +} +\value{ +A data frame of standardized detections from the input file. +} +\description{ +Processes Innovasea ALS files +} +\keyword{internal}