pophistToArray: Convert "pophist" object to an array

View source: R/pophistToArray.r

pophistToArrayR Documentation

Convert "pophist" object to an array

Description

This function converts a "pophist" object to an array. This function is helpful for converting a "pophist" object to input for the bioticVelocity function.

Usage

pophistToArray(x, longitude = NULL, latitude = NULL, times = NULL, warn = TRUE)

Arguments

x

A pophist object (a list).

longitude

Either NULL (default) or a vector of longitudes, one per column in the output object. Note that if longitude is NULL and the "pophist" object in x contains a field named x$pophist$longitude, then this will be used (and will override the values in longitude if it is specified).

latitude

Either NULL (default) or a vector of latitudes, one per row in the output object. Note that if latitude is NULL and the "pophist" object in x contains a field named x$pophist$latitude, then this will be used (and will override the values in latitude if it is specified).

times

Either NULL (default) or a numeric vector. This specifies the time period represented by each column in x. Times must appear in sequential order. For example, if time periods are 24 kybp, 23 kybp, 22 kybp, use c(-24, -23, -22), not c(24, 23, 22). Note that if times is NULL and the "pophist" object in x contains a field named x$pophist$times, then this will be used (and will override the values in times if it is specified).

warn

Logical, if TRUE then display function-specific warnings.

Details

Utility function for pre-processing an Nvecs matrix from a pophist object for biotic velocity calculations.

Value

A list object with:

  • pophistAsArray: Array representing values in x$pophist with one "layer" (3rd dimension) per time period.

  • longitude: Array representing longitudes.

  • latitude: Array representing latitudes.

  • times: Vector representing times.

See Also

getpophist2.cells, NvecNAs, bioticVelocity

Examples

library(holoSimCell)
parms <- drawParms(control = system.file("extdata/ashpaper","Ash_priors.csv",package="holoSimCell"))
load(file=paste0(system.file(package="holoSimCell"),"/extdata/landscapes/",pollenPulls[[1]]$file))
refpops <- pollenPulls[[1]]$refs
avgCellsz <- mean(c(res(landscape$sumrast)))

ph = getpophist2.cells(h = landscape$details$ncells, xdim = landscape$details$x.dim, ydim = landscape$details$y.dim,
                       landscape=landscape,
                       refs=refpops,   
                       refsz=parms$ref_Ne,
                       lambda=parms$lambda,
                       mix=parms$mix,  
                       shortscale=parms$shortscale*avgCellsz,  
                       shortshape=parms$shortshape, 
                       longmean=parms$longmean*avgCellsz,  
                       ysz=res(landscape$sumrast)[2], 
                       xsz=res(landscape$sumrast)[1], 
                       K = parms$Ne) 

times_1k <- seq(-21000,0,by=990)
   
pharray <- pophistToArray(NvecNAs(ph, landscape), times = times_1G)
   
metrics <- c('centroid', 'nsQuants', 'summary')

BV_permill_all <- bioticVelocity(
  x=pharray$pophistAsArray,
  times = times_1G,
  atTimes = times_1k,
  longitude=pharray$longitude,
  latitude=pharray$latitude,
  metrics=metrics,
  quants=c(0.05, 0.1, 0.9, 0.95),
  onlyInSharedCells = FALSE)


stranda/holoSimCell documentation built on Aug. 4, 2023, 1:12 p.m.