Skip to content
Snippets Groups Projects
Commit 072179c4 authored by Raimon Tolosana-Delgado's avatar Raimon Tolosana-Delgado
Browse files

added methods for as.gmCgram

parent e0b3f17d
No related branches found
No related tags found
No related merge requests found
Package: gmGeostats
Version: 0.10-8-9000
Version: 0.10-8-9001
Date: 2021-07-15
Title: Geostatistics for Compositional Analysis
Authors@R: c(person(given = "Raimon",
......
# gmGeostats 0.10.8-9001
* (2021-07-22) conversion methods between variogram models: `as.gmCgram()` methods for "variogramModel" and "variogramModelList" objects (from package "gstat")
# gmGeostats 0.10.8-9000
* (2021-07-15) documented abstract union classes, specifying required methods for the member classes
......
......@@ -51,7 +51,12 @@ as.AnisotropyScaling.AnisotropyScaling = function(x) x
#' @export
as.AnisotropyScaling.numeric = function(x){
if(length(x)==2) return(anis2D.par2A(ratio=x[2], angle=x[1]))
if(length(x)==5) stop("as.AnisotropyScaling: 3D from 5-vector values not yet implemented") # return(anis3D.par2A(ratios=x[4:5], angles=x[1:3]))
if(length(x)==5){
if(sum( (x[4:5]-1)^2)<1e-12){
return(diag(3))
}
stop("as.AnisotropyScaling: 3D from arbitrary 5-vector values not yet implemented") # return(anis3D.par2A(ratios=x[4:5], angles=x[1:3]))
}
stop("as.AnisotropyScaling.numeric: only works for length=2 1.angle+1.ratio, or lenth=5 3.angles+2.ratios")
}
......
......@@ -699,7 +699,39 @@ as.LMCAnisCompo.variogramModelList <-
#' @describeIn as.gmCgram Convert theoretical structural functions to gmCgram format
#' @method as.gmCgram variogramModelList
as.gmCgram.variogramModelList = function(m, ...) stop("not yet available")
as.gmCgram.variogramModelList = function(m, ...){
as.gmCgram(as.LMCAnisCompo(m, ...), ...)
}
#' @describeIn as.gmCgram Convert theoretical structural functions to gmCgram format
#' @method as.gmCgram variogramModel
as.gmCgram.variogramModel = function(m, ...){
# extract nugget
isNugget = m$model=="Nug"
if(any(isNugget)){
nuggetValue = m[isNugget, "psill"]
m = m[!isNugget,, drop=FALSE]
}
# extract model names
modelName = gsi.validModels[paste("vg", m$model,sep=".")]
# if any model name is not identified
if(any(is.na(modelName))){
stop("as.gmCgram.variogramModel: found an unidentified variogram model; check content of internal variable gsi.valiModels to see which models are permissible")
}
# otherwise, extract parametres
tt = function(x) t(t(x))
out = setCgram(type = modelName[1], nugget = tt(nuggetValue), sill = tt(m[1, "psill"]), anisRanges =
as.AnisotropyScaling(unlist(m[1, -(1:4)])), extraPar = m[1, "kappa"])
if(nrow(m)>1){
for(im in 1:nrow(m)){
out = out + setCgram(type = modelName[im], sill = tt(m[im, "psill"]), anisRanges =
as.AnisotropyScaling(unlist(m[im, -(1:4)])), extraPar = m[im, "kappa"])
}
}
return(out)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment