Skip to content

Commit

Permalink
Merge pull request #189 from mhpob/dev-contrib-patch
Browse files Browse the repository at this point in the history
Remove references to GitLab
  • Loading branch information
jdpye authored Jan 5, 2024
2 parents c55f8ee + 58b8dd0 commit ca0c9bf
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 108 deletions.
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ You may have a feature or function that you'd like to contribute to the package.
Clone the `glatos` repository onto your local machine. On the command line, you would CD to a working directory, then do:

```
git clone git@gitlab.oceantrack.org:GreatLakes/glatos.git
git clone git@github.com:ocean-tracking-network/glatos.git
cd glatos
git fetch
git checkout -b dev origin/dev
Expand All @@ -36,17 +36,17 @@ git push -u origin myfeature

You can push to your feature branch as many times as you like, this way you and another developer can collaborate on the feature, or just when you've reached a point that you feel you're ready to come back into the main package.

Finally, alert the package maintainers (@chrisholbrook , @trbinder , @thayden , @frank.smith , @jdpye) that your feature's ready for integration with `dev` by issuing a [Merge Request](https://gitlab.oceantrack.org/GreatLakes/glatos/merge_requests) for `myfeature` into `dev`. GitLab will run the reports on what you've changed and how it affects the current state of the `dev` branch, even if the `dev` branch has changed since you last checked!
Finally, alert the package maintainers (@chrisholbrook , @trbinder , @thayden , @frank.smith , @jdpye) that your feature's ready for integration with `dev` by issuing a [Pull Request](https://github.com/ocean-tracking-network/glatos/pulls) for `myfeature` into `dev`. GitHub will run the reports on what you've changed and how it affects the current state of the `dev` branch, even if the `dev` branch has changed since you last checked!

Responsibility for making sure your branch won't break everything now falls to the package maintainers. They'll merge in your feature if it's in good working order and it will be further tested and then eventually merged into the `master` branch, from which all the end-users of the `glatos` package run code.
Responsibility for making sure your branch won't break everything now falls to the package maintainers. They'll merge in your feature if it's in good working order and it will be further tested and then eventually merged into the `master` branch, from which all the end-users of the `glatos` package run code.

In the near future, testing will be an important part of contributing code to the package. Any tests that you can write to verify the integrity of your feature will be included as part of the build procedure for releasing official versions of `glatos`. Add them in a subfolder called `tests\myfeature` where myfeature is the name of your feature. For testing, the R package [testthat](https://cran.r-project.org/web/packages/testthat/testthat.pdf) is a good starting point.
In the near future, testing will be an important part of contributing code to the package. Any tests that you can write to verify the integrity of your feature will be included as part of the build procedure for releasing official versions of `glatos`. Add them in a subfolder called `tests\myfeature` where myfeature is the name of your feature. For testing, the R package [testthat](https://cran.r-project.org/web/packages/testthat/testthat.pdf) is a good starting point.

Documentation is done using the [roxygen](https://cran.r-project.org/web/packages/roxygen2/vignettes/rd.html) package and associated notation, so annotating your feature's functions in that way will be most helpful for integration purposes.

## Method 2: The 'Wishing Well' Method

If all that sounded quite complicated, and you'd like to see a feature added to the package, but can only describe it in plain English and not in a sweet, sweet .R file full of declarative statements and function calls, then create an [Issue](https://gitlab.oceantrack.org/GreatLakes/glatos/issues), describe what you'd like to see in the new feature, and assign it the Feature Request label. From there, any member of the community could pounce on your idea, assign it to themselves, write and commit it and claim ~~all~~ an appropriate amount of the credit.
If all that sounded quite complicated, and you'd like to see a feature added to the package, but can only describe it in plain English and not in a sweet, sweet .R file full of declarative statements and function calls, then create an [Issue](https://github.com/ocean-tracking-network/glatos/issues), describe what you'd like to see in the new feature, and assign it the Feature Request label. From there, any member of the community could pounce on your idea, assign it to themselves, write and commit it and claim ~~all~~ an appropriate amount of the credit.


In either contribution paradigm, providing supporting literature for the analysis methods you propose should be prioritized. Everyone likes to see their name in a references list, and collaborative analysis packages can be a great way to get some sunshine on that analysis method you really like.
Expand Down
72 changes: 36 additions & 36 deletions R/util-convert_glatos_to_att.r
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#' Convert detections and receiver metadata to a format that
#' Convert detections and receiver metadata to a format that
#' ATT accepts.
#'
#'
#' Convert `glatos_detections` and `glatos_receiver` objects to `ATT` for compatibility with the Animal Tracking Toolbox (<https://github.com/vinayudyawer/ATT>).
#'
#'
#' @param detectionObj a list from `read_glatos_detections`
#'
#' @param receiverObj a list from `read_glatos_receivers`
Expand All @@ -13,14 +13,14 @@
#' and transforms them into one list containing 3 `tibble::tibble`
#' objects. The input that AAT uses to get this data product is located here:
#' https://github.com/vinayudyawer/ATT/blob/master/README.md and our mappings
#' are found here: https://gitlab.oceantrack.org/GreatLakes/glatos/issues/83
#' in a comment by Ryan Gosse.
#' are found here: https://github.com/ocean-tracking-network/glatos/issues/75#issuecomment-982822886
#' in a comment by Ryan Gosse.
#'
#' @author Ryan Gosse
#'
#' @return a list of 3 tibble::tibbles containing tag dectections, tag metadata,
#' and station metadata, to be ingested by VTrack/ATT
#'
#'
#' @examples
#'
#' #--------------------------------------------------
Expand All @@ -31,21 +31,21 @@
#' package = "glatos")
#' walleye_detections <- read_glatos_detections(wal_det_file) # load walleye data
#'
#' rec_file <- system.file("extdata", "sample_receivers.csv",
#' rec_file <- system.file("extdata", "sample_receivers.csv",
#' package = "glatos")
#' rcv <- read_glatos_receivers(rec_file) # load receiver data
#'
#' ATTdata <- convert_glatos_to_att(walleye_detections, rcv)
#' @export

convert_glatos_to_att <- function(detectionObj, receiverObj,
convert_glatos_to_att <- function(detectionObj, receiverObj,
crs = sp::CRS("+init=epsg:4326")) {

transmitters <-
if(all(grepl("-", detectionObj$transmitter_id, fixed=TRUE))) {
detectionObj$transmitter_id
} else {
concat_list_strings(detectionObj$transmitter_codespace,
transmitters <-
if(all(grepl("-", detectionObj$transmitter_id, fixed=TRUE))) {
detectionObj$transmitter_id
} else {
concat_list_strings(detectionObj$transmitter_codespace,
detectionObj$transmitter_id)
}

Expand All @@ -54,57 +54,57 @@ convert_glatos_to_att <- function(detectionObj, receiverObj,
Transmitter = as.factor(transmitters),
Common.Name = as.factor(detectionObj$common_name_e)
))

tagMetadata <- unique(tagMetadata) # Cut out dupes

nameLookup <- tibble::tibble( # Get all the unique common names
Common.Name = unique(tagMetadata$Common.Name)
)
nameLookup <- dplyr::mutate(nameLookup, # Add scinames to the name lookup
Sci.Name = as.factor(purrr::map(nameLookup$Common.Name, query_worms_common))
)
# Apply sci names to frame
tagMetadata <- dplyr::left_join(tagMetadata, nameLookup, by = "Common.Name")
tagMetadata <- dplyr::left_join(tagMetadata, nameLookup, by = "Common.Name")


releaseData <- tibble::tibble( # Get the rest from detectionObj
Tag.ID = as.integer(detectionObj$animal_id),
Tag.Project = as.factor(detectionObj$glatos_project_transmitter),
Release.Latitude = detectionObj$release_latitude,
Release.Longitude = detectionObj$release_longitude,
Tag.ID = as.integer(detectionObj$animal_id),
Tag.Project = as.factor(detectionObj$glatos_project_transmitter),
Release.Latitude = detectionObj$release_latitude,
Release.Longitude = detectionObj$release_longitude,
Release.Date = as.Date(detectionObj$utc_release_date_time),
Sex = as.factor(detectionObj$sex)
)

releaseData <- dplyr::mutate(releaseData,
releaseData <- dplyr::mutate(releaseData,
# Convert sex text and null missing columns
Sex = as.factor(purrr::map(Sex, convert_sex)),
Tag.Life = as.integer(NA),
Tag.Status = as.factor(NA),
Bio = as.factor(NA)
)
)
# Final version of Tag.Metadata
tagMetadata <- dplyr::left_join(tagMetadata, releaseData, by = "Tag.ID")
tagMetadata <- dplyr::left_join(tagMetadata, releaseData, by = "Tag.ID")

detectionObj <- detectionObj %>%
dplyr::mutate(dummy = TRUE) %>%
dplyr::left_join(dplyr::select(receiverObj %>%
dplyr::mutate(dummy=TRUE),
glatos_array, station_no, deploy_lat, deploy_long,
station, dummy, ins_model_no, ins_serial_no,
dplyr::left_join(dplyr::select(receiverObj %>%
dplyr::mutate(dummy=TRUE),
glatos_array, station_no, deploy_lat, deploy_long,
station, dummy, ins_model_no, ins_serial_no,
deploy_date_time, recover_date_time),
by = c("glatos_array", "station_no", "deploy_lat",
by = c("glatos_array", "station_no", "deploy_lat",
"deploy_long", "station", "dummy")) %>%
dplyr::filter(detection_timestamp_utc >= deploy_date_time,
dplyr::filter(detection_timestamp_utc >= deploy_date_time,
detection_timestamp_utc <= recover_date_time) %>%
dplyr::mutate(ReceiverFull = concat_list_strings(ins_model_no,
dplyr::mutate(ReceiverFull = concat_list_strings(ins_model_no,
ins_serial_no)) %>%
dplyr::select(-dummy)

detections <- unique(tibble::tibble(
Date.Time = detectionObj$detection_timestamp_utc,
Transmitter = as.factor(
concat_list_strings(detectionObj$transmitter_codespace,
concat_list_strings(detectionObj$transmitter_codespace,
detectionObj$transmitter_id)),
Station.Name = as.factor(detectionObj$station),
Receiver = as.factor(detectionObj$ReceiverFull),
Expand All @@ -116,7 +116,7 @@ convert_glatos_to_att <- function(detectionObj, receiverObj,

stations <- unique(tibble::tibble(
Station.Name = as.factor(receiverObj$station),
Receiver = as.factor(concat_list_strings(receiverObj$ins_model_no,
Receiver = as.factor(concat_list_strings(receiverObj$ins_model_no,
receiverObj$ins_serial_no)),
Installation = as.factor(NA),
Receiver.Project = as.factor(receiverObj$glatos_project),
Expand All @@ -126,19 +126,19 @@ stations <- unique(tibble::tibble(
Station.Longitude = receiverObj$deploy_long,
Receiver.Status = as.factor(NA)
))

att_obj <- list(
Tag.Detections = detections,
Tag.Metadata = unique(tagMetadata),
Station.Information = unique(stations)
)

class(att_obj) <- "ATT"


if (inherits(crs, "CRS")) {
attr(att_obj, "CRS") <- crs
}
}
else {
message("Geographic projection for detection positions not recognised, reverting to WGS84 global coordinate reference system")
attr(att_obj, "CRS") <- eval(formals()$crs)
Expand All @@ -152,7 +152,7 @@ stations <- unique(tibble::tibble(
# columns, row by row.
concat_list_strings <- function(list1, list2, sep = "-") {
if (length(list1) != length(list2)) {
stop(sprintf("Lists are not the same size. %d != %d.",
stop(sprintf("Lists are not the same size. %d != %d.",
length(list1), length(list2)))
}
return (paste(list1, list2, sep = sep))
Expand Down
72 changes: 36 additions & 36 deletions R/util-convert_otn_erddap_to_att.r
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#' 3 `tibble::tibble` objects inside of a list. The input that AAT uses
#' to get this data product is located here:
#' https://github.com/vinayudyawer/ATT/blob/master/README.md and our mappings
#' are found here: https://github.com/ocean-tracking-network/glatos/issues/75
#' are found here: https://github.com/ocean-tracking-network/glatos/issues/75#issuecomment-982822886
#' in a comment by Ryan Gosse. The OTN ERDDAP instance is here:
#' https://members.oceantrack.org/erddap/tabledap/index.html but please note
#' that this only contains public data.
Expand Down Expand Up @@ -71,80 +71,80 @@
convert_otn_erddap_to_att <- function(detectionObj, erdTags, erdRcv, erdAni,
crs = sf::st_crs(4326)) {

transmitters <-
transmitters <-
if(all(grepl("-", detectionObj$transmitter_id, fixed=TRUE))){
detectionObj$transmitter_id
} else {
} else {
concat_list_strings(detectionObj$transmitter_codespace, detectionObj$transmitter_id)
}

tagMetadata <- unique(tibble::tibble( # Start building Tag.Metadata table
Tag.ID = detectionObj$animal_id,
Transmitter = as.factor(transmitters),
Common.Name = as.factor(detectionObj$common_name_e)
))

tagMetadata <- unique(tagMetadata) # Cut out dupes

nameLookup <- tibble::tibble( # Get all the unique common names
Common.Name = unique(tagMetadata$Common.Name)
)
nameLookup <- dplyr::mutate(nameLookup, # Add scinames to the name lookup
Sci.Name = as.factor(purrr::map(nameLookup$Common.Name, query_worms_common))
)
# Apply sci names to frame
tagMetadata <- dplyr::left_join(tagMetadata, nameLookup)
tagMetadata <- dplyr::left_join(tagMetadata, nameLookup)

# Matching cols that have different names
colnames(erdTags)[colnames(erdTags) == "tag_device_id"] <- "transmitter_id"
colnames(erdTags)[colnames(erdTags) == "tag_device_id"] <- "transmitter_id"
detectionObj <- dplyr::left_join(detectionObj, erdTags)
erdRcv <- dplyr::mutate(erdRcv,
station = as.character(purrr::map(erdRcv$receiver_reference_id,
station = as.character(purrr::map(erdRcv$receiver_reference_id,
extract_station))
)
# Matching cols that have different names
colnames(erdAni)[colnames(erdAni) == "animal_reference_id"] <- "animal_id"
colnames(erdAni)[colnames(erdAni) == "animal_reference_id"] <- "animal_id"
detectionObj <- dplyr::left_join(detectionObj, erdAni)

releaseData <- tibble::tibble( # Get the rest from detectionObj
Tag.ID = detectionObj$animal_id,
Tag.Project = as.factor(detectionObj$animal_project_reference),
Release.Latitude = as.double(detectionObj$latitude),
Release.Longitude = as.double(detectionObj$longitude),
Tag.ID = detectionObj$animal_id,
Tag.Project = as.factor(detectionObj$animal_project_reference),
Release.Latitude = as.double(detectionObj$latitude),
Release.Longitude = as.double(detectionObj$longitude),
Release.Date = as.Date(detectionObj$time),
Sex = as.factor(detectionObj$sex)
)

releaseData <- dplyr::mutate(releaseData,
releaseData <- dplyr::mutate(releaseData,
# Convert sex text and null missing columns
Sex = as.factor(purrr::map(Sex, convert_sex)),
Tag.Life = as.integer(NA),
Tag.Status = as.factor(NA),
Bio = as.factor(NA)
)
)
# Final version of Tag.Metadata
tagMetadata <- unique(dplyr::left_join(tagMetadata, releaseData))
tagMetadata <- unique(dplyr::left_join(tagMetadata, releaseData))

datetime_timezone = unique(detectionObj$timezone)

detectionObj <- detectionObj %>%
dplyr::mutate(dummy=TRUE) %>%
dplyr::left_join(dplyr::select(erdRcv %>% dplyr::mutate(dummy = TRUE),
rcv_latitude = latitude,
rcv_longitude = longitude,
station,
receiver_model,
receiver_serial_number,
dummy,
deploy_datetime_utc = time,
dplyr::left_join(dplyr::select(erdRcv %>% dplyr::mutate(dummy = TRUE),
rcv_latitude = latitude,
rcv_longitude = longitude,
station,
receiver_model,
receiver_serial_number,
dummy,
deploy_datetime_utc = time,
recovery_datetime_utc)) %>%
dplyr::mutate(deploy_datetime_utc = as.POSIXct(deploy_datetime_utc,
format = "%Y-%m-%dT%H:%M:%OS", tz = datetime_timezone),
recovery_datetime_utc = as.POSIXct(recovery_datetime_utc,
dplyr::mutate(deploy_datetime_utc = as.POSIXct(deploy_datetime_utc,
format = "%Y-%m-%dT%H:%M:%OS", tz = datetime_timezone),
recovery_datetime_utc = as.POSIXct(recovery_datetime_utc,
format="%Y-%m-%dT%H:%M:%OS", tz = datetime_timezone)) %>%
dplyr::filter(detection_timestamp_utc >= deploy_datetime_utc,
dplyr::filter(detection_timestamp_utc >= deploy_datetime_utc,
detection_timestamp_utc <= recovery_datetime_utc) %>%
dplyr::mutate(ReceiverFull = concat_list_strings(receiver_model,
dplyr::mutate(ReceiverFull = concat_list_strings(receiver_model,
receiver_serial_number)) %>%
dplyr::select(-dummy)

Expand Down Expand Up @@ -180,7 +180,7 @@ convert_otn_erddap_to_att <- function(detectionObj, erdTags, erdRcv, erdAni,

if (inherits(crs, "CRS")) {
attr(att_obj, "CRS") <- crs
}
}
else {
message("Geographic projection for detection positions not recognised, reverting to WGS84 global coordinate reference system")
attr(att_obj, "CRS") <- eval(formals()$crs)
Expand All @@ -190,11 +190,11 @@ convert_otn_erddap_to_att <- function(detectionObj, erdTags, erdRcv, erdAni,
}


# Function for taking 2 lists of string of the same length and concatenating
# Function for taking 2 lists of string of the same length and concatenating
# the columns, row by row.
concat_list_strings <- function(list1, list2, sep = "-") {
if (length(list1) != length(list2)) {
stop(sprintf("Lists are not the same size. %d != %d.",
stop(sprintf("Lists are not the same size. %d != %d.",
length(list1), length(list2)))
}
return (paste(list1, list2, sep = sep))
Expand All @@ -207,6 +207,6 @@ extract_station <- function(reciever_ref) {
return( # Split the string by _ and drop the array name
unlist(
strsplit(c(reciever_ref), c("_"))
)[-1]
)[-1]
)
}
Loading

0 comments on commit ca0c9bf

Please sign in to comment.