diff --git a/NAMESPACE b/NAMESPACE index 5e80fbe..2434667 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +export(glatos_to_ato) export(imos_otn_column_map) export(imos_to_otn_detections) export(imos_to_otn_receivers) @@ -7,6 +8,7 @@ export(imos_to_otn_tags) export(map_otn_file) export(otn_imos_column_map) export(otn_imos_new_style_column_map) +export(otn_to_ato) export(rollup) importFrom(dplyr,'%>%') importFrom(dplyr,arrange) diff --git a/R/ato_ani_from_glatos.R b/R/ato_ani_from_glatos.R new file mode 100644 index 0000000..aebfab7 --- /dev/null +++ b/R/ato_ani_from_glatos.R @@ -0,0 +1,20 @@ +ato_ani_from_glatos <- function(glatos_file) { + # Load the data file we've been given- probably detections data since published glatos data will only have detections and receivers. + glatos_data <- load_file(glatos_file) + + # We don't really have the option here to get this from an 'animal metadata' file so we're always going to be deriving. + ani <- make_ani( + animal = as.character(glatos_data$animal_id), + capture_location = as.character(glatos_data$capture_location), + capture_datetime = as.POSIXct(glatos_data$glatos_caught_date), + capture_lat = NA_real_, + capture_lon = NA_real_, + release_loaction = glatos_data$release_location, + release_datetime = as.POSIXct(glatos_data$utc_release_date_time), + release_lat = glatos_data$release_latitude, + release_lon = glatos_data$release_longitude, + tz = "UTC" + ) + + return(ani) +} diff --git a/R/ato_ani_from_otn.R b/R/ato_ani_from_otn.R new file mode 100644 index 0000000..f9c8e37 --- /dev/null +++ b/R/ato_ani_from_otn.R @@ -0,0 +1,18 @@ +ato_ani_from_otn <- function(otn_file) { + # Import the file we've got. + otn_data <- load_file(otn_file) + + # OTN doesn't have a bespoke animal file so we'll take what we get from the tag file. + ani <- make_ani( + animal = otn_data$ANIMAL_ID, + capture_location = otn_data$CAPTURE_LOCATION, + capture_datetime = as.POSIXct(NA_real_), + capture_lat = otn_data$CAPTURE_LAT, + capture_lon = otn_data$CAPTURE_LON, + release_location = otn_data$RELEASE_LOCATION, + release_datetime = as.POSIXct(otn_data$UTC_RELEASE_DATE_TIME), + release_lat = otn_data$RELEASE_LATITUDE, + release_lon = otn_data$RELEASE_LONGITUDE, + tz = "UTC", + ) +} diff --git a/R/glatos_to_ato.R b/R/glatos_to_ato.R index bf5428b..06dbee8 100644 --- a/R/glatos_to_ato.R +++ b/R/glatos_to_ato.R @@ -1,6 +1,6 @@ ##' @title Convert GLATOS detection data to an ATO object. ##' -##' @description Takes a GLATOS detection sheet and optionally receiver/tag metadata and returns an ATO object. +##' @description Takes a GLATOS detection sheet and optionally receiver metadata and returns an ATO object. ##' ##' @param otn_detections The dataframe containing detection information. ##' @param otn_receivers The dataframe containing receiver information. @@ -15,7 +15,7 @@ ##' @export ##' -glatos_to_ato <- function(glatos_detections, glatos_receivers = "", glatos_tags = "") { +glatos_to_ato <- function(glatos_detections, glatos_receivers = "") { glatos_detections <- load_file(glatos_detections) # Now we have a dataframe we can start loading into an ATO object. Let's make an instance of the object. @@ -34,9 +34,8 @@ glatos_to_ato <- function(glatos_detections, glatos_receivers = "", glatos_tags GLATOS_ATO <- add(GLATOS_ATO, det) # I used to have a 'derive' argument as in some of the original OTN-to-IMOS functions but then I realised it was safer to just - # automatically try to derive receiver/tag metadata from the extract if no file is supplied. + # automatically try to derive receiver metadata from the extract if no file is supplied. dep <- "" - tag <- "" # In both cases, if a file is supplied, we'll make the metadata objects using the information therein; # otherwise, we'll attempt to make approximately correct receiver/tag metadata from only what's contained in @@ -49,15 +48,11 @@ glatos_to_ato <- function(glatos_detections, glatos_receivers = "", glatos_tags GLATOS_ATO <- add(GLATOS_ATO, dep) - # In the detection extract zip I had for reference there didn't seem to be a bespoke Tag metadata file. I'll leave this structure here in case we need to build it out further but I think it's only ever going to flop into the else. - # if (glatos_tags != "") { - # tag <- ato_tag_from_glatos(glatos_tags, type = "meta") + # Tag information is not part of what's distributed in glatos publications so we can neither load it nor meaningfully derive it. - # } else { - # tag <- ato_tag_from_glatos(glatos_detections, type = "extract") - # } + ani <- ato_ani_from_glatos(glatos_detections) - # GLATOS_ATO <- add(GLATOS_ATO, tag) + GLATOS_ATO <- add(GLATOS_ATO, ani) return(GLATOS_ATO) } diff --git a/R/otn_to_ato.R b/R/otn_to_ato.R index 6a22d80..34f3a2b 100644 --- a/R/otn_to_ato.R +++ b/R/otn_to_ato.R @@ -63,6 +63,10 @@ otn_to_ato <- function(otn_detections, otn_receivers = "", otn_tags = "") { if (otn_tags != "") { tag <- ato_tag_from_otn(otn_tags, type = "meta") + # If we have a tag metadata file, we can derive an animal object; if we don't, there's hardly enough information to bother, + # and if people are so inclined they can add it manually through the ATO's default functions and ATools. + ani <- ato_ani_from_otn(otn_tags) + OTN_ATO <- add(OTN_ATO, ani) } else { tag <- ato_tag_from_otn(otn_detections, type = "extract") } diff --git a/man/glatos_to_ato.Rd b/man/glatos_to_ato.Rd new file mode 100644 index 0000000..a6f6cb9 --- /dev/null +++ b/man/glatos_to_ato.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/glatos_to_ato.R +\name{glatos_to_ato} +\alias{glatos_to_ato} +\title{Convert GLATOS detection data to an ATO object.} +\usage{ +glatos_to_ato(glatos_detections, glatos_receivers = "") +} +\arguments{ +\item{otn_detections}{The dataframe containing detection information.} + +\item{otn_receivers}{The dataframe containing receiver information.} + +\item{otn_tags}{The dataframe containing tag information.} +} +\value{ +Returns an ATO object. +} +\description{ +Takes a GLATOS detection sheet and optionally receiver metadata and returns an ATO object. +} diff --git a/man/otn_to_ato.Rd b/man/otn_to_ato.Rd new file mode 100644 index 0000000..93556eb --- /dev/null +++ b/man/otn_to_ato.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/otn_to_ato.R +\name{otn_to_ato} +\alias{otn_to_ato} +\title{Convert OTN detection data to an ATO object.} +\usage{ +otn_to_ato(otn_detections, otn_receivers = "", otn_tags = "") +} +\arguments{ +\item{otn_detections}{The dataframe containing detection information.} + +\item{otn_receivers}{The dataframe containing receiver information.} + +\item{otn_tags}{The dataframe containing tag information.} +} +\value{ +Returns an ATO object. +} +\description{ +Takes an OTN detection extract and optionally receiver/tag metadata and returns an ATO object. +}