Using rebird
while waiting for the eBird’s full dataset
library("sf")
landkreis_konstanz <- osmdata::getbb("Landkreis Konstanz",
format_out = "sf_polygon")
plot(landkreis_konstanz)
coord <- sf::st_coordinates(landkreis_konstanz)
bbox <- c(x1 = min(coord[, "X"]),
x2 = max(coord[, "X"]),
y1 = min(coord[, "Y"]),
y2 = max(coord[, "Y"]))
center <- c(x = (bbox["x1"] + bbox["x2"])/2,
y = (bbox["y1"] + bbox["y2"])/2)
dist <- landkreis_konstanz %>%
sf::st_cast("POINT") %>%
sf::st_distance() %>%
max() * 0.5
dist
## 24129.15 m
birds <- rebird::ebirdgeo(species = NULL,
lng = center["x.x1"],
lat = center["y.y1"],
back = 30,
dist = as.numeric(
units::set_units(dist, "km")))
nrow(birds)
## [1] 83
str(birds)
## Classes 'tbl_df', 'tbl' and 'data.frame': 83 obs. of 12 variables:
## $ lng : num 8.87 8.87 8.87 8.87 8.87 ...
## $ locName : chr "Stein am Rhein--Nilibucht" "Stein am Rhein--Nilibucht" "Stein am Rhein--Nilibucht" "Stein am Rhein--Nilibucht" ...
## $ howMany : int 30 20 4 1 1 1 6 20 20 15 ...
## $ sciName : chr "Hirundo rustica" "Larus michahellis" "Motacilla alba" "Aythya fuligula" ...
## $ obsValid : logi TRUE TRUE TRUE TRUE TRUE TRUE ...
## $ locationPrivate: logi FALSE FALSE FALSE FALSE FALSE FALSE ...
## $ obsDt : chr "2018-08-31 15:20" "2018-08-31 15:20" "2018-08-31 15:20" "2018-08-31 15:20" ...
## $ obsReviewed : logi FALSE FALSE FALSE FALSE TRUE FALSE ...
## $ comName : chr "Barn Swallow" "Yellow-legged Gull" "White Wagtail" "Tufted Duck" ...
## $ lat : num 47.7 47.7 47.7 47.7 47.7 ...
## $ locID : chr "L4951881" "L4951881" "L4951881" "L4951881" ...
## $ locId : chr "L4951881" "L4951881" "L4951881" "L4951881" ...
crs <- sf::st_crs(landkreis_konstanz)
birds_sf <- sf::st_as_sf(birds,
coords = c("lng", "lat"),
crs = crs)
library("ggplot2")
ggplot() +
geom_sf(data = landkreis_konstanz) +
geom_sf(data = birds_sf) +
theme(legend.position = "bottom") +
hrbrthemes::theme_ipsum() +
ggtitle("eBird observations over the last 30 days",
subtitle = "Observations within a circle around the County of Constance")
in_indices <- sf::st_within(birds_sf, landkreis_konstanz)
trimmed_birds <- dplyr::filter(birds_sf,
lengths(in_indices) > 0)
summarized_birds <- trimmed_birds %>%
dplyr::group_by(locName) %>%
dplyr::summarise(n = n())
mpi <- opencage::opencage_forward("Am Obstberg 1 78315 Radolfzell",
limit = 1)$results
coords <- data.frame(lon = mpi$geometry.lng,
lat = mpi$geometry.lat)
crs <- sf::st_crs(landkreis_konstanz)
mpi_sf <- sf::st_as_sf(coords,
coords = c("lon", "lat"),
crs = crs)
ggplot() +
geom_sf(data = landkreis_konstanz) +
geom_sf(data = summarized_birds,
aes(size = n), show.legend = "point") +
hrbrthemes::theme_ipsum() +
ggtitle("eBird observations over the last 30 days",
subtitle = "County of Constance, MPI as a triangle") +
geom_sf(data = mpi_sf,
shape = 2)
birds2 <- spocc::occ(from = "ebird",
ebirdopts = list(method = "ebirdgeo",
species = NULL,
lng = center["x.x1"],
lat = center["y.y1"],
back = 30,
dist = as.numeric(
units::set_units(dist, "km"))))
mapr::map_leaflet(birds2)
Using auk
to process EBD dataset for Germany
Preparing the dataset
ebd_dir <- "C:/Users/Maelle/Documents/ropensci/ebird"
f <- file.path(ebd_dir, "ebd_DE_relMay-2018.txt")
f_clean <- file.path(ebd_dir, "ebd_DE_relMay-2018_clean.txt")
auk::auk_clean(f, f_out = f_clean, remove_text = TRUE)
ebd_dir <- "C:/Users/Maelle/Documents/ropensci/ebird"
f_in_ebd <- file.path(ebd_dir, "ebd_DE_relMay-2018_clean.txt")
library("magrittr")
landkreis_konstanz_coords <- sf::st_coordinates(landkreis_konstanz)
ebd_filter <- auk::auk_ebd(f_in_ebd) %>%
auk::auk_extent(c(min(landkreis_konstanz_coords[, "X"]),
min(landkreis_konstanz_coords[, "Y"]),
max(landkreis_konstanz_coords[, "X"]),
max(landkreis_konstanz_coords[, "Y"])))
ebd_filter
## Input
## EBD: C:\Users\Maelle\Documents\ropensci\ebird\ebd_DE_relMay-2018_clean.txt
##
## Output
## Filters not executed
##
## Filters
## Species: all
## Countries: all
## States: all
## BCRs: all
## Spatial extent: Lon 8.6 - 9.2; Lat 47.7 - 47.9
## Date: all
## Start time: all
## Last edited date: all
## Protocol: all
## Project code: all
## Duration: all
## Distance travelled: all
## Records with breeding codes only: no
## Complete checklists only: no
fs::dir_create("ebird")
f_out_ebd <- "ebird/ebd_lk_konstanz.txt"
f_out_sampling <- "ebird/ebd_lk_konstanz_sampling.txt"
ebd_filtered <- auk::auk_filter(ebd_filter, file = f_out_ebd,
overwrite = TRUE)
crs <- sf::st_crs(landkreis_konstanz)
ebd <- auk::read_ebd(f_out_ebd) %>%
sf::st_as_sf(coords = c("longitude", "latitude"),
crs = crs)
in_indices <- sf::st_within(ebd, landkreis_konstanz)
ebd <- dplyr::filter(ebd, lengths(in_indices) > 0)
ebd <- as.data.frame(ebd)
What are the observed birds?
library("ggplot2")
dim(ebd)
## [1] 10156 41
ebd %>%
dplyr::mutate(year = lubridate::year(observation_date)) %>%
ggplot() +
geom_bar(aes(year)) +
hrbrthemes::theme_ipsum(base_size = 12, axis_title_size = 12, axis_text_size = 12) +
ylab("No. of eBird observations") +
xlab("Time (years)") +
ggtitle("Full eBird dataset for the County of Constance")
ebd %>%
dplyr::filter(approved) %>%
dplyr::count(scientific_name, common_name) %>%
dplyr::arrange(- n) %>%
head(n = 10) %>%
knitr::kable()
Corvus corone |
Carrion Crow |
288 |
Turdus merula |
Eurasian Blackbird |
285 |
Anas platyrhynchos |
Mallard |
273 |
Fulica atra |
Eurasian Coot |
268 |
Parus major |
Great Tit |
266 |
Podiceps cristatus |
Great Crested Grebe |
254 |
Ardea cinerea |
Gray Heron |
236 |
Cygnus olor |
Mute Swan |
234 |
Cyanistes caeruleus |
Eurasian Blue Tit |
233 |
Chroicocephalus ridibundus |
Black-headed Gull |
223 |
ebd %>%
dplyr::select(scientific_name, common_name,
approved, reviewed, reason) %>%
dplyr::filter(!approved) %>%
knitr::kable()
Cygnus atratus |
Black Swan |
FALSE |
TRUE |
Species-Introduced/Exotic |
Cygnus atratus |
Black Swan |
FALSE |
TRUE |
Species-Introduced/Exotic |
Cygnus atratus |
Black Swan |
FALSE |
TRUE |
Species-Introduced/Exotic |
Oxyura leucocephala |
White-headed Duck |
FALSE |
TRUE |
Species-Introduced/Exotic |
Mareca sibilatrix |
Chiloe Wigeon |
FALSE |
TRUE |
Species-Introduced/Exotic |
Who observed birds?
(first_birder <- ebd %>%
dplyr::count(observer_id) %>%
dplyr::arrange(- n) %>%
head(n = 1) )
## # A tibble: 1 x 2
## observer_id n
## <chr> <int>
## 1 obsr457108 3551
(proportion <- round(first_birder$n/nrow(ebd),
digits = 2))
## [1] 0.35