Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e443ce5
Disable check because it falsely triggered errors
hambrecht Jul 26, 2024
7a49aba
Make AI adjusted to memory handeling
hambrecht Jul 14, 2025
a75c762
Merge branch 'master' of https://github.com/hambrecht/dsims
hambrecht Jul 14, 2025
aafe318
AI improvements
hambrecht Jul 14, 2025
9621a1b
added check function
hambrecht Jul 14, 2025
0df8612
fix typo
hambrecht Jul 14, 2025
933d9cf
Merge branch 'DistanceDevelopment:master' into master
hambrecht May 4, 2026
7ca339d
feat: add spatially-explicit raster covariate support to detectability
hambrecht May 4, 2026
f115ffb
fix: allow plotting detectability with raster covariates
hambrecht May 5, 2026
f496c0a
feat: add spatially-explicit raster covariate support to detectability
hambrecht May 5, 2026
45d9abc
fix: allow plotting detectability with raster covariates
hambrecht May 5, 2026
f0a65e7
perf(parallel): switch to worker-state load-balanced execution
hambrecht May 5, 2026
3fc6aba
perf(spatial): vectorize detection-distance joins with sf indexes
hambrecht May 5, 2026
e709ebd
perf(raster): add worker-local cov.surface cache
hambrecht May 5, 2026
971b41a
Potential fix for pull request finding
hambrecht May 5, 2026
58d2d6a
perf(results): stream per-repetition payloads instead of full result …
hambrecht May 5, 2026
d5e4fe8
merge: record upstream-clean raster feature branch into master
hambrecht May 6, 2026
4a393d5
perf(parallel): switch to worker-state load-balanced execution
hambrecht May 5, 2026
33e982a
perf(spatial): vectorize detection-distance joins with sf indexes
hambrecht May 5, 2026
0cec92e
perf(raster): add worker-local cov.surface cache
hambrecht May 5, 2026
c6777bb
perf(results): stream per-repetition payloads instead of full result …
hambrecht May 5, 2026
eb2bef4
merge: record parallel performance branch into master
hambrecht May 6, 2026
c05c025
perf: read cov.surface values at animal locations instead of caching …
hambrecht Sep 25, 2026
037f015
perf(parallel): run repetitions on mirai daemons, parallel by default
hambrecht Oct 20, 2026
a4855cb
bench: add before/after benchmark script for run.simulation
hambrecht Oct 20, 2026
f7811da
merge: record mirai parallel backend branch into master
hambrecht Oct 20, 2026
519c96c
feat(analysis): allow a uniform key in make.ds.analysis()
hambrecht Oct 20, 2026
d668415
merge: record uniform key branch into master
hambrecht Oct 20, 2026
9771fc5
fix: require whole-number N when fixed.N = TRUE
hambrecht Oct 21, 2026
71604a8
merge: record fixed.N fix branch into master
hambrecht Oct 21, 2026
a979452
feat: population generator hook and zero-detection handling (1.2.0)
hambrecht Nov 17, 2026
281ed86
fix: uniform key no longer errors when nobody is within truncation
hambrecht Nov 18, 2026
8cb81d4
fix: restore the Density validity check
hambrecht Nov 24, 2026
49b79b6
test: ignore empty transects when checking detection distances
hambrecht Nov 24, 2026
c265772
fix: avoid the R CMD check NOTE for lib.paths in launch.daemons()
hambrecht Nov 24, 2026
c722f4d
merge: record raster covariate PR branch (#99) doc fix into master
hambrecht Nov 24, 2026
212eb0a
docs: regenerate Detectability-class.Rd for the cov.param description
hambrecht Nov 24, 2026
a6f6b85
chore: remove local editor settings
hambrecht Nov 24, 2026
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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ cran-comments.md
^pkgdown$
^vignettes

^bench$
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ doc
Meta
/doc/
/Meta/
bench/lib_*/
bench/results.csv
bench/benchmark.log
10 changes: 6 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@ Imports:
mrds,
Distance,
sf,
terra,
ggplot2,
purrr,
dplyr,
mgcv,
methods,
rstudioapi,
mirai,
parallel,
parallelly,
gridExtra,
rlang
Suggests:
testthat,
bookdown,
parallel,
pbapply,
knitr,
lwgeom,
rmarkdown
Type: Package
Title: Distance Sampling Simulations
Version: 1.0.6
Version: 1.2.0
Authors@R: c(
person("Laura", "Marshall", email = "lhm@st-and.ac.uk", role = c("aut", "cre")),
person("Thomas", "Len", email = "len.thomas@st-andrews.ac.uk", role = "ctb"))
Expand Down Expand Up @@ -84,6 +85,7 @@ Collate:
'get.density.surface.R'
'message.handler.R'
'modify.strata.for.analysis.R'
'population.generator.R'
'process.dist.shapes.R'
'read.line.transects.R'
'read.point.transects.R'
Expand Down
17 changes: 10 additions & 7 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,19 @@ importFrom(methods,slot)
importFrom(methods,slotNames)
importFrom(methods,validObject)
importFrom(mgcv,predict.gam)
importFrom(mirai,daemons)
importFrom(mirai,daemons_set)
importFrom(mirai,everywhere)
importFrom(mirai,is_error_value)
importFrom(mirai,is_mirai_error)
importFrom(mirai,mirai)
importFrom(mirai,mirai_map)
importFrom(mirai,unresolved)
importFrom(mrds,dht)
importFrom(parallel,clusterEvalQ)
importFrom(parallel,detectCores)
importFrom(parallel,makeCluster)
importFrom(parallel,parLapply)
importFrom(parallel,stopCluster)
importFrom(parallel,nextRNGStream)
importFrom(parallelly,availableCores)
importFrom(purrr,reduce)
importFrom(rlang,.data)
importFrom(rstudioapi,versionInfo)
importFrom(sf,as_Spatial)
importFrom(sf,st_area)
importFrom(sf,st_as_sf)
Expand Down Expand Up @@ -112,6 +116,5 @@ importFrom(stats,rnorm)
importFrom(stats,rpois)
importFrom(stats,runif)
importFrom(stats,sd)
importFrom(utils,flush.console)
importFrom(utils,packageVersion)
importFrom(utils,write.table)
40 changes: 40 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
# dsims 1.2.0

Enhancements

* `make.simulation()` has a new argument `population.generator`, a `function(simulation, rep)` which is called in each repetition instead of `generate.population(simulation)`. It returns a `Population` object or `list(population = <Population>, truth = list(N = , D = ))`. This allows, for example, a population to be drawn over a whole study area in every repetition with only the individuals inside the survey region (the design region) being surveyed. The returned population is checked (class, required columns, strata names and that all individuals lie inside the design region) and an informative error is given if a check fails. The random number generator state is saved before the generator is called and restored afterwards, so the generator can use its own seed stream (e.g. one which depends only on `rep`): simulations which differ only in their design then see identical populations in each repetition, and the transects, detections and analyses are unaffected by the random numbers the generator uses. The generator works with `run.simulation(run.parallel = TRUE)`; see the 'Population generator' section of `?make.simulation` for the requirements.
* If the population generator returns `truth`, the per-repetition true N and/or D of the whole target area are stored in `simulation@results$truth` (array `[1, c("N", "D"), reps + 2]`) and `summary()` uses them, instead of the population description, for the truth, percent bias, RMSE and CI coverage of the total abundance / density. The printed summary shows the source of the truth (also stored in the new `truth.source` slot of `Simulation.Summary`).
* The realised number of individuals in the design region is now stored for every repetition in `simulation@results$individuals$true.N` (and `simulation@results$clusters$true.N` for clusters), with one row per stratum as in the other results arrays.
* `make.ds.analysis()` has a new argument `zero.n = c("fail", "zero")`. With `"zero"` a repetition with no detections within the truncation distance is recorded as a successful estimate of zero (N and D Estimate = 0, lcl = 0, se, cv and ucl = NA, with n = 0 and the area, covered area and effort recorded as usual) and flagged in the new `ZeroDetections` column of `simulation@results$Detection`. `summary()` includes these repetitions in the mean, SD, RMSE and bias (CI coverage only uses repetitions with a defined confidence interval) and reports their number. Repetitions with detections where no model could be fitted remain failures. The default `"fail"` keeps the previous behaviour.

Bug Fixes

* CI coverage in `summary()` was calculated from the first k repetitions rather than the k included repetitions when some repetitions had failed (or with `use.max.reps = FALSE` and some models not converging). It now uses the included repetitions. Results are unchanged when no repetitions are excluded.
* Surveying a population with no individuals no longer gives warnings from `sf`.
* With the uniform detection function (`key.function = "uf"` in `make.detectability()`), a repetition in which no individual was within the truncation distance of any transect stopped with "invalid arguments" from `rbinom()` and was skipped. It is now handled like the other keys (a failure with the default `zero.n = "fail"`, an estimate of zero with `zero.n = "zero"`). Previously, skipping these repetitions biased results upwards in sparse scenarios.

Other changes

* `simulation@results$Detection` has an additional column, `ZeroDetections` (0 for repetitions analysed as usual). With `population.generator` and `zero.n` left at their defaults, simulation results are otherwise identical to dsims 1.1.0 for the same seed.

# dsims 1.1.0

Enhancements

* Parallel processing now uses the mirai package. Repetitions are distributed to workers as they become free, and workers start faster than with the previous cluster setup.
* Simulations are now run in parallel by default (`run.parallel = TRUE`). The default number of workers is `parallelly::availableCores(omit = 1)`, which respects limits set by HPC schedulers and containers. Daemons set up by the user with `mirai::daemons()` (including remote / HPC daemons) are used if present.
* Each repetition uses its own random number stream, so after `set.seed()` results are identical whether run in serial or in parallel, regardless of the number of workers.
* A repetition that fails with an error no longer stops the simulation; it is skipped and reported in the summary of warnings and errors.
* The progress counter is now shown when running in parallel and includes the elapsed and estimated remaining time.
* `make.ds.analysis()` now accepts `key = "unif"` (or `"uf"`) to fit a uniform detection function, giving the strip transect estimate n / covered area. Covariates cannot be used with the uniform key. Previously only "hn" and "hr" were allowed although the documentation listed uniform.

Bug Fixes

* Fractional values of `N` with `fixed.N = TRUE` were silently rounded up when generating each stratum's population, while the unrounded `N` was used as the true abundance. With many small strata this inflated the simulated population relative to the truth. `make.population.description()` now stops if `N` is not a whole number when `fixed.N = TRUE`.

Breaking Changes

* Results from simulations run with a given seed will differ from those obtained with previous versions of dsims, as the random number streams have changed.
* `N` must be whole numbers when `fixed.N = TRUE` (see Bug Fixes).
* Worker processes now appear as `mirai::daemon(...)` rather than PSOCK workers (`workRSOCK`), which affects scripts that monitor the worker processes.

# dsims 1.0.6

Bug Fixes
Expand Down
Loading