-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_site_template.Rmd
308 lines (246 loc) · 9.68 KB
/
_site_template.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
---
title: 'Site: `r params$site_name`'
params:
site_id: usa-fkc
site_name: "False Klamath Cove"
editor_options:
chunk_output_type: console
---
```{r setup, include=F}
knitr::opts_chunk$set(echo = F, message = F, warning = F, python.reticulate = F)
```
```{r}
source(here::here("scripts/functions.R"))
if (!exists("params"))
params <- list(
# site_name = "Kibesillah Hill",
# site_id = "usa-kib")
site_name = "Mar del Plata - Faro",
site_id = "arg-mardelplata-faro")
site <- read_csv(here("data/sites.csv"), col_types=cols()) %>%
filter(id == params$site_id)
site_photo_csv <- "https://docs.google.com/spreadsheets/d/1-1rIIiH9OV1C7vPzAH4R_PpC1fFj3ZoA6sV8J28Loxc/gviz/tq?tqx=out:csv&sheet=site_photos.csv"
photos <- read_csv(site_photo_csv, col_types=cols()) %>%
filter(id == params$site_id)
sst <- info('jplMURSST41mday' , url = "https://upwell.pfeg.noaa.gov/erddap/")
chl <- info("VIIRS_OC_NRT_7D" , url = "https://cwcgom.aoml.noaa.gov/erddap/")
scape <- info("noaa_aoml_4729_9ee6_ab54", url = "https://cwcgom.aoml.noaa.gov/erddap/")
```
- Country: **`r str_to_upper(site$country)`**
- Organization: **`r site$org`**
## Photos
```{r}
if (nrow(photos) > 0){
carousel <- bs_carousel(id = "photos", use_indicators = TRUE)
for (i in 1:nrow(photos)){
photo <- photos[i,]
carousel <- bs_append(
carousel,
content = bs_carousel_image(src = photo$url),
caption = bs_carousel_caption(photo$caption))
}
carousel
} else {
cat("No photos yet posted.")
}
```
## Maps {.tabset}
### Temperature
```{r}
# get most recent date
d <- get_dates(sst)[2]
```
Map of the most recent (`r format(d,"%Y-%m-%d")`) sea-surface temperature around the site. Data source: PFEG CoastWatch via ERDDAP.
```{r}
# box <- get_box(site$lon, site$lat, cells_wide=10)
# r <- get_raster(sst, lon=box$lon, lat=box$lat, date="last", field="sst")
# map_raster(r, site_lon=site$lon, site_lat=site$lat, site_label=site$name, title="SST")
# bounding box offset around site marker for extent of map
b <- 3.0
leaflet(
options = leafletOptions(
crs = leafletCRS(crsClass = "L.CRS.EPSG4326"))) %>%
# basemap from GBIF in 4326
addTiles("//tile.gbif.org/4326/omt/{z}/{x}/{y}@1x.png?style=gbif-geyser") %>%
# sst
addWMSTiles(
baseUrl = 'https://coastwatch.pfeg.noaa.gov/erddap/wms/jplMURSST41mday/request?',
layers = "jplMURSST41mday:sst",
options = WMSTileOptions(
version = "1.3.0", format = "image/png", transparent = T, opacity = 0.7,
time = format(d,"%Y-%m-%dT00:00:00Z"))) %>%
addMarkers(lng = ~lon, lat = ~lat, label = ~name, data=site) %>%
addMouseCoordinates() %>%
fitBounds(site$lon - b, site$lat - b, site$lon + b, site$lat + b) %>%
addLegend(
position="bottomright",
title = paste0("SST (°C)<br>", format(d,"%Y-%m-%d")),
colorNumeric("Spectral", c(0,32), reverse=T), seq(0,32))
```
### Chlorophyll
```{r}
# get most recent date
d_2 <- get_dates(chl)[2]
```
Map of the most recent (`r format(d_2, "%Y-%m-%d")`) Chlorophyll-a around the site. Data Source: PFEG CoastWatch via ERDDAP.
```{r}
# box_2 <- get_box(site$lon, site$lat, cells_wide=10)
# r_2 <- get_raster(chl, lon=box$lon, lat=box$lat, date="last", field="chl")
# map_raster(r, site_lon=site$lon, site_lat=site$lat, site_label=site$name, title="CHL")
# bounding box offset around site marker for extent of map
b_2 <- 3.0
leaflet(
options = leafletOptions(
crs = leafletCRS(crsClass = "L.CRS.EPSG4326"))) %>%
# basemap from GBIF in 4326
addTiles("//tile.gbif.org/4326/omt/{z}/{x}/{y}@1x.png?style=gbif-geyser") %>%
# sst
addWMSTiles(
baseUrl = 'https://cwcgom.aoml.noaa.gov/erddap/wms/VIIRS_OC_NRT_7D/request?',
layers = "VIIRS_OC_NRT_7D:chlor_a",
options = WMSTileOptions(
version = "1.3.0", format = "image/png", transparent = T, opacity = 0.7,
time = format(d_2,"%Y-%m-%dT00:00:00Z"))) %>%
addMarkers(lng = ~lon, lat = ~lat, label = ~name, data=site) %>%
addMouseCoordinates() %>%
fitBounds(site$lon - b_2, site$lat - b_2, site$lon + b_2, site$lat + b_2) %>%
addLegend(
position="bottomright",
title = paste0("CHL (mg m^-3)<br>", format(d_2,"%Y-%m-%d")),
colorNumeric("Spectral", c(0,4), reverse=T), seq(0,4))
```
### Seascape
```{r}
# get most recent date
d_2 <- get_dates(scape)[2]
```
Map of the most recent (`r format(d_2, "%Y-%m-%d")`) seascapes around the site. Data Source: AOML CWCGOM via ERDDAP.
```{r}
# box_2 <- get_box(site$lon, site$lat, cells_wide=10)
# r_2 <- get_raster(chl, lon=box$lon, lat=box$lat, date="last", field="chl")
# map_raster(r, site_lon=site$lon, site_lat=site$lat, site_label=site$name, title="CHL")
# bounding box offset around site marker for extent of map
b_2 <- 3.0
leaflet(
options = leafletOptions(
crs = leafletCRS(crsClass = "L.CRS.EPSG4326"))) %>%
# basemap from GBIF in 4326
addTiles("//tile.gbif.org/4326/omt/{z}/{x}/{y}@1x.png?style=gbif-geyser") %>%
# sst
addWMSTiles(
baseUrl = 'https://cwcgom.aoml.noaa.gov/erddap/wms/noaa_aoml_4729_9ee6_ab54/request?',
layers = "noaa_aoml_4729_9ee6_ab54:CLASS",
options = WMSTileOptions(
version = "1.3.0", format = "image/png", transparent = T, opacity = 0.7,
time = format(d_2,"%Y-%m-%dT00:00:00Z"))) %>%
addMarkers(lng = ~lon, lat = ~lat, label = ~name, data=site) %>%
addMouseCoordinates() %>%
fitBounds(site$lon - b_2, site$lat - b_2, site$lon + b_2, site$lat + b_2) %>%
addLegend(
position="bottomright",
title = paste0("CLASS<br>", format(d_2,"%Y-%m-%d")),
colorNumeric("Spectral", c(1,33), reverse=T), seq(1,33))
```
Read more about seascapes [here](https://coastwatch.noaa.gov/cw/satellite-data-products/multi-parameter-models/seascape-pelagic-habitat-classification.html){target="_blank"}.
## Timeseries {.tabset}
### Temperature, Satellite
```{r}
csv <- here(glue("data/sst/sst_{site$id}.csv"))
d <- get_timeseries(sst, lon=site$lon, lat=site$lat, csv=csv, field="sst")
plot_timeseries(d, title="SST", color="red")
```
Download data: [`r basename(csv)`](https://raw.githubusercontent.com/marinebon/p2p/master/data/sst/`r basename(csv)`){target="_blank"}
```{python, eval=F}
# transform something like
# https://marinebon.github.io/home/travis/build/marinebon/p2p/data/sst/sst_wi-maracas.csv
# into
# https://raw.githubusercontent.com/marinebon/p2p/master/data/sst/sst_wi-maracas.csv
csv = str(r.csv).replace("/marinebon/p2p/data/", "/marinebon/p2p/master/data/")
csv_link = "https://raw.githubusercontent.com/" + csv.split("/marinebon/p2p/")[1]
```
```{r, results='asis'}
# source("scripts/functions.R")
if (!exists("params"))
params <- list(
site_name = "Arraial do Cabo - Fortaleza",
site_id = "bra-arraialdocabo-fortaleza")
temp_csv <- here(glue("data/temperature_in-situ/{params$site_id}.csv"))
meta_yml <- here(glue("data/temperature_in-situ/{params$site_id}_meta.yml"))
site_url <- glue("https://raw.githubusercontent.com/marinebon/p2p/master/data/temperature_in-situ/{basename(temp_csv)}")
has_temp_insitu <- all(file.exists(c(temp_csv, meta_yml)))
```
```{r, child=if (has_temp_insitu) '_temperature_in-situ.Rmd'}
```
### Chlorophyll
```{r}
csv <- here(glue("data/chl/chl_{site$id}.csv"))
# TODO: fix get_timeseries() -> griddap() -> erd_up_GET()
d_chl <- get_timeseries(chl, lon=site$lon, lat=site$lat, csv=csv, field="chlor_a")
plot_timeseries(d_chl, title="CHL", color="green")
```
Download data: [`r basename(csv)`](https://raw.githubusercontent.com/marinebon/p2p/master/data/chl/`r basename(csv)`){target="_blank"}
## Taxonomic records in [OBIS](https://obis.org/){target="_blank"} {.tabset}
### Time Series
```{r, eval = T}
library(readr)
library(sf)
library(ggplot2)
# obis_taxa_hist_png <- here(glue("images/sites/{params$site_id}_obis_taxa_hist.png"))
obis_data_csv <- here("data/obis/obis_data.csv")
# read in OBIS data ----
# previously fetched OBIS data by scripts/obis_download.R
obis_data <- read_csv(obis_data_csv, col_types = cols()) %>%
st_as_sf(
coords = c("decimalLongitude", "decimalLatitude"),
crs = 4326,
remove = F)
obis_sites <- read_sf(here("data/obis/obis_sites.geojson"))
# get obis data for site ----
# params <- list(site_id = "arg-puertomadryn2")
obis_site <- obis_sites %>%
filter(id == params$site_id)
d_obis_site <- obis_data[st_intersects(obis_data, obis_site, sparse = F),] %>%
mutate(
taxa = ifelse(
kingdom == "Plantae",
"Kingdom:\n Plantae",
glue("Phylum:\n {phylum}", .trim = F))) %>%
rename(year = date_year)
## Plot the data ----
g <- d_obis_site %>%
st_drop_geometry() %>%
plot_obis_hist(year, taxa)
# ggsave(filename = obis_taxa_hist_png)
# knitr::include_graphics(obis_taxa_hist_png)
# TODO: title <- glue("Data source: https://obis.org/area/{site$area_code}")
# TODO: get institution field since institutionID is blank
# plot_obis_hist(d_obis_site, year, institutionID)
plotly::ggplotly(g)
```
### Maps
**Mollusca**
```{r, echo=FALSE, message=FALSE, warning=FALSE}
d_obis_site %>%
filter(phylum == "Mollusca") %>%
map_obis_pts(obis_site)
```
**Echinodermata**
```{r, echo=FALSE, message=FALSE, warning=FALSE}
d_obis_site %>%
filter(phylum == "Echinodermata") %>%
map_obis_pts(obis_site)
```
**Annelida**
```{r, echo=FALSE, message=FALSE, warning=FALSE}
d_obis_site %>%
filter(phylum == "Annelida") %>%
map_obis_pts(obis_site)
```
**Plantae**
```{r, echo=FALSE, message=FALSE, warning=FALSE}
d_obis_site %>%
filter(kingdom == "Plantae") %>%
map_obis_pts(obis_site)
```
## Data source:
Data shown here is extracted using the [occurrence](https://www.rdocumentation.org/packages/robis/versions/1.0.1/topics/occurrence){target="_blank"} function of the [robis](https://www.rdocumentation.org/packages/robis/versions/1.0.1){target="_blank"} package within a 0.25 x 0.25 degrees box centered at monitoring sites.