-
Notifications
You must be signed in to change notification settings - Fork 2
/
03_FieldDataQC.Rmd
319 lines (212 loc) · 10.8 KB
/
03_FieldDataQC.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
---
title: "Bird Observation Data QC"
author: "John Paul Schmit"
date: "5/18/2020"
output: html_document
---
```{r Field_Setup, include=F}
TotObs<-nrow(QCBirds) #Total Number of visits checked
# 3.1.0
Birds_Bad_Unit<-QCBirds %>%
filter(!Admin_Unit_Code %in% c("ANTI", "CATO", "CHOH", "GWMP", "HAFE", "MANA", "MONO", "NACE", "PRWI", "ROCR", "WOTR")) %>%
select(Admin_Unit_Code, Point_Name, EventDate, AOU_Code)
#3.2.0
Birds_Missing_Point<-QCBirds %>%
filter(is.na(Point_Name) | Point_Name=="" | !Point_Name %in% QCPoints$Point_Name) %>%
select(Admin_Unit_Code, Point_Name, EventDate, AOU_Code)
#3.3.0
Birds_No_Date<-QCBirds %>%
filter(is.na(EventDate) | EventDate==""| !EventDate %in% QCVisits$EventDate) %>%
select(Admin_Unit_Code,Point_Name, Year, EventDate, AOU_Code)
#3.4.0
Birds_Bad_Year<-QCBirds %>% filter(Year!=year(EventDate)) %>%
select(Admin_Unit_Code, Point_Name, EventDate, Year, AOU_Code)
#3.5.0
Birds_Bad_Visit<-QCBirds %>%
anti_join(QCVisits %>% select(Point_Name, EventDate, Visit)) %>%
select(Admin_Unit_Code, Point_Name, EventDate, Visit, AOU_Code)
#3.6.0
Birds_No_AOU<-QCBirds %>%
filter(is.na(AOU_Code) | AOU_Code=="" ) %>%
select(Admin_Unit_Code, Point_Name, Year, EventDate, AOU_Code)
Birds_No_Latin<-QCBirds %>%
filter(is.na(Scientific_Name) | Scientific_Name=="" ) %>%
select(Admin_Unit_Code, Point_Name, Year, EventDate, AOU_Code, Scientific_Name)
Birds_No_Common<-QCBirds %>%
filter(is.na(Common_Name) | Common_Name=="" ) %>%
select(Admin_Unit_Code, Point_Name, Year, EventDate, AOU_Code, Common_Name)
Birds_No_Taxon_Code<-QCBirds %>%
filter(is.na(NPSTaxonCode) | NPSTaxonCode=="" ) %>%
select(Admin_Unit_Code, Point_Name, Year, EventDate, AOU_Code, NPSTaxonCode)
Birds_No_TSN<-QCBirds %>%
filter(is.na(AcceptedTSN) | AcceptedTSN=="" ) %>%
select(Admin_Unit_Code, Point_Name, Year, EventDate, AOU_Code, AcceptedTSN)
#3.7.0
Birds_Bad_Interval<-QCBirds %>%
filter(!(Interval==1 & Interval_Length=="0-2.5 min") &
!(Interval==2 & Interval_Length=="2.5 - 5 min") &
!(Interval==3 & Interval_Length=="5 - 7.5 min") &
!(Interval==4 & Interval_Length=="7.5 - 10 min")) %>%
select(Admin_Unit_Code, Point_Name, Year, EventDate, AOU_Code, Interval, Interval_Length)
#3.8.0
Birds_Bad_Method<-QCBirds %>%
filter(!(ID_Method_Code=="C" & ID_Method=="Calling") &
!(ID_Method_Code=="S" & ID_Method=="Singing") &
!(ID_Method_Code=="V" & ID_Method=="Visualization") ) %>%
select(Admin_Unit_Code, Point_Name, Year, EventDate, AOU_Code, ID_Method_Code, ID_Method)
#3.9.0
Birds_Bad_Distance<-QCBirds %>%
filter(!(Distance_id==1 & Distance=="<= 50 Meters") &
!(Distance_id==2 & Distance=="50 - 100 Meters") &
!(Distance_id==4 & Distance=="<= 25 Meters") &
!(Distance_id==5 & Distance=="25 - 50 Meters") &
!(is.na(Distance_id) & Flyover_Observed )) %>%
select(Admin_Unit_Code, Point_Name, Year, EventDate, AOU_Code, Distance_id, Distance)
Birds_Anachronoistic_Distance<- QCBirds %>%
filter( (Distance_id==1 & Year>2018) |
(Distance_id==4 & Year<2019) |
(Distance_id==5 & Year<2019) ) %>%
select(Admin_Unit_Code, Point_Name, Year, EventDate, AOU_Code, Distance_id, Distance)
#3.10.0
Birds_Bad_Sex<-QCBirds %>%
filter(!(Sex_ID==1 & Sex=="Undetermined") &
!(Sex_ID==2 & Sex=="Male") &
!(Sex_ID==3 & Sex =="Female") ) %>%
select(Admin_Unit_Code, Point_Name, Year, EventDate, AOU_Code, Sex_ID, Sex)
#3.11.0
Birds_Bad_Flyover<-QCBirds %>%
filter(!Flyover_Observed %in% c(0,1)) %>%
select(Admin_Unit_Code, Point_Name, Year, EventDate, AOU_Code, Flyover_Observed)
#3.12.0
Birds_Bad_Three_Min<-QCBirds %>%
filter(!Initial_Three_Min_Cnt %in% c(0,1)) %>%
select(Admin_Unit_Code, Point_Name, Year, EventDate, AOU_Code, Initial_Three_Min_Cnt)
#3.13.0
Birds_Bad_Stewardship<-QCBirds %>%
filter(!Regional_Stewardship_Status %in% c(0,1)) %>%
select(Admin_Unit_Code, Point_Name, Year, EventDate, AOU_Code, Regional_Stewardship_Status)
#3.14.0
Birds_Bad_Watchlist<-QCBirds %>%
filter(!PIF_Watchlist_Status %in% c(0,1)) %>%
select(Admin_Unit_Code, Point_Name, Year, EventDate, AOU_Code, PIF_Watchlist_Status)
#3.15.0
Birds_Bad_Count<-QCBirds %>%
filter(is.na(Bird_Count) | Bird_Count<1) %>%
select(Admin_Unit_Code, Point_Name, Year, EventDate, AOU_Code, Bird_Count)
```
#### **Bird Observations Checked:** `r TotObs` ####
### Bird Observation Unit Codes
```{r Bird_Location, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Incorrect Unit Code**<br>")
if(nrow(Birds_Bad_Unit)==0) cat("All bird observations have a recoginized unit code.<br>") else {
errorText("Bird observations without a recognized unit code:"); NiceTable(Birds_Bad_Unit)}
```
---
### Bird Observation Points
```{r Bird_Points, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Incorrect Point Name**<br>")
if(nrow(Birds_Missing_Point)==0) cat("All bird observations have a point name that we use.<br>") else {
errorText("Bird observations without a point name, or from a point we don't monitor:"); NiceTable(Birds_Missing_Point)}
```
---
### Visit Date
```{r Bird_Date, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Incorrect Visit Date**<br>")
if(nrow(Visits_No_Date)==0) cat("All bird observations have a valid visit date.<br>") else {
errorText("Birds observatiosn without a valid visit date:"); NiceTable(Birds_No_Date)}
cat("<br>**Year should match Visit Date**<br>")
if(nrow(Birds_Bad_Year)==0) cat("All bird observation years match their event dates.<br>") else {
errorText("There is a mismach between year and event date:"); NiceTable(Birds_Bad_Year)}
```
---
### Visit Number
```{r Birds_visit_mumber, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Incorrect Visit Number**<br>")
if(nrow(Birds_Bad_Visit)==0) cat("All bird observstions have a valid visit number.<br>") else {
errorText("Bird obsservations without a valid visit number or a visit number that does not match the visti data:"); NiceTable(Birds_Bad_Visit)}
```
---
### Bird Identification
```{r Birds_Identification, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing AOU Code**<br>")
if(nrow(Birds_No_AOU)==0) cat("All bird observations have an AOU code.<br>") else {
errorText("Bird observations without an AOU code:"); NiceTable(Birds_No_AOU)}
cat("<br>**Missing Scientific Name**<br>")
if(nrow(Birds_No_Latin)==0) cat("All bird observations have a scientific name.<br>") else {
errorText("Bird observations without a scientific name:"); NiceTable(Birds_No_Latin)}
cat("<br>**Missing Common Name**<br>")
if(nrow(Birds_No_Common)==0) cat("All bird observations have a common name.<br>") else {
errorText("Bird observations without a common name:"); NiceTable(Birds_No_Common)}
cat("<br>**Missing NPS Taxon Code**<br>")
if(nrow(Birds_No_Taxon_Code)==0) cat("All bird observations have an NPS taxon code.<br>") else {
errorText("Bird observations without an NPS taxon code:"); NiceTable(Birds_No_Taxon_Code)}
cat("<br>**Missing Accepted TSN**<br>")
if(nrow(Birds_No_TSN)==0) cat("All bird observations have an accpeted TSN.<br>") else {
errorText("Bird observations without an accepted TSN:"); NiceTable(Birds_No_TSN)}
```
---
### Interval
```{r Birds_Interval, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Inconsistent Interval and Interval Length**<br>")
if(nrow(Birds_Bad_Interval)==0) cat("All bird observations have consistent intrevals and interval lengths.<br>") else {
errorText("Bird observatrions with inconsistent intervals and interval lengths:"); NiceTable(Birds_Bad_Interval)}
```
---
### ID Method
```{r Birds_Method, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Inconsistent ID Method and Code**<br>")
if(nrow(Birds_Bad_Method)==0) cat("All bird observations have consistent ID Methods and ID Method Codes.<br>") else {
errorText("Bird observatrions with inconsistent ID Methods and ID Method Codes:"); NiceTable(Birds_Bad_Method)}
```
---
### Distance
```{r Birds_Distance, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Inconsistent Distance ID and Distance**<br>")
if(nrow(Birds_Bad_Distance)==0) cat("All bird observations have consistent Distance IDs and Distances.<br>") else {
errorText("Bird observatrions with inconsistent Distance IDs and Distances:"); NiceTable(Birds_Bad_Distance)}
cat("<br>**Anachronistic Distance Bands**<br>")
if(nrow(Birds_Anachronoistic_Distance)==0) cat("All bird observations have Distance IDs and Distances that were in use that year.<br>") else {
errorText("Bird observatrions with Distance IDs and Distances that were not in use in that year:"); NiceTable(Birds_Bad_Distance)}
```
---
### Sex
```{r Birds_Sex, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Inconsistent Sex ID and Sex**<br>")
if(nrow(Birds_Bad_Sex)==0) cat("All bird observations have consistent Sex IDs and Sexes.<br>") else {
errorText("Bird observations with inconsistent Sex IDs and Sexes:"); NiceTable(Birds_Bad_Sex)}
```
---
### Flyovers
```{r Birds_Flyovers, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Invalid Flyover Codes**<br>")
if(nrow(Birds_Bad_Flyover)==0) cat("All bird observations have valid Flyover codes.<br>") else {
errorText("Bird observatrions with invalid flyover codes:"); NiceTable(Birds_Bad_Flyover)}
```
---
### Initial Three Minute Count
```{r Birds_Three_Min, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Invalid Three Minute Count Codes**<br>")
if(nrow(Birds_Bad_Three_Min)==0) cat("All bird observations have valid Initial Three Minute Count codes.<br>") else {
errorText("Bird observations with invalid Three Minue Count Codes:"); NiceTable(Birds_Bad_Three_Min)}
```
---
### Retgional Stewardship Status
```{r Birds_Stewardship, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Invalid Regional Stewardship Status Codes**<br>")
if(nrow(Birds_Bad_Stewardship)==0) cat("All bird observations have valid Regional Stewardship Status codes.<br>") else {
errorText("Bird observations with invalid Regional Stewardship Status codes:"); NiceTable(Birds_Bad_Stewardship)}
```
---
### PIF Watchlist Status
```{r Birds_Watchlist, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Invalid PIF Watchlist Status Codes**<br>")
if(nrow(Birds_Bad_Watchlist)==0) cat("All bird observations have valid PIF Watchlist Status codes.<br>") else {
errorText("Bird observations with invalid PIF Wathclist Status codes:"); NiceTable(Birds_Bad_Watchlist)}
```
---
### Bird Count
```{r Birds_Count, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Invalid Bird Count**<br>")
if(nrow(Birds_Bad_Count)==0) cat("All bird observations have a Bird Count >0.<br>") else {
errorText("Bird observations with a missing or <1 Bird Count:"); NiceTable(Birds_Bad_Count)}
```