The ctdp package is an R package to load and process
camera-trap data stored in camtrap-dp format. The
package builds upon the frictionless and camtraptor packages, which
first need to be installed (using the devtools package,
which may need installation first) from github:
devtools::install_github("frictionlessdata/frictionless-r")
devtools::install_github("inbo/camtraptor")
Then, install the ctdp package from the WUR gitlab
repo:
devtools::install_gitlab(repo = "camtrap/ctdp", host = "git.wur.nl")
The main data structure of the ctdp package is an object
of class ctdp, which essentially is a named
list with a “settings” slot (a list with settings), and 6
tibbles, which together form a relational database:
The ctdp package contains an example dataset:
camsample:
camsample
## ctdp datapackage which is a list with elements:
## - settings
##
## and tables:
## - locations (n = 6)
## - deployments (n = 42)
## - sequences (n = 10,899)
## - observations (n = 11,998)
## - media (n = 0)
## - taxonomy (n = 31)
##
## Zip file: bcnm-mammal-monitoring-team-20230223112118.zip
## Timezone: Etc/GMT+5
## Interval: TRUE
## Primary keys: locationID, deploymentID, sequenceID, observationID, taxonID, mediaID
## Nr of stations: 6
## Nr of species: 31
## Media have been dropped
## Time range: 2017/01/01 -- 2018/01/01
A camtrap-dp export can be loaded Via the function
read_ctdp
single file (.zip)
unzipped folder
see function set_GMT_offset
set_GMT_offset(-5)
## [1] "Etc/GMT+5"
dat <- read_ctdp("C:/data/ctdp/bcnm-mammal-monitoring-team-20230223112118.zip",
tz = "Etc/GMT+5")
dat
## ctdp datapackage which is a list with elements:
## - settings
##
## and tables:
## - locations (n = 6)
## - deployments (n = 42)
## - sequences (n = 10,899)
## - observations (n = 11,998)
## - media (n = 0)
## - taxonomy (n = 31)
##
## Zip file: bcnm-mammal-monitoring-team-20230223112118.zip
## Timezone: Etc/GMT+5
## Interval: TRUE
## Primary keys: locationID, deploymentID, sequenceID, observationID, taxonID, mediaID
## Nr of stations: 6
## Nr of species: 31
## Media have been dropped
## Time range: 2017/01/01 -- 2018/01/01
Using function as_ctdp you can convert an object read
via the read_camtrap_dp of the camptraptor
package into an object of class ctdp:
x <- read_camtrap_dp("C:/data/ctdp/bcnm-mammal-monitoring-team-20230223112118/datapackage.json",
tz = "Etc/GMT+5")
dat <- as_ctdp(x)
Todo: function read_ctdp_list to load a series of
exports into a single ctdp object.
function check_integrity function will become available
which will be a wrapper function perfoming various checks, see
“Specifics” tab
check_annotations(dat)
## $noNAs
## [1] TRUE
##
## $isFactor
## [1] TRUE
##
## $correctLevels
## [1] TRUE
test <- check_deployments(dat)
test %>% filter(nr_false != 0) %>% slice_head(n=1) %>% str()
## tibble [1 × 23] (S3: tbl_df/tbl/data.frame)
## $ deploymentID : chr "09ea8772-75a8-44f5-a2b7-9cf714ce4df3"
## $ nr_false : num 1
## $ ok_start : logi TRUE
## $ ok_end : logi TRUE
## $ ok_startend : logi TRUE
## $ ok_lon : logi TRUE
## $ ok_lat : logi TRUE
## $ ok_name : logi TRUE
## $ ok_sea_start : logi FALSE
## $ ok_sea_end : logi TRUE
## $ ok_duration : logi TRUE
## $ locationID : chr "fe093582-fe93-4a2c-998e-2f1b2edf8174"
## $ deployment_interval:Formal class 'Interval' [package "lubridate"] with 3 slots
## .. ..@ .Data: num 995671
## .. ..@ start: POSIXct[1:1], format: "2017-01-01"
## .. ..@ tzone: chr "Etc/GMT+5"
## $ longitude : num -79.8
## $ latitude : num 9.17
## $ locationName : chr "BCI-3-01"
## $ seq_start : POSIXct[1:1], format: "2017-01-01 09:42:39"
## $ seq_end : POSIXct[1:1], format: "2017-01-12 12:34:31"
## $ duration : num 11.5
## $ sea_start : num -75.1
## $ sea_end : num 59.3
## $ dt_start : num -0.405
## $ dt_end : num 0
check_duplicates(dat)
## $locations
## [1] TRUE
##
## $deployments
## [1] TRUE
##
## $sequences
## [1] TRUE
##
## $observations
## [1] TRUE
##
## $media
## [1] TRUE
##
## $taxonomy
## [1] TRUE
check_joins(dat)
## $allunique
## [1] TRUE
##
## $alljoins
## [1] TRUE
##
## $unique
## # A tibble: 1 × 6
## locations deployments sequences observations media taxonomy
## <lgl> <lgl> <lgl> <lgl> <lgl> <lgl>
## 1 TRUE TRUE TRUE TRUE TRUE TRUE
##
## $anti_joins
## $anti_joins$loc_notin_dep
## character(0)
##
## $anti_joins$dep_notin_loc
## character(0)
##
## $anti_joins$dep_notin_seq
## character(0)
##
## $anti_joins$seq_notin_dep
## character(0)
##
## $anti_joins$seq_notin_obs
## character(0)
##
## $anti_joins$obs_notin_seq
## character(0)
##
## $anti_joins$obs_notin_tax
## character(0)
Several functions allow you to retrieve general information from an
object of class ctdp:
is_ctdp(dat)
## [1] TRUE
is.na(dat)
## [1] FALSE
time_zone(dat)
## [1] "Etc/GMT+5"
time_range(dat)
## [1] "2017-01-01 -05" "2018-01-01 -05"
primary_keys(dat)
## $locations
## [1] "locationID"
##
## $deployments
## [1] "deploymentID"
##
## $sequences
## [1] "sequenceID"
##
## $observations
## [1] "observationID"
##
## $taxonomy
## [1] "taxonID"
##
## $media
## [1] "mediaID"
has_media(dat)
## [1] FALSE
column_names(dat)
##
##
## Table $locations:
## - locationID
## - locationName
## - longitude
## - latitude
## - transect
##
## Table $deployments:
## - deploymentID
## - locationID
## - deployment_interval
## - array
## - habitat
##
## Table $sequences:
## - sequenceID
## - deploymentID
## - captureMethod
## - sequence_interval
## - nrphotos
##
## Table $observations:
## - observationID
## - sequenceID
## - taxonID
## - observationType
## - cameraSetupType
## - classificationMethod
## - cameraSetup
## - count
##
## Table $media:
## - mediaID
## - sequenceID
## - media_timestamp
## - filePath
## - fileName
## - fileMediatype
## - exifData
## - favourite
## - media_comments
## - media__id
##
## Table $taxonomy:
## - taxonID
## - class
## - order
## - scientificName
## - vernacularNames.en
## - vernacularNames.nl
Information on camera trap locations can be retrieved in different, equivalent, ways:
locations(dat)
get_table(dat, "locations")
dat$locations
For example:
locations(dat)
## # A tibble: 6 × 5
## locationID locationName longitude latitude transect
## <chr> <chr> <dbl> <dbl> <int>
## 1 638c14c5-8c77-4ebe-8bcc-b202f7aafd3b BCI-1-26 -79.8 9.16 1
## 2 fe093582-fe93-4a2c-998e-2f1b2edf8174 BCI-3-01 -79.8 9.17 3
## 3 9999afd2-a5df-4780-87ea-257a0fe74c84 BCI-3-03 -79.8 9.16 3
## 4 a59f1f07-3113-4adf-aa5b-b2289cd6908a BCI-3-02 -79.9 9.15 3
## 5 b434cff8-be1b-4700-b34a-16f991eeed7e BCI-1-25 -79.8 9.15 1
## 6 eb087178-bac2-4a0e-9df9-1491eda5bd5d BCI-1-24 -79.9 9.15 1
Retrieving the locations information without the
longitude and latitude columns:
locations(dat, addLonlat = FALSE)
## # A tibble: 6 × 3
## locationID locationName transect
## <chr> <chr> <int>
## 1 638c14c5-8c77-4ebe-8bcc-b202f7aafd3b BCI-1-26 1
## 2 fe093582-fe93-4a2c-998e-2f1b2edf8174 BCI-3-01 3
## 3 9999afd2-a5df-4780-87ea-257a0fe74c84 BCI-3-03 3
## 4 a59f1f07-3113-4adf-aa5b-b2289cd6908a BCI-3-02 3
## 5 b434cff8-be1b-4700-b34a-16f991eeed7e BCI-1-25 1
## 6 eb087178-bac2-4a0e-9df9-1491eda5bd5d BCI-1-24 1
Information on camera trap deployments can be retrieved in different, equivalent, ways:
deployments(dat)
get_table(dat, "deployments")
dat$deployments
For example:
deployments(dat)
## # A tibble: 42 × 5
## deploymentID locat…¹ deployment_interval array habitat
## <chr> <chr> <Interval> <chr> <chr>
## 1 09ea8772-75a8-44f5-a2b7-9… fe0935… 2017-01-01 00:00:00 -05--2017-01-12 12:34:31 -05 <NA> <NA>
## 2 0cbb925c-b07a-4f34-909d-a… fe0935… 2017-07-28 09:34:13 -05--2017-10-14 00:00:00 -05 <NA> <NA>
## 3 103cc5fe-29be-4b9c-a9e4-2… 638c14… 2017-12-18 17:39:12 -05--2018-01-01 00:00:00 -05 <NA> <NA>
## 4 157d2d1e-d5b7-4927-8058-2… 9999af… 2017-10-24 08:32:02 -05--2017-12-04 09:39:28 -05 <NA> <NA>
## 5 1687bfe3-a714-4714-bca7-2… fe0935… 2017-04-07 11:43:23 -05--2017-06-09 09:36:42 -05 <NA> <NA>
## 6 17c9654d-44cd-4939-a5a4-8… 638c14… 2017-07-07 09:04:47 -05--2017-08-08 04:05:00 -05 <NA> <NA>
## 7 1c82bb10-3392-440b-b707-0… fe0935… 2017-02-17 10:32:38 -05--2017-04-07 11:35:21 -05 <NA> <NA>
## 8 1d1036e2-1861-4b1e-8b35-2… b434cf… 2017-01-18 08:56:11 -05--2017-01-20 00:00:00 -05 <NA> <NA>
## 9 224ff78b-d516-4aab-8334-c… fe0935… 2017-12-14 11:40:26 -05--2018-01-01 00:00:00 -05 <NA> <NA>
## 10 2c8ea383-0778-4864-93d3-c… b434cf… 2017-01-18 08:56:11 -05--2017-01-20 00:00:00 -05 <NA> <NA>
## # … with 32 more rows, and abbreviated variable name ¹locationID
Information on sequences can be retrieved in different, equivalent, ways:
sequences(dat)
get_table(dat, "sequences")
dat$sequences
For example:
sequences(dat)
## # A tibble: 10,899 × 5
## sequenceID deplo…¹ captu…² sequence_interval nrpho…³
## <chr> <chr> <fct> <Interval> <int>
## 1 02e18499-749e-4d37-948c… 09ea87… motion… 2017-01-02 10:22:23 -05--2017-01-02 10:23:00 -05 20
## 2 056b98e3-1b06-4faf-bd79… 09ea87… motion… 2017-01-02 03:35:16 -05--2017-01-02 03:35:23 -05 10
## 3 09e17296-0f81-42ba-9e78… 09ea87… motion… 2017-01-05 19:18:55 -05--2017-01-05 19:19:24 -05 30
## 4 0c2dda0a-f364-43e1-ac79… 09ea87… motion… 2017-01-02 08:50:54 -05--2017-01-02 08:51:15 -05 20
## 5 0eb5c6cd-b1d1-4301-b4ee… 09ea87… time l… 2017-01-10 12:00:00 -05--2017-01-10 12:00:00 -05 1
## 6 0fc2ad50-af4c-4f41-a853… 09ea87… motion… 2017-01-01 09:42:39 -05--2017-01-01 09:42:48 -05 10
## 7 141bb3c1-0ffb-48ce-a360… 09ea87… time l… 2017-01-08 12:00:00 -05--2017-01-08 12:00:00 -05 1
## 8 1a125fac-9a66-4101-971e… 09ea87… time l… 2017-01-11 00:00:00 -05--2017-01-11 00:00:00 -05 1
## 9 1dc8a2d0-7fbf-4399-9163… 09ea87… time l… 2017-01-12 12:00:00 -05--2017-01-12 12:00:00 -05 1
## 10 280ff901-3b88-4b95-b86d… 09ea87… motion… 2017-01-12 12:34:20 -05--2017-01-12 12:34:31 -05 10
## # … with 10,889 more rows, and abbreviated variable names ¹deploymentID, ²captureMethod, ³nrphotos
Information on observations can be retrieved in different, equivalent, ways:
observations(dat)
get_table(dat, "observations")
dat$observations
For example:
observations(dat)
## # A tibble: 11,998 × 8
## observationID sequenceID taxonID obser…¹ camer…² class…³ camer…⁴ count
## <chr> <chr> <chr> <fct> <fct> <fct> <lgl> <dbl>
## 1 0fc2ad50-af4c-4f41-a853-6802d3991fdc:seq 0fc2ad50-… <NA> unclas… <NA> <NA> FALSE NA
## 2 d34d5d1d-97fd-4a0a-a0c2-4a535705c92d:seq d34d5d1d-… <NA> unclas… <NA> <NA> FALSE NA
## 3 90d9e04a-8ad6-4164-82c8-b7cfb6c897a2:seq 90d9e04a-… <NA> unclas… <NA> <NA> FALSE NA
## 4 056b98e3-1b06-4faf-bd79-39837abb679d:seq 056b98e3-… <NA> unclas… <NA> <NA> FALSE NA
## 5 c9f4f532-bdb0-411d-95d3-b6de36e4d6b3:seq c9f4f532-… <NA> unclas… <NA> <NA> FALSE NA
## 6 0c2dda0a-f364-43e1-ac79-04de3c89e8ab:seq 0c2dda0a-… <NA> unclas… <NA> <NA> FALSE NA
## 7 02e18499-749e-4d37-948c-dba1234e2960:seq 02e18499-… <NA> unclas… <NA> <NA> FALSE NA
## 8 eba7d893-5d8d-4d99-b33f-1f361743e47a:seq eba7d893-… <NA> unclas… <NA> <NA> FALSE NA
## 9 48519654-6cf7-45c8-abb2-64d790fc248b:seq 48519654-… <NA> unclas… <NA> <NA> FALSE NA
## 10 83b3caac-a218-4543-b136-890e5e54db2b:seq 83b3caac-… <NA> unclas… <NA> <NA> FALSE NA
## # … with 11,988 more rows, and abbreviated variable names ¹observationType, ²cameraSetupType,
## # ³classificationMethod, ⁴cameraSetup
Information on the used taxonomy can be retrieved in different, equivalent, ways:
taxonomy(dat)
get_table(dat, "taxonomy")
dat$taxonomy
For example:
taxonomy(dat)
## # A tibble: 31 × 6
## taxonID class order scientificName vernacularNames.en vernacu…¹
## <chr> <chr> <chr> <chr> <chr> <chr>
## 1 C5QJ Mammalia Primates Alouatta palliata mantled howler mantelbr…
## 2 V2 Aves <NA> Aves bird sp. vogel
## 3 NYVX Aves Accipitriformes Buteogallus anthracinus common black hawk zwarte b…
## 4 5XG3M Aves Accipitriformes Cathartes aura turkey vulture roodkopg…
## 5 RYZ5 Mammalia Primates Cebus capucinus Colombian white-faced capuchin witschou…
## 6 Y9SZ Aves Accipitriformes Coragyps atratus black vulture zwarte g…
## 7 6BPX8 Mammalia Rodentia Cuniculus paca lowland paca paca
## 8 349R6 Mammalia Rodentia Dasyprocta punctata Central American agouti Midden-A…
## 9 349W8 Mammalia Cingulata Dasypus novemcinctus nine-banded armadillo negenban…
## 10 35WKD Mammalia Didelphimorphia Didelphis marsupialis common opossum zuidelij…
## # … with 21 more rows, and abbreviated variable name ¹vernacularNames.nl
To retrieve the classes, orders, species names, and taxon identifiers:
taxon_classes(dat)
## [1] "Aves" "Mammalia" "Squamata"
taxon_orders(dat)
## [1] "Accipitriformes" "Artiodactyla" "Carnivora" "Cingulata" "Columbiformes"
## [6] "Didelphimorphia" "Galliformes" "Passeriformes" "Perissodactyla" "Pilosa"
## [11] "Primates" "Rodentia" "Tinamiformes"
taxon_species(dat)
## [1] "Bairds tapir" "Central American agouti"
## [3] "Central American red brocket" "Colombian white-faced capuchin"
## [5] "Robinsons mouse opossum" "Tomes spiny rat"
## [7] "bird sp." "black vulture"
## [9] "brown four-eyed opossum" "capybara"
## [11] "chestnut-backed antbird" "collared peccary"
## [13] "common black hawk" "common opossum"
## [15] "crab-eating raccoon" "crested guan"
## [17] "great tinamou" "green iguana"
## [19] "grey-chested dove" "human"
## [21] "lowland paca" "mantled howler"
## [23] "nine-banded armadillo" "northern tamandua"
## [25] "ocelot" "red-tailed squirrel"
## [27] "rodents" "spotted antbird"
## [29] "tayra" "turkey vulture"
## [31] "white-nosed coati"
taxon_id(dat)
## [1] "C5QJ" "V2" "NYVX" "5XG3M" "RYZ5" "Y9SZ" "6BPX8" "349R6" "349W8" "35WKD" "38VYB" "6MB3T"
## [13] "6MK7J" "3NGM8" "6MV3G" "3T78D" "3TYGD" "3Y83J" "3YJ7Z" "42952" "743L7" "6S6BF" "6TW4J" "76H2H"
## [25] "6VY96" "4MQLJ" "3Z5" "6XY2N" "54M4Y" "54TF2" "7CB5D"
To get the taxon identifiers (column “taxonID”) of specific species:
taxon_id(dat, spp = "lowland paca")
## [1] "6BPX8"
The function also works with variations in writing:
taxon_id(dat, spp = "lowland paca")
## [1] "6BPX8"
taxon_id(dat, spp = "LowlandPaca")
## [1] "6BPX8"
taxon_id(dat, spp = "_LowLand_ PaCa")
## [1] "6BPX8"
Whether or not the object has media data included can be checked with
the has_media function:
has_media(dat)
## [1] FALSE
Information on media can be retrieved in different, equivalent, ways:
media(dat)
get_table(dat, "media")
dat$media
For example:
media(dat)
## # A tibble: 0 × 10
## # … with 10 variables: mediaID <chr>, sequenceID <chr>, media_timestamp <dttm>, filePath <chr>,
## # fileName <chr>, fileMediatype <chr>, exifData <chr>, favourite <lgl>, media_comments <chr>,
## # media__id <chr>
dat %>%
ctdp_interval() %>%
distinct() %>%
drop_na_cols() %>%
drop_media()
## ctdp datapackage which is a list with elements:
## - settings
##
## and tables:
## - locations (n = 6)
## - deployments (n = 42)
## - sequences (n = 10,899)
## - observations (n = 11,998)
## - media (n = 0)
## - taxonomy (n = 31)
##
## Zip file: bcnm-mammal-monitoring-team-20230223112118.zip
## Timezone: Etc/GMT+5
## Interval: TRUE
## Primary keys: locationID, deploymentID, sequenceID, observationID, taxonID, mediaID
## Nr of stations: 6
## Nr of species: 31
## Media have been dropped
## Time range: 2017/01/01 -- 2018/01/01
drop_columns removes all columns except those listed in
data ctdp_mainCols
The add_location_info function allows adding information
to the locations table (automatically matched by the
identifier and other matching columns:
datInfo <- locations(dat)
datInfo <- datInfo %>%
mutate(group = str_sub(locationName, 1, 5))
dat <- add_location_info(dat, datInfo)
locations(dat)
## # A tibble: 6 × 6
## locationID locationName longitude latitude transect group
## <chr> <chr> <dbl> <dbl> <int> <chr>
## 1 638c14c5-8c77-4ebe-8bcc-b202f7aafd3b BCI-1-26 -79.8 9.16 1 BCI-1
## 2 fe093582-fe93-4a2c-998e-2f1b2edf8174 BCI-3-01 -79.8 9.17 3 BCI-3
## 3 9999afd2-a5df-4780-87ea-257a0fe74c84 BCI-3-03 -79.8 9.16 3 BCI-3
## 4 a59f1f07-3113-4adf-aa5b-b2289cd6908a BCI-3-02 -79.9 9.15 3 BCI-3
## 5 b434cff8-be1b-4700-b34a-16f991eeed7e BCI-1-25 -79.8 9.15 1 BCI-1
## 6 eb087178-bac2-4a0e-9df9-1491eda5bd5d BCI-1-24 -79.9 9.15 1 BCI-1
The filter_station allows to filter an object of class
ctdp by the properties of a camera station:
filter_station(dat, transect == 1)
## ctdp datapackage which is a list with elements:
## - settings
##
## and tables:
## - locations (n = 3)
## - deployments (n = 22)
## - sequences (n = 5,099)
## - observations (n = 5,990)
## - media (n = 0)
## - taxonomy (n = 31)
##
## Zip file: bcnm-mammal-monitoring-team-20230223112118.zip
## Timezone: Etc/GMT+5
## Interval: TRUE
## Primary keys: locationID, deploymentID, sequenceID, observationID, taxonID, mediaID
## Nr of stations: 3
## Nr of species: 31
## Media have been dropped
## Time range: 2017/01/01 -- 2018/01/01
The filter_timerange allows to truncate an object of
class ctdp by specifying start and end points in time (see
the orders argument for how to specify these):
filter_timerange(dat, start = "2016/1/1", end = "2017/1/1")
## ctdp datapackage which is a list with elements:
## - settings
##
## and tables:
## - locations (n = 0)
## - deployments (n = 0)
## - sequences (n = 0)
## - observations (n = 0)
## - media (n = 0)
## - taxonomy (n = 31)
##
## Zip file: bcnm-mammal-monitoring-team-20230223112118.zip
## Timezone: Etc/GMT+5
## Interval: TRUE
## Primary keys: locationID, deploymentID, sequenceID, observationID, taxonID, mediaID
## Nr of stations: 0
## Nr of species: 31
## Media have been dropped
## Time range: --
Columns that are not part of the main columns as specified in the
dataset ctdp_mainCols can be removed using
drop_columns:
drop_columns(dat)
## ctdp datapackage which is a list with elements:
## - settings
##
## and tables:
## - locations (n = 6)
## - deployments (n = 42)
## - sequences (n = 10,899)
## - observations (n = 11,998)
## - media (n = 0)
## - taxonomy (n = 31)
##
## Zip file: bcnm-mammal-monitoring-team-20230223112118.zip
## Timezone: Etc/GMT+5
## Interval: TRUE
## Primary keys: locationID, deploymentID, sequenceID, observationID, taxonID, mediaID
## Nr of stations: 6
## Nr of species: 31
## Media have been dropped
## Time range: 2017/01/01 -- 2018/01/01
Locations can be plotted on a leaflet map using function
plot_locations:
plot_locations(dat)
The plot_time_coverage plot the time coverage of the
depolyments:
plot_time_coverage(dat)
or, when grouping by some column (y-axis ordering and colour):
plot_time_coverage(dat, grouping = "transect")
plot_time_coverage(dat, grouping = "transect")
Some functions allow you to explore the annotation status:
plot_status, summarise_deployments and
fraction_annotated:
plot_status(dat)
or, when grouping by some column (y-axis ordering and colour):
plot_status(dat, grouping = "transect")
The status of deployments (or other groupings) can also be obtained
in table form, using the summarise_deployments
function:
summarise_deployments(dat)
## # A tibble: 42 × 6
## deploymentID effort fracAnnotated nrSeqs nrSeqsAnnotated nrPhotos
## <chr> <dbl> <dbl> <int> <int> <int>
## 1 09ea8772-75a8-44f5-a2b7-9cf714ce4df3 11.5 0 12 0 200
## 2 0cbb925c-b07a-4f34-909d-af6b968fcc80 77.6 0.962 210 202 4688
## 3 103cc5fe-29be-4b9c-a9e4-2bd40c0ad3d8 13.3 0 73 0 1170
## 4 157d2d1e-d5b7-4927-8058-2ec715156fce 41.0 0.00234 427 1 9917
## 5 1687bfe3-a714-4714-bca7-2172db4bed58 62.9 0.00990 101 1 1960
## 6 17c9654d-44cd-4939-a5a4-8c95654262f5 31.8 0.944 428 404 9855
## 7 1c82bb10-3392-440b-b707-0911e4cb5c89 49.0 0.971 70 68 1270
## 8 1d1036e2-1861-4b1e-8b35-2171461e3369 1.63 NA NA NA NA
## 9 224ff78b-d516-4aab-8334-cb1f5acc5aa5 17.5 0 59 0 900
## 10 2c8ea383-0778-4864-93d3-cd4344deb5a5 1.63 0 1 0 100
## # … with 32 more rows
The datatable argument specifies whether or not to view
the table in an interactive datatable in the viewer:
summarise_deployments(dat, datatable = TRUE)
Function summarise_deployment calls other function
fraction_annotated:
fraction_annotated(dat)
## # A tibble: 41 × 5
## deploymentID fracAnnotated nrSeqs nrSeqsAnnotated nrPhotos
## <chr> <dbl> <int> <int> <dbl>
## 1 09ea8772-75a8-44f5-a2b7-9cf714ce4df3 0 12 0 200
## 2 0cbb925c-b07a-4f34-909d-af6b968fcc80 0.962 210 202 4688
## 3 103cc5fe-29be-4b9c-a9e4-2bd40c0ad3d8 0 73 0 1170
## 4 157d2d1e-d5b7-4927-8058-2ec715156fce 0.00234 427 1 9917
## 5 1687bfe3-a714-4714-bca7-2172db4bed58 0.00990 101 1 1960
## 6 17c9654d-44cd-4939-a5a4-8c95654262f5 0.944 428 404 9855
## 7 1c82bb10-3392-440b-b707-0911e4cb5c89 0.971 70 68 1270
## 8 224ff78b-d516-4aab-8334-cb1f5acc5aa5 0 59 0 900
## 9 2c8ea383-0778-4864-93d3-cd4344deb5a5 0 1 0 100
## 10 3a6ad3f5-0b4a-40ca-9230-5fafcccdfe4b 0 83 0 1560
## # … with 31 more rows
To plot the effort over time (defaults to a dynamic plot):
plot_effort(dat)
or, static ggplot plot, pass argument dynamic = FALSE,
i.e. plot_effort(dat, dynamic = FALSE).
To get a point estimate: the number of active camera stations at a given time:
point_effort(dat, "2017/6/21 12:00:00")
## [1] 3
Tthe calc_effort function is the main function computing
effort (total number of camera-trap days), which optionally takes
arguments:
by: column name(s) of the station/deployment tables by
which to group the effort computationstart,end: start and end timepoints to
truncate the data, see function filter_timerangesubset: an expression to filter the camera station
locations, see function filter_stationTotal effort:
calc_effort(dat)
## # A tibble: 1 × 1
## effort
## <dbl>
## 1 1649.
Total effort computer for each station identified by column “locationName”:
calc_effort(dat, by = "locationName")
## # A tibble: 6 × 2
## locationName effort
## <chr> <dbl>
## 1 BCI-1-24 278.
## 2 BCI-1-25 264.
## 3 BCI-1-26 303.
## 4 BCI-3-01 305.
## 5 BCI-3-02 235.
## 6 BCI-3-03 265.
Idem, but now for specified time range and transect:
calc_effort(dat,
by = "locationName",
start = "2017/4/1",
end = "2017/8/1",
subset = transect == 3)
## # A tibble: 3 × 2
## locationName effort
## <chr> <dbl>
## 1 BCI-3-01 305.
## 2 BCI-3-02 235.
## 3 BCI-3-03 265.
Another option to compute the total effort (total number of active
camera-trap-days) is via the function integrate_effort:
integrate_effort(dat)
## [1] 1649.253
Or, between 2 time points, integrate effort, thus compute total number of active camera-trap-days between these two points in time:
integrate_effort(dat, start = "2017/4/1", end = "2017/8/1")
## [1] 581.5341
The captures function is the main function to compute
captures and capture rates:
captures(dat)
## # A tibble: 16 × 9
## observationType class order taxonID vernacularNames…¹ verna…² captu…³ effort captu…⁴
## <fct> <chr> <chr> <chr> <chr> <chr> <int> <dbl> <dbl>
## 1 animal Aves Galliformes 76H2H crested guan kuifsj… 5 1649. 3.03e-3
## 2 animal Aves Tinamiformes 7CB5D great tinamou grote … 8 1649. 4.85e-3
## 3 animal Aves <NA> V2 bird sp. vogel 5 1649. 3.03e-3
## 4 animal Mammalia Artiodactyla 3YJ7Z Central American… <NA> 162 1649. 9.82e-2
## 5 animal Mammalia Artiodactyla 6TW4J collared peccary halsba… 599 1649. 3.63e-1
## 6 animal Mammalia Carnivora 38VYB tayra tayra 1 1649. 6.06e-4
## 7 animal Mammalia Carnivora 3T78D ocelot ocelot 5 1649. 3.03e-3
## 8 animal Mammalia Carnivora 6S6BF white-nosed coati witsnu… 205 1649. 1.24e-1
## 9 animal Mammalia Cingulata 349W8 nine-banded arma… negenb… 4 1649. 2.43e-3
## 10 animal Mammalia Didelphimorphia 35WKD common opossum zuidel… 2 1649. 1.21e-3
## 11 animal Mammalia Primates RYZ5 Colombian white-… witsch… 6 1649. 3.64e-3
## 12 animal Mammalia Rodentia 349R6 Central American… Midden… 2016 1649. 1.22e+0
## 13 animal Mammalia Rodentia 3Z5 rodents knaagd… 3 1649. 1.82e-3
## 14 animal Mammalia Rodentia 4MQLJ Tomes spiny rat Tomes … 2 1649. 1.21e-3
## 15 animal Mammalia Rodentia 6BPX8 lowland paca paca 233 1649. 1.41e-1
## 16 animal <NA> <NA> 6XY2N red-tailed squir… roodst… 3 1649. 1.82e-3
## # … with abbreviated variable names ¹vernacularNames.en, ²vernacularNames.nl, ³captures,
## # ⁴capture_rate
Optionally, you can specify a taxonomic class to focus on:
captures(dat, class = "Mammalia")
## # A tibble: 12 × 9
## observationType class order taxonID vernacularNames…¹ verna…² captu…³ effort captu…⁴
## <fct> <chr> <chr> <chr> <chr> <chr> <int> <dbl> <dbl>
## 1 animal Mammalia Artiodactyla 3YJ7Z Central American… <NA> 162 1649. 9.82e-2
## 2 animal Mammalia Artiodactyla 6TW4J collared peccary halsba… 599 1649. 3.63e-1
## 3 animal Mammalia Carnivora 38VYB tayra tayra 1 1649. 6.06e-4
## 4 animal Mammalia Carnivora 3T78D ocelot ocelot 5 1649. 3.03e-3
## 5 animal Mammalia Carnivora 6S6BF white-nosed coati witsnu… 205 1649. 1.24e-1
## 6 animal Mammalia Cingulata 349W8 nine-banded arma… negenb… 4 1649. 2.43e-3
## 7 animal Mammalia Didelphimorphia 35WKD common opossum zuidel… 2 1649. 1.21e-3
## 8 animal Mammalia Primates RYZ5 Colombian white-… witsch… 6 1649. 3.64e-3
## 9 animal Mammalia Rodentia 349R6 Central American… Midden… 2016 1649. 1.22e+0
## 10 animal Mammalia Rodentia 3Z5 rodents knaagd… 3 1649. 1.82e-3
## 11 animal Mammalia Rodentia 4MQLJ Tomes spiny rat Tomes … 2 1649. 1.21e-3
## 12 animal Mammalia Rodentia 6BPX8 lowland paca paca 233 1649. 1.41e-1
## # … with abbreviated variable names ¹vernacularNames.en, ²vernacularNames.nl, ³captures,
## # ⁴capture_rate
Or, focus on specific species (access via function
taxon_id):
captures(dat, species = c("Central American agouti","CollaredPeccary"))
## # A tibble: 2 × 9
## observationType class order taxonID vernacularNames.en verna…¹ captu…² effort captu…³
## <fct> <chr> <chr> <chr> <chr> <chr> <int> <dbl> <dbl>
## 1 animal Mammalia Artiodactyla 6TW4J collared peccary halsba… 599 1649. 0.363
## 2 animal Mammalia Rodentia 349R6 Central American ago… Midden… 2016 1649. 1.22
## # … with abbreviated variable names ¹vernacularNames.nl, ²captures, ³capture_rate
Like in the computation of effort, capture rates can be computed
using the arguments by, start/end,
subset in order to group analyses by some identifier
column, compute for a subset of the locations or truncate in time,
e.g.:
captures(dat,
species = c("Central American agouti","CollaredPeccary"),
by = "locationName",
start = "2017/4/1",
end = "2017/8/1",
subset = transect == 3)
## # A tibble: 6 × 10
## observationType class order locationName taxonID vernac…¹ verna…² captu…³ effort captu…⁴
## <fct> <chr> <chr> <chr> <chr> <chr> <chr> <int> <dbl> <dbl>
## 1 animal Mammalia Artiodactyla BCI-3-01 6TW4J collare… halsba… 82 305. 0.269
## 2 animal Mammalia Artiodactyla BCI-3-02 6TW4J collare… halsba… 111 235. 0.471
## 3 animal Mammalia Artiodactyla BCI-3-03 6TW4J collare… halsba… 1 265. 0.00378
## 4 animal Mammalia Rodentia BCI-3-01 349R6 Central… Midden… 395 305. 1.30
## 5 animal Mammalia Rodentia BCI-3-02 349R6 Central… Midden… 15 235. 0.0637
## 6 animal Mammalia Rodentia BCI-3-03 349R6 Central… Midden… 115 265. 0.435
## # … with abbreviated variable names ¹vernacularNames.en, ²vernacularNames.nl, ³captures,
## # ⁴capture_rate
Activity patterns can be fitted and plotted using the
activity_ctdp function, in a similar veign as the
captures and calc_effort functions do:
activity_ctdp(dat)
focussing on taxonomic class:
activity_ctdp(dat, class = "Mammalia")
Or, for some specific species in a subset of the stations
activity_ctdp(dat,
species = c("Central American agouti","CollaredPeccary"),
by = "locationName",
start = "2017/4/1",
end = "2017/8/1",
subset = transect == 3)
The function returns the data silently:
test <- activity_ctdp(dat,
species = c("Central American agouti","CollaredPeccary"),
by = "locationName",
start = "2017/4/1",
end = "2017/8/1",
subset = transect == 3)
test
## # A tibble: 7 × 6
## observationType vernacularNames.en label locat…¹ data fact
## <fct> <chr> <fct> <chr> <list> <list>
## 1 unclassified <NA> BCI-3-01_unclassified BCI-3-… <tibble> <actmod>
## 2 unclassified <NA> BCI-3-03_unclassified BCI-3-… <tibble> <actmod>
## 3 unclassified <NA> BCI-3-02_unclassified BCI-3-… <tibble> <actmod>
## 4 animal Central American agouti BCI-3-01_Central American agouti BCI-3-… <tibble> <actmod>
## 5 animal Central American agouti BCI-3-03_Central American agouti BCI-3-… <tibble> <actmod>
## 6 animal collared peccary BCI-3-01_collared peccary BCI-3-… <tibble> <actmod>
## 7 animal collared peccary BCI-3-02_collared peccary BCI-3-… <tibble> <actmod>
## # … with abbreviated variable name ¹locationName
The merge_tibbles and nest_tibbles join all
the tibbles of the relational database into 1 bit tibble, where the
merge_tibbles results in 1 record (i.e. row) being a single
observation, whereas when using the nest_tibbles
function, 1 row equals to 1 sequence where the observations and
other information are stored as list columns.
merge_tibbles(dat) # 1 row = 1 observation
## # A tibble: 11,998 × 26
## locati…¹ deplo…² seque…³ obser…⁴ taxonID captu…⁵ sequence_interval
## <chr> <chr> <chr> <chr> <chr> <fct> <Interval>
## 1 fe09358… 09ea87… 02e184… 02e184… <NA> motion… 2017-01-02 10:22:23 -05--2017-01-02 10:23:00 -05
## 2 fe09358… 09ea87… 056b98… 056b98… <NA> motion… 2017-01-02 03:35:16 -05--2017-01-02 03:35:23 -05
## 3 fe09358… 09ea87… 09e172… 09e172… <NA> motion… 2017-01-05 19:18:55 -05--2017-01-05 19:19:24 -05
## 4 fe09358… 09ea87… 0c2dda… 0c2dda… <NA> motion… 2017-01-02 08:50:54 -05--2017-01-02 08:51:15 -05
## 5 fe09358… 09ea87… 0eb5c6… 0eb5c6… <NA> time l… 2017-01-10 12:00:00 -05--2017-01-10 12:00:00 -05
## 6 fe09358… 09ea87… 0fc2ad… 0fc2ad… <NA> motion… 2017-01-01 09:42:39 -05--2017-01-01 09:42:48 -05
## 7 fe09358… 09ea87… 141bb3… 141bb3… <NA> time l… 2017-01-08 12:00:00 -05--2017-01-08 12:00:00 -05
## 8 fe09358… 09ea87… 1a125f… 1a125f… <NA> time l… 2017-01-11 00:00:00 -05--2017-01-11 00:00:00 -05
## 9 fe09358… 09ea87… 1dc8a2… 1dc8a2… <NA> time l… 2017-01-12 12:00:00 -05--2017-01-12 12:00:00 -05
## 10 fe09358… 09ea87… 280ff9… 280ff9… <NA> motion… 2017-01-12 12:34:20 -05--2017-01-12 12:34:31 -05
## # … with 11,988 more rows, 19 more variables: nrphotos <int>, observationType <fct>,
## # cameraSetupType <fct>, classificationMethod <fct>, cameraSetup <lgl>, count <dbl>,
## # deployment_interval <Interval>, array <chr>, habitat <chr>, locationName <chr>,
## # longitude <dbl>, latitude <dbl>, transect <int>, group <chr>, class <chr>, order <chr>,
## # scientificName <chr>, vernacularNames.en <chr>, vernacularNames.nl <chr>, and abbreviated
## # variable names ¹locationID, ²deploymentID, ³sequenceID, ⁴observationID, ⁵captureMethod
nest_tibbles(dat) # 1 row = 1 sequence
## Object of class 'seqnest': a 'tibble' where each row represents a single sequence (with identifier: sequenceID), and corresponding data in list-columns.
##
## # A tibble: 10,899 × 7
## sequen…¹ sequence_interval captu…² nrpho…³ locat…⁴ deplo…⁵ obser…⁶
## <chr> <Interval> <fct> <int> <list> <list> <list>
## 1 00164fe… 2017-03-07 07:34:35 -05--2017-03-07 07:34:43 -05 motion… 10 <dt> <dt> <dt>
## 2 001c222… 2017-02-25 01:00:00 -05--2017-02-25 01:00:00 -05 time l… 1 <dt> <dt> <dt>
## 3 001ede1… 2017-11-14 20:02:15 -05--2017-11-14 20:02:21 -05 motion… 10 <dt> <dt> <dt>
## 4 0020527… 2017-02-10 12:00:00 -05--2017-02-10 12:00:00 -05 time l… 1 <dt> <dt> <dt>
## 5 0020921… 2017-09-30 12:00:00 -05--2017-09-30 12:00:00 -05 time l… 1 <dt> <dt> <dt>
## 6 0020fb4… 2017-11-20 15:25:23 -05--2017-11-20 15:25:34 -05 motion… 10 <dt> <dt> <dt>
## 7 0024430… 2017-04-16 00:00:00 -05--2017-04-16 00:00:00 -05 time l… 1 <dt> <dt> <dt>
## 8 002d11a… 2017-03-25 08:32:44 -05--2017-03-25 08:32:51 -05 motion… 10 <dt> <dt> <dt>
## 9 003305f… 2017-10-25 06:27:04 -05--2017-10-25 06:27:18 -05 motion… 20 <dt> <dt> <dt>
## 10 0037c5e… 2017-02-15 14:52:05 -05--2017-02-15 14:52:14 -05 motion… 10 <dt> <dt> <dt>
## # … with 10,889 more rows, and abbreviated variable names ¹sequenceID, ²captureMethod, ³nrphotos,
## # ⁴locations, ⁵deployments, ⁶observations
To unnest a list-column, e.g. here the “locations” column:
nest_tibbles(dat) %>%
unnest(locations)
## # A tibble: 10,899 × 12
## sequen…¹ sequence_interval captu…² nrpho…³ locat…⁴ locat…⁵ longi…⁶
## <chr> <Interval> <fct> <int> <chr> <chr> <dbl>
## 1 00164fe… 2017-03-07 07:34:35 -05--2017-03-07 07:34:43 -05 motion… 10 638c14… BCI-1-… -79.8
## 2 001c222… 2017-02-25 01:00:00 -05--2017-02-25 01:00:00 -05 time l… 1 a59f1f… BCI-3-… -79.9
## 3 001ede1… 2017-11-14 20:02:15 -05--2017-11-14 20:02:21 -05 motion… 10 9999af… BCI-3-… -79.8
## 4 0020527… 2017-02-10 12:00:00 -05--2017-02-10 12:00:00 -05 time l… 1 fe0935… BCI-3-… -79.8
## 5 0020921… 2017-09-30 12:00:00 -05--2017-09-30 12:00:00 -05 time l… 1 9999af… BCI-3-… -79.8
## 6 0020fb4… 2017-11-20 15:25:23 -05--2017-11-20 15:25:34 -05 motion… 10 fe0935… BCI-3-… -79.8
## 7 0024430… 2017-04-16 00:00:00 -05--2017-04-16 00:00:00 -05 time l… 1 638c14… BCI-1-… -79.8
## 8 002d11a… 2017-03-25 08:32:44 -05--2017-03-25 08:32:51 -05 motion… 10 638c14… BCI-1-… -79.8
## 9 003305f… 2017-10-25 06:27:04 -05--2017-10-25 06:27:18 -05 motion… 20 9999af… BCI-3-… -79.8
## 10 0037c5e… 2017-02-15 14:52:05 -05--2017-02-15 14:52:14 -05 motion… 10 fe0935… BCI-3-… -79.8
## # … with 10,889 more rows, 5 more variables: latitude <dbl>, transect <int>, group <chr>,
## # deployments <list>, observations <list>, and abbreviated variable names ¹sequenceID,
## # ²captureMethod, ³nrphotos, ⁴locationID, ⁵locationName, ⁶longitude
this tutorial was generated using the command:
write_tutorial(dat)
todo