Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull request #1

Open
wants to merge 115 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
cdbf8bc
wording tweaks
raymondben Mar 14, 2019
705e25b
add code of conduct
raymondben Mar 14, 2019
e5b2d98
fix hyperlinks
raymondben Mar 14, 2019
28c1889
minor edits to wording
raymondben Mar 14, 2019
1713426
Update README.md
Antonarctica Mar 14, 2019
737f23f
Update README.md
Antonarctica Mar 14, 2019
cbf1f12
Update README.md
Antonarctica May 20, 2019
496af9d
Add files via upload
Antonarctica May 20, 2019
cc7ddf2
Update README.md
Antonarctica May 20, 2019
905a8b3
Update README.md
Antonarctica May 20, 2019
a457431
Update README.md
Antonarctica May 20, 2019
2ecc64c
Delete Grant
Antonarctica May 20, 2019
9ac6f2f
Add files via upload
Antonarctica May 20, 2019
ff3afa7
bookdown setup
raymondben May 24, 2019
f80177f
run bookdown
raymondben May 24, 2019
bf80676
updates to overview
raymondben May 28, 2019
7d39758
tweaks for recent SOmap updates
raymondben Jun 3, 2019
d67b93d
placeholders for other sections
raymondben Jun 3, 2019
d146d0e
updated for SOmap 0.3.0
raymondben Jun 4, 2019
d21a472
add issue tracker link, build instructions
raymondben Jun 7, 2019
c8dd808
Update README.md
Antonarctica Jun 24, 2019
335facb
Update README.md
Antonarctica Jul 1, 2019
ff6cb48
Merge branch 'master' into master
Antonarctica Jul 2, 2019
00999aa
intro to R link
raymondben Jul 11, 2019
b718445
mapping
raymondben Jul 15, 2019
b6adc4d
Merge branch 'course_content' of https://github.com/SCAR/EGABIcourse1…
raymondben Jul 15, 2019
3f35fca
some SOmap stuff
raymondben Jul 15, 2019
2567cf5
add _bookdown_files cache to .gitignore
raymondben Jul 15, 2019
601a782
more mapping bits
raymondben Jul 15, 2019
76a655c
mapping
raymondben Jul 16, 2019
7474e40
more mapping
raymondben Jul 18, 2019
18ba51f
env data chapter placeholder
raymondben Jul 18, 2019
57aafe0
start on env data
raymondben Jul 18, 2019
dee858a
more env, mapping
raymondben Jul 19, 2019
36c578c
Create readme.md
Antonarctica Jul 22, 2019
6ff2385
Create participants
Antonarctica Jul 22, 2019
cc882af
Rename participants to participants.md
Antonarctica Jul 22, 2019
525cadc
Delete participants.md
Antonarctica Jul 22, 2019
a34c2ef
Add files via upload
Antonarctica Jul 22, 2019
dfe0e79
Create participants.md
Antonarctica Jul 22, 2019
0193564
Update participants.md
Antonarctica Jul 22, 2019
3cb90cc
Update participants.md
Antonarctica Jul 22, 2019
cf1a0c0
Delete AnaLauraMachando.JPG
Antonarctica Jul 22, 2019
08035fd
Delete HenrikChristiansen.jpg
Antonarctica Jul 22, 2019
e7a50e4
Add files via upload
Antonarctica Jul 22, 2019
3eb70e2
Update participants.md
Antonarctica Jul 22, 2019
17d78c5
tweaks
raymondben Jul 23, 2019
12a3d63
SOmap legend example, rerender
raymondben Jul 23, 2019
01b2c1f
Merge branch 'course_content'
raymondben Jul 23, 2019
a1b2ace
remove redundant file
raymondben Jul 23, 2019
490eac3
add .nojekyll file
raymondben Jul 23, 2019
2af157e
Delete participants.md
Antonarctica Jul 23, 2019
c784555
cache code chunks by default, add mapping intro section
raymondben Jul 23, 2019
3e22e17
Merge branch 'master' of https://github.com/SCAR/EGABIcourse19
raymondben Jul 23, 2019
aeaea0d
update mapping with new SO_plotter func
raymondben Jul 23, 2019
d89ae14
add relayer example
raymondben Jul 24, 2019
70a4e7a
ggnewscale example
raymondben Jul 24, 2019
64a76c9
pointers to various other pkgs
raymondben Jul 24, 2019
0ff4db7
partial merge of AVDP content
raymondben Jul 29, 2019
827f052
formatting
raymondben Jul 29, 2019
0396e10
metadata section
raymondben Jul 29, 2019
d6a3d89
juggling structure, clean up metadata section
raymondben Jul 29, 2019
58b3da1
fix typos
raymondben Jul 30, 2019
437f859
change affil for GH
raymondben Aug 7, 2019
a79fce8
schedule updated
raymondben Aug 11, 2019
998b385
local copy of intro-to-R pdf
raymondben Aug 11, 2019
570b15f
rerun bookdown
raymondben Aug 11, 2019
9c66a3d
oops, fix link URL
raymondben Aug 11, 2019
823e252
Removed registration link
Antonarctica Aug 22, 2019
bb6431d
Update README.md
Antonarctica Aug 22, 2019
faca892
rename 'extra' dir to 'course_material'
raymondben Aug 28, 2019
56f3dd0
add tidyverse intro material
raymondben Aug 28, 2019
d0f9619
rerun bookdown
raymondben Aug 28, 2019
d598f8d
update
raymondben Aug 29, 2019
6c5be60
authors
raymondben Aug 29, 2019
1776e21
Update README.md
Antonarctica Aug 29, 2019
706c6bc
tidy up overview page
raymondben Aug 30, 2019
f9a22ba
Merge branch 'master' of https://github.com/SCAR/EGABIcourse19
raymondben Aug 30, 2019
12c6100
rnd example for labels
raymondben Aug 30, 2019
05d4aaf
note re SOmap dev version
raymondben Aug 30, 2019
b8d6442
typo
raymondben Aug 30, 2019
9d41f33
SOmap notes
raymondben Aug 30, 2019
b90b6e5
tidyverse pres to PDF, include R script inline
raymondben Sep 1, 2019
46e417e
add SDM models section
raymondben Sep 1, 2019
67b37a7
spelling
raymondben Sep 1, 2019
e569554
add SDM pdfs, exercises, data
raymondben Sep 1, 2019
a191b50
link exercise.docx
raymondben Sep 1, 2019
4b4dbe5
add intro/vis/cleaning material
raymondben Sep 1, 2019
ae96ac2
fix bowerbird github URL
raymondben Sep 1, 2019
b80fdef
RR bio
raymondben Sep 2, 2019
ac9fcf4
img alignment
raymondben Sep 2, 2019
d35ca9a
link to bookdown
raymondben Sep 2, 2019
0543c34
Fix link to Anton's talk. fix #4
ryanreisinger Sep 2, 2019
97a1503
fix link in html
raymondben Sep 2, 2019
b4b25a6
remove commented code fragment
raymondben Sep 3, 2019
02421f5
name the code chunks in the sdm algorithms section
raymondben Sep 3, 2019
92eed5e
typo
raymondben Sep 3, 2019
19bda3d
add 'SDM extras' section
raymondben Sep 3, 2019
ef6baad
add SDM past applications
raymondben Sep 3, 2019
17a3d3f
Add files via upload
Antonarctica Sep 3, 2019
f292022
Delete SDM_EXERCISE.pdf
Antonarctica Sep 3, 2019
39f6652
Delete SDM_FINAL.pdf
Antonarctica Sep 3, 2019
89f0b76
Add files via upload
Antonarctica Sep 3, 2019
796a672
link exercise PDFs
raymondben Sep 3, 2019
641de47
alt logo
raymondben Sep 3, 2019
cbb203c
Add files via upload
Antonarctica Sep 3, 2019
0558a31
Update README.md
Antonarctica Sep 3, 2019
3368b7d
Update README.md
Antonarctica Sep 3, 2019
8484b86
Add files via upload
Antonarctica Sep 3, 2019
f3b7e40
Update README.md
Antonarctica Sep 3, 2019
6d47789
fix SOmap example of removing/changing bathy layer
raymondben Sep 5, 2019
dfbe62f
Update README.md
Antonarctica Sep 5, 2019
74b4e58
Update README.md
Antonarctica Sep 5, 2019
d3ac435
add note about maps inside for loops
raymondben Oct 10, 2019
7c54420
minor update following SOmap dev merge into master
raymondben Oct 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
.DS_Store
*~
.Rproj.user
.Rhistory
data-library
_bookdown_files/
58 changes: 58 additions & 0 deletions 01_Schedule.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Course schedule

