-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_tag_push_summary.qmd
243 lines (180 loc) · 6.63 KB
/
make_tag_push_summary.qmd
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
---
params:
project_name: NULL
project_number: NULL
matched: NULL
push_log: system.file("push_log.csv", package = "otndo")
since: NULL
format:
html:
self-contained: true
execute:
echo: false
title: "`r paste('Transmitter data push summary:', params$project_name)`"
author: "Created with the [`otndo` R package](https://otndo.obrien.page) (v. `r packageVersion('otndo')`)"
---
```{r, setup, include=FALSE}
knitr::opts_chunk$set(
echo = FALSE, warning = FALSE, message = FALSE
)
```
```{r}
#| label: packages
#| message: false
library(data.table)
library(otndo)
library(reactable)
library(leaflet)
```
```{r}
#| label: extraction-files-read
matched <- fread(params$matched)
matched[, day := as.Date(datecollected)]
release <- matched[receiver == "release"]
matched <- matched[receiver != "release"]
push_log <- fread(params$push_log)
```
```{r}
#| label: n-pis
#| warning: false
pis <- project_contacts(matched, type = "tag")
```
```{r}
#| label: otn-query
projects <- unique(matched$detectedby)
otn_tables <- otn_query(projects)
```
```{r}
#| label: proper-urls
## check what the proj name comes out as... send to proper URL if ACT
# if(act_eval){
# act <- paste0('https://matos.asascience.com/project/detail/',
# params$project_number)
# otn <- paste0('https://members.oceantrack.org/OTN/project?ccode=ACT.PROJ',
# params$project_number)
# }else{
act <- "https://matos.asascience.com/project"
otn <- "https://members.oceantrack.org/OTN/projects"
# }
```
These are data related to matched transmitter data from the `r format(push_log$date[nrow(push_log)], '%B %Y')` OTN data push. New matched-to-animal files (["matched" files](https://members.oceantrack.org/data/otn-detection-extract-documentation-matched-to-animals#autotoc-item-autotoc-1)) were uploaded on `r format(push_log$date[nrow(push_log)], '%B %d')`. The previous data push occurred on `r format(push_log$date[nrow(push_log) - 1], '%B %d, %Y')`.
## Overall
A total of `r format(nrow(matched), big.mark = ',')` detections of `r uniqueN(matched, by = 'tagname')` individuals have been matched via [ACT](`r act`), [FACT](https://secoora.org/fact/projects/), and/or [OTN](`r otn`). The detections span across `r uniqueN(matched, by = 'detectedby')` different projects consisting of `r length(unique(unlist(strsplit(pis$PI, ',\\s?'))))` principal investigators.
```{r}
#| label: otn-match-table
#| column: page
#| fig-cap: Table 1. Total detections and number of individual fish heard by other OTN node projects.
#| fig-cap-location: top
match_table(matched, type = "tag")
```
```{r}
#| label: otn-match-map
#| fig-cap: Figure 1. Bounding box of external projects that recorded a transmitter from this project. This does not necessarily reflect the distribution of this project's fish.
otn_sf <- match_map(otn_tables)
```
```{r}
#| label: temporal-distribution
#| fig-cap: Figure 2. Temporal distribution of detections by external project, i.e., the dates when other projects heard this project's fish.
temp_dist <- temporal_distribution(matched, "tag")
temp_dist
```
```{r}
#| label: abacus-plot
#| fig-cap: Figure 3. Abacus plot of detected transmitters, colored by OTN node projects.
matched_abacus(temp_dist$data, release)
```
```{r}
#| label: station-summary-table
station_summary <- station_table(matched, type = "tag")
# station_summary |>
# gt() |>
# # tab_header(title = 'Records by receivers') |>
# # tab_footnote('statons listed N-S, W-E',
# # locations = cells_title()) |>
# as_raw_html()
# reactable(station_summary,
# groupBy = 'PI',
# columns = list(
# Project = colDef(aggregate = 'unique'),
# Station = colDef(aggregate = 'count'),
# Detections = colDef(aggregate = 'sum'),
# Individuals = colDef(aggregate = 'sum')
# )
# )
```
```{r}
#| label: detection-map-leaflet
#| fig-cap: Figure 4. Number of detections per receiver. Points represent receiver locations, while size and color reflect the number of detections at that location.
station_spatial <- prep_station_spatial(matched, type = "tag")
mapview::mapview(station_spatial,
zcol = "Detections",
cex = "Individuals",
layer.name = "Matched detections"
)
```
```{r}
#| label: tags-remaining
#| fig-cap: Figure 5. Transmitters estimated to be at liberty.
remaining_transmitters(matched, push_log, release)
```
```{r results='asis', echo=FALSE}
if (is.null(params$since)) {
# further lines are not shown (the HTML is commented out)...
cat("<!---")
# ...BUT they are still evaluated, so putting this in here to make the code run.
# It will be nonsense.
since_date <- min(matched$datelastmodified)
}
```
## What's new?
```{r}
# \ label: new-matches
if (!is.null(params$since)) {
since_date <- as.IDate(params$since)
}
new_matches <- matched[datelastmodified > since_date]
```
Since `r format(since_date, '%B %Y')`, `r format(nrow(matched[datelastmodified > since_date]), big.mark = ',')` detections of `r uniqueN(matched[datelastmodified > since_date], by = 'tagname')` individuals have been updated or newly-matched.
```{r}
#| label: new-otn-match-table
#| column: page
#| fig-cap: Table 2. Total newly-added detections and number of individual fish heard by other OTN node projects.
#| fig-cap-location: top
#| eval: !expr "nrow(new_matches) > 0"
match_table(new_matches, type = "tag")
```
```{r}
#| label: new-otn-match-map
#| fig-cap: Figure 6. Bounding box of external projects providing detections added since the last data push. This does not necessarily reflect the distribution of fish heard by the project's receivers.
#| eval: !expr "nrow(new_matches) > 0"
new_otn_tables <- lapply(
otn_tables,
function(.) {
.[grepl(
paste(gsub(".*\\.", "", unique(new_matches$detectedby)), collapse = "|"),
collectioncode
)]
}
)
match_map(new_otn_tables)
```
```{r}
#| label: new-station-summary-table
#| fig-cap: Table 3. PIs, projects, and receivers providing the newly-added detections.
#| fig-cap-location: top
#| eval: !expr "nrow(new_matches) > 0"
new_station_summary <- station_table(new_matches, "tag")
reactable(new_station_summary)
```
```{r}
#| label: new-detection-map-leaflet
#| fig-cap: Figure 7. Number of newly-added detections per receiver. Points represent receiver locations, where color reflects the number of detections and size reflects the number of fish at that location.
#| eval: !expr "nrow(new_matches) > 0"
new_station_spatial <- prep_station_spatial(new_matches, type = "tag")
leaflet_graph(new_station_spatial)
```
```{r results='asis', echo=FALSE}
if (is.null(params$since)) {
cat("-->")
}
```