Skip to contents

Reads the folder written by sheepdog::export_occupancy_data(), which follows the sheepdog-occupancy schema (version 1.x): every occasion of a passive acoustic survey, the classifier predictions, the reviewed clips with their sampling design, and the recordings annotated by ear. The tables come back in the forms that fp_aggregate() and fp_data() expect.

Usage

fp_read_sheepdog(path, species = NULL, keep_top = FALSE)

Arguments

path

Folder of the export, holding schema.json.

species

Optional species to keep, matched against species_code (the classifier label, such as "Nyctidromus albicollis_Common Pauraque") and species (the short code that sheepdog derives from it). Without it, an export of several species is kept whole, and the verdicts and annotated recordings of all species are mixed: name the target species. For the multispecies model, name the species to keep (all of them: species = schema$species, from schema.json); every table then keeps its species columns, and fp_draws_data() builds the data of all of them.

keep_top

Keep reviewed clips drawn with sampling_mode = "top"? See Details. Clips of "score_bands" are dropped either way.

Value

A list of class fp_sheepdog with the data frames occasions (site, occasion_id, source_audio, recording_date, recording_hour, night, start, duration, then any occasion covariates), detections (one row per prediction: site, occasion_id, species_code, species, start, confidence), scores (highest score and number of predictions per occasion and species), validation (one row per reviewed clip, with start, end, confidence, sampling_mode, inclusion_prob, verdict as TRUE, FALSE or NA, identity, identity_certainty), verified (one row per annotated recording, with y, 1 or 0, and inclusion_prob), sites, the parsed schema, and files (paths of the tables found). Tables absent from the export are NULL.

Details

Which reviewed clips. The false-positive models of crywolf treat the checked detections as chosen independently of the classifier's score. Clips of the "random_detections" design are; clips of the "top" design, the highest-scoring detections, are not: they hold fewer false positives than a random sample and would make the false-positive rate look lower than it is. By default they are dropped with a warning (keep_top = FALSE); they remain useful to calibrate the classifier within sheepdog. Clips of the "directed_pps" design (sheepdog's select_directed()) are kept with a warning: within each review unit (for example site x species) the occasion is drawn independently of the score, but the units are drawn with unequal probabilities (inclusion_prob), which crywolf does not use. That is right when the size of the units came from a model of data the new fit also holds, as with fp_review_priority(): the fit then conditions on everything that chose the units, and the selection is ignorable for the model. It is not right when the size came from the scores, which the model does not hold; estimates are then conditional on the units drawn. Design-based estimates from the clips alone still need the weights 1 / inclusion_prob.

Clips of the "score_bands" design are always dropped, whatever keep_top, with a warning. sheepdog draws them at random within bands of score, so that thresholds and calibration curves see the whole score range; being chosen by their score, they over-represent some bands and would bias the false-positive rate in either direction. They serve sheepdog::threshold_bootstrap(), sheepdog::calibrate() and sheepdog::fit_calibration(), not these models. When every reviewed clip is of this design and the export has no annotated recordings, there is nothing left to estimate false positives from, and fp_read_sheepdog() stops: review clips drawn with "random_detections" or annotate recordings drawn with "random_recordings".

Clips and recordings. A positive clip proves that the species called in its occasion; a negative clip says only that this prediction was false. These go to validation, for the observation-confirmation design through fp_aggregate(validation = ). A recording annotated by ear ("random_recordings") gives the state of the whole occasion; these go to verified, the verified method of fp_data().

True identity of reviewed clips. From schema version 1.5, the reviewer may record what a clip held (identity) and how sure they were (identity_certainty, "sure" or "probable"). For a false positive, identity names what the classifier mistook for the species, such as another class of the classifier, an insect or rain; several identities are separated by "|" and mean any one of them. Both columns are read into validation as text, NA where the reviewer gave none and in exports before version 1.5. The models of crywolf do not use them (see "Confusion between species" in fp_occu()); they show which confusions the false-positive rate holds.

Censored scores. Only predictions with a confidence of at least schema$min_confidence were exported, so thresholds below it count every exported prediction and no more.

Occasions are identified by site and occasion_id; pass by = c("site", "occasion_id") to fp_aggregate(). Identifiers, dates and the keys of the calibration (such as month) are read as text. The occasion covariates of the export (schema$occasion_covariates, from schema version 1.1) are extra columns of occasions. The calibration draws (calibration_draws.parquet) and the detection histories sheepdog drew from them (occasion_draws.parquet, schema 1.2), when present, are not read here; their path is in files. When the calibration has continuous covariates (schema$calibration$covariates, schema 1.3), the export holds only the histories sheepdog drew, and no calibration draws.

Examples

# a small export of sheepdog with three species, shipped with crywolf
dir <- system.file("extdata", "sheepdog-export", package = "crywolf")
# the tables hold only the target species, so fp_aggregate() needs no
# `species`; the reviewed clips of this export are top-scoring clips,
# dropped with a warning, so no detection is confirmed
x <- fp_read_sheepdog(dir, species = "phy_cuv")
#> Warning: 320 reviewed clip(s) drawn with sampling_mode = "top" were dropped: they were chosen for their high scores and would make the false-positive rate look lower than it is. Use keep_top = TRUE to keep them.
auto <- fp_aggregate(x$occasions, x$detections, threshold = 0.5,
                     by = c("site", "occasion_id"), validation = x$validation)
d <- fp_data(auto, x$sites)
d
#> <fp_data>
#>   sites:                  4
#>   automated occasions:    354 (naive occupancy 1.00)
#>   verified sites:         0 (0 occasions; verified detections at 0 sites)
#>   sites known occupied:   0
#>   observation covariates: occasion_id, source_audio, recording_date, recording_hour, night, start, duration, temp_z, n_detections, score