## Monday

Time Item
---- ----
9:00 [Course introduction][Course introduction], housekeeping, presentation of participants
10:00 Break
10:15 [Introduction to R and the Tidyverse]
11:15 Break
11:30 [Open data and data cleaning]
12:30 Lunch
13:00 Finding and downloading data through the rOpenSci packages
14:00 Break
14:15 [Mapping]
15:15 Break
15:30 [Data visualisation]
17:30 End day 1



## Tuesday
Time Item
---- ----
9:00 [What are species distribution models?][SDM introduction and review]
10:00 Break
10:15 [Recent and past application of SDMs]
11:15 Break
11:30 Preparation for exercises
12:30 Lunch
13:30 [Run a simple SDM, understand and generate SDM outputs][SDM outputs]
15:00 Break
15:15 [SDM calibration: what you should know before running a model][Calibration]
17:30 End day 2

## Wednesday
Time Item
---- ----
9:30 [Introduction to different SDM algorithms][SDM algorithms]
10:30 Break
10:45 Questions, complete previous courses if necessary
12:30 Lunch
13:30 Personal work
17:30 End day 3


## Thursday
Time Item
---- ----
9:30 Personal work (with breaks)
17:30 End Day 4


## Friday
Time Item
---- ----
9:30 Personal work, final presentations, and discussion (with breaks)
17:00 End Day 5
3 changes: 3 additions & 0 deletions 02_Course_Introduction.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Course Introduction

