Commit fad4e9e0 authored by Jean-Karim Heriche's avatar Jean-Karim Heriche
Browse files

Added scale option to locprec2cov().

parent 0d5801c4
......@@ -89,10 +89,11 @@ ary2ps <- function(ary, bkg = 0) {
#' Converts localization precision columns to a list of arrays of covariance matrices
#'
#' @param point.sets a list of n point sets with locprec columns (locprecz column required for 3D data)
#' @param scale logical, whether to scale the localization precision by the variance of the coordinates
#' @return a list of 2x2xn or 3x3xn arrays.
#' @export
locprec2cov <- function(point.sets) {
locprec2cov <- function(point.sets, scale = FALSE) {
C <- list()
d <- 3 # Assume 3D data
# 3D data require locprecz column
......@@ -101,12 +102,21 @@ locprec2cov <- function(point.sets) {
for(i in 1:length(point.sets)) {
ns <- nrow(point.sets[[i]])
C[[i]] <- array(0, dim = c(d,d,ns))
if(scale) {
v <- apply(point.sets[[i]], 2, var)
}
for(j in 1:ns) {
if (d==3) {
# locprec applies to x and y
C[[i]][,,j] <- diag(point.sets[[i]][j, c("locprec", "locprec", "locprecz")], 3)
if(scale) {
C[[i]][,,j] <- C[[i]][,,j] / v[c("x", "y", "z")]
}
} else {
C[[i]][,,j] <- diag(point.sets[[i]][j, c("locprec", "locprec")], 2)
if(scale) {
C[[i]][,,j] <- C[[i]][,,j] / v[c("x", "y")]
}
}
}
}
......
......@@ -4,10 +4,12 @@
\alias{locprec2cov}
\title{locprec2cov}
\usage{
locprec2cov(point.sets)
locprec2cov(point.sets, scale = FALSE)
}
\arguments{
\item{point.sets}{a list of n point sets with locprec columns (locprecz column required for 3D data)}
\item{scale}{logical, whether to scale the localization precision by the variance of the coordinates}
}
\value{
a list of 2x2xn or 3x3xn arrays.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment