diff --git a/DESCRIPTION b/DESCRIPTION index 5aaf6fbebd71c2f139455571b2f980f576ea12ba..1b8fadd2ce80a939636e20eff34188fcce5d4ba1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ 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", diff --git a/NEWS.md b/NEWS.md index 0ca5835417bea9846232ba015ff0c3c305cc7f14..590be6e55bed0882f987d037abd4c13196cf66bc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# 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 diff --git a/R/gmAnisotropy.R b/R/gmAnisotropy.R index fc387eb2d8b59300eb555503d9c55e9cae4a722b..83eef9b96e2e4ec293b2e7e044206e392ebc7731 100644 --- a/R/gmAnisotropy.R +++ b/R/gmAnisotropy.R @@ -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") } diff --git a/R/gstatCompatibility.R b/R/gstatCompatibility.R index bcf7b7af6f8fda0d7babf1f2e30475623103c08a..c7bfed67a37734311d10fd50dbeafbec713bc9ed 100644 --- a/R/gstatCompatibility.R +++ b/R/gstatCompatibility.R @@ -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) +}