[Presentation (PDF)](./course_material/AVDP_01_INTRODUCTION.pdf)
196 changes: 196 additions & 0 deletions 05_Overview.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
# Overview

An example analysis that very briefly demonstrates some of the tasks that we'll tackle during the workshop.

## Preparation

Make sure we have the packages we need from CRAN:

```{r pkgs1, message = FALSE}
pkgs <- c("dplyr", "ncdf4", "raster", "remotes", "robis", "worrms")
pkgs <- setdiff(pkgs, installed.packages()[, 1])
if (length(pkgs) > 0) install.packages(pkgs)

library(dplyr)
```

And from GitHub:

```{r pkgs2}
## packages with required minimum version
pkgs <- c("SCAR/antanym" = NA, "AustralianAntarcticDivision/blueant" = NA,
"AustralianAntarcticDivision/SOmap" = "0.5.1")
for (pkg in names(pkgs)) {
if (!basename(pkg) %in% installed.packages()[, 1] ||
(!is.na(pkgs[[pkg]]) && packageVersion(basename(pkg)) < pkgs[[pkg]])) {
remotes::install_github(pkg)
}
}
```

## Taxonomy

```{r tax1, message = FALSE}
library(worrms)

my_species <- "Euphausia crystallorophias"
tax <- wm_records_names(name = my_species)
tax

## the Aphia ID (taxonomic ID) of our species
my_aphia_id <- tax[[1]]$valid_AphiaID
```

## Occurrences

