Skip to content

Commit bff3e94

Browse files
committed
Refinements to extract_ctd_cast to compute time (s) variable after extracting downcast data.
1 parent 39064c0 commit bff3e94

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

R/ctd.R

+5-4
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ extract_ctd_header <- function(header.filename, type) {
8888
#' @param cast.filename Name of cast file.
8989
#' @param type Cast type (CTD or UCTD).
9090
#' @param skip Number of lines to skip (default = 79 for Valeport files)
91+
#' @param min.Z Minimum depth (Z, m) for identifying downcast data (default = 2)
9192
#' @return A data frame containing cast data.
9293
#' @export
93-
extract_ctd_cast <- function(cast.filename, type, skip = 79) {
94+
extract_ctd_cast <- function(cast.filename, type, skip = 79, min.Z = 2) {
9495

9596
# Extract cast name from file path
9697
if(stringr::str_detect(cast.filename, ".asc")) {
@@ -130,6 +131,8 @@ extract_ctd_cast <- function(cast.filename, type, skip = 79) {
130131
# Read cast data and rename columns
131132
read.table(cast.filename, skip = skip,
132133
col.names = c("date","time","Z","P","T","C","S","Sv","Dens","ChlA","Ticks")) %>%
134+
# Include only downcast data
135+
dplyr::slice(which(Z > min.Z)[1]:which.max(Z)) %>%
133136
dplyr::mutate(
134137
scan = seq_along(date),
135138
t = lubridate::ymd_hms(paste(date, time)),
@@ -142,9 +145,7 @@ extract_ctd_cast <- function(cast.filename, type, skip = 79) {
142145
dZt = dplyr::na_if(dZt, Inf),
143146
Z = -Z,
144147
cast = cast,
145-
path = cast.filename) %>%
146-
# Include only downcast data
147-
dplyr::slice(which(Z < -2)[1]:which.min(Z))
148+
path = cast.filename)
148149
}
149150

150151
} else if (type == "CTD") {

man/extract_ctd_cast.Rd

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)