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: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
branches: [main, master, dev]
pull_request:
branches: [main, master]

Expand Down
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Package: swfscDAS
Title: Processing DAS Data Files
Version: 0.6.4
Version: 0.7.0.9000
Authors@R:
person("Sam", "Woodman", email = "sam.woodman@noaa.gov", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-6071-8186"))
Description: Process and summarize DAS data files.
These files are typically, but do not have to be
DAS <https://swfsc-publications.fisheries.noaa.gov/publications/TM/SWFSC/NOAA-TM-NMFS-SWFSC-305.PDF> data
DAS <https://repository.library.noaa.gov/view/noaa/3174> data
produced by the Southwest Fisheries Science Center (SWFSC) program 'WinCruz'.
This package standardizes and streamlines basic DAS data processing,
and includes a PDF with the DAS data format requirements expected by the package.
Expand All @@ -31,5 +31,6 @@ Suggests:
testthat (>= 2.1.0)
License: Apache License (== 2)
Encoding: UTF-8
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
VignetteBuilder: knitr
Config/roxygen2/version: 8.0.0
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ S3method(das_comments,das_dfr)
S3method(das_comments,data.frame)
S3method(das_effort,das_df)
S3method(das_effort,data.frame)
S3method(das_effort_strata,das_df)
S3method(das_effort_strata,data.frame)
S3method(das_intersects_strata,data.frame)
S3method(das_intersects_strata,list)
S3method(das_process,character)
Expand Down Expand Up @@ -54,6 +56,7 @@ export(das_process)
export(das_read)
export(das_segdata)
export(das_sight)
export(das_spcodes_read)
export(distance_greatcircle)
export(randpicks_convert)
importFrom(dplyr,add_row)
Expand Down Expand Up @@ -97,6 +100,7 @@ importFrom(purrr,pmap_int)
importFrom(purrr,pmap_lgl)
importFrom(readr,col_character)
importFrom(readr,cols)
importFrom(readr,fwf_cols)
importFrom(readr,fwf_positions)
importFrom(readr,read_fwf)
importFrom(rlang,"!!")
Expand Down
17 changes: 17 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# swfscDAS 0.7.0.9000

* Fix bug in `das_process` of incorrect OffsetGMT values, stemming from `as.Date` using 'UTC' tz by default (#16)

* Added an exported function `das_spcodes_read` for consistent reading of shipboard SpCode files

* Changed the argument name in `das_check` of the user-provided SpCodes file from `sp.codes` to `sp.codes.file`. Also added a `sp.codes.skip` argument to pass to `das_spcodes_read`

* Moved example data files to an 'extdata' folder within 'inst'

* Update link to NOAA Tech Memo describing DAS data; now (https://repository.library.noaa.gov/view/noaa/3174)[https://repository.library.noaa.gov/view/noaa/3174](#17)

* Update roxygen to use markdown, fix documentation issues related to upgrade to roxygen2 v8.0

* Added the SpCodes.dat file from [`CruzPlot`](https://github.com/SWFSC/CruzPlot) to 'inst' to have available as a default


# swfscDAS 0.6.4

* The DateTime column in `das_read` output now has a timezone of `""` (#13)
Expand Down
39 changes: 26 additions & 13 deletions R/das_check.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
#' @param skip integer: see \code{\link[readr]{read_fwf}}. Default is 0
#' @param file.out filename to which to write the error log;
#' default is \code{NULL}
#' @param sp.codes character; filename of .dat file from which to read
#' accepted species codes. If \code{NULL}, species codes will not be checked.
#' Default is \code{NULL}
#' @param sp.codes.file character; default is `NULL`.
#' Filename of the SpCodes file from which to read the species codes.
#' If `NULL`, the default (internal) file will be used.
#' The SpCodes file will be read by [das_spcodes_read()]
#' @param sp.codes.skip integer; default is 0.
#' Passed directly to `skip` argument of [das_spcodes_read()]
#' @param print.cruise.nums logical; indicates if a table with all the
#' cruise numbers in the \code{x} should be printed using
#' \code{\link[base]{table}}. Default is \code{TRUE}
Expand Down Expand Up @@ -90,12 +93,22 @@
#' A warning is printed if any events are r events; see \code{\link{das_process}} for details about r events
#'
#' @examples
#' y <- system.file("das_sample.das", package = "swfscDAS")
#' y <- system.file("extdata", "das_sample.das", package = "swfscDAS")
#' if (interactive()) das_check(y)
#'
#' # Using your own SpCodes file
#' sp.codes.file <- system.file("extdata", "SpCodes.dat", package = "swfscDAS")
#' if (interactive()) das_check(y, sp.codes.file = sp.codes.file)
#'
#' @export
das_check <- function(file, skip = 0, file.out = NULL, sp.codes = NULL,
print.cruise.nums = TRUE) {
das_check <- function(
file,
skip = 0,
file.out = NULL,
sp.codes.file = NULL,
sp.codes.skip = 0,
print.cruise.nums = TRUE
) {

if (length(unique(file)) != length(file))
warning("Not all files are unique - this likely will cause an error in ",
Expand Down Expand Up @@ -133,10 +146,10 @@ das_check <- function(file, skip = 0, file.out = NULL, sp.codes = NULL,

#----------------------------------------------------------------------------
### Process sp.codes file
if (!is.null(sp.codes)) {
if (!is.null(sp.codes.file)) {
message("Reading and processing SpCodes file")
sp.acc.df <- read_fwf(
sp.codes,
sp.codes.file,
col_positions = fwf_positions(start = c(1, 6, 18, 58), end = c(4, 15, 57, NA)),
col_types = cols(.default = col_character()),
trim_ws = TRUE, skip = 0, skip_empty_rows = FALSE
Expand All @@ -146,7 +159,7 @@ das_check <- function(file, skip = 0, file.out = NULL, sp.codes = NULL,
sp.acc.all <- c(sp.acc, tolower(sp.acc))

if (!all(nchar(sp.acc) %in% 2:3))
warning("Some species codes from sp.codes are not two or three charcters. ",
warning("Some species codes from sp.codes.file are not two or three charcters. ",
"Did you load the correct species code .dat file?",
immediate. = TRUE)
}
Expand Down Expand Up @@ -485,8 +498,8 @@ das_check <- function(file, skip = 0, file.out = NULL, sp.codes = NULL,
idx.a.4 <- .check_character(x, "A", "Data4", c("N", "Y", "n", "y", NA))
txt.a.4 <- "Birds (Data4 of A events) is not one of N, Y, n, y, or NA"

txt.a.spcode <- "Species code(s) were not one of the accepted codes provided via sp.codes"
idx.a.spcode <- if (is.null(sp.codes)) {
txt.a.spcode <- "Species code(s) were not one of the accepted codes provided via sp.codes.file"
idx.a.spcode <- if (is.null(sp.codes.file)) {
integer(0)
} else {
.check_character(x, "A", paste0("Data", 5:8), c(sp.acc.all, NA))
Expand All @@ -500,8 +513,8 @@ das_check <- function(file, skip = 0, file.out = NULL, sp.codes = NULL,
)

# Turtle
txt.t.spcode <- "Turtle species code was not one of the accepted codes provided via sp.codes"
idx.t.spcode <- if (is.null(sp.codes)) {
txt.t.spcode <- "Turtle species code was not one of the accepted codes provided via sp.codes.file"
idx.t.spcode <- if (is.null(sp.codes.file)) {
integer(0)
} else {
.check_character(x, "t", paste0("Data", 2), c(sp.acc.all, NA))
Expand Down
4 changes: 2 additions & 2 deletions R/das_chop_equallength.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
#' \code{x} (i.e., using the same DAS data) in the future. Note that when
#' saving with \code{\link[utils:read.table]{write.csv}}, users must specify
#' \code{row.names = FALSE} so that the CSV file only has two columns. For an
#' example randpicks file, see \code{system.file("das_sample_randpicks.csv",
#' package = "swfscDAS")}
#' example randpicks file, see
#' `system.file("extdata", "das_sample_randpicks.csv", package = "swfscDAS")`
#'
#' If the column \code{dist_from_prev} does not exist, the distance between
#' subsequent events is calculated as described in \code{\link{das_effort}}
Expand Down
4 changes: 2 additions & 2 deletions R/das_chop_section.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#' See the Examples section for an example where the two methods give the same output.
#' Note that the longest continuous effort section in the sample data is ~22km.
#'
#' @return See \code{\link{das_chop_equallength}}. The randpicks values will all be \code{NA}
#' @return See [das_chop_equallength()]. The randpicks values will all be `NA`
#'
#' @examples
#' y <- system.file("das_sample.das", package = "swfscDAS")
#' y <- system.file("extdata", "das_sample.das", package = "swfscDAS")
#' y.proc <- das_process(y)
#'
#' y.eff1 <- das_effort(y.proc, method = "equallength", seg.km = 25, num.cores = 1)
Expand Down
2 changes: 1 addition & 1 deletion R/das_comments.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' comment_str containing the concatenated comment strings
#'
#' @examples
#' y <- system.file("das_sample.das", package = "swfscDAS")
#' y <- system.file("extdata", "das_sample.das", package = "swfscDAS")
#' y.proc <- das_process(y)
#'
#' das_comments(y.proc)
Expand Down
111 changes: 56 additions & 55 deletions R/das_effort.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,65 +39,66 @@
#' @param ... arguments passed to the specified chopping function, such as
#' \code{seg.km} or \code{seg.min.km}
#'
#' @details This is the top-level function for chopping processed DAS data into
#' modeling segments (henceforth 'segments'), and assigning sightings and
#' related information (e.g., weather conditions) to each segment. This
#' function returns data frames with all relevant information for the effort
#' segments and associated sightings ('segdata' and 'sightinfo',
#' respectively). Before chopping, the DAS data is filtered for events (rows)
#' where either the 'OnEffort' column is \code{TRUE} or the 'Event' column
#' "E". In other words, the data is filtered for continuous effort sections
#' (henceforth 'effort sections'), where effort sections run from "R" to "E"
#' events (inclusive), and then passed to the chopping function specified
#' using \code{method}. Note that while B events immediately preceding an R
#' are on effort, they are ignored during effort chopping. In addition, all on
#' effort events (other than ? and numeric events) with \code{NA} DateTime,
#' Lat, or Lon values are verbosely removed.
#' @details
#' This is the top-level function for chopping processed DAS data into modeling
#' segments (henceforth 'segments'), and assigning sightings and related
#' information (e.g., weather conditions) to each segment. This function returns
#' data frames with all relevant information for the effort segments and
#' associated sightings ('segdata' and 'sightinfo', respectively). Before
#' chopping, the DAS data is filtered for events (rows) where either the
#' 'OnEffort' column is \code{TRUE} or the 'Event' column "E". In other words,
#' the data is filtered for continuous effort sections (henceforth 'effort
#' sections'), where effort sections run from "R" to "E" events (inclusive), and
#' then passed to the chopping function specified using \code{method}. Note that
#' while B events immediately preceding an R are on effort, they are ignored
#' during effort chopping. In addition, all on effort events (other than ? and
#' numeric events) with \code{NA} DateTime, Lat, or Lon values are verbosely
#' removed.
#'
#' If \code{strata.files} is not \code{NULL}, then the effort lines will be
#' split by the user-provided stratum (strata). In this case, a column
#' 'stratum' will be added to the end of the segdata data frame with the
#' user-provided name of the stratum that the segment was in, or \code{NA} if
#' the segment was not in any of the strata. If no name was provided for the
#' stratum in \code{strata.files}, then the value will be "Stratum#", where
#' "#" is the index of the applicable stratum in \code{strata.files}. While
#' the user can provide as many strata as they want, these strata can share
#' boundaries but they cannot overlap. See \code{\link{das_effort_strata}} for
#' more details.
#' If \code{strata.files} is not \code{NULL}, then the effort lines will be
#' split by the user-provided stratum (strata). In this case, a column 'stratum'
#' will be added to the end of the segdata data frame with the user-provided
#' name of the stratum that the segment was in, or \code{NA} if the segment was
#' not in any of the strata. If no name was provided for the stratum in
#' \code{strata.files}, then the value will be "Stratum#", where "#" is the
#' index of the applicable stratum in \code{strata.files}. While the user can
#' provide as many strata as they want, these strata can share boundaries but
#' they cannot overlap. See \code{\link{das_effort_strata}} for more details.
#'
#' The following chopping methods are currently available: "condition",
#' "equallength", and "section. When using the "condition" method, effort
#' sections are chopped into segments every time a condition changes, thereby
#' ensuring that the conditions are consistent across the entire segment. See
#' \code{\link{das_chop_condition}} for more details about this method,
#' including arguments that must be passed to it via the argument \code{...}
#' The following chopping methods are currently available: "condition",
#' "equallength", and "section. When using the "condition" method, effort
#' sections are chopped into segments every time a condition changes, thereby
#' ensuring that the conditions are consistent across the entire segment. See
#' \code{\link{das_chop_condition}} for more details about this method,
#' including arguments that must be passed to it via the argument \code{...}
#'
#' The "equallength" method consists of chopping effort sections into
#' equal-length segments of length \code{seg.km}, and doing a weighted average
#' of the conditions for the length of that segment. See
#' \code{\link{das_chop_equallength}} for more details about this method,
#' including arguments that must be passed to it via the argument \code{...}
#' The "equallength" method consists of chopping effort sections into
#' equal-length segments of length \code{seg.km}, and doing a weighted average
#' of the conditions for the length of that segment. See
#' \code{\link{das_chop_equallength}} for more details about this method,
#' including arguments that must be passed to it via the argument \code{...}
#'
#' The "section" method involves 'chopping' the effort into continuous effort
#' sections, i.e. each continuous effort section is a single effort segment.
#' See \code{\link{das_chop_section}} for more details about this method.
#' The "section" method involves 'chopping' the effort into continuous effort
#' sections, i.e. each continuous effort section is a single effort segment. See
#' \code{\link{das_chop_section}} for more details about this method.
#'
#' The distance between the lat/lon points of subsequent events is calculated
#' using the method specified in \code{distance.method}. If "greatcircle",
#' \code{\link{distance_greatcircle}} is used, while
#' \code{\link[swfscMisc]{distance}} is used otherwise. See
#' \code{\link{das_sight}} for how the sightings are processed.
#' The distance between the lat/lon points of subsequent events is calculated
#' using the method specified in \code{distance.method}. If "greatcircle",
#' \code{\link{distance_greatcircle}} is used, while
#' \code{\link[swfscMisc]{distance}} is used otherwise. See
#' \code{\link{das_sight}} for how the sightings are processed.
#'
#' The sightinfo data frame includes the column 'included', which is used in
#' \code{\link{das_effort_sight}} when summarizing the number of sightings and
#' animals for selected species. \code{\link{das_effort_sight}} is a separate
#' function to allow users to personalize the included values as desired for
#' their analysis. By default, i.e. in the output of this function, 'included'
#' is \code{TRUE} if: the sighting was made when on effort, by a standard
#' observer (see \code{\link{das_sight}}), and in a Beaufort sea state less
#' than or equal to five.
#' The sightinfo data frame includes the column 'included', which is used in
#' \code{\link{das_effort_sight}} when summarizing the number of sightings and
#' animals for selected species. \code{\link{das_effort_sight}} is a separate
#' function to allow users to personalize the included values as desired for
#' their analysis. By default, i.e. in the output of this function, 'included'
#' is \code{TRUE} if: the sighting was made when on effort, by a standard
#' observer (see \code{\link{das_sight}}), and in a Beaufort sea state less than
#' or equal to five.
#'
#' @return List of three data frames:
#' @return
#' List of three data frames:
#' \itemize{
#' \item segdata: one row for every segment, and columns for information
#' including unique segment number (segnum), the corresponding effort
Expand All @@ -123,7 +124,7 @@
#' \code{\link{das_chop_section}}, \code{\link{das_segdata}}
#'
#' @examples
#' y <- system.file("das_sample.das", package = "swfscDAS")
#' y <- system.file("extdata", "das_sample.das", package = "swfscDAS")
#' y.proc <- das_process(y)
#'
#' # Using "condition" method
Expand All @@ -137,14 +138,14 @@
#'
#' \donttest{
#' # Using "equallength" method
#' y.rand <- system.file("das_sample_randpicks.csv", package = "swfscDAS")
#' y.rand <- system.file("extdata", "das_sample_randpicks.csv", package = "swfscDAS")
#' das_effort(
#' y.proc, method = "equallength", seg.km = 10, randpicks.load = y.rand,
#' num.cores = 1
#' )
#'
#' # Using "section" method and chop by strata
#' stratum.file <- system.file("das_sample_stratum.csv", package = "swfscDAS")
#' stratum.file <- system.file("extdata", "das_sample_stratum.csv", package = "swfscDAS")
#' das_effort(
#' y.proc, method = "section", strata.files = list(Poly1 = stratum.file),
#' num.cores = 1
Expand Down
2 changes: 1 addition & 1 deletion R/das_effort_sight.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#' the sightings that were included in the effort segment summaries
#'
#' @examples
#' y <- system.file("das_sample.das", package = "swfscDAS")
#' y <- system.file("extdata", "das_sample.das", package = "swfscDAS")
#' y.proc <- das_process(y)
#' y.eff.cond <- das_effort(
#' y.proc, method = "condition", conditions = "Bft", seg.min.km = 0.05,
Expand Down
Loading
Loading