Get all data from the [Antarctic Euphausiacea occurence data from "German Antarctic Marine Living Resources" (GAMLR) Expeditions](https://ipt.biodiversity.aq/resource?r=gamlr) data set:

```{r occ1, message = FALSE}
library(robis)
x <- occurrence(datasetid = "cb16377b-56a8-4d95-802d-4eec02466773")
```

Plot the complete distribution of samples in black, and *Euphausia crystallorophias* in green:

```{r map1, message = FALSE}
library(SOmap)
SOmap_auto(x$decimalLongitude, x$decimalLatitude, input_lines = FALSE, pcol = "black", pcex = 0.2)
with(x %>% dplyr::filter(aphiaID == my_aphia_id),
SOplot(decimalLongitude, decimalLatitude, pch = 19, cex = 0.2, col = "green"))
```

Or as a polar stereo map:

```{r map2, message = FALSE}
basemap <- SOmap(trim = ceiling(max(x$decimalLatitude))+1, bathy_legend = FALSE)
plot(basemap)
SOplot(x$decimalLongitude, x$decimalLatitude, pch = 19, cex = 0.2, col = "black")
with(x %>% dplyr::filter(aphiaID == my_aphia_id),
SOplot(decimalLongitude, decimalLatitude, pch = 19, cex = 0.2, col = "green"))
```

We're going to fit a species (presence/absence) distribution model, so first let's reorganise our data into presence/absence by sampling site:

```{r dat1}
xfit <- x %>% dplyr::rename(lon = "decimalLongitude", lat = "decimalLatitude") %>%
group_by(lon, lat) %>%
dplyr::summarize(present = any(my_aphia_id %in% aphiaID))
```

## Environmental data

```{r envdat1, message = FALSE}
library(blueant)
## put the data into a temporary directory
my_data_directory <- tempdir()

## the data source we want
data_source <- sources_sdm("Southern Ocean marine environmental data")

## fetch the data
status <- bb_get(data_source, local_file_root = my_data_directory, verbose = TRUE)
```

```{r envdat2, message = FALSE}
nc_files <- Filter(function(z) grepl("\\.nc$", z), status$files[[1]]$file)

## create a raster stack of all layers
env_stack <- stack(nc_files)

## the first few layers
head(names(env_stack))
```

Select just the `depth` and `ice_cover_mean` layers and extract their values at our sampling locations:

```{r envdat3}
env_stack <- subset(env_stack, c("depth", "ice_cover_mean"))

temp <- as.data.frame(raster::extract(env_stack, xfit[, c("lon", "lat")]))

xfit <- bind_cols(xfit, temp)
head(xfit)
```

## Fit model

We have presence/absence data, so we'll fit a simple binomial model. The probability of presence of *Euphausia crystallorophias* is fitted as a smooth function of depth and mean sea ice cover:

```{r mod1, message = FALSE}
library(mgcv)

fit <- gam(present ~ s(depth) + s(ice_cover_mean), family = binomial, data = xfit)

summary(fit)
```

The fits to depth and ice cover:

```{r mod2, message = FALSE}
plot(fit, pages = 1, shade = TRUE)
```

This suggests that we are more likely to find *Euphausia crystallorophias* in shallow areas with high annual ice cover, which seems plausible given that this species is typically found in coastal/shelf waters.

## Predict from model

```{r pred1}
xpred <- expand.grid(lon = seq(from = floor(min(xfit$lon)), to = ceiling(max(xfit$lon)), by = 0.25),
lat = seq(from = floor(min(xfit$lat)), to = ceiling(max(xfit$lat)), by = 0.25))

xpred <- bind_cols(as.data.frame(xpred), as.data.frame(raster::extract(env_stack, xpred[, c("lon", "lat")])))

xpred$predicted <- predict(fit, newdata = xpred, type = "response")

## create raster
pr <- rasterFromXYZ(xpred[, c("lon", "lat", "predicted")])
projection(pr) <- "+proj=longlat +datum=WGS84"

my_cmap <- if (getRversion() >= "3.6") hcl.colors(21, "Geyser") else c("#008585", "#359087", "#539B8A", "#6DA590", "#85AF97", "#9BBAA0", "#AEC4AA", "#BED0B0", "#D0DCB5", "#E5E7BC", "#FBF2C4", "#F3E3B2", "#EDD59F", "#E7C68C", "#E3B77A", "#DEA868", "#DA9857", "#D58847", "#D1773A", "#CC6530", "#C7522B")
```

Plot it:

```{r predmap2}
p <- SOmap_auto(x = pr, bathy = pr)
p$bathy_palette <- my_cmap
p
```

```{r predmap}
plot(basemap)
SOplot(pr, col = my_cmap)
```

## Other bits and pieces

### Place names

```{r placenames1}
library(antanym)

## get full SCAR gazetteer data
xn <- an_read(cache = "session", sp = TRUE)

## reduce to one name per feature
xn <- an_preferred(xn, origin = "United Kingdom")

## ask for suggestions in our region to show on our map
xns <- an_suggest(xn, map_scale = 20e6, map_extent = extent(pr))

## transform to our map projection, convert to data frame, take the top 10
xns <- as_tibble(SOproj(xns, target = basemap$projection)) %>% head(10)
```

Add them to the map:

```{r predmap3}
plot(basemap)
SOplot(pr, col = my_cmap)

## placename points
with(xns, points(x = longitude, y = latitude, pch = 16, cex = 0.4))
## and labels
with(xns, text(x = longitude, y = latitude, labels = place_name,
cex = 0.75, pos = 2 + 2*(seq_len(nrow(xns)) %% 2)))
```
Expand Down
Loading