Commit 987ef545 authored by Marco De Lucia's avatar Marco De Lucia
Browse files

checking and building

parent a98a7adc
Package: RedModRphree
Title: R infrastructure for training and applying geochemical surrogate models to reactive transport.
Version: 0.0.4
Title: Programmable interface to the phreeqc geochemical solver adding features such as surrogate models, reactive transport and Pourbaix diagrams
Version: 0.2
Authors@R: c(person("Marco", "De Lucia", email = "delucia@gfz-potsdam.de", role = c("aut", "cre")),
person("Janis", "Jatnieks", email = "deltaxzz@gmail.com", role = c("ctb")))
Description: In the framework of RedMod project, we develop an R infrastructure for training and applying geochemical surrogate models to reactive transport.
Depends: R (>= 3.2.0), doParallel, plyr, data.table, phreeqc, caret, mgcv, randomForest, graphics, methods
Author: Marco De Lucia [aut, cre],
Janis Jatnieks [ctb]
Maintainer: Marco De Lucia <delucia@gfz-potsdam.de>
Description: Programmable interface to the phreeqc geochemical solver adding features such as surrogate models, reactive transport and Pourbaix diagrams.
Depends: R (>= 3.2.0), doParallel, phreeqc, mgcv, graphics, methods, stats, utils, plyr, foreach
License: LGPL-2.1
Encoding: UTF-8
LLazyData: true
......
This diff is collapsed.
# Generated by roxygen2: do not edit by hand
export(AME)
export(Act2pH)
export(AddProp)
export(AdvectionPQC)
export(AllowSomeNegativeColumns)
export(AnalyticalLogK)
export(BalanceEquations)
export(BatchPreProc)
export(BatchPreProc_)
export(BestModelCluster)
export(CHT)
export(CheckBalance)
export(CheckColsNumValues)
export(Cols2Fact)
export(CompareTimesteps)
export(Deltas)
export(Distribute)
export(DistributeKin)
export(DistributeKinMatrix)
export(DistributeMatrix)
export(DownSampler)
export(ElementalBalanceMin)
export(ExtractPphases)
export(ExtractSamples)
export(ExtractSpecies)
export(ExtractTotals)
export(FastClust)
export(Filtering)
export(FindAllMinNames)
export(FindAllSpeciesNames)
export(FindAllTotNames)
export(FindLogK)
export(FindPhase)
export(FitSurrogates)
export(FitWithDice)
export(FormulaFromBal)
export(GetModelNames)
export(GetRanges)
export(InitPreProc)
export(Loadata)
export(MAD)
export(MASE)
export(Matplot)
export(MatplotSingle)
export(ModelSelector)
export(MultiRound)
export(NPSC)
export(NumericallyCompareTables)
export(OverrideValueRange)
export(ParseFormula)
export(PlotModsInSample)
export(RPhreeFile)
export(RPhreeWriteInp)
export(RReadOut)
export(RReadOutKin)
export(RSS)
export(RangeTableCreator)
export(ReactTranspBalanceEq)
export(ReactTranspBalanceKin)
export(RecomposeState)
export(ReduceState)
export(Refit)
export(Relcal)
export(RepSol)
export(Reshaping)
export(RunModelList)
export(RunPQC)
export(RunSurrogates)
export(SAD)
export(SDrift)
export(SelectActiveColumns)
export(SelectColsByPredix)
export(SelectMinActiveColumns)
export(SelectPreProc)
export(ShowTopProfiler)
export(SparseChangeCluster)
export(StoichiometricMatrix)
export(SubstractCommonTableCols)
export(SuppressSim)
export(Surrogate)
export(TByElem)
export(Tminus)
export(TrailSpaces)
export(Train)
export(TranspAsPert)
export(WriteModel)
export(WriteModelResiduals)
export(all_mda_mars_impvars)
export(allcoluniquevals)
export(cf)
export(cfa)
export(coltypes)
export(coluniquevals)
export(coluniratio)
export(colwise_RSS)
export(colwise_rescale)
export(createTuneGrids)
export(custom_scaler)
export(dt2v)
export(exc)
export(exc_type)
export(f2i)
export(hb)
export(mae)
export(mda_mars_importance)
export(mrm)
export(msg)
export(na.to.zero)
export(namewithin)
export(nan.to.zero)
export(outminus)
export(pH2Act)
export(paralap)
export(rescaling)
export(roundbycol)
export(rsi)
export(safe_get_cores)
export(seekcoltypeidx)
export(seekcoltypename)
export(sharedvalues)
export(sliding_join)
export(smartround)
export(splitMultiFix)
export(splitMultiKin)
export(start_up)
export(stopmsg)
export(striplast)
export(striplastx)
export(take_top_pct_cols)
export(to.zero)
export(uvc)
export(uvcm)
export(uvt)
export(write_evals)
import(caret)
import(data.table)
import(doParallel)
import(foreach)
import(graphics)
import(methods)
import(mgcv)
import(phreeqc)
import(plyr)
import(randomForest)
### File-related utility functions for RedModRphree
### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2018
### Time-stamp: "Last modified 2018-05-03 11:00:16 delucia"
### Time-stamp: "Last modified 2021-04-12 12:39:15 delucia"
##' Reads a normal PHREEQC input file and prepares it for
......@@ -156,7 +156,7 @@ RReadOut <- function(out)
npure <- endpure[n] - startpure - 1
pure_conn <- textConnection( tot[startpure:(startpure+npure)])
pure <- read.table( pure_conn, row.names=1, fill=TRUE, as.is=TRUE)
pure <- utils::read.table( pure_conn, row.names=1, fill=TRUE, as.is=TRUE)
close(pure_conn)
indreactants <- which(pure[,2]=="reactant")
if (length(indreactants) > 0)
......@@ -180,7 +180,7 @@ RReadOut <- function(out)
startcomp <- endpure[n] + 2
ncomp <- endcomp[n]-startcomp
comp_conn <- textConnection(tot[startcomp:(startcomp+ncomp-1)])
comp <- read.table(comp_conn,row.names=1,fill=TRUE)
comp <- utils::read.table(comp_conn,row.names=1,fill=TRUE)
close(comp_conn)
colnames(comp) <- c("molal","moles")
## if (verbose)
......@@ -218,7 +218,7 @@ RReadOut <- function(out)
block_conn <- textConnection(block)
## Now we can read.table it
tmp <- read.table( block_conn, fill=TRUE, as.is=TRUE)[,c(1,2,3)]
tmp <- utils::read.table( block_conn, fill=TRUE, as.is=TRUE)[,c(1,2,3)]
close(block_conn)
## remove duplicated
rnames <- tmp$V1
......@@ -230,7 +230,7 @@ RReadOut <- function(out)
## Now saturation indexes
block <- tot[(endspec[n] + 2) :( endsim[n] - 4)]
block_conn <- textConnection(block)
SI <- read.table(block_conn, fill=TRUE, row.names=1, as.is=TRUE)
SI <- utils::read.table(block_conn, fill=TRUE, row.names=1, as.is=TRUE)
close(block_conn)
names(SI) <- c("SI","IAP","logK","formula")
......@@ -322,7 +322,7 @@ RReadOutKin <- function(out, strip=TRUE, verbose=FALSE)
nkin <- endkin[n] - start
kconn <- textConnection(tot[(start):(start+nkin-1)])
kin <- read.table(kconn, row.names=1,fill=TRUE)[,c(2,1)]
kin <- utils::read.table(kconn, row.names=1,fill=TRUE)[,c(2,1)]
close(kconn)
colnames(kin) <- c("moles","delta")
......@@ -333,7 +333,7 @@ RReadOutKin <- function(out, strip=TRUE, verbose=FALSE)
startpure <- endkin[n]+3
npure <- endpure[n] - startpure - 1
pconn <- textConnection(tot[startpure:(startpure+npure)])
pure <- read.table(pconn, row.names=1,fill=TRUE)[,c(5,6)]
pure <- utils::read.table(pconn, row.names=1,fill=TRUE)[,c(5,6)]
close(pconn)
colnames(pure) <- c("moles","delta")
......@@ -345,7 +345,7 @@ RReadOutKin <- function(out, strip=TRUE, verbose=FALSE)
ncomp <- endcomp[n]-startcomp
sconn <- textConnection(tot[startcomp:(startcomp+ncomp-1)])
comp <- read.table(sconn, row.names=1,fill=TRUE)
comp <- utils::read.table(sconn, row.names=1,fill=TRUE)
close(sconn)
colnames(comp) <- c("molal","moles")
......@@ -384,7 +384,7 @@ RReadOutKin <- function(out, strip=TRUE, verbose=FALSE)
block_conn <- textConnection(block)
## Now we can read.table it
tmp <- read.table( block_conn, fill=TRUE, as.is=TRUE)[,c(1,2,3)]
tmp <- utils::read.table( block_conn, fill=TRUE, as.is=TRUE)[,c(1,2,3)]
close(block_conn)
## remove duplicated
rnames <- tmp$V1
......@@ -399,7 +399,7 @@ RReadOutKin <- function(out, strip=TRUE, verbose=FALSE)
## Now saturation indexes
block <- tot[(endspec[n] + 2) :( endsim[n]-1)]
block_conn <- textConnection(block)
SI <- read.table(block_conn, fill=TRUE, row.names=1, as.is=TRUE)
SI <- utils::read.table(block_conn, fill=TRUE, row.names=1, as.is=TRUE)
close(block_conn)
names(SI) <- c("SI","IAP","logK","formula")
......
## Functions for dealing with simulations with kinetics
### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2018
### Time-stamp: "Last modified 2018-12-12 14:25:38 delucia"
##' This function just runs the generated input buffer - or a list
##' thereof - through \code{phreeqc}. Obviously it requires the
##' \code{phreeqc} package. Also the database must be previously and
##' explicitely loaded by the user using
##' \code{phreeqc::phrLoadDatabaseString(db <-
##' RPhreeFile("phreeqc.dat", is.db=TRUE ))}
### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2021
### Time-stamp: "Last modified 2021-04-12 12:46:35 delucia"
##' This function runs the generated input buffer (or a list thereof)
##' through \code{phreeqc}, which has been already loaded as
##' dependency. Also the database must be previously and explicitely
##' loaded by the user using, e.g.,
##' \code{db <- RPhreeFile('/path/to/database.dat', is.db=TRUE)}
##' followed by
##' \code{phreeqc::phrLoadDatabaseString(db)}
##' or using one of the databases included in \code{phreeqc}, e.g.,
##' \code{phreeqc::phrLoadDatabaseString(phreeqc.dat)}.
##'
##' Currently parallelization is achieved using
##' \code{parallel::parLapply}, this can change in the future. At the
##' moment the function doesn't check that the SELCTED_OUTPUT block is
##' Parallelization is achieved using \code{%dopar%} from package
##' \code{foreach}, while the backend should have been previously set
##' with appropriate call to \code{doParallel}. At the moment the
##' function doesn't check that the SELCTED_OUTPUT block is
##' well-formed, so this is responsibility of the user.
##' @title Run the generated input buffer using phreeqc
##' @title Run the input buffer using phreeqc's \code{phrRunString}
##' @param input The input buffer, or list of inputs
##' @param procs the number of processes to employ
##' @param second logical, if TRUE skips each odd row
......@@ -26,7 +30,6 @@
RunPQC <- function(input, procs=1, second=TRUE) {
.runPQC <- function(input, onlysecond) {
require(phreeqc)
phreeqc::phrRunString(input)
out <- phreeqc::phrGetSelectedOutput()[[1]]
nso <- colnames(out)
......@@ -53,7 +56,7 @@ RunPQC <- function(input, procs=1, second=TRUE) {
## old one
## res <- parallel::mclapply(input, .runPQC, mc.silent=TRUE, mc.cores=procs)
## res <- parallel::parLapply(ThisRunCluster, input, .runPQC)
res <- foreach(i=seq_along(input), .combine=rbind) %dopar% .runPQC(input[[i]], onlysecond=second)
res <- foreach::foreach(i=seq_along(input), .combine=rbind) %dopar% .runPQC(input[[i]], onlysecond=second)
## ## a is the string containing the rbind of each element of the list
## a <- paste("rbind(",paste("res[[",1:procs,"]]",sep="", collapse = ", "),")")
......
## Functions for dealing with surrogate simulations
### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2018
### Time-stamp: "Last modified 2019-05-08 17:19:57 delucia"
### Time-stamp: "Last modified 2021-04-12 12:37:10 delucia"
##' Todo
......@@ -39,7 +39,7 @@ AdvectionPQC <- function(conc, inflow=rep(0,ncol(conc)), dx, dt)
sptr <- colnames(val)
ind <- match(sptr,spin)
bound <- numeric(ncol(val))
bound[!is.na(ind)] <- inflow[na.omit(ind)]
bound[!is.na(ind)] <- inflow[stats::na.omit(ind)]
cj <- rbind(bound,val)
remnames <- colnames(cj)
if (typeof(cj)!="double") {
......@@ -178,8 +178,6 @@ RecomposeState <- function(state, reduced)
##' @export
ReduceState <- function(data)
{
require(mgcv)
red <- mgcv::uniquecombs(data)
colnames(red) <- colnames(data)
attr(red,"immobile") <- attr(data,"immobile")
......@@ -223,7 +221,6 @@ ReactTranspBalanceEq <- function(setup, init, maxtime, step=c("time","iter","fix
surrogate.FUN, model, baleq, tol=1E-9, call_pqc=TRUE)
{
require(doParallel)
if (surrogate) {
if (missing(surrogate.FUN))
stopmsg("Need a valid function to apply surrogate instead of chemistry")
......
## Functions for dealing with surrogate simulations
### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2018
### Time-stamp: "Last modified 2018-05-06 20:16:47 delucia"
### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2021
### Time-stamp: "Last modified 2021-04-12 11:45:32 delucia"
##' Computes the average of absolute values of a vector
##' @title Average of absolute values
......
## Time-stamp: "Last modified 2018-05-16 14:37:47 delucia"
## Time-stamp: "Last modified 2021-04-12 11:40:11 delucia"
##' @title Extracts input/output tables from a list of Reactive
##' Transport Simulations
##' @param simlist a list containing the simulations
......
This diff is collapsed.
## Some definitions and imports for RedModRphree
### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2018
### Time-stamp: "Last modified 2018-05-03 17:37:43 delucia"
### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2021
### Time-stamp: "Last modified 2021-04-12 12:50:48 delucia"
##' @import phreeqc mgcv plyr data.table
##' @import graphics caret randomForest
##' @import phreeqc mgcv doParallel foreach methods plyr
##' @import graphics
NULL
##' Display a message prepending the name of the calling function
......
......@@ -2,7 +2,7 @@
% Please edit documentation in R/Rphree_Kinetics.R
\name{RunPQC}
\alias{RunPQC}
\title{Run the generated input buffer using phreeqc}
\title{Run the input buffer using phreeqc's \code{phrRunString}}
\usage{
RunPQC(input, procs = 1, second = TRUE)
}
......@@ -19,18 +19,18 @@ a data.frame containing the SELECTED_OUTPUT, ordered if
of the colnames are also made.
}
\description{
This function just runs the generated input buffer - or a list
thereof - through \code{phreeqc}. Obviously it requires the
\code{phreeqc} package. Also the database must be previously and
explicitely loaded by the user using
\code{phreeqc::phrLoadDatabaseString(db <-
RPhreeFile("phreeqc.dat", is.db=TRUE ))}
This function runs the generated input buffer (or a list thereof)
through \code{phreeqc}, which has been already loaded as
dependency. Also the database must be previously and explicitely
loaded by the user using, e.g.,
\code{db <- RPhreeFile('/path/to/database.dat', is.db=TRUE)}
followed by
\code{phreeqc::phrLoadDatabaseString(db)}
or using one of the databases included in \code{phreeqc}, e.g.,
\code{phreeqc::phrLoadDatabaseString(phreeqc.dat)}.
}
\details{
Currently parallelization is achieved using
\code{parallel::parLapply}, this can change in the future. At the
moment the function doesn't check that the SELCTED_OUTPUT block is
well-formed, so this is responsibility of the user.
}
\author{
MDL
......
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