-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path02_BirdVisitsQC.Rmd
307 lines (221 loc) · 11.2 KB
/
02_BirdVisitsQC.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
---
title: "Bird Visit QC"
author: "John Paul Schmit"
date: "5/18/2020"
output: html_document
---
```{r Events_Setup, include=F}
TotVisits<-nrow(QCVisits) #Total Number of visits checked
# 2.1.0
Visits_Bad_Unit<-QCVisits %>%
filter(!Admin_Unit_Code %in% c("ANTI", "CATO", "CHOH", "GWMP", "HAFE", "MANA", "MONO", "NACE", "PRWI", "ROCR", "WOTR")) %>%
select(Admin_Unit_Code, Point_Name)
#2.2.0
Visits_Missing_Point<-QCVisits %>%
filter(is.na(Point_Name) | Point_Name=="" | !Point_Name %in% QCPoints$Point_Name) %>%
select(Admin_Unit_Code, Point_Name, Year)
#2.3.0
Visits_No_Date<-QCVisits %>% left_join(QCPoints, by=c("Admin_Unit_Code","Point_Name")) %>%
filter(is.na(EventDate) | EventDate=="") %>%
select(Admin_Unit_Code,Point_Name, Year, EventDate)
Visits_Date_Dupliacated<-QCVisits %>%
group_by(Admin_Unit_Code, Point_Name, Year, EventDate) %>%
summarise(Vists=n()) %>%
filter(Vists!=1) %>%
select(Admin_Unit_Code,Point_Name, Year, EventDate)
#2.4.0
Visits_Bad_Year<-QCVisits %>% filter(Year!=year(EventDate)) %>%
select(Admin_Unit_Code, Point_Name, EventDate, Year)
#2.5.0
Visits_Bad_StartTime<-QCVisits %>%
filter(is.na(StartTime) | StartTime=="" | !is.difftime(StartTime)) %>%
select(Admin_Unit_Code, Point_Name, EventDate, StartTime)
Visits_Bad_EndTime<-QCVisits %>%
filter(is.na(EndTime) | EndTime=="" | !is.difftime(EndTime)) %>%
select(Admin_Unit_Code, Point_Name, EventDate, EndTime)
Visits_Bad_Length <-QCVisits %>%
filter(EndTime- StartTime != 600) %>%
mutate(Length=EndTime - StartTime) %>%
select(Admin_Unit_Code, Point_Name, EventDate, StartTime, EndTime, Length)
#2.6.0
Visits_Bad_Visit<-QCVisits %>%
filter(!Visit %in% 1:3) %>%
select(Admin_Unit_Code, Point_Name, EventDate, Visit)
Visits_Duplicated_Visit<-QCVisits %>%
group_by(Admin_Unit_Code, Point_Name, Year, Visit) %>%
mutate(N=n()) %>%
filter(N!=1) %>%
select(Admin_Unit_Code,Point_Name, Year,Visit, EventDate)
Visits_Missing_Visit <-QCVisits %>%
group_by(Admin_Unit_Code, Point_Name, Year) %>%
filter(n()!=max(Visit)) %>%
select(Admin_Unit_Code,Point_Name, Year,Visit, EventDate) %>%
pivot_wider(id_cols=c(Admin_Unit_Code, Point_Name, Year), names_from=Visit, names_prefix="Visit ", names_sort=T, values_from=EventDate)
Visits_Bad_Order <-QCVisits %>%
group_by(Admin_Unit_Code, Point_Name, Year, Visit) %>%
mutate(Event_Order=rank(EventDate, ties.method = "average"),Visit_Order=rank(Visit, ties.method = "average")) %>%
filter(Event_Order!=Visit_Order) %>%
select(Admin_Unit_Code, Point_Name, Year, EventDate, Event_Order, Visit, Visit_Order)
#2.7.0
Visits_Bad_Temp<-QCVisits %>%
filter(is.na(Temperature) | Temperature=="" | Temperature < 7 | Temperature>37) %>%
select(Admin_Unit_Code, Point_Name, Year, EventDate, Temperature)
Visits_Big_Temp_Range<-QCVisits %>%
group_by(Admin_Unit_Code, Year, EventDate) %>%
summarise(Temp_Min=min(Temperature), Temp_Max=max(Temperature), Temp_Range=Temp_Max-Temp_Min) %>%
filter(Temp_Range>10) %>%
select(Admin_Unit_Code, Year, EventDate, Temp_Min, Temp_Max, Temp_Range)
#2.8.0
Visits_Bad_Humidity<-QCVisits %>%
filter(is.na(Humidity) | Humidity=="" | Humidity < 40 | Humidity > 100) %>%
select(Admin_Unit_Code, Point_Name, Year, EventDate, Humidity)
Visits_Big_Humidity_Range<-QCVisits %>%
group_by(Admin_Unit_Code, Year, EventDate) %>%
summarise(Humidity_Min=min(Humidity), Humidity_Max=max(Humidity), Humidity_Range=Humidity_Max-Humidity_Min) %>%
filter(Humidity_Range>20) %>%
select(Admin_Unit_Code, Year, EventDate, Humidity_Min, Humidity_Max, Humidity_Range)
#2.9.0
Visits_Bad_Survey<-QCVisits %>%
filter(!Survey_Type %in% c("Forest","Grassland")) %>%
select(Admin_Unit_Code, Year, EventDate, Survey_Type)
#2.10.0
Visits_Bad_Sky <-QCVisits %>%
filter(
!(Sky_Condition ==0 & Sky =="Clear or Few Clouds") & !(Sky_Condition==1 & Sky== "Partly Cloudy") &
!(Sky_Condition ==2 & Sky =="Cloudy/Overcast") & !(Sky_Condition ==3 & Sky=="Fog") &
!(Sky_Condition ==4 & Sky =="Mist/Drizzle") & !(Sky_Condition ==5 & Sky == "Rain Showers")
) %>%
select(Admin_Unit_Code, Year, EventDate, Sky_Condition, Sky)
#2.11.0
Visits_Bad_Wind <-QCVisits %>%
filter(
!(Wind_Code ==0 & Wind =="Calm (< 1 mph) smoke rises vertically") & !(Wind_Code==1 & Wind == "Light air movement (1-3 mph) smoke drifts") &
!(Wind_Code ==2 & Wind =="Light breeze (4-7 mph) wind felt on face") & !(Wind_Code ==3 & Wind =="Gentle breeze (8-12 mph), leaves in motion") &
!(Wind_Code ==4 & Wind =="Moderate breeze (13-18 mph), moves small branches") & !(Wind_Code ==5 & Wind == "Fresh breeze (19-24 mph), small trees sway")
) %>%
select(Admin_Unit_Code, Year, EventDate, Wind_Code, Wind)
#2.12.0
Visits_Bad_Disturbance <-QCVisits %>%
filter(
!(Disturbance_Level ==0 & Disturbance =="No effect on count") &
!(Disturbance_Level ==1 & Disturbance == "Slight effect on count") &
!(Disturbance_Level ==2 & Disturbance =="Moderate effect on count") &
!(Disturbance_Level ==3 & Disturbance =="Serious effect on count")
) %>%
select(Admin_Unit_Code, Year, EventDate, Disturbance_Level, Disturbance)
#2.13.0
Visits_Bad_Observer <- QCVisits %>%
filter(is.na(Observer) | Observer == "") %>%
select(Admin_Unit_Code, Year, EventDate, Observer)
```
#### **Visits Checked:** `r TotVisits` ####
### Visits Unit Codes
```{r Visit_location, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Incorrect Visits Unit Code**<br>")
if(nrow(Visits_Bad_Unit)==0) cat("All visits have a recoginized unit code.<br>") else {
errorText("Visits without a recognized unit code:"); NiceTable(Visits_Bad_Unit)}
```
---
### Visit Points
```{r Visit_Points, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Incorrect Point Name**<br>")
if(nrow(Visits_Missing_Point)==0) cat("All visits have a point name that we use.<br>") else {
errorText("Visits without a point name, or from a point we don't monitor:"); NiceTable(Visits_Missing_Point)}
```
---
### Visit Date
```{r Visit_Date, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Incorrect Event Date**<br>")
if(nrow(Visits_No_Date)==0) cat("All visits have an event date.<br>") else {
errorText("Visits with no date:"); NiceTable(Visits_No_Date)}
cat("<br>**Mulitple Visits to a Point on the Same Day**<br>")
if(nrow(Visits_Date_Dupliacated)==0) cat("No point was visited more than once on a single day.<br>") else {
errorText("Points with more than one visits on a single day:"); NiceTable(Visits_Date_Dupliacated)}
cat("<br>**Year should match Visit Date**<br>")
if(nrow(Visits_Bad_Year)==0) cat("All visit years match their event dates.<br>") else {
errorText("There is a mismach between year and event date:"); NiceTable(Visits_Bad_Year)}
```
---
### Visit Time
```{r Visit_Time, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Incorrect Start Time**<br>")
if(nrow(Visits_Bad_StartTime)==0) cat("All visits have a start time.<br>") else {
errorText("Visits without a starting time:"); NiceTable(Visits_Bad_StartTime)}
cat("<br>**Missing or Incorrect End Time**<br>")
if(nrow(Visits_Bad_EndTime)==0) cat("All visits have an end time.<br>") else {
errorText("Visits without an ending time:"); NiceTable(Visits_Bad_EndTime)}
cat("<br>**Visits that lasted other than 10 minutes**<br>")
if(nrow(Visits_Bad_Length)==0) cat("All visits lasted 10 minutes.<br>") else {
errorText("Visits that were not 10 minutes long:"); NiceTable(Visits_Bad_Length)}
```
---
### Visit Number
```{r Visits_visit_mumber, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Incorrect Visit Number**<br>")
if(nrow(Visits_Bad_Visit)==0) cat("All visits have a valid visit number.<br>") else {
errorText("Visits without a valid visit number:"); NiceTable(Visits_Bad_Visit)}
cat("<br>**Duplicated Visit Numbers**<br>")
if(nrow(Visits_Duplicated_Visit)==0) cat("No visit numbers were duplicated at a point in a single year.<br>") else {
errorText("Duplicated Visit Numbers:"); NiceTable(Visits_Duplicated_Visit)}
cat("<br>**Missing Visits**<br>")
if(nrow(Visits_Missing_Visit)==0) cat("No visit numbers were skipped at a point in a single year.<br>") else {
errorText("Groups of visits with a missing visit number:"); NiceTable(Visits_Missing_Visit)}
cat("<br>**Visit Order vs Event Date Order**<br>")
if(nrow(Visits_Bad_Order)==0) cat("All visit numbers are in the same order as their event dates.<br>") else {
errorText("Viis numnber that are in a different order than their event dates:"); NiceTable(Visits_Bad_Order)}
```
---
### Temperature
```{r Visit_Temperature, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Suspicious Temperatures**<br>")
if(nrow(Visits_Bad_Temp)==0) cat("All visits have a temperature between 7 and 37 C.<br>") else {
errorText("Visits without temperature between 7 and 37 C:"); NiceTable(Visits_Bad_Temp)}
cat("<br>**Big Temperature Range**<br>")
if(nrow(Visits_Big_Temp_Range)==0) cat("All dates have a temperature range of less than 10 degrees C.<br>") else {
errorText("Event dates where the temperature range is 10 or more degrees C:"); NiceTable(Visits_Big_Temp_Range)}
```
---
### Humidity
```{r Visit_Humidity, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Suspicious Humidity**<br>")
if(nrow(Visits_Bad_Humidity)==0) cat("All visits have a humidity between 40 and 100%.<br>") else {
errorText("Visits without humidity between 40 and 100%:"); NiceTable(Visits_Bad_Humidity)}
cat("<br>**Big Humidity Range**<br>")
if(nrow(Visits_Big_Humidity_Range)==0) cat("All dates have a humidity range of less than 20 %.<br>") else {
errorText("Event dates where the humidity range is 20 or more %:"); NiceTable(Visits_Big_Humidity_Range)}
```
---
### Survey Type
```{r Visit_Survey, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Incorrect Survey Type**<br>")
if(nrow(Visits_Bad_Survey)==0) cat("All visits have a survey type of Forest or Grassland.<br>") else {
errorText("Visits with a survey type that is not Forest or Grassalnd:"); NiceTable(Visits_Bad_Survey)}
```
---
### Sky Conditions
```{r Visit_Sky, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Incorrect Sky Conditions**<br>")
if(nrow(Visits_Bad_Sky)==0) cat("All visits have valid Sky and Sky Condidtion values <br>") else {
errorText("Visits with Sky or Sky Condition values we don't use:"); NiceTable(Visits_Bad_Sky)}
```
---
### Wind
```{r Visit_Wind, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Incorrect Wind**<br>")
if(nrow(Visits_Bad_Wind)==0) cat("All visits have valid Wind and Wind Code values <br>") else {
errorText("Visits with Wind or Wind Code values we don't use:"); NiceTable(Visits_Bad_Wind)}
```
---
### Distrubance
```{r Visit_Disturbance, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing or Incorrect Disturbance**<br>")
if(nrow(Visits_Bad_Disturbance)==0) cat("All visits have valid Disturbance and Distrubance Level values <br>") else {
errorText("Visits with Disturbance or Disturbance Level values we don't use:"); NiceTable(Visits_Bad_Disturbance)}
```
---
### Observers
```{r Visit_Observers, echo=FALSE, hold=FALSE, results="asis"}
cat("<br>**Missing Observers**<br>")
if(nrow(Visits_Bad_Observer)==0) cat("All visits have an Observer.<br>") else {
errorText("Visits that are missing an Observer:"); NiceTable(Visits_Bad_Observer)}
```