## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
oldpar <- par(no.readonly = TRUE)

## ----setup, echo=F------------------------------------------------------------
library(terra)
library(rTARDIS)

## ----eval = F-----------------------------------------------------------------
#  library(chronosphere)
#  datasets()[which(datasets()$defaultClass == "RasterArray"),4]

## ----echo = F-----------------------------------------------------------------
cdf <- readRDS(system.file("extdata", "cdf.RData", package = "rTARDIS"))
cdf[which(cdf$defaultClass == "RasterArray"),4]

## ----eval=F-------------------------------------------------------------------
#  dem <- fetch("paleomap", "dem")

## ----eval = F-----------------------------------------------------------------
#  tms <- dem@index
#  dem <- dem@stack
#  unloadNamespace("via")
#  tms

## ----echo = F-----------------------------------------------------------------
tms <- readRDS(system.file("extdata", "idm.RData", package = "rTARDIS"))
tms

## ----eval=FALSE---------------------------------------------------------------
#  # load the dataset: slices 49 to 46 correspond to 385, 380, 375, and 370 million years ago
#  dvn <- dem[[78:75]]
#  
#  # create the land-sea mask
#  dvn_l <- classify(dvn, matrix(c(-Inf, 0, NA, 0, Inf, 1), ncol = 3, byrow = T), right = F)
#  
#  # convert to geoglist
#  hexes <- rast_to_geoglist(dvn, dvn_l, times = c(387.5, 382.5, 377.5, 372.5, 367.5), as.hex = T, hex = 3)
#  
#  # plot
#  plot(hexes, 2)

## ----include=F----------------------------------------------------------------
dvn <- readRDS(system.file("extdata", "rdm.RData", package = "rTARDIS"))

# create the land-sea mask
dvn_l <- classify(dvn, matrix(c(-Inf, 0, NA, 0, Inf, 1), ncol = 3, byrow = T), right = F)

# convert to geoglist
hexes <- rast_to_geoglist(dvn, dvn_l, times = c(387.5, 382.5, 377.5, 372.5, 367.5), as.hex = T, hex = 3)

## ----echo=F, fig.width=9.5, fig.height=4.5, dev="svg"-------------------------
# plot
plot(hexes, 2)

## ----eval=FALSE---------------------------------------------------------------
#  # link islands
#  hexes <- link_islands(hexes, klink = 1)
#  
#  # plot
#  plot(hexes, 2)

## ----echo=F, fig.width=9.5, fig.height=4.5, dev="svg"-------------------------
# link islands
hexes <- link_islands(hexes, klink = 1)

# plot
plot(hexes, 2)

## ----eval = F-----------------------------------------------------------------
#  # get rotations for the PALEOMAP model
#  rots <- get_rotations(hexes, hexes$tdat, "PALEOMAP")
#  
#  # interrogate the output
#  length(rots)
#  head(rots[[1]])

## ----echo = F-----------------------------------------------------------------
rots <- readRDS(system.file("extdata", "rots.RData", package = "rTARDIS"))
length(rots)
head(rots[[1]])

## -----------------------------------------------------------------------------
# build tardis
htd <- build_tardis(hexes, rotations = rots)

## ----include = F--------------------------------------------------------------
par(oldpar)

