Installation
Install the package from r-universe as follows. The source code is available on GitHub.
# Install tbeploads in R:
install.packages('tbeploads', repos = c('https://tbep-tech.r-universe.dev', 'https://cloud.r-project.org'))
Load the package in an R session after installation:
library(tbeploads)
Usage
Load estimates are broadly defined as domestic point source (DPS), industrial point source (IPS), nonpoint source (NPS), atmospheric deposition (AD), and groundwater sources and springs (GW). The functions are build around these source with unique inputs for each.
DPS
The DPS functions are designed to work with raw entity data provided
by partners. The core function is anlz_dps_facility()
that
requires only a vector of file paths as input, where each path points to
a file with monthly parameter concentration (mg/L) and flow data
(million gallons per day). The data also describe whether the
observations are end of pipe (direct inflow to the bay) or reuse
(applied to the land), with each defined by outfall Ids typically noted
as D-001, D-002, etc. and R-001, R-002, etc, respectively. Both are
estimated as concentration times flow, whereas reuse includes an
attenuation factor for land application depending on location. The file
names must follow a specific convention, where metadata for each entity
is found in the facilities()
file included with the package
using information in the file name.
For convenience, three example files are included with the package. The paths to these files are used as input to the function. Non-trivial data preprocessing is needed for each file and those included in the package are the correct format. The output is returned as tons per month for TN, TP, TSS, and BOD and million cubic meters per month for flow (hy).
fls <- list.files(system.file('extdata/', package = 'tbeploads'),
pattern = '\\.txt$', full.names = TRUE)
anlz_dps_facility(fls)
#> # A tibble: 144 × 11
#> Year Month entity facility coastco source tn_load tp_load tss_load bod_load
#> <int> <int> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 2021 1 Clearw… City of… 387 D-001 0.617 0.0301 0.251 1.65
#> 2 2021 2 Clearw… City of… 387 D-001 0.789 0.373 0.279 2.24
#> 3 2021 3 Clearw… City of… 387 D-001 0.393 0.344 0.135 0.842
#> 4 2021 4 Clearw… City of… 387 D-001 0.299 0.234 0.141 0.760
#> 5 2021 5 Clearw… City of… 387 D-001 0.0123 0.0171 0.00776 0.0447
#> 6 2021 6 Clearw… City of… 387 D-001 0.194 0.320 0.113 0.527
#> 7 2021 7 Clearw… City of… 387 D-001 0.610 0.683 0.302 0.604
#> 8 2021 8 Clearw… City of… 387 D-001 0.534 0.487 0.315 0.594
#> 9 2021 9 Clearw… City of… 387 D-001 1.01 1.07 0.534 0.762
#> 10 2021 10 Clearw… City of… 387 D-001 0.310 0.324 0.135 0.237
#> # ℹ 134 more rows
#> # ℹ 1 more variable: hy_load <dbl>
The anlz_dps()
function uses
anlz_dps_facility()
to summarize the DPS results by
location as facility (combines outfall data), entity (combines facility
data), bay segment (combines entity data), and as all (combines bay
segment data). The results can also be temporally summarized as monthly
or annual totals. The location summary is defined by the
summ
argument and the temporal summary is defined by the
summtime
argument. The fls
argument used by
anlz_dpd_entity()
is also used by anlz_dps()
.
The output is tons per month for TN, TP, TSS, and BOD and as million
cubic meters per month for flow (hy) if summtime = 'month'
or tons per year for TN, TP, TSS, and BOD and million cubic meters per
year for flow (hy) if summtime = 'year'
.
# combine by enity and month
anlz_dps(fls, summ = 'entity', summtime = 'month')
#> # A tibble: 108 × 10
#> Year Month source entity segment tn_load tp_load tss_load bod_load hy_load
#> <int> <int> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 2017 1 DPS - e… Hills… Hillsb… 0.0924 1.32e-2 0.0388 0.0955 0.0704
#> 2 2017 2 DPS - e… Hills… Hillsb… 0.105 1.79e-2 0.0497 0.182 0.0901
#> 3 2017 3 DPS - e… Hills… Hillsb… 0.0167 2.46e-3 0.00647 0.0127 0.0117
#> 4 2017 4 DPS - e… Hills… Hillsb… 0.00249 2.88e-4 0.000626 0.00175 0.00114
#> 5 2017 5 DPS - e… Hills… Hillsb… 0.0219 1.05e-2 0.0116 0.0396 0.0211
#> 6 2017 6 DPS - e… Hills… Hillsb… 0.329 8.41e-2 0.134 0.281 0.238
#> 7 2017 7 DPS - e… Hills… Hillsb… 0.215 5.95e-2 0.114 0.293 0.208
#> 8 2017 8 DPS - e… Hills… Hillsb… 0.369 1.05e-1 0.188 0.493 0.341
#> 9 2017 9 DPS - e… Hills… Hillsb… 0.603 1.51e-1 0.202 0.548 0.360
#> 10 2017 10 DPS - e… Hills… Hillsb… 0.286 6.08e-2 0.113 0.371 0.204
#> # ℹ 98 more rows
# combine by bay segment and year
anlz_dps(fls, summ = "segment", summtime = "year")
#> # A tibble: 9 × 8
#> Year source segment tn_load tp_load tss_load bod_load hy_load
#> <int> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 2017 DPS - end of pipe Hillsboroug… 2.18 0.512 0.885 2.38 1.59
#> 2 2018 DPS - end of pipe Hillsboroug… 0 0 0 0 0
#> 3 2019 DPS - end of pipe Hillsboroug… 15.4 2.00 2.98 10.0 7.11
#> 4 2021 DPS - end of pipe Old Tampa B… 5.66 4.08 2.71 9.06 4.39
#> 5 2017 DPS - reuse Hillsboroug… 1.14 0.0339 0.0706 0.195 1.53
#> 6 2018 DPS - reuse Hillsboroug… 0.126 0.00110 0.00462 0.00971 0.101
#> 7 2019 DPS - reuse Hillsboroug… 3.84 0.0778 0.123 0.408 3.44
#> 8 2021 DPS - reuse Hillsboroug… 2.87 0 0 0 1.74
#> 9 2021 DPS - reuse Old Tampa B… 1.19 0.177 0.0972 0.379 1.99