-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils_boo_data.R
633 lines (535 loc) · 33.6 KB
/
utils_boo_data.R
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
#' Get functional group data
#' @param ... to allow use of join when used within another function
#' @param Survey CPR or NRS data
#' @param Type Zooplankton or phytoplankton data
#'
#' @return dataframe for plotting functional group time series info
#' @export
#'
#' @examples
#' NRSfgz <- pr_get_FuncGroups("NRS", "Z")
#' NRSfgp <- pr_get_FuncGroups("NRS", "P")
#' CPRfgz <- pr_get_FuncGroups("CPR", "Z", near_dist_km = 250)
#' CPRfgp <- pr_get_FuncGroups("CPR", "P")
pr_get_FuncGroups <- function(Survey = "NRS", Type = "Z", ...){
if(Survey == "CPR"){
df <- pr_get_CPRData(Type, Variable = "abundance", Subset = "htg") %>%
pr_add_Bioregions(...)
} else if(Survey == "NRS"){
df <- pr_get_NRSData(Type, Variable = "abundance", Subset = "htg") %>%
dplyr::filter(.data$StationName != "Port Hacking 4")
}
if(Type == "P"){
var_names <- c("Centric diatom", "Ciliate", "Cyanobacteria", "Dinoflagellate", "Flagellate", "Foraminifera",
"Pennate diatom", "Radiozoa", "Silicoflagellate")
} else if(Type == "Z"){
var_names <- c("Ascidian", "Ciliate", "Ciliophora", "Coelenterate", "Ctenophore", "Echinoderm", "Euphausiid",
"Mysida", "Ostracod", "Phoronid", "Polychaete", "Urochordata", "Amphipod", "Appendicularian",
"Brachiopod", "Bryozoan", "Cephalochordate", "Cephalopod", "Chaetognath", "Cirripedia",
"Cladoceran", "Cnidarian", "Copepod", "Cumacean", "Decapod", "Egg", "Fish", "Foraminifera",
"Hemichordata", "Isopod", "Mollusc", "Nematode", "Nemertean", "Noctilucaceae", "Platyhelminthes",
"Radiozoa", "Rotifer", "Sipunculid", "Thaliacean", "Thecostraca")
}
if(Survey == "CPR"){
df <- df %>%
dplyr::select("BioRegion", "SampleTime_Local", "Month_Local", "Year_Local", tidyselect::any_of(var_names)) %>%
dplyr::filter(!is.na(.data$BioRegion), !.data$BioRegion %in% c("North", "North-west")) %>%
droplevels()
} else if(Survey == "NRS"){
df <- df %>%
dplyr::select("StationName", "StationCode", "SampleTime_Local",
"Month_Local", "Year_Local", tidyselect::any_of(var_names))
}
df <- df %>%
tidyr::pivot_longer(tidyselect::any_of(var_names), values_to = "Values", names_to = "Parameters") %>%
dplyr::mutate(Values = .data$Values + min(.data$Values[.data$Values>0], na.rm = TRUE)) %>%
dplyr::filter(.data$Parameters != "Flagellate") %>%
pr_reorder()
if(Type == "P"){
df <- df %>%
dplyr::mutate(Parameters = ifelse(.data$Parameters %in% c("Ciliate","Foraminifera", "Radiozoa", "Silicoflagellate"), "Other", .data$Parameters),
Parameters = factor(.data$Parameters, levels = c("Centric diatom", "Pennate diatom", "Dinoflagellate", "Cyanobacteria",
"Other")))
} else if(Type == "Z"){
df <- df %>%
dplyr::mutate(Parameters = ifelse(.data$Parameters %in% c("Copepod", "Appendicularian", "Mollusc", "Cladoceran", "Chaetognath", "Thaliacean"), .data$Parameters, "Other"),
Parameters = factor(.data$Parameters, levels = c("Copepod", "Appendicularian", "Mollusc", "Cladoceran", "Chaetognath", "Thaliacean",
"Other")))
}
df <- df %>%
dplyr::group_by(dplyr::across(-"Values")) %>%
dplyr::summarise(Values = sum(.data$Values, na.rm = TRUE),
.groups = "drop") %>%
dplyr::mutate(Values = ifelse(.data$Values < 1, 1, .data$Values))
return(df)
}
#' Get data for frequency map plots
#'
#' @param Type Phytoplankton (P) or Zooplankton (Z), defaults to phyto
#'
#' @return dataframe for plotting with pr_plot_FreqMap
#' @export
#'
#' @examples
#' dfp <- pr_get_FreqMap("P")
#' dfz <- pr_get_FreqMap("Z")
pr_get_FreqMap <- function(Type = "Z"){
NRSSamp <- pr_get_NRSTrips() %>%
dplyr::rename(Sample = "TripCode") %>%
dplyr::mutate(Survey = 'NRS') %>%
dplyr::select("Sample", "Survey", "SampleTime_Local", "Month_Local", "Latitude", "Longitude")
CPRSamp <- pr_get_CPRTrips() %>%
dplyr::mutate(Survey = 'CPR',
Latitude = round(.data$Latitude, 4),
Longitude = round(.data$Longitude, 4)) %>%
dplyr::select("Sample", "Survey", "SampleTime_Local", "Month_Local", "Latitude", "Longitude")
SampLocs <- dplyr::bind_rows(CPRSamp, NRSSamp) %>%
dplyr::mutate(DOY = lubridate::yday(.data$SampleTime_Local),
Start = as.Date(paste0(min(lubridate::year(.data$SampleTime_Local))-1, "-12-31")),
days = difftime(as.Date(.data$SampleTime_Local), .data$Start, units = "days") %>% as.numeric(),
thetadoy = (.data$days %% 365.25)/365.25 * 2 * base::pi, ## leap years...
Lat = round(.data$Latitude/0.5, 0)*0.5,
Long = round(.data$Longitude/0.5, 0)*0.5,
Season = dplyr::case_when(.data$Month_Local > 2 & .data$Month_Local < 6 ~ "March - May",
.data$Month_Local > 5 & .data$Month_Local < 9 ~ "June - August",
.data$Month_Local > 8 & .data$Month_Local < 12 ~ "September - November",
TRUE ~ "December - February")) %>%
dplyr::select("Sample", "Survey", "Lat", "Long", "Season")
if(Type == "P"){
PhytoCountNRS <- pr_get_NRSData(Type = "phytoplankton", Variable = "abundance", Subset = "species") %>%
tidyr::pivot_longer(cols = !dplyr::all_of(pr_get_NonTaxaColumns(Survey = "NRS", Type = "P")),
names_to = "Taxon", values_to = "Counts") %>%
dplyr::rename(Sample = "TripCode") %>%
dplyr::filter(.data$Counts > 0) %>%
dplyr::mutate(Survey = 'NRS')
PhytoCountCPR <- pr_get_CPRData(Type = "phytoplankton", Variable = "abundance", Subset = "species") %>%
tidyr::pivot_longer(cols = !dplyr::all_of(pr_get_NonTaxaColumns(Survey = "CPR", Type = "P")),
names_to = "Taxon", values_to = "Counts") %>%
dplyr::filter(.data$Counts > 0) %>%
dplyr::mutate(Survey = 'CPR') %>%
dplyr::left_join(CPRSamp %>%
dplyr::select(-c("Survey", "Month_Local")),
by = c("Latitude", "Longitude", "SampleTime_Local")) #TODO get rid of this step if product contains sample
obs <- dplyr::bind_rows(PhytoCountCPR, PhytoCountNRS) %>%
dplyr::mutate(Counts = as.integer(as.logical(.data$Counts))) %>%
dplyr::select("Sample", "Survey", "Taxon", "Counts") %>%
dplyr::arrange(.data$Taxon)
} else if(Type == "Z"){
ZooCountNRS <- pr_get_NRSData(Type = "zooplankton", Variable = "abundance", Subset = "species") %>%
tidyr::pivot_longer(cols = !tidyselect::all_of(pr_get_NonTaxaColumns(Survey = "NRS", Type = "Z")),
names_to = "Taxon", values_to = "Counts") %>%
dplyr::rename(Sample = "TripCode") %>%
dplyr::filter(.data$Counts > 0) %>%
dplyr::mutate(Survey = "NRS")
ZooCountCPR <- pr_get_CPRData(Type = "zooplankton", Variable = "abundance", Subset = "species") %>%
tidyr::pivot_longer(cols = !tidyselect::all_of(pr_get_NonTaxaColumns(Survey = "CPR", Type = "Z")),
names_to = "Taxon", values_to = "Counts") %>%
dplyr::filter(.data$Counts > 0) %>%
dplyr::mutate(Survey = "CPR") %>%
dplyr::left_join(CPRSamp %>%
dplyr::select(-c("Survey", "Month_Local")),
by = c("Latitude", "Longitude", "SampleTime_Local")) #TODO get rid of this step if product contains sample
obs <- dplyr::bind_rows(ZooCountCPR, ZooCountNRS) %>%
dplyr::mutate(Counts = as.integer(as.logical(.data$Counts))) %>%
dplyr::select("Sample", "Survey", "Taxon", "Counts") %>%
dplyr::arrange(.data$Taxon)
}
mapdata <- obs %>%
dplyr::select("Sample", "Taxon", "Counts") %>%
dplyr::left_join(SampLocs, by="Sample") %>%
tidyr::drop_na() %>%
dplyr::group_by(.data$Season, .data$Survey, .data$Taxon, .data$Lat, .data$Long) %>%
dplyr::summarise(freq = dplyr::n(), .groups = "drop") %>%
dplyr::left_join(SampLocs %>%
dplyr::group_by(.data$Lat, .data$Long, .data$Season) %>%
dplyr::summarise(samples = dplyr::n(), .groups = "drop"),
by = c("Lat", "Long", "Season")) %>%
dplyr::ungroup() %>%
dplyr::mutate(freqsamp = .data$freq/.data$samples,
freqfac = as.factor(dplyr::case_when(.data$freqsamp < 0.375 ~ "Seen in 25%",
.data$freqsamp > 0.875 ~ "100 % of Samples",
.data$freqsamp > 0.375 & .data$freqsamp < 0.625 ~ "50%",
TRUE ~ "75%")),
Season = factor(.data$Season, levels = c("December - February","March - May","June - August","September - November")),
Taxon = as.factor(.data$Taxon)) %>%
dplyr::select("Season", "Survey", "Lat", "Long", "Taxon", "freqsamp", "freqfac")
absences <- SampLocs %>%
dplyr::distinct(.data$Survey, .data$Lat, .data$Long, .data$Season) %>%
dplyr::mutate(Taxon = "Taxon",
freqsamp = 0,
freqfac = as.factor("Absent"))
freqMapData <- dplyr::bind_rows(mapdata, absences) %>%
dplyr::mutate(freqfac = factor(.data$freqfac, levels = c("Absent", "Seen in 25%", "50%", "75%", "100 % of Samples"))) %>%
dplyr::arrange(.data$freqfac)
return(freqMapData)
}
# Add day/night marker to dataframe
# @param Type Phyto or zoo, defaults to phyto
#
# @return df to be used with pr_plot_DayNight
# @export
#
# @examples
# df <- pr_get_Indices(Survey = "NRS", Type = "Z")
# df <- pr_add_daynight(df)
# pr_add_daynight <- function(df){
#
# dates <- df %>%
# dplyr::select("SampleTime_Local", "Latitude", "Longitude") %>%
# dplyr::rename(date = .data$SampleTime_Local,
# lat = .data$Latitude,
# lon = .data$Longitude) %>%
# dplyr::mutate(date = lubridate::as_date(.data$date))
#
# daynight_df <- suncalc::getSunlightTimes(data = dates, #TODO quicker to change to Local now that it exists.
# keep = c("sunrise", "sunset"),
# tz = lutz::tz_lookup_coords(dates$lat, dates$lon, method = "fast", warn = FALSE)) %>% # TODO remove this when we can get tz into all dataframes
# dplyr::bind_cols(df["SampleTime_Local"]) %>%
# dplyr::mutate(daynight = dplyr::if_else(.data$SampleTime_Local > .data$sunrise &
# .data$SampleTime_Local < .data$sunset, "Day", "Night"))
#
# df <- df %>%
# dplyr::bind_cols(daynight_df["daynight"])
#
# }
#' Get data for plots of species abundance by day and night using CPR data
#' @param Type "P" or "Z" (default)
#'
#' @return df to be used with pr_plot_DayNight
#' @export
#'
#' @examples
#' df <- pr_get_DayNight(Type = "Z")
pr_get_DayNight <- function(Type = "Z"){
if(Type == "Z"){
dat <- pr_get_CPRData(Type = "Z", Variable = "abundance", Subset = "copepods")
} else if (Type == "P"){
dat <- pr_get_CPRData(Type = "P", Variable = "abundance", Subset = "species")
}
dates <- dat %>%
dplyr::select("SampleTime_UTC", "Latitude", "Longitude") %>%
dplyr::rename(date = "SampleTime_UTC",
lat = "Latitude",
lon = "Longitude") %>%
dplyr::mutate(date = lubridate::as_date(.data$date))
daynight_df <- suncalc::getSunlightTimes(data = dates, #TODO quicker to change to Local now that it exists.
keep = c("sunrise", "sunset"),
tz = "UTC") %>%
dplyr::bind_cols(dat["SampleTime_UTC"]) %>%
dplyr::mutate(daynight = ifelse(.data$SampleTime_UTC > .data$sunrise & .data$SampleTime_UTC < .data$sunset, "Day", "Night"))
dat <- dat %>%
dplyr::bind_cols(daynight_df["daynight"]) %>%
dplyr::select(tidyselect::all_of(pr_get_NonTaxaColumns(Survey = "CPR", Type = Type)), tidyselect::everything()) %>%
tidyr::pivot_longer(-tidyselect::any_of(c(pr_get_NonTaxaColumns(Survey = "CPR", Type = Type), "daynight")), values_to = "Species_m3", names_to = "Species") %>%
dplyr::group_by(.data$Month_Local, .data$daynight, .data$Species) %>%
dplyr::summarise(Species_m3 = mean(.data$Species_m3, na.rm = TRUE),
.groups = "drop")
}
#' Get data for STI plots of species abundance
#' @param Type Phyto or zoo, defaults to phyto
#'
#' @return df to be sued with pr_plot_STI
#' @export
#'
#' @examples
#' df <- pr_get_STIdata("P")
#' df <- pr_get_STIdata("Z")
pr_get_STIdata <- function(Type = "P"){
if(Type == "Z"){
cprdat <- pr_get_CPRData(Type, Variable = "abundance", Subset = "copepods")
nrsdat <- pr_get_NRSData(Type, Variable = "abundance", Subset = "copepods")
parameter <- "CopeAbundance_m3"
} else if(Type == "P"){
cprdat <- pr_get_CPRData(Type, Variable = "abundance", Subset = "species")
nrsdat <- pr_get_NRSData(Type, Variable = "abundance", Subset = "species")
parameter <- "PhytoAbundance_m3"
}
## These will be replace with proper satellite data from extractions in time
nrssat <- readr::read_csv(system.file("extdata", "NRS_SatData.csv", package = "planktonr", mustWork = TRUE),
show_col_types = FALSE,
na = c("NA", "")) %>%
pr_rename() %>%
dplyr::rename(SampleTime_Local = "SAMPLEDATE_LOCAL")
cprsat <- readr::read_csv(system.file("extdata", "CPR_SatData.csv", package = "planktonr", mustWork = TRUE),
show_col_types = FALSE) %>%
pr_rename() %>%
dplyr::rename(SampleTime_UTC = "SAMPLEDATE_UTC")
cpr <- cprdat %>%
tidyr::pivot_longer(-tidyselect::all_of(pr_get_NonTaxaColumns(Survey = "CPR", Type = Type)), names_to = "Species", values_to = parameter) %>%
dplyr::left_join(cprsat, by = c("Latitude", "Longitude", "SampleTime_UTC")) %>%
dplyr::select("Species", "SST", tidyselect::all_of(parameter)) %>%
dplyr::filter(!is.na(.data$SST) & .data[[parameter]] > 0) %>%
dplyr::mutate(Project = "cpr",
Species_m3 = .data[[parameter]] + min(.data[[parameter]][.data[[parameter]]>0], na.rm = TRUE))
nrs <- nrsdat %>%
tidyr::pivot_longer(-tidyselect::all_of(pr_get_NonTaxaColumns(Survey = "NRS", Type = Type)), names_to = "Species", values_to = parameter) %>%
dplyr::left_join(nrssat, by = c("Latitude", "Longitude", "SampleTime_Local")) %>%
dplyr::select("Species", "SST", tidyselect::all_of(parameter)) %>%
dplyr::filter(!is.na(.data$SST) & .data[[parameter]] > 0) %>%
dplyr::mutate(Project = "nrs",
Species_m3 = .data[[parameter]] + min(.data[[parameter]][.data[[parameter]]>0], na.rm = TRUE))
comball <- cpr %>%
dplyr::bind_rows(nrs) %>%
dplyr::mutate(SST = round(.data$SST/0.5) * 0.5) %>%
dplyr::arrange(.data$Species)
}
#' Get STI kernel density for each species
#'
#' @param Type Zooplankton (Copepods) or phytoplankton species
#'
#' @return df of STI kernel density for each species
#' @export
#'
#' @examples
#' df <- pr_get_STI('P')
#'
pr_get_STI <- function(Type = "Z"){
df <- pr_get_STIdata(Type)
species <- unique(df$Species)
calc_sti <- function(species){
means <- df %>%
dplyr::group_by(.data$Project) %>%
dplyr::summarise(mean = mean(.data$Species_m3, na.rm = TRUE))
#means are so different so log data as the abundance scale is so wide
sti <- df %>%
dplyr::filter(.data$Species == species) %>%
dplyr::left_join(means, by = "Project") %>%
dplyr::mutate(relab = .data$Species_m3/.data$mean) %>%
dplyr::group_by(.data$SST, .data$Species) %>%
dplyr::summarize(relab = sum(.data$relab),
freq = dplyr::n(),
a = sum(.data$relab)/dplyr::n(),
.groups = "drop")
n <- length(sti$SST)
# have a stop if n < 10
## STI via kernel density
kernStep <- 0.001
kernMin <- 0
kernMax <- 32
kernN <- round((kernMax - kernMin) / kernStep + 1)
kernTemps <- seq(kernMin, kernMax, length.out=kernN)
kernBw <- 2
kern_yp <- matrix(0, nrow = kernN, ncol = 1)
kypout <- matrix(0, nrow = kernN, ncol = 1)
taxon <- unique(sti$Species)
sti$Species <- factor(sti$Species)
sti$weight <- with(sti, abs(relab) / sum(relab))
kernOut <- with(sti,
density(SST, weight=weight,
bw=kernBw,
from=kernMin,
to=kernMax,
n=kernN))
z <- data.frame(kernTemps, y = kernOut$y)
STI <- round(z[which.max(z[,2]),]$kernTemps,1)
}
STI <- purrr::map(species, calc_sti)
STI <- data.frame(Species = species, STI = matrix(unlist(STI), nrow = length(STI), byrow = TRUE))
}
#' Get CTI for sample
#'
#' @param Type Zooplankton (Copepods) or phytoplankton species
#'
#' @return df of CTI for each sample
#' @export
#'
#' @examples
#' df <- pr_get_CTI("P")
#'
pr_get_CTI <- function(Type = 'Z'){
df <- pr_get_STI(Type)
if(Type == 'Z'){
dat <- pr_get_NRSData("zooplankton", "abundance", "species")
vars <- pr_get_NonTaxaColumns(Survey = "NRS", Type)
} else {
dat <- pr_get_NRSData("phytoplankton", "abundance", "species")
vars <- pr_get_NonTaxaColumns(Survey = "NRS", Type)
}
dat <- dat %>%
dplyr::mutate(StationCode = ifelse(.data$StationCode == 'PH4', 'PHB', .data$StationCode)) %>%
dplyr::select(-(tidyselect::any_of(vars)), "SampleTime_Local", "StationCode", "Project") %>%
tidyr::pivot_longer(-c("SampleTime_Local", "StationCode", "Project"), values_to = "Abundance", names_to = "Species") %>%
dplyr::inner_join(df, by = 'Species') %>%
dplyr::group_by(.data$SampleTime_Local, .data$StationCode, .data$Project) %>%
dplyr::summarise(CTI = sum(.data$Abundance * .data$STI, na.rm = TRUE)/sum(.data$Abundance, na.rm = TRUE),
.groups = "drop") %>%
as.data.frame()
return(dat)
}
# Get the summary plankton observations
#
# Get the summary plankton observations from the NRS and CPR.
# @return a dataframe with a species summary
#
# @param Type The group of plankton requested. Either "Z" or "P"
#
# @export
#
# @examples
# df <- pr_get_SppCount("P")
# df <- pr_get_SppCount("Z")
# pr_get_SppCount <- function(Type = "Z"){
#
# if (Type == "P"){
# gp <- "Phytoplankton"
# } else if (Type == "Z"){
# gp <- "Zooplankton"
# }
#
# out <- sppSummary %>%
# dplyr::filter(.data$Group == gp)
#
# }
#' Random facts about plankton
#'
#' This function randomly returns a fun fact about plankton.
#'
#' @return A random plankton fact as a string
#' @export
#'
#' @examples
#' pr_get_Facts()
pr_get_Facts <- function(){
facts <- list("Zooplankton are not only a major food source for commercial and invertebrate fisheries, but some groups are harvest directly for human consumption: 1.2 million tonnes of jellyfish are harvested each year in China, and about 400,000 tonnes of krill are caught annually in the Southern Ocean and off Japan, for human consumption and for fish meal (CCAMLR 2021).",
"Omega-3 fatty acids support human neurological function, cardiovascular health, and immune response (Calder 2015). As zooplankton have high levels of Omega-3 fatty acids, 1000 tonnes of the copepod _Calanus finmarchicus_ are harvested by Norway annually for use in human supplements.",
"Almost all wild-caught fish (80 million tonnes per year) and crustaceans (prawns, shrimps, lobsters and crabs: 3.4 million tonnes) have larval stages that live as plankton drifting in the water column.",
"Plankton such as flagellates, diatoms, copepods, krill and mysids are used extensively in aquaculture production for rearing fish larvae and juveniles, and for feeding shellfish (Richardson et al. 2019)",
"Some phytoplankton species produce toxins that cause skin and eye irritation, digestive upsets, breakdown of liver cells, attack the nervous system, and can even cause death. The major pathway to humans is when we eat shellfish that have filtered toxic phytoplankton from the water.",
"Zooplankton with chitinous exoskeletons, particularly copepods, are hosts for bacterial pathogens such as Vibrio cholerae, which is responsible for ~5 million cases and 120 000 deaths per year.",
"Zooplankton, phytoplankton, bacterioplankton and marine viruses are used in bioprospecting and other commercial products.",
"Copepods and larvae of crabs, prawns and mysids are used in studies assessing acute and sublethal pollutant impacts because they are extremely sensitive to toxins, can be mass cultured, have a short life cycle, and have distinct stages that provides endpoints to determine toxicity of contaminants (Van Dam et al. 2008).",
"Plankton are commonly used as ecological indicators in report cards and ecosystem assessments to assess the health of marine systems. These plankton indicators have been developed to assess human impacts on marine systems: climate change, ocean acidification and heatwaves; eutrophication; overfishing; and species invasions (Richardson et al. 2020).",
"Biomimetics is the field of imitation of natural systems to solve human problems. For example, the elegant and diverse body forms of diatoms, coccolithophores, silicoflagellates, tintinnids, radiolarians, foraminiferans and acantharians are inspiring novel building designs by architects and engineers (Pohl & Nachtigall 2015).",
"Biomimetics is the field of imitation of natural systems to solve human problems. For example, scientists are studying how plankton produce composite materials, in different orientations, to make their structure strong and lightweight (Pohl & Nachtigall 2015).",
"The biological pump, controlled by phytoplankton and zooplankton, fixes vast amounts of CO2 via photosynthesis, which is ultimately removed from surface to deeper waters by sinking and active transport. How the biological pump will be stimulated or impeded with climate change is an area of active research.",
"Harpacticoid copepods are valuable in marine aquaria because they clean the substrate and aquarium panels, and their nauplii and copepodites provide food for invertebrates such as corals, clams and sea cucumbers.",
"As phytoplankton and zooplankton are key to processing and cycling nutrients in the marine food web, data on their abundance and type are used to assess the eReefs biogeochemical model for managing water quality on the Great Barrier Reef (Robson et al. 2020; Skerratt et al. 2018).")
# Krill – biology, ecology and fishing. Commission for the Conservation of Antarctic Marine Living Resources. Retrieved 17 October 2021. https://www.ccamlr.org/en/fisheries/krill-%E2%80%93-biology-ecology-and-fishing
# Calder PC (2015) Functional roles of fatty acids and their effects on human health. Journal of Parenteral and Enteral Nutrition, 39, 18S–32S.
# Richardson AJ, Uribe-Palomino J, Slotwinski A, Coman F, Miskiewicz AG, Rothlisberg PC, Young JW, Suthers IM (2019) Chapter 8. Coastal and marine zooplankton: identification, biology and ecology. In Plankton: A Guide to Their Ecology and Monitoring for Water Quality. Edited by Suthers I, Rissik D, Richardson AJ. 2nd edition. CSIRO Publishing. pp. 141-208
# Vezzulli L, Grande C, Reid PC, Hélaouët P, Edwards M, Höfle MG, et al. (2016) Climate influence on Vibrio and associated human diseases during the past half-century in the coastal North Atlantic. Proceedings of the National Academy of Sciences of the United States of America 113, E5062–E5071. doi:10.1073/pnas.1609157113
# Van Dam RA, Harford AJ, Houston MA, Hogan AC, Negri AP (2008) Tropical marine toxicity testing in Australia: a review and recommendations. Australasian Journal of Ecotoxicology 14: 55–88.
# Richardson AJ, Eriksen R, Moltmann T, Hodgson-Johnston I, Wallis JR (2020) State and Trends of Australia’s Ocean Report, Integrated Marine Observing System, Hobart. 164 pp. https://www.imosoceanreport.org.au/
# Pohl G, Nachtigall W (2015) Biomimetics for Architecture and Design. Nature – Analogies – Technology. 1st edn. Springer, Heidelberg, Germany.
# Robson BJ, Skerratt J, Baird ME, Davies C, Herzfeld M, Jones EM, Mongin M, Richardson AJ, Rizwi F, Wild-Allen K, Steven A (2020) Enhanced assessment of the eReefs marine models for the Great Barrier Reef using a four-level model evaluation framework. Environmental Modelling and Software 129: 104707. 15 pp.
# Skerratt JH, Mongin M, Wild-Allen KA, Baird ME, Robson BJ, Schaffelke B, Soja-Wozniak M, Margvelashvili N, Davies CH, Richardson AJ, Steven ADL (2019) Simulated nutrient and plankton dynamics in the Great Barrier Reef (2011-2016). Journal of Marine Systems 192: 51-74
r <- round(stats::runif(1, min = 1, max = length(facts)))
out <- facts[[r]]
return(out)
}
#' Random scientific papers using IMOS data
#'
#' This function randomly returns a publication that uses the IMOS plankton data
#'
#' @return A random publication reference as a string
#' @export
#'
#' @examples
#' pr_get_Papers()
pr_get_Papers <- function(){
papers <- list(
"Campbell MD, Schoeman DS, Venables W, Abu-Alhaija R, Batten SD, Chiba S, et al. Testing Bergmann\'s rule in marine copepods. Ecography. 2021;n/a(n/a). doi: https://doi.org/10.1111/ecog.05545.",
"Ajani P, Davies C, Eriksen R, Richardson A. Global Warming Impacts Micro-Phytoplankton at a Long-Term Pacific Ocean Coastal Station. Frontiers in Marine Science. 2020;7. doi: https:// doi.org/10.3389/fmars.2020.576011 . PubMed PMID: WOS:000580605700001.",
"Hallegraeff G, Eriksen R, Davies C, Slotwinski A, McEnnulty F, Coman F, et al. The marine planktonic dinoflagellate Tripos: 60 years of species-level distributions in Australian waters. Australian Systematic Botany. 2020;33(4):392-411. doi: https:// doi.org/10.1071/SB19043. PubMed PMID: WOS:000548434100004.",
"Landry MR, Hood RR, Davies CH. Mesozooplankton biomass and temperature-enhanced grazing along a 110\U00B0E transect in the eastern Indian Ocean. Marine Ecology Progress Series. 2020;649:1-19. DOI: https://doi.org/10.3354/meps13444",
"McCosker E, Davies C, Beckley L. Oceanographic influence on coastal zooplankton assemblages at three IMOS National Reference Stations in Western Australia. Marine and Freshwater Research. 2020;71(12):1672-85. doi: https:// doi.org/10.1071/MF19397. PubMed PMID: WOS:000556426000001.",
"McEnnulty F, Davies C, Armstrong A, Atkins N, Coman F, Clementson L, et al. A database of zooplankton biomass in Australian marine waters. Scientific Data. 2020;7(1). doi: https://doi.org/10.1038/s41597-020-00625-9. PubMed PMID: WOS:000571812600010.",
"Robson B, Skerratt J, Baird M, Davies C, Herzfeld M, Jones E, et al. Enhanced assessment of the eReefs biogeochemical model for the Great Barrier Reef using the Concept/State/Process/System model evaluation framework. Environmental Modelling & Software. 2020;129. doi: https:// doi.org/10.1016/j.envsoft.2020.104707. PubMed PMID: WOS:000540077900007.",
"Bailey K, Steinberg C, Davies C, Galibert G, Hidas M, McManus M, et al. Coastal Mooring Observing Networks and Their Data Products: Recommendations for the Next Decade. Frontiers in Marine Science. 2019;6. doi: https:// doi.org/10.3389/fmars.2019.00180. PubMed PMID: WOS:000464606500001.",
"Berry T, Saunders B, Coghlan M, Stat M, Jarman S, Richardson A, et al. Marine environmental DNA biomonitoring reveals seasonal patterns in biodiversity and identifies ecosystem responses to anomalous climatic events. Plos Genetics. 2019;15(2). doi: https://doi.org/10.1371/journal.pgen.1007943. PubMed PMID: WOS:000459970100030.",
"Eriksen R, Davies C, Bonham P, Coman F, Edgar S, McEnnulty F, et al. Australia\'s Long-Term Plankton Observations: The Integrated Marine Observing System National Reference Station Network. Frontiers in Marine Science. 2019;6. doi: https:// doi.org/10.3389/fmars.2019.00161. PubMed PMID: WOS:000465444800001.",
"Skerratt J, Mongin M, Baird M, Wild-Allen K, Robson B, Schaffelke B, et al. Simulated nutrient and plankton dynamics in the Great Barrier Reef (2011-2016). Journal of Marine Systems. 2019;192:51-74. doi: https:// doi.org/10.1016/j.jmarsys.2018.12.006. PubMed PMID: WOS:000459523000005.",
"Brown MV, van de Kamp J, Ostrowski M, Seymour JR, Ingleton T, Messer LF, et al. Systematic, continental scale temporal monitoring of marine pelagic microbiota by the Australian Marine Microbial Biodiversity Initiative. Scientific Data. 2018;5(1):180130. doi: https:// doi.org/10.1038/sdata.2018.130.",
"Davies C, Ajani P, Armbrecht L, Atkins N, Baird M, Beard J, et al. A database of chlorophyll a in Australian waters. Scientific Data. 2018;5. doi: https:// doi.org/10.1038/sdata.2018.18. PubMed PMID: WOS:000425502700003.",
"Dornelas M, Antao L, Moyes F, Bates A, Magurran A, Adam D, et al. BioTIME: A database of biodiversity time series for the Anthropocene. Global Ecology and Biogeography. 2018;27(7):760-86. doi: https:// doi.org/10.1111/geb.12729. PubMed PMID: WOS:000439785700001.",
"Everett J, Baird M, Buchanan P, Bulman C, Davies C, Downie R, et al. Modeling What We Sample and Sampling What We Model: Challenges for Zooplankton Model Assessment. Frontiers in Marine Science. 2017;4. doi: https:// doi.org/10.3389/fmars.2017.00077. PubMed PMID: WOS:000457690600077.",
"Kelly P, Clementson L, Davies C, Corney S, Swadling K. Zooplankton responses to increasing sea surface temperatures in the southeastern Australia global marine hotspot. Estuarine Coastal and Shelf Science. 2016;180:242-57. doi: https:// doi.org/10.1016/j.ecss.2016.07.019. PubMed PMID: WOS:000384866900024.",
"Davies CH, Armstrong AJ, Baird M, Coman F, Edgar S, Gaughan D, et al. Over 75 years of zooplankton data from Australia. Ecology. 2014;95(11):3229-. doi: https:// doi.org/10.1890/14-0697.1.",
"Hallegraeff G, Coman F, Davies C, Hayashi A, McLeod D, Slotwinski A, et al. Australian Dust Storm Associated with Extensive Aspergillus sydowii Fungal Bloom in Coastal Waters. Applied and Environmental Microbiology. 2014;80(11):3315-20. doi: https:// doi.org/10.1128/AEM.04118-13. PubMed PMID: WOS:000336035200004."
)
r <- round(stats::runif(1, min = 1, max = length(papers)))
out <- papers[[r]]
return(out)
}
#' Data for IMOS progress map
#'
#' @param Survey one of NRS, CPR or Both
#' @param interactive A logical TRUE/FALSE if the data is to be used for an interactive plot.
#' @param ... variables to be passed to pr_add_Bioregions. At the moment it only supports `near_dist_km` which is the distance (km) around each bioregion to pad the allocation of points.
#'
#' @return A dataframe for input into pr_plot_Progress()
#' @export
#'
#' @examples
#' df <- pr_get_ProgressMapData(c("NRS", "CPR"))
#' df <- pr_get_ProgressMapData(c("NRS", "CPR"), interactive = TRUE)
pr_get_ProgressMapData <- function(Survey = c("NRS", "CPR"), interactive = FALSE, ...){
if (interactive == FALSE){
if("NRS" %in% Survey) {
PMapDataNRS <- planktonr::pr_get_NRSTrips(Type = c("P", "Z")) %>%
dplyr::select("StationCode", "Longitude", "Latitude") %>%
dplyr::rename(Region = "StationCode") %>%
dplyr::mutate(Survey = "NRS") %>%
dplyr::filter(.data$Region != "PH4")
if (("CPR" %in% Survey) == FALSE){ # Return data if no CPR
return(PMapDataNRS)
}
}
if ("CPR" %in% Survey) {
PMapDataCPR <- pr_get_s3("cpr_samp") %>%
dplyr::select("REGION", "LONGITUDE", "LATITUDE") %>%
pr_rename() %>%
dplyr::mutate(Survey = "CPR")
if (("NRS" %in% Survey) == FALSE){ # Return data if no NRS
return(PMapDataCPR)
}
}
if(("NRS" %in% Survey & "CPR" %in% Survey) | "Both" %in% Survey) {
PMapData <- dplyr::bind_rows(PMapDataNRS, PMapDataCPR)
return(PMapData)
}
} else if (interactive == TRUE){
PMapDataNRS <- dplyr::bind_rows(planktonr::pr_get_Indices(Survey = "NRS", Type = "Z", ...),
planktonr::pr_get_Indices(Survey = "NRS", Type = "P", ...)) %>%
dplyr::filter(.data$Parameters == "ZoopAbundance_m3" | .data$Parameters == "PhytoAbundance_CellsL") %>%
tidyr::pivot_wider(names_from = "Parameters", values_from = "Values") %>%
dplyr::rename(Name = "StationName") %>%
dplyr::select(-"StationCode") %>%
dplyr::mutate(Survey = "NRS")
PMapDataCPR <- dplyr::bind_rows(planktonr::pr_get_Indices(Survey = "CPR", Type = "Z", ...),
planktonr::pr_get_Indices(Survey = "CPR", Type = "P", ...)) %>%
dplyr::filter(.data$Parameters == "ZoopAbundance_m3" |
.data$Parameters == "PhytoAbundance_Cellsm3" |
.data$Parameters == "PCI") %>%
tidyr::pivot_wider(names_from = "Parameters", values_from = "Values") %>%
dplyr::mutate(PhytoAbundance_Cellsm3 = .data$PhytoAbundance_Cellsm3/1e3,
Survey = "CPR") %>%
dplyr::rename(PhytoAbundance_CellsL = "PhytoAbundance_Cellsm3",
Name = "BioRegion")
PMapData <- dplyr::bind_rows(PMapDataNRS, PMapDataCPR) %>%
dplyr::select(-c("Year_Local", "Month_Local", "tz"))
# Map colours for easy plotting
PMapData <- PMapData %>%
dplyr::left_join(mbr %>%
sf::st_drop_geometry(),
by = c("Name" = "REGION"))
return(PMapData)
}
}
#' Get taxa accumulation data for plotting
#'
#' @param Survey "NRS or "CPR"
#' @param Type "Z" or "P"
#'
#' @return A data frame
#' @export
#'
#' @examples
#' df <- pr_get_TaxaAccum(Survey = "NRS", Type = "Z")
pr_get_TaxaAccum <- function(Survey = "NRS", Type = "Z"){
if (Survey == "NRS"){
dat <- pr_get_NRSData(Type = Type, Variable = "abundance", Subset = "raw")
} else if (Survey == "CPR"){
dat <- pr_get_CPRData(Type = Type, Variable = "abundance", Subset = "raw")
}
}