Skip to content

Commit

Permalink
Include updated stream points dataset. Remove RSA date filter. Use mo…
Browse files Browse the repository at this point in the history
…st recent dumpsite impact assessment
  • Loading branch information
shannarucker committed Feb 6, 2025
1 parent e6d7e7f commit 7d04315
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 90 deletions.
11 changes: 2 additions & 9 deletions R/dumpsites.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
#'
#' @param df_point Point data from Rapid Stream Assessment (RSA) dataset.
#' @param df_reach Reach data from Rapid Stream Assessment (RSA) dataset.
#' @param start_date Beginning of timeframe being evaluated (ex. first day of
#' five-year assessment period).
#' @param end_date End of timeframe being evaluated (ex. last day of
#' five-year assessment period).
#' @param reach_prefix_from_table Field name prefix sourced from RSA reach
#' attribute table. Should be consistent with the name of the stream reach
#' attribute table from the RSA geodatabase.
Expand All @@ -24,21 +20,18 @@
#'
#' @examples assess_dumpsites(df_point_example,
#' df_reach_example,
#' "2020-01-01",
#' "2024-12-31",
#' "StreamReachAttributes",
#' "StreamReaches",
#' "StreamPointAttributes",
#' "StreamPoints_Intersect" )

assess_dumpsites <- function(df_point, df_reach, start_date, end_date, reach_prefix_from_table, reach_prefix_from_layer, point_prefix_from_table, point_prefix_from_layer){
assess_dumpsites <- function(df_point, df_reach, reach_prefix_from_table, reach_prefix_from_layer, point_prefix_from_table, point_prefix_from_layer){

df_length <- df_reach %>%
dplyr::select(location_name = dplyr::all_of(paste0(reach_prefix_from_layer, ".subshed")),
reach_length = dplyr::all_of(paste0(reach_prefix_from_layer, ".Shape_Length")),
id = dplyr::all_of(paste0(reach_prefix_from_table, ".featureGlobalID_key")),
date = dplyr::all_of(paste0(reach_prefix_from_table, ".assessment_time"))) %>%
dplyr::filter(date >= start_date & date <= end_date) %>%
dplyr::group_by(id) %>%
dplyr::slice_max(date, n=1, with_ties = FALSE) %>% # Remove duplicate reaches. Keep most recent reach assessment. If same date/time and ID, maintain only one record
dplyr::ungroup() %>%
Expand All @@ -53,7 +46,7 @@ assess_dumpsites <- function(df_point, df_reach, start_date, end_date, reach_pre
date = dplyr::all_of(paste0(point_prefix_from_table, ".assessment_time")),
d_impact = dplyr::all_of(paste0(point_prefix_from_table, ".d_impact")),
) %>%
dplyr::filter(date >= start_date & date <= end_date) %>%
tidyr::drop_na(d_impact) %>% # remove NA records in d_impact field. Likely assessments of existing points that did not change. Need to reference original record.
dplyr::group_by(id) %>%
dplyr::slice_max(date, n=1, with_ties = FALSE) %>% # Remove duplicate point. Keep most recent point assessment. If same date/time and ID, maintain only one record
dplyr::ungroup() %>%
Expand Down
11 changes: 4 additions & 7 deletions R/trash.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#' Calculate trash scores.
#'
#' @param df_reach Reach data from Rapid Stream Assessment (RSA) dataset.
#' @param start_date Beginning of timeframe being evaluated (ex. first day of
#' five-year assessment period).
#' @param end_date End of timeframe being evaluated (ex. last day of
#' five-year assessment period).
#' @param reach_prefix_from_table Field name prefix sourced from RSA reach
#' attribute table. Should be consistent with the name of the stream reach
#' attribute table from the RSA geodatabase.
Expand All @@ -15,11 +11,12 @@
#' @return List of 2 dataframes: summary and score.
#' @export
#'
#' @examples assess_trash(df_reach_example, "2020-01-01", "2024-12-31",
#' "StreamReachAttributes", "StreamReaches")
#' @examples assess_trash(df_reach_example,
#' "StreamReachAttributes",
#' "StreamReaches")


assess_trash <- function(df_reach, start_date, end_date, reach_prefix_from_table, reach_prefix_from_layer) {
assess_trash <- function(df_reach, reach_prefix_from_table, reach_prefix_from_layer) {

df_summary <- df_reach %>%
dplyr::select(location_name = dplyr::all_of(paste0(reach_prefix_from_layer, ".subshed")),
Expand Down
12 changes: 8 additions & 4 deletions R/wq_nutrients.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#' Calculate water quality scores for nutrients
#'
#' @param df DOEE Ambient Water Quality Data that has been processed and formatted
#' @param parameter_name String to indicate target parameter: "Nitrogen", "Phosphorus, Total (as P)"
#' @param piedmont_criteria Nutrient criteria recommendation for Piedmont Ecoregion 64 in mg/L
#' @param coastal_plain_criteria Nutrient criteria recommendation for Coastal Plain Ecoregion 65 in mg/L
#' @param df DOEE Ambient Water Quality Data that has been processed and
#' formatted
#' @param parameter_name String to indicate target parameter: "Nitrogen",
#' "Phosphorus, Total (as P)"
#' @param piedmont_criteria Nutrient criteria recommendation for Piedmont
#' Ecoregion 64 in mg/L
#' @param coastal_plain_criteria Nutrient criteria recommendation for Coastal
#' Plain Ecoregion 65 in mg/L
#'
#' @return List of three dataframes: results, summary, score
#' @export
Expand Down
Binary file modified data/StreamPoints_20241105_INT.xlsx
Binary file not shown.
10 changes: 0 additions & 10 deletions man/assess_dumpsites.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 4 additions & 15 deletions man/assess_trash.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions man/assess_wq_nutrients.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 26 additions & 26 deletions output/all_scores.csv
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
"","sci_subshed","Trash","Dumpsites","Effective Impervious Area","Temperature, water","pH","Dissolved oxygen (DO)","Escherichia coli","Turbidity","Conductivity","Nitrogen","Phosphorus, Total (as P)","Connectivity","Fish","Habitat","Macroinvertebrates"
"1","Battery Kemble Creek",8.43478260869565,10,6,10,10,10,7.17122657287291,10,1.32946707229891,1.1722461961956,10,10,3,4,7
"2","Broad Branch",8.88235294117647,8,2,10,9.49484604605374,10,3.96201632162848,10,1.39551171022171,2.53189561427939,10,10,2,4,6
"3","Dumbarton Oaks",10,10,4,10,10,10,8.54782802837774,10,1.70833294620897,1.32807710704536,2.8679579947462,10,3,5,7
"4","Fenwick Branch",7.42857142857143,10,3,9.49476657878656,10,10,6.8791964501452,10,1.75285115573104,2.32427732195356,10,10,2,3,6
"5","Fort Davis Tributary",8.33333333333333,2,2,10,10,10,4.56378937695466,3.40381314529514,1.28521704525446,0.950005376536892,1.78543632558786,1,1,5,5
"6","Fort Dupont Tributary",7.64285714285714,7,8,10,10,8.19644566724721,4.39637929649141,3.667361623274,2.99612324159937,0.749069894299005,10,1,3,4,6
"7","Fort Stanton Tributary",6.47058823529412,4,1,9.49458887028815,10,10,3.49306972579195,8.24161710963122,2.14961627380251,0.950005376536892,10,1,1,3,7
"8","Foundry Branch",8.83333333333333,10,2,10,10,10,5.43588122762784,4.44089503244838,2.9615349603606,2.05698424129608,10,1,1,4,NA
"9","Hickey Run",8.03846153846154,10,9,9.32570696570447,10,9.31006357105735,1.71733915151806,7.52739827502453,1.92353016456839,0.749069894299005,2.7927191991411,10,6,2,4
"10","Klingle Valley Run",6.25,10,2,10,10,10,6.5392010054142,10,2.16336911176854,1.52948677601239,10,10,2,3,6
"11","Luzon Branch",5.2,10,1,10,10,10,2.74149789121648,5.16856938057974,1.68139016788936,2.13654818496565,2.91985046082419,10,2,3,6
"12","Normanstone Creek",7.21428571428571,10,1,10,8.9888961180284,10,4.46891175504634,10,1.49230558316491,2.58568816872641,10,10,3,3,6
"13","Oxon Run",5.85714285714286,8,1,9.49482509665549,10,10,4.08034192298863,7.26446748330366,2.73668115439965,0.677223449104501,0.963293817107756,10,4,4,4
"14","Pinehurst Branch",8.66666666666667,10,6,10,9.45561327204199,10,6.86529198320573,10,1.64381726305677,2.53189561427939,10,10,2,4,5
"15","Piney Branch",8,10,1,10,10,10,6.24485935433058,10,1.37920467622303,2.43350524767764,10,10,3,2,4
"16","Pope Branch",8,10,3,10,10,10,6.70307871860358,4.63848137391428,2.04750999680075,0.950005376536892,10,1,4,7,8
"17","Portal Branch",7,10,3,10,8.98692894850945,10,4.24400479220216,6.90674993457207,1.02448007263146,2.74453544775747,10,10,1,3,6
"18","Reservation 630",9.21052631578947,10,3,9.49484222518253,10,10,4.89875662885154,6.54810880322023,1.95694969141548,2.32427732195356,10,10,4,7,7
"19","Rock Creek",8.23913043478261,7,1,9.03991429859265,9.63931584712039,10,4.75298766520739,8.85351874858907,3.01758638876789,2.35646823207748,10,10,5,4,5
"20","Soapstone Creek",8.71428571428571,10,1,10,8.98764540312439,10,6.80566463860387,10,1.91408087817814,2.53189561427939,2.88434296861746,10,2,3,6
"21","Texas Avenue Tributary",7,10,3,10,10,10,3.54658539291944,7.3375495518317,1.74050116850977,0.837784090876652,10,1,1,4,3
"22","Watts Branch",3.55,6,1,9.32024027311975,9.03799489304956,9.94283156569335,3.52383649640539,8.10990235278729,2.71307679688268,0.80598894736693,4.92721388547487,10,4,3,6
"23","Dalecarlia Tributary",NA,10,4,9.49281310022025,9.49429215204554,10,2.26543812278347,7.88130147148155,1.57723215112077,1.64140564675688,1.50035060003774,1,2,3,6
"24","Fort Chaplin Tributary",NA,10,2,10,10,9.44055926057385,3.66863632512962,8.77121712686461,2.01955422326341,1.09628813677057,10,1,1,4,3
"25","Nash Run",NA,10,3,8.97058038494947,9.49162145959481,10,2.85130675778872,8.98648127446675,3.13741218623777,1.09628813677057,10,10,6,5,4
"","sci_subshed","Dumpsites","Effective Impervious Area","Temperature, water","pH","Dissolved oxygen (DO)","Escherichia coli","Turbidity","Conductivity","Nitrogen","Phosphorus, Total (as P)","Connectivity","Fish","Habitat","Macroinvertebrates"
"1","Broad Branch",7,2,10,9.49484604605374,10,3.96201632162848,10,1.39551171022171,2.53189561427939,10,10,2,4,6
"2","Fort Davis Tributary",1,2,10,10,10,4.56378937695466,3.40381314529514,1.28521704525446,0.950005376536892,1.78543632558786,1,1,5,5
"3","Fort Dupont Tributary",2,8,10,10,8.19644566724721,4.39637929649141,3.667361623274,2.99612324159937,0.749069894299005,10,1,3,4,6
"4","Fort Stanton Tributary",4,1,9.49458887028815,10,10,3.49306972579195,8.24161710963122,2.14961627380251,0.950005376536892,10,1,1,3,7
"5","Normanstone Creek",4,1,10,8.9888961180284,10,4.46891175504634,10,1.49230558316491,2.58568816872641,10,10,3,3,6
"6","Oxon Run",8,1,9.49482509665549,10,10,4.08034192298863,7.26446748330366,2.73668115439965,0.677223449104501,0.963293817107756,10,4,4,4
"7","Pinehurst Branch",7,6,10,9.45561327204199,10,6.86529198320573,10,1.64381726305677,2.53189561427939,10,10,2,4,5
"8","Rock Creek",7,1,9.03991429859265,9.63931584712039,10,4.75298766520739,8.85351874858907,3.01758638876789,2.35646823207748,10,10,5,4,5
"9","Watts Branch",5,1,9.32024027311975,9.03799489304956,9.94283156569335,3.52383649640539,8.10990235278729,2.71307679688268,0.80598894736693,4.92721388547487,10,4,3,6
"10","Battery Kemble Creek",10,6,10,10,10,7.17122657287291,10,1.32946707229891,1.1722461961956,10,10,3,4,7
"11","Dalecarlia Tributary",10,4,9.49281310022025,9.49429215204554,10,2.26543812278347,7.88130147148155,1.57723215112077,1.64140564675688,1.50035060003774,1,2,3,6
"12","Dumbarton Oaks",10,4,10,10,10,8.54782802837774,10,1.70833294620897,1.32807710704536,2.8679579947462,10,3,5,7
"13","Foundry Branch",10,2,10,10,10,5.43588122762784,4.44089503244838,2.9615349603606,2.05698424129608,10,1,1,4,NA
"14","Fort Chaplin Tributary",10,2,10,10,9.44055926057385,3.66863632512962,8.77121712686461,2.01955422326341,1.09628813677057,10,1,1,4,3
"15","Fenwick Branch",10,3,9.49476657878656,10,10,6.8791964501452,10,1.75285115573104,2.32427732195356,10,10,2,3,6
"16","Hickey Run",10,9,9.32570696570447,10,9.31006357105735,1.71733915151806,7.52739827502453,1.92353016456839,0.749069894299005,2.7927191991411,10,6,2,4
"17","Klingle Valley Run",10,2,10,10,10,6.5392010054142,10,2.16336911176854,1.52948677601239,10,10,2,3,6
"18","Luzon Branch",10,1,10,10,10,2.74149789121648,5.16856938057974,1.68139016788936,2.13654818496565,2.91985046082419,10,2,3,6
"19","Reservation 630",10,3,9.49484222518253,10,10,4.89875662885154,6.54810880322023,1.95694969141548,2.32427732195356,10,10,4,7,7
"20","Nash Run",10,3,8.97058038494947,9.49162145959481,10,2.85130675778872,8.98648127446675,3.13741218623777,1.09628813677057,10,10,6,5,4
"21","Pope Branch",10,3,10,10,10,6.70307871860358,4.63848137391428,2.04750999680075,0.950005376536892,10,1,4,6,8
"22","Portal Branch",10,3,10,8.98692894850945,10,4.24400479220216,6.90674993457207,1.02448007263146,2.74453544775747,10,10,1,3,6
"23","Piney Branch",10,1,10,10,10,6.24485935433058,10,1.37920467622303,2.43350524767764,10,10,3,2,4
"24","Soapstone Creek",10,1,10,8.98764540312439,10,6.80566463860387,10,1.91408087817814,2.53189561427939,2.88434296861746,10,2,3,6
"25","Texas Avenue Tributary",10,3,10,10,10,3.54658539291944,7.3375495518317,1.74050116850977,0.837784090876652,10,1,1,5,3
Binary file modified vignettes/figures/rsa_join.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 8 additions & 5 deletions vignettes/pre-processing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ knitr::opts_chunk$set(

- The R functions assess_trash() and assess_dumpsites() require dataframe inputs of processed RSA reach data and RSA point data (dumpsites only)

- The watershed layer included in RSA database was not used due to issue found. For example, layer "Watersheds_Notes_RSA2021" has missing area in Rock Creek. Instead used: [DC Subwatersheds  Open Data Layer](https://opendata.dc.gov/datasets/dc-subwatersheds/explore?location=38.890772%2C-77.021832%2C12.98&showTable=true).
- The watershed layer included in RSA database was not used due to issue found. For example, layer "Watersheds_Notes_RSA2021" has missing area in Rock Creek. Instead used: [DC Subwatersheds Open Data Layer](https://opendata.dc.gov/datasets/dc-subwatersheds/explore?location=38.890772%2C-77.021832%2C12.98&showTable=true).

<br>

Expand All @@ -34,26 +34,29 @@ knitr::opts_chunk$set(

- This step is needed so that the GlobalID information will be included in the intersected table

2. Intersect [DC Subwatersheds  Open Data Layer](https://opendata.dc.gov/datasets/dc-subwatersheds/explore?location=38.890772%2C-77.021832%2C12.98&showTable=true) with StreamPoints layer
2. Intersect [DC Subwatersheds Open Data Layer](https://opendata.dc.gov/datasets/dc-subwatersheds/explore?location=38.890772%2C-77.021832%2C12.98&showTable=true) with StreamPoints layer

3. Run the 'Add Attribute Index' tool:
3. Run the 'Add Attribute Index' tool on the Intersected layer so that ID field is indexed:

- Field to Index: GlobalID_copy

- Index Name: GlobalID_index

4. Join StreamPoints attributes table to StreamPoints feature layer. See settings in screenshot below:

- If 'One to Many" Join Operation not an option, make sure attribute table and feature layer are in the same geodatabase

![](figures/rsa_join.png){width="326"}

5. Export joined StreamPoints table to Excel
5. Export joined StreamPoints by using 'Table to Excel' geoprocessing tool

- Save file to R package data folder

- Update file name input variable in workflow.R file

6. In the input variables section of workflow.R, update the field name prefix variables (if needed)

7. Repeat steps 1, 3,4, 5 and 6 using StreamReaches feature layer and attribute table
7. Repeat steps 1, 3, 4, 5 and 6 using StreamReaches feature layer and attribute table

- Skip Step 2 since subshed information is already included as a field in the StreamReaches feature layer

Expand Down
16 changes: 6 additions & 10 deletions workflow.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@ df_point <- readxl::read_excel("data/StreamPoints_20241105_INT.xlsx")
start_date <- "2015-07-01"
end_date <- "2020-06-30"

# Date ranges used for filtering RSA data (for trees and dumpsites)
rsa_start_date <- "2020-01-01"
rsa_end_date <- "2024-12-31"


# Field name prefixes for RSA dataset
# Prefixes change depending on layer and table names pulled from geodatabase
reach_prefix_from_table <- "StreamReachAttributes" # Should match name of stream reach attribute table from RSA .gdb
reach_prefix_from_layer <- "StreamReaches" # Should match name of stream reach polyline layer from RSA .gdb

point_prefix_from_table <- "StreamPointAttributes" # Should match name of stream point attribute table from RSA .gdb
point_prefix_from_layer <- "StreamPoints_Intersect" # Should match name of intersected stream point layer from RSA .gdb
point_prefix_from_layer <- "StreamPoints_Nov2024_Intersect" # Should match name of intersected stream point layer from RSA .gdb



Expand Down Expand Up @@ -112,18 +107,19 @@ macro <- macroinvertebrate_summary %>% dplyr::select(sci_subshed,


# Assess RSA Data
trash <- assess_trash(df_reach, rsa_start_date, rsa_end_date, reach_prefix_from_table, reach_prefix_from_layer)
# trash <- assess_trash(df_reach, reach_prefix_from_table, reach_prefix_from_layer)
dumpsite <- assess_dumpsites(df_point, df_reach,
rsa_start_date, rsa_end_date,
reach_prefix_from_table, reach_prefix_from_layer,
point_prefix_from_table, point_prefix_from_layer)

# EIA
eia <- assess_eia()

# Compile scores
all_scores <- trash[["score"]] %>%
dplyr::full_join(dumpsite[["score"]]) %>%
all_scores <-
# trash[["score"]] %>%
# dplyr::full_join(dumpsite[["score"]]) %>%
dumpsite[["score"]] %>%
dplyr::full_join(eia[["score"]]) %>%
dplyr::full_join(temp[["score"]]) %>%
dplyr::full_join(ph[["score"]]) %>%
Expand Down

0 comments on commit 7d04315

Please sign in to comment.