Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Suggests:
rmarkdown
Type: Package
Title: Distance Sampling Simulations
Version: 1.0.5
Version: 1.0.5.9000
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
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# dsims 1.0.6

Bug Fixes

* Fixed bug when simulation checks generated an error for projected shapes. Issue #94

# dsims 1.0.5

Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion R/Simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ setValidity("Simulation",
# Check the intersection between design and population regions - they must overlap
intersect <- suppressWarnings(sf::st_intersection(object@design@region@region, object@population.description@density@density.surface[[1]]))
intersect.area <- sum(sf::st_area(intersect))
if(intersect.area == 0){
if(as.numeric(intersect.area) == 0){
return("The regions associated with the design and the population description do not overlap!")
}
# Compare the area of the design region and population region with the intersection.
Expand Down
51 changes: 51 additions & 0 deletions tests/testthat/test-check_Constructors.R
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,54 @@ test_that("Test simulation validation and consistency checks", {

#expect_warning(make.simulation(population.description = pop.desc),"The population density surface extends beyond the design survey region, only part of the population will be surveyed.")
})


test_that("Test issue 94", {
#Load a multi strata unprojected shapefile
# Find the full file path to the shapefile on the users machine
shapefile.path <- system.file("extdata", "AreaRProjStrata.shp", package = "dssd")

# Create the region object
region <- make.region(region.name = "study area",
strata.name = c("North", "NW", "West Upper", "West Lower", "SW", "South"),
shape = shapefile.path)

# Plot the survey region
design <- make.design(region = region,
transect.type = "line",
design = "systematic",
spacing = c(rep(16000, 3), rep(8000, 3)),
design.angle = c(160, 135, 80, 135, 50, 150),
edge.protocol = "minus",
truncation = 1500)

# Make a density grid with values of 1 across the region
my.density <- make.density(region = region,
x.space = 2500,
y.space = 2500,
constant = 1)

# Create the population description
pop.description <- make.population.description(region = region,
density = my.density,
N = rep(400,6),
fixed.N = TRUE)

# Create the detectability
detect <- make.detectability(key.function = "hn",
scale.param = 750,
truncation = 1500)

# Define the analyses - both the hn and hr models use the ~strata.group formula
ds.analyses <- make.ds.analysis(truncation = 1500)

# Make simulation
simulation <- make.simulation(reps = 3,
design = design,
population.description = pop.description,
detectability = detect,
ds.analysis = ds.analyses)

# Check a simulation object is returned
expect_true(is(simulation, "Simulation"))
})
Loading