[CHNOSZ-commits] r295 - in pkg/CHNOSZ: . R demo inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Nov 21 16:16:10 CET 2017
Author: jedick
Date: 2017-11-21 16:16:10 +0100 (Tue, 21 Nov 2017)
New Revision: 295
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/NAMESPACE
pkg/CHNOSZ/R/util.data.R
pkg/CHNOSZ/demo/DEW.R
pkg/CHNOSZ/inst/NEWS
pkg/CHNOSZ/man/util.data.Rd
Log:
add dumpdata()
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2017-11-16 17:12:39 UTC (rev 294)
+++ pkg/CHNOSZ/DESCRIPTION 2017-11-21 15:16:10 UTC (rev 295)
@@ -1,6 +1,6 @@
-Date: 2017-11-17
+Date: 2017-11-21
Package: CHNOSZ
-Version: 1.1.3-1
+Version: 1.1.3-2
Title: Thermodynamic Calculations for Geobiochemistry
Authors at R: c(
person("Jeffrey", "Dick", , "j3ffdick at gmail.com", role = c("aut", "cre"),
Modified: pkg/CHNOSZ/NAMESPACE
===================================================================
--- pkg/CHNOSZ/NAMESPACE 2017-11-16 17:12:39 UTC (rev 294)
+++ pkg/CHNOSZ/NAMESPACE 2017-11-21 15:16:10 UTC (rev 295)
@@ -58,7 +58,9 @@
# added 20170301 or later
"GHS_Tr", "calculateDensity", "calculateGibbsOfWater",
"calculateEpsilon", "calculateQ", "water.DEW", "berman",
- "maxdiff", "expect_maxdiff", "Bdot"
+ "maxdiff", "expect_maxdiff", "Bdot",
+# added 20171121 or later
+ "dumpdata"
)
# Load shared objects
Modified: pkg/CHNOSZ/R/util.data.R
===================================================================
--- pkg/CHNOSZ/R/util.data.R 2017-11-16 17:12:39 UTC (rev 294)
+++ pkg/CHNOSZ/R/util.data.R 2017-11-21 15:16:10 UTC (rev 295)
@@ -353,6 +353,23 @@
return(out)
}
+# dump all thermodynamic data in CHNOSZ 20171121
+dumpdata <- function(file=NULL) {
+ # default database (OBIGT)
+ Odata <- get("thermo")$obigt
+ Odata <- cbind(source="OBIGT", Odata)
+ # optional data
+ Ddata <- read.csv(system.file("extdata/OBIGT/DEW_aq.csv", package="CHNOSZ"), as.is=TRUE)
+ Ddata <- cbind(source="DEW", Ddata)
+ Sdata <- read.csv(system.file("extdata/OBIGT/SUPCRTBL.csv", package="CHNOSZ"), as.is=TRUE)
+ Sdata <- cbind(source="SUPCRTBL", Sdata)
+ # put it all together
+ out <- rbind(Odata, Ddata, Sdata)
+ # quote columns 2 (name) and 3 (abbrv) because they have commas for some entries
+ if(!is.null(file)) write.csv(out, file, row.names=FALSE, quote=c(2, 3))
+ else(return(out))
+}
+
### unexported functions ###
# Take a data frame in the format of thermo$obigt of one or more rows,
Modified: pkg/CHNOSZ/demo/DEW.R
===================================================================
--- pkg/CHNOSZ/demo/DEW.R 2017-11-16 17:12:39 UTC (rev 294)
+++ pkg/CHNOSZ/demo/DEW.R 2017-11-21 15:16:10 UTC (rev 295)
@@ -150,28 +150,33 @@
mod.buffer("QFM_Berman", c("quartz", "fayalite", "magnetite"), "cr_Berman", 0)
## calculate logfO2 in QFM buffer
basis("O2", "QFM_Berman")
-T <- seq(600, 1000, 5); T100 <- seq(600, 1000, 100)
+T <- seq(600, 1000, 100)
buf <- affinity(T=T, P=50000, return.buffer=TRUE)
## add species
species(c(inorganics, organics))
## generate spline functions from IS, pH, and molC values at every 100 degC
-IS <- splinefun(T100, c(0.39, 0.57, 0.88, 1.45, 2.49))
-pH <- splinefun(T100, c(3.80, 3.99, 4.14, 4.25, 4.33))
-molC <- splinefun(T100, c(0.03, 0.2, 1, 4, 20))
+IS <- c(0.39, 0.57, 0.88, 1.45, 2.49)
+pH <- c(3.80, 3.99, 4.14, 4.25, 4.33)
+molC <- c(0.03, 0.2, 1, 4, 20)
## use Debye-Huckel equation with B-dot set to zero
nonideal("Helgeson0")
## calculate affinities on the T-logfO2-pH-IS transect
-a <- affinity(T = T, O2 = buf$O2 - 2, IS = IS(T), pH = pH(T), P = 50000)
+a <- affinity(T = T, O2 = buf$O2 - 2, IS = IS, pH = pH, P = 50000)
## calculate metastable equilibrium activities using the total
## carbon molality as an approximation of total activity
-e <- equilibrate(a, loga.balance = log10(molC(T)))
+e <- equilibrate(a, loga.balance = log10(molC))
## make the diagram; don't plot names of low-abundance species
names <- c(inorganics, organics)
names[c(4, 5, 7, 9)] <- ""
col <- rep("black", length(names))
col[c(1, 3, 6, 8, 10)] <- c("red", "darkgreen", "purple", "orange", "navyblue")
-diagram(e, alpha = "balance", ylab = "carbon fraction", names = names, col = col, ylim = c(0, 0.8))
+if(packageVersion("CHNOSZ") > "1.1.3") {
+ diagram(e, alpha = "balance", names = names, col = col, ylim = c(0, 0.8), ylab="carbon fraction", spline.method="natural")
+} else {
+ diagram(e, alpha = "balance", names = names, col = col, ylim = c(0, 0.8), ylab="carbon fraction")
+}
+
## add legend and title
ltxt1 <- "P = 50000 bar"
ltxt2 <- substitute(logfO2=="QFM-2", list(logfO2 = axis.label("O2")))
@@ -184,7 +189,7 @@
### additional checks
## check that we're within 0.1 of the QFM-2 values used by SSH14
-stopifnot(maxdiff((buf$O2-2)[!T%%100], c(-17.0, -14.5, -12.5, -10.8, -9.4)) < 0.1)
+stopifnot(maxdiff((buf$O2-2), c(-17.0, -14.5, -12.5, -10.8, -9.4)) < 0.1)
# Here are the logKs of aqueous species dissociation reactions at 600 degC and 50000 bar,
# values from EQ3NR output in Supporting Information of the paper (p. 103-109):
Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS 2017-11-16 17:12:39 UTC (rev 294)
+++ pkg/CHNOSZ/inst/NEWS 2017-11-21 15:16:10 UTC (rev 295)
@@ -1,10 +1,13 @@
-CHANGES IN CHNOSZ 1.1.3-1 (2017-11-17)
+CHANGES IN CHNOSZ 1.1.3-2 (2017-11-21)
--------------------------------------
- Lines in 1-D diagram()s can optionally be drawn as splines using the
method for splinefun() given in the 'spline.method' argument (the
default of NULL means no splines).
+- Add dumpdata() for returning/writing all packaged data (including
+ default database and optional data files).
+
CHANGES IN CHNOSZ 1.1.3 (2017-11-13)
------------------------------------
Modified: pkg/CHNOSZ/man/util.data.Rd
===================================================================
--- pkg/CHNOSZ/man/util.data.Rd 2017-11-16 17:12:39 UTC (rev 294)
+++ pkg/CHNOSZ/man/util.data.Rd 2017-11-21 15:16:10 UTC (rev 295)
@@ -5,6 +5,7 @@
\alias{checkEOS}
\alias{checkGHS}
\alias{check.obigt}
+\alias{dumpdata}
\alias{RH2obigt}
\title{Functions for Checking Thermodynamic Data}
\description{
@@ -17,6 +18,7 @@
checkEOS(eos, state, prop, ret.diff = FALSE)
checkGHS(ghs, ret.diff = FALSE)
check.obigt()
+ dumpdata(file)
RH2obigt(compound = NULL, state = "cr",
file = system.file("extdata/thermo/RH98_Table15.csv", package = "CHNOSZ"))
}
@@ -28,8 +30,8 @@
\item{prop}{character, property of interest (\samp{Cp} or \samp{V})}
\item{ret.diff}{logical, return the difference between calculated and tabulated values?}
\item{ghs}{dataframe, containing G, H and S, in the format of \code{thermo$obigt}}
+ \item{file}{character, path to a file}
\item{compound}{character, name of compound(s) in group additivity calculation}
- \item{file}{character, path to a file}
}
\details{
@@ -53,6 +55,9 @@
\code{check.obigt} is a function to check self-consistency of each entry in the thermodynamic database, using \code{checkEOS} and \code{checkGHS}.
The output is a table listing only species that exceed at least one of the tolerance limits, giving the species index (rownumber in `thermo$obigt`), species name and state, and DCp, DV and DG, for the calculated differences (only those above the tolerances are given). This function is used to generate the file found at \code{extdata/thermo/obigt_check.csv}.
+\code{dumpdata} returns all of the available data, from both the default and optional data files, or writes it to a file if \code{file} is not NULL.
+The format is the same as \code{\link{thermo}$obigt}, except for a single prepended column named \samp{source}, giving the source of the data (\samp{OBIGT} refers to the default database, and \samp{DEW} and \samp{SUPCRTBL} are the optional data files).
+
\code{RH2obigt} implements a group additivity algorithm for standard molal thermodynamic properties and equations of state parameters of crystalline and liquid organic molecules from Richard and Helgeson, 1998. The names of the \code{compound}s and their physical \code{state} are searched for in the indicated \code{file}, that also contains chemical formulas and group stoichiometries; the names of the groups are stored in the column names of this file, and must be present in \code{\link{thermo}$obigt}. The default \code{file} (\code{\link{extdata}/thermo/RH98_Table15.csv}) includes data taken from Table 15 of Richard and Helgeson, 1998 for high molecular weight compounds in \samp{cr}ystalline and \samp{liq}uid states. An error is produced if any of the \code{compound}-\code{state} combinations is not found in the \code{file}, if any of the group names for a given \code{compound}-\code{state} combination is not found in \code{thermo$obigt}, or if the chemical formula calculated from group additivity (with the aid of \code{\link{i2A}} and \code{\link{as.chemical.formula}}) is not identical to that listed in the \code{file}.
}
More information about the CHNOSZ-commits
mailing list