-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finish first cut of ml functions and vignette entry
- Loading branch information
Showing
15 changed files
with
167 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#' Calculate material loss (ML) loads and summarize | ||
#' | ||
#' Calculate material loss (ML) loads and summarize | ||
#' | ||
#' @param fls vector of file paths to raw entity data, one to many | ||
#' @param summ `r summ_params('summ')` | ||
#' @param summtime `r summ_params('summtime')` | ||
#' | ||
#' @details | ||
#' Input data files in \code{fls} are first processed by \code{\link{anlz_ml_facility}} to calculate ML loads for each facility. `r summ_params('descrip')` | ||
#' | ||
#' @return data frame with loading data for TN as tons per month/year. Columns for TP, TSS, BOD, and hydrologic load are also returned with zero load for consistency with other point source load calculation functions. | ||
#' | ||
#' @export | ||
#' | ||
#' @seealso \code{\link{anlz_ml_facility}} | ||
#' | ||
#' @examples | ||
#' fls <- list.files(system.file('extdata/', package = 'tbeploads'), | ||
#' pattern = 'ps_indml', full.names = TRUE) | ||
#' anlz_ml(fls) | ||
anlz_ml <- function(fls, summ = c('entity', 'facility', 'segment', 'all'), summtime = c('month', 'year')){ | ||
|
||
# get facility and outfall level data | ||
mlbyfac <- anlz_ml_facility(fls) | ||
|
||
# add bay segment and source, must use facilities object since no coastco | ||
baysegs <- facilities |> | ||
dplyr::filter(grepl('Material Losses', source)) |> | ||
dplyr::select(bayseg, entity, facility = facname) | ||
mlld <- mlbyfac |> | ||
dplyr::left_join(baysegs, by = c('entity', 'facility')) |> | ||
dplyr::mutate( | ||
segment = dplyr::case_when( | ||
bayseg == 1 ~ "Old Tampa Bay", | ||
bayseg == 2 ~ "Hillsborough Bay", | ||
bayseg == 3 ~ "Middle Tampa Bay", | ||
bayseg == 4 ~ "Lower Tampa Bay", | ||
TRUE ~ NA_character_ | ||
), | ||
source = 'ML' | ||
) |> | ||
dplyr::select(-bayseg) | ||
|
||
## | ||
# summarize by selection | ||
|
||
out <- util_ps_summ(mlld, summ = summ, summtime = summtime) | ||
|
||
return(out) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
Facility.Name year tn_tonsyr | ||
Facility.Name Year tn_tonsyr | ||
CSX Rockport 2020 0.88388253765 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Facility.Name year tn_tonsyr | ||
Facility.Name Year tn_tonsyr | ||
Kinder Morgan Tampaplex 2017 0.18758685 | ||
Kinder Morgan Tampaplex 2018 0.1896925 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
Facility.Name year tn_tonsyr | ||
Facility.Name Year tn_tonsyr | ||
Kinder Morgan Tampaplex 2019 0.192658902 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
Facility.Name year tn_tonsyr | ||
Facility.Name Year tn_tonsyr | ||
Mosaic Riverview 2021 0.986666666666667 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
# Test cases | ||
test_that("anlz_dps returns correct results for facility, month", { | ||
|
||
# summarize by facility and year | ||
result <- anlz_dps(psdomfls, summ = 'facility', summtime = 'month') | ||
result <- names(result) | ||
expected <- c("Year", "Month", "source", "entity", "facility", "segment", "tn_load", | ||
"tp_load", "tss_load", "bod_load", "hy_load") | ||
expect_identical(result, expected) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
# Test cases | ||
test_that("anlz_ips returns correct results for facility, month", { | ||
|
||
# summarize by facility and year | ||
result <- anlz_ips(psindfls, summ = 'facility', summtime = 'month') | ||
result <- names(result) | ||
expected <- c("Year", "Month", "source", "entity", "facility", "segment", "tn_load", | ||
"tp_load", "tss_load", "bod_load", "hy_load") | ||
expect_identical(result, expected) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
test_that("anlz_ml returns correct results for facility, month", { | ||
|
||
# summarize by facility and year | ||
result <- anlz_ml(indmlfls, summ = 'facility', summtime = 'month') | ||
result <- names(result) | ||
expected <- c("Year", "Month", "source", "entity", "facility", "segment", "tn_load", | ||
"tp_load", "tss_load", "bod_load", "hy_load") | ||
expect_identical(result, expected) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
test_that("Check load calculations", { | ||
|
||
result <- ml |> | ||
filter(Year == 2021 & Month == 1 & facility == 'Riverview') |> | ||
mutate_if(is.numeric, round, 3) | ||
|
||
expect_equal(result$tn_load[[1]], 0.082) | ||
expect_equal(result$tp_load[[1]], NA) | ||
expect_equal(result$tss_load[[1]], NA) | ||
expect_equal(result$bod_load[[1]], NA) | ||
expect_equal(result$hy_load[[1]], NA) | ||
|
||
}) | ||
|
||
test_that("Verify output class", { | ||
|
||
expect_s3_class(ips, "data.frame") | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters