Skip to content

Commit

Permalink
Merge branch 'master' into staging
Browse files Browse the repository at this point in the history
master
  • Loading branch information
Ian Jonsen committed Jun 4, 2024
2 parents b15a7ef + b1104b0 commit 9488712
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions R/sim_fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ sim_fit <-
}

reflect_y <- function(mu, y_rng) {
# if(is.na(mu[2])) browser()
if(mu[2] < y_rng[1]) {
c(mu[1], y_rng[1] * 2 - mu[2])
} else if(mu[2] > y_rng[2]) {
Expand Down Expand Up @@ -151,7 +152,7 @@ sim_fit <-
dts <- loc$date
dt <- as.numeric(difftime(dts, c(as.POSIXct(NA), dts[-length(dts)]), units = "hours"))
dt[1] <- 0

## get parameters from model fit object
switch(model,
crw = {
Expand All @@ -178,7 +179,7 @@ sim_fit <-
stop("Implausible travel rates detected, check SSM fit for implausible locations")
## implausible for pinnipeds but not for eg. birds** need to re-think this...***
})

###############################
## Simulate movement process ##
###############################
Expand All @@ -203,7 +204,6 @@ sim_fit <-

## wrap x values, reflect y values
mu1 <- wrap_x(mu[i-1,] + v[i,] * dt[i], ex[1:2])

mu1 <- reflect_y(mu1, ex[3:4])
if(!is.null(grad)) {
pv <- as.numeric(extract(grad, rbind(mu1)))
Expand Down Expand Up @@ -253,10 +253,12 @@ sim_fit <-
sigma = Sigma * dt[i]^2,
lower = vmin,
upper = vmax,
algorithm = "gibbs", burn.in.samples = 100)
algorithm = "gibbs",
burn.in.samples = 100)

dxy <- dxy[which(!is.na(dxy))[1],]

if(all(is.na(dxy))) dxy <- c(1,1)

## wrap x values, reflect y values
mu1 <- wrap_x(mu[i-1,] + dxy, ex[1:2])
mu1 <- reflect_y(mu1, ex[3:4])
Expand Down

0 comments on commit 9488712

Please sign in to comment.