Recombine 100-Day Deployments Into Continuous Long-Term Deployments
Source:R/recombine_deployment_groups.R
recombine_deployment_groups.RdThe WildObs data curation pipeline splits long camera deployments into pieces
of at most 100 days, so each piece fits inside a single-season survey
(deploymentGroups). Long-term analyses (multi-season occupancy models,
Living Planet Index style trends, the Threatened Species Index) want the
opposite: one deployment per camera for as long as it ran without a break.
This function stitches the pieces back together using the
multiSeason_deploymentGroup column, which already groups consecutive
surveys at a locationName that are separated by 30 days or less.
A data package goes in and a data package comes out, so every resource that
carries deploymentID (deployments, covariates, observations and, if
present, media) is updated together and stays joinable, and the package's
temporal metadata describes the same survey groups as its data.
Arguments
- dp
A WildObs camtrap data package, as returned by
wildobs_dp_download, holding at least thedeploymentsresource. The deployments must includedeploymentID,locationID,deploymentStart,deploymentEnd,deploymentGroupsandmultiSeason_deploymentGroup.- max_gap_days
Numeric. The longest gap, in days, allowed between one piece ending and the next starting at the same camera before the run is split into a new
_partNdeployment. Defaults to 30, matching the gap that separates multi-season groups.
Value
The same data package with:
one
deploymentsrow per continuous camera run, withdeploymentGroupsreplaced by itsmultiSeason_deploymentGroup;covariatescollapsed to match the new deployments;deploymentIDremapped inobservationsandmedia, except obscured threatened-species rows (obscured_for_<category>_species), which have no camera and are kept unchanged with a message;temporalmetadata holding one block permultiSeason_deploymentGroup;a new
deployment_crosswalkresource with one row per original piece:original_deploymentID,deploymentID(the new one),original_deploymentGroups,pieceStartandpieceEnd;dp$data, the in-memory copy of the tables thatwildobs_dp_downloadadds, refreshed to match the resources.
Stops if max_gap_days is not a single non-negative number, if a required
resource or column is missing, if two pieces of the same camera overlap in time,
or if observations or media hold a deploymentID (other than an obscured
placeholder) that is not in the deployments.
Details
100-day deployments (i.e., pieces) are chained in three steps:
Pieces are grouped by
locationID,multiSeason_deploymentGroupand the_CamNsuffix that the camDB pipeline appends todeploymentIDwhen one station holds several cameras in the same survey (e.g. a lured and an unlured camera).Within a group, pieces are ordered by
deploymentStart. A piece starts a new chain when it begins more thanmax_gap_daysafter the previous piece ended, because the 30-day rule behindmultiSeason_deploymentGroupapplies to the wholelocationName, so a single station can sit idle for much longer inside one group. A piece that starts before the previous one ended cannot be the same camera, so the function stops and names it; the cameras need relabelling in curation before the package can be recombined.Each chain becomes one deployment named
<locationID>_ms<N>[_CamN][_partN], whereNorders the multi-season groups at that station in time.
Columns are merged across the pieces of a chain as follows. A value shared by
every piece is kept as is, including NA. Otherwise:
deploymentStarttakes the earliest piece start anddeploymentEndthe latest piece end;numeric columns take a mean weighted by each piece's duration, rounded for integer columns;
logical columns are
TRUEif any piece isTRUE;factor columns (controlled vocabularies such as
featureType) take the value that covers the most time, so they stay inside their vocabulary;other date and date-time columns also take the value that covers the most time, keeping their class and time zone;
deploymentTagskeeps eachkey: valuepair once. Where pieces disagree on a key, placeholder values (unspecified,unknown,-,NAor empty, ignoring case) are dropped if a real value exists, then the value that covers the most time is kept, so every key appears once;other character columns list the distinct values, separated by
" | ".
The new deploymentStart/deploymentEnd span includes any gaps of up
to max_gap_days between pieces. Calculate sampling effort from pieceStart and
pieceEnd in deployment_crosswalk, not from the recombined span.
observationID and eventID are left unchanged; they remain unique.
In the temporal metadata, the per-deploymentGroups blocks are
replaced by one block per multiSeason_deploymentGroup. Each new block
starts at the earliest start and ends at the latest end of the single-season
blocks it absorbs. The package-level start, end and
timeZone are left unchanged.
See also
survey_and_deployment_generator, which creates the 100-day deployments.
Examples
# the Woomargama project shipped with WildObsR ran four surveys over two years
dp <- example_datapackages("NSW_Woomargama_wombats_Linley_2021-22_WildObsID_0010")[[1]]
long_dp <- recombine_deployment_groups(dp)
#> NSW_Woomargama_wombats_Linley_2021-22_WildObsID_0010: 94 obscured observations row(s) kept unchanged in recombine_deployment_groups(); they have no camera to join to.
# fewer, longer deployments
nrow(frictionless::read_resource(dp, "deployments"))
#> [1] 219
nrow(frictionless::read_resource(long_dp, "deployments"))
#> [1] 57
# and every original piece, for calculating effort without the gaps
head(frictionless::read_resource(long_dp, "deployment_crosswalk"))
#> # A tibble: 6 × 5
#> original_deploymentID deploymentID original_deploymentG…¹ pieceStart
#> <chr> <chr> <chr> <dttm>
#> 1 10_WildObsID_0010_202… 10_WildObsI… Woomargama_NP_2021_a_… 2021-07-04 00:36:04
#> 2 10_WildObsID_0010_202… 10_WildObsI… Woomargama_NP_2021_b_… 2021-10-07 03:20:43
#> 3 10_WildObsID_0010_202… 10_WildObsI… Woomargama_NP_2022_a_… 2022-01-16 02:41:54
#> 4 10_WildObsID_0010_202… 10_WildObsI… Woomargama_NP_2022_b_… 2022-04-23 16:03:39
#> 5 10_WildObsID_0010_202… 10_WildObsI… Woomargama_NP_2021_a_… 2021-06-28 21:36:44
#> 6 10_WildObsID_0010_202… 10_WildObsI… Woomargama_NP_2021_b_… 2021-10-05 17:37:17
#> # ℹ abbreviated name: ¹original_deploymentGroups
#> # ℹ 1 more variable: pieceEnd <dttm>