-
Notifications
You must be signed in to change notification settings - Fork 0
/
nrsaLandownerReport_fromApp.Rmd
214 lines (167 loc) · 10.3 KB
/
nrsaLandownerReport_fromApp.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
---
title: "National Rivers and Streams Assessment Field Visit Summary"
author: ""
date: ""
params:
userDataRMD: 'NULL'
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
#suppressPackageStartupMessages(library(tidyverse))
suppressPackageStartupMessages(library(knitr))
suppressPackageStartupMessages(library(kableExtra))
```
```{r verif, echo=FALSE}
include_graphics("NRSA_logo_sm.jpg")
verification <- subset(params[['userDataRMD']][['VERIFICATION']][[1]], PARAMETER %in% c('SITE_ID','VISIT_NO', "DATE_COL","LOC_NAME","CREW",
"LAT_DD","LON_DD","VALXSITE",'ADD_SITE_CHAR',
"DRCTNS","RCHWIDTH","TRCHLEN","SITESAMP"),
select = c('PARAMETER','RESULT'))
sampled <- subset(verification, PARAMETER=='SITESAMP')$RESULT
verification_tbl <- subset(verification, !(PARAMETER %in% c("CREW","DRCTNS","RCHWIDTH","SITESAMP")))
verification_tbl$PARAMETER[verification_tbl$PARAMETER=='SITE_ID'] <- 'Site ID'
verification_tbl$PARAMETER[verification_tbl$PARAMETER=='LAT_DD'] <- 'Latitude'
verification_tbl$PARAMETER[verification_tbl$PARAMETER=='LON_DD'] <- 'Longitude'
verification_tbl$PARAMETER[verification_tbl$PARAMETER=='VISIT_NO'] <- 'Visit Number'
verification_tbl$PARAMETER[verification_tbl$PARAMETER=='DATE_COL'] <- 'Sample Date'
verification_tbl$PARAMETER[verification_tbl$PARAMETER=='LOC_NAME'] <- 'Location'
verification_tbl$PARAMETER[verification_tbl$PARAMETER=='VALXSITE'] <- 'Sample Type'
verification_tbl$PARAMETER[verification_tbl$PARAMETER=='ADD_SITE_CHAR'] <- 'Site Characteristics'
# verification_tbl$PARAMETER[verification_tbl$PARAMETER=='GEN_COM'] <- 'General Site Comments'
verification_tbl$PARAMETER[verification_tbl$PARAMETER=='TRCHLEN'] <- 'Reach Length'
# verification_tbl$PARAMETER[verification_tbl$PARAMETER=='CREW_LEADER'] <- 'Crew Leader'
verification_tbl$RESULT[verification_tbl$PARAMETER=='Reach Length'] <- paste(verification_tbl$RESULT[verification_tbl$PARAMETER=='Reach Length'], 'm', sep=' ')
```
```{r field,echo=F}
## Field parameters
if(sampled=='Y' & !is.null(params[['userDataRMD']][['FIELD']])){
field <- subset(params[['userDataRMD']][['FIELD']][[1]], PARAMETER %in% c("LOCATION","TIME" ,"DO","TEMPERATURE" ,
"PH","CONDUCTIVITY","CORRECTED"))
CONDUCTIVITYunits <- ifelse(as.character(subset(field, PARAMETER == 'CORRECTED')$RESULT)=='Y', 'uS/cm @ 25C','uS/cm')
field_tbl <- subset(field, PARAMETER %in% c('TEMPERATURE','DO','PH', 'CONDUCTIVITY'), select = c('PARAMETER','RESULT'))
field_tbl$group <- field_tbl$PARAMETER
field_tbl$RESULT[field_tbl$PARAMETER == 'DO'] <- paste(field_tbl$RESULT[field_tbl$PARAMETER == 'DO'], 'mg/L', sep = ' ')
field_tbl$RESULT[field_tbl$PARAMETER == 'TEMPERATURE'] <- paste(field_tbl$RESULT[field_tbl$PARAMETER == 'TEMPERATURE'], 'C', sep = ' ')
field_tbl$RESULT[field_tbl$PARAMETER == 'CONDUCTIVITY'] <- paste(field_tbl$RESULT[field_tbl$PARAMETER == 'CONDUCTIVITY'], CONDUCTIVITYunits, sep = ' ')
field_tbl$group[field_tbl$group == 'TEMPERATURE'] <- 1
field_tbl$group[field_tbl$group == 'DO'] <- 2
field_tbl$group[field_tbl$group == 'PH'] <- 3
field_tbl$group[field_tbl$group == 'CONDUCTIVITY'] <- 4
field_tbl$PARAMETER[field_tbl$PARAMETER=='TEMPERATURE'] <- 'Temperature'
field_tbl$PARAMETER[field_tbl$PARAMETER=='DO'] <- 'Dissolved Oxygen'
field_tbl$PARAMETER[field_tbl$PARAMETER=='PH'] <- 'pH'
field_tbl$PARAMETER[field_tbl$PARAMETER=='CONDUCTIVITY'] <- 'Conductivity'
field_tbl <- field_tbl[order(field_tbl$group),]
field_tbl <- subset(field_tbl, select = -group)
}
```
```{r assess, echo=FALSE}
## Assessment info
if(sampled=='Y' & !is.null(params[['userDataRMD']][['ASSESSMENT']])){
assessment <- subset(params[['userDataRMD']][['ASSESSMENT']][[1]], PARAMETER %in% c('WEATHER','CONDITIONS','BEAVER_FLOW_MOD'),
select = c('PARAMETER','RESULT'))
if(sampled=='Y' & nrow(assessment)>0){
assessment$PARAMETER[assessment$PARAMETER == 'BEAVER_FLOW_MOD'] <- 'Beaver Flow Modifications'
assessment$PARAMETER[assessment$PARAMETER == 'WEATHER'] <- 'Weather'
assessment$PARAMETER[assessment$PARAMETER == 'CONDITIONS'] <- 'Conditions'
assessment$group <- assessment$PARAMETER
assessment$group[assessment$group == 'Beaver Flow Modifications'] <- 4
assessment$group[assessment$group == 'Weather'] <- 1
assessment$group[assessment$group == 'Conditions'] <- 2
assessment$group[assessment$group == 'Observations'] <- 3
assessment <- assessment[order(assessment$group),]
assessment <- subset(assessment, PARAMETER!='Conditions', select = -group)
}
}
```
```{r samples, echo=FALSE}
if(sampled=='Y' & !is.null(params[['userDataRMD']][['SAMPLES']])){
## samples collected
# generic samples and description
samples <- data.frame(Sample = c('CHEM', 'WCHL', 'PERI', 'PCHL', 'PBIO', 'PDNA', 'MICX', 'ENTE','BENT',
'BCUL', 'BDNA'),
Sample.Name = c('Water Chemistry','Water Chlorophyll a','Periphyton Assemblage','Periphyton Chlorophyll a','Periphyton Biomass','Periphyton DNA',
"Microcystin & Cylindrospermopsin", 'Enterococci','Benthic Macroinvertebrates',
'Bacteria Culture', 'Bacteria DNA'),
Description = c('Nutrients (nitrogen and phosphorus), basic anions & cations, turbidity, organic carbon',
'Chlorophyll a content in water sample','Algal species composition',
'Chlorophyll a content in periphyton sample','Biomass in periphyton scraping',
'eDNA fragments in water','Analyzed for algal toxins in water','*E.coli* and enterococci',
'Benthic macroinvertebrate composition',
'Antimicrobial resistance bacteria culture sample',
'Antimicrobial resistance bacteria DNA sample'), stringsAsFactors=F)
# filter to only what was collected
samplesData <- unique(params[['userDataRMD']][['SAMPLES']][[1]]$SAMPLE_TYPE)[!(unique(params[['userDataRMD']][['SAMPLES']][[1]]$SAMPLE_TYPE) %in% 'SAMP')]
samplesNotColl <- params[['userDataRMD']][['SAMPLES']][[1]]$SAMPLE_TYPE[params[['userDataRMD']][['SAMPLES']][[1]]$PARAMETER=='NOT_COLLECTED' & params[['userDataRMD']][['SAMPLES']][[1]]$RESULT=='Y']
samplesTaken <- setdiff(samplesData, samplesNotColl)
samples_tbl <- subset(samples, (Sample %in% samplesTaken))
samples_tbl <- samples_tbl[!duplicated(samples_tbl[,c('Sample.Name')]), c('Sample.Name','Description')]
}
```
```{r fish, echo=F}
if(sampled=='Y' & !is.null(params[['userDataRMD']][['FISH']])){
## Fish
# Add code to handle cases where fish not collected
fishTaxa <- subset(params[['userDataRMD']][['FISH']][[1]], SAMPLE_TYPE == 'FISH', select = c('LINE','PARAMETER','RESULT'))
fishTaxa <- subset(fishTaxa, PARAMETER!='REVIEW')
if(nrow(fishTaxa)>0){
# First get fish counts
fishCounts <- subset(fishTaxa, grepl("COUNT_", PARAMETER))
fishCounts.1 <- aggregate(x = list(Count = fishCounts$RESULT), by = fishCounts[c('LINE')], FUN = function(x){sum(as.numeric(x), na.rm=TRUE)})
# then fix taxa and join
fishTaxa.1 <- subset(fishTaxa, PARAMETER == 'NAME_COM')
fishTaxa.1 <- merge(fishTaxa.1, fishCounts.1, by = 'LINE')
fishTaxa.1 <- subset(fishTaxa.1, select = c('RESULT','Count'))
fishTaxa.1 <- fishTaxa.1[order(fishTaxa.1$Count),]
}else if(!is.null(params[['userDataRMD']][['FISHGEAR']])){
fishTaxa.1 <- subset(params[['userDataRMD']][['FISHGEAR']][[1]], PARAMETER %in% c('FISH_PROTOCOL','PROTOCOL_COMMENT'),
select = c('PARAMETER', 'RESULT'))
fishTaxa.1$PARAMETER[fishTaxa.1$PARAMETER=='FISH_PROTOCOL'] <- 'Fish Protocol Result'
fishTaxa.1$PARAMETER[fishTaxa.1$PARAMETER=='PROTOCOL_COMMENT'] <- 'Comment'
}
}
```
#### About
This report provides landowners with preliminary data available after sampling. Additional information can be provided to you after laboratory analyses are completed. If you would like to be notified when this information is available, please contact the Crew Leader.
```{r row 1 tables, echo=F}
kable(verification_tbl,col.names=c('Station Information',''), row.names=FALSE, align=c('l','r')) %>%
kable_styling(bootstrap_options = 'condensed', full_width = F, position = "float_left") %>%
column_spec(1, border_right = T) %>%
column_spec(2, width = "16em")
if(sampled=='Y' & exists("field_tbl")){
kable(field_tbl,col.names=c('Field Data',''), row.names=FALSE, align=c('l','r')) %>%
kable_styling(bootstrap_options = 'condensed', full_width = F, position = "float_left") %>%
column_spec(1, border_right = T, width = "10em") %>%
column_spec(2, width = "16em")
}
if(sampled=='Y' & exists("assessment")){
kable(assessment ,col.names=c('Field Assessment',''), row.names =FALSE, align=c('l','r')) %>%
kable_styling(bootstrap_options = 'condensed', full_width = F, position = "float_left") %>%
column_spec(1, border_right = T, width = "10em") %>%
column_spec(2, width = "16em")
}
```
```{r row 2 tables, echo=F}
if(sampled=='Y' & exists("samples_tbl")){
kable(samples_tbl, col.names=c('Sample Name', 'Description'), row.names = FALSE, align=c('l','r')) %>%
add_header_above(c('Samples Sent for Laboratory Analysis'=2)) %>%
kable_styling(bootstrap_options = 'condensed', full_width = T) %>%
column_spec(1, border_right = T, width = "15em") %>%
column_spec(2, width = "20em")
}
```
```{r row 2 tables 2, echo=F}
if(sampled=='Y' & exists("fishTaxa.1")){
if(nrow(fishTaxa)>0){
kable(fishTaxa.1, align=c('l','r'), col.names = c('Common Name', 'Count'), row.names = FALSE) %>%
add_header_above(c("Fish Caught" = 2)) %>%
kable_styling(bootstrap_options = 'condensed', full_width = F, position = 'left') %>%
column_spec(1, border_right = T, width = "15em") %>%
column_spec(2, width = "12em")
}else{
kable(fishTaxa.1, col.names = c('Fish Not Collected', ''), row.names = FALSE, align=c('l','r')) %>%
kable_styling(bootstrap_options = 'condensed', full_width = F, position = 'left')
}
}
```