Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# 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)
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)
Expand Down
20 changes: 20 additions & 0 deletions R/ato_ani_from_glatos.R
Original file line number Diff line number Diff line change
@@ -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)
}
18 changes: 18 additions & 0 deletions R/ato_ani_from_otn.R
Original file line number Diff line number Diff line change
@@ -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",
)
}
17 changes: 6 additions & 11 deletions R/glatos_to_ato.R
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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)
}
4 changes: 4 additions & 0 deletions R/otn_to_ato.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
21 changes: 21 additions & 0 deletions man/glatos_to_ato.Rd

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

21 changes: 21 additions & 0 deletions man/otn_to_ato.Rd

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

Loading