[CHNOSZ-commits] r311 - in pkg/CHNOSZ: . R data inst inst/extdata/Berman man tests/testthat vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Mar 28 08:01:11 CEST 2018


Author: jedick
Date: 2018-03-28 08:01:10 +0200 (Wed, 28 Mar 2018)
New Revision: 311

Added:
   pkg/CHNOSZ/inst/extdata/Berman/testing/
Removed:
   pkg/CHNOSZ/inst/extdata/Berman/unused/
Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/berman.R
   pkg/CHNOSZ/data/opt.csv
   pkg/CHNOSZ/inst/NEWS
   pkg/CHNOSZ/man/berman.Rd
   pkg/CHNOSZ/man/data.Rd
   pkg/CHNOSZ/man/extdata.Rd
   pkg/CHNOSZ/tests/testthat/test-berman.R
   pkg/CHNOSZ/vignettes/obigt.Rmd
Log:
berman(): read user-supplied data from file specified in thermo$opt$Berman


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2018-03-28 04:31:38 UTC (rev 310)
+++ pkg/CHNOSZ/DESCRIPTION	2018-03-28 06:01:10 UTC (rev 311)
@@ -1,6 +1,6 @@
 Date: 2018-03-28
 Package: CHNOSZ
-Version: 1.1.3-18
+Version: 1.1.3-19
 Title: Thermodynamic Calculations for Geobiochemistry
 Authors at R: c(
     person("Jeffrey", "Dick", , "j3ffdick at gmail.com", role = c("aut", "cre"),

Modified: pkg/CHNOSZ/R/berman.R
===================================================================
--- pkg/CHNOSZ/R/berman.R	2018-03-28 04:31:38 UTC (rev 310)
+++ pkg/CHNOSZ/R/berman.R	2018-03-28 06:01:10 UTC (rev 311)
@@ -22,11 +22,19 @@
   DS10 <- read.csv(paste0(dir, "/DS10.csv"), as.is=TRUE)
   FDM14 <- read.csv(paste0(dir, "/FDM+14.csv"), as.is=TRUE)
   BDat17 <- read.csv(paste0(dir, "/BDat17.csv"), as.is=TRUE)
-  if(file.exists("berman.csv")) {
-    BDat_user <- read.csv("berman.csv", as.is=TRUE)
-    # assemble the files in reverse chronological order
-    dat <- rbind(BDat_user, BDat17, FDM14, DS10, JUN92, ZS92, SHD91, Ber90, Ber88)
-  } else dat <- rbind(BDat17, FDM14, DS10, JUN92, ZS92, SHD91, Ber90, Ber88)
+  userfile <- get("thermo")$opt$Berman
+  userfileexists <- FALSE
+  dat <- rbind(BDat17, FDM14, DS10, JUN92, ZS92, SHD91, Ber90, Ber88)
+  if(!is.na(userfile)) {
+    if(userfile!="") {
+      if(file.exists(userfile)) {
+        userfileexists <- TRUE
+        BDat_user <- read.csv(userfile, as.is=TRUE)
+        # assemble the files in reverse chronological order
+        dat <- rbind(BDat_user, BDat17, FDM14, DS10, JUN92, ZS92, SHD91, Ber90, Ber88)
+      } else stop("the file named in thermo$opt$Berman (", userfile, ") does not exist")
+    } 
+  }
   # remove duplicates (only the first, i.e. most recent entry is kept)
   dat <- dat[!duplicated(dat$name), ]
   # remove the multipliers on volume parameters
@@ -37,7 +45,10 @@
   if(missing(name)) return(dat)
   # which row has data for this mineral?
   irow <- which(dat$name == name)
-  if(length(irow)==0) stop("Data for ", name, " not available. Please add it to berman.csv")
+  if(length(irow)==0) {
+    if(userfileexists) stop("Data for ", name, " not available. Please add it to ", userfile)
+    if(!userfileexists) stop("Data for ", name, " not available. Please add it to your_data_file.csv and run thermo$obigt$Berman <<- 'path/to/your_data_file.csv'")
+  }
   # the function works fine with just the following assign() call,
   # but an explicit dummy assignment here is used to avoid "Undefined global functions or variables" in R CMD check
   GfPrTr <- HfPrTr <- SPrTr <- Tlambda <- Tmax <- Tmin <- Tref <- VPrTr <-

Modified: pkg/CHNOSZ/data/opt.csv
===================================================================
--- pkg/CHNOSZ/data/opt.csv	2018-03-28 04:31:38 UTC (rev 310)
+++ pkg/CHNOSZ/data/opt.csv	2018-03-28 06:01:10 UTC (rev 311)
@@ -1,2 +1,2 @@
 cutoff,E.units,T.units,P.units,state,water,G.tol,Cp.tol,V.tol,varP,IAPWS.sat,paramin,ideal.H,ideal.e,nonideal,Berman
-1E-10,cal,C,bar,aq,SUPCRT92,100,1,1,FALSE,liquid,1000,TRUE,TRUE,Helgeson,FALSE
+1E-10,cal,C,bar,aq,SUPCRT92,100,1,1,FALSE,liquid,1000,TRUE,TRUE,Helgeson,NA

Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS	2018-03-28 04:31:38 UTC (rev 310)
+++ pkg/CHNOSZ/inst/NEWS	2018-03-28 06:01:10 UTC (rev 311)
@@ -1,4 +1,4 @@
-CHANGES IN CHNOSZ 1.1.3-18 (2018-03-28)
+CHANGES IN CHNOSZ 1.1.3-19 (2018-03-28)
 ---------------------------------------
 
 THERMODYNAMIC DATA
@@ -30,11 +30,12 @@
   have been removed, except for 10^5, 10^5, 10^5, and 10^8 on v1 to v4
   (to be consistent with the winTWQ data format).
 
-- berman() now reads data from a user-supplied file berman.csv if it is
-  present in the working directory.
+- berman() now reads data from a user-supplied file specified in
+  thermo$opt$Berman.
 
 - Add mineral data from Berman and Aranovich, 1996 to
-  extdata/Berman/unused/BA96.csv.
+  extdata/Berman/testing/BA96.csv and an example of using this file via
+  thermo$opt$Berman (see ?berman).
 
 - Correct swapped v1 <-> v3 and v2 <-> v4 in extdata/Berman/DS10.csv.
 

Modified: pkg/CHNOSZ/man/berman.Rd
===================================================================
--- pkg/CHNOSZ/man/berman.Rd	2018-03-28 04:31:38 UTC (rev 310)
+++ pkg/CHNOSZ/man/berman.Rd	2018-03-28 06:01:10 UTC (rev 311)
@@ -126,6 +126,26 @@
        legend=c("Helgeson et al., 1978 (unadjusted)",
        "Berman, 1988", "    (adjusted by Sverjensky et al., 1991)"), bty="n")
 title(main="Comparison of Helgeson and Berman datasets at 1000 bar")
+
+## Getting data from a user-supplied file
+## Ol-Opx exchange equilibrium, after Berman and Aranovich, 1996
+E.units("J")
+species <- c("fayalite", "enstatite", "ferrosilite", "forsterite")
+coeffs <- c(-1, -2, 2, 1)
+T <- seq(600, 1500, 50)
+Gex_Ber88 <- subcrt(species, coeffs, T=T, P=1)$out$G
+# add data from BA96
+datadir <- system.file("extdata/Berman/testing", package="CHNOSZ")
+add.obigt(file.path(datadir, "BA96_obigt.csv"))
+thermo$opt$Berman <<- file.path(datadir, "BA96.csv")
+Gex_BA96 <- subcrt(species, coeffs, T=seq(600, 1500, 50), P=1)$out$G
+# Ber88 is lower than BA96 at low T
+stopifnot((Gex_BA96 - Gex_Ber88)[1] > 0)
+# the curves cross at about 725 deg C (BA96 Fig. 8)
+# (actually, in our calculation they cross closer to 800 deg C)
+stopifnot(T[which.min(abs(Gex_BA96 - Gex_Ber88))] == 800)
+# reset the database (thermo$opt$E.units, thermo$obigt, and thermo$opt$Berman)
+data(thermo)
 }
 
 \references{
@@ -133,6 +153,8 @@
 
 Berman, R. G. (1988) Internally-consistent thermodynamic data for minerals in the system Na{\s2}O-K{\s2}O-CaO-MgO-FeO-Fe{\s2}O{\s3}-Al{\s2}O{\s3}-SiO{\s2}-TiO{\s2}-H{\s2}O-CO{\s2}. \emph{J. Petrol.} \bold{29}, 445-522. \url{https://doi.org/10.1093/petrology/29.2.445}
 
+Berman, R. G. and Aranovich, L. Ya. (1996) Optimized standard state and solution properties of minerals. I. Model calibration for olivine, orthopyroxene, cordierite, garnet, and ilmenite in the system FeO-MgO-CaO-Al{\s2}O{\s3}-TiO{\s2}-SiO{\s2}. \emph{Contrib. Mineral. Petrol.} \bold{126}, 1-24. \url{https://doi.org/10.1007/s004100050233}
+
 Berman, R. G. (2007) winTWQ (version 2.3): A software package for performing internally-consistent thermobarometric calculations. \emph{Open File} \bold{5462}, Geological Survey of Canada, 41 p. \url{https://doi.org/10.4095/223425}
 
 Helgeson, H. C., Delany, J. M., Nesbitt, H. W. and Bird, D. K. (1978) Summary and critique of the thermodynamic properties of rock-forming minerals. \emph{Am. J. Sci.} \bold{278-A}, 1--229. \url{http://www.worldcat.org/oclc/13594862}

Modified: pkg/CHNOSZ/man/data.Rd
===================================================================
--- pkg/CHNOSZ/man/data.Rd	2018-03-28 04:31:38 UTC (rev 310)
+++ pkg/CHNOSZ/man/data.Rd	2018-03-28 06:01:10 UTC (rev 311)
@@ -22,7 +22,7 @@
 The computational settings are changed using \code{\link{water}}, \code{\link{P.units}}, \code{\link{T.units}}, \code{\link{E.units}}, and some other commands (e.g. \code{\link{mod.buffer}}).
 
 Some settings can only be changed by direct manipulation of \code{thermo$opt}.
-In an interactive session, this should be done using the super-assignment operator (e.g. \code{thermo$opt$Berman <<- TRUE}) so that the \code{thermo} object is not copied to the global environment.
+In an interactive session, this should be done using the super-assignment operator (e.g. \code{thermo$opt$ideal.H <<- FALSE}) so that the \code{thermo} object is not copied to the global environment.
 (Doing so would cause problems, as many functions are designed to access the \code{thermo} object in the \code{CHNOSZ} environment.)
 
 To restore the default computational settings, thermodynamic database, and system settings, run \code{data(thermo)}.
@@ -59,7 +59,7 @@
       \code{ideal.H} \tab logical \tab Should \code{\link{nonideal}} ignore the proton? [\code{TRUE}] \cr
       \code{ideal.e} \tab logical \tab Should \code{\link{nonideal}} ignore the electron? [\code{TRUE}] \cr
       \code{nonideal} \tab character \tab Method for \code{\link{nonideal}} [\code{Helgeson}] \cr
-      \code{Berman} \tab logical \tab Should \code{\link{info}} preferentially return Berman minerals? [\code{FALSE}]
+      \code{Berman} \tab character \tab User data file for mineral parameters in the Berman equations [\code{NA}]
 }
 
     \item \code{thermo$element}

Modified: pkg/CHNOSZ/man/extdata.Rd
===================================================================
--- pkg/CHNOSZ/man/extdata.Rd	2018-03-28 04:31:38 UTC (rev 310)
+++ pkg/CHNOSZ/man/extdata.Rd	2018-03-28 06:01:10 UTC (rev 311)
@@ -17,6 +17,7 @@
     Following conventions used in other data files, the names of sanidine and microcline were changed to K-feldspar,high and K-feldspar,low.
     \item \code{*.csv} contain thermodynamic data from other sources.
     \item \code{sympy.R} is an R script used to symbolically integrate heat capacity and volume (to calculate enthalpy, entropy and Gibbs energy), using \CRANpkg{rSymPy}.
+    \item The \code{testing} directory contains data files based on Berman and Aranovich (1996). These are used to demonstrate the addition of data from a user-supplied file (see \code{\link{berman}}).
   }
 
   Files in \code{abundance} contain protein abundance and microbial occurrence data:
@@ -114,6 +115,8 @@
 
 Berman, R. G. (1988) Internally-consistent thermodynamic data for minerals in the system Na{\s2}O-K{\s2}O-CaO-MgO-FeO-Fe{\s2}O{\s3}-Al{\s2}O{\s3}-SiO{\s2}-TiO{\s2}-H{\s2}O-CO{\s2}. \emph{J. Petrol.} \bold{29}, 445-522. \url{https://doi.org/10.1093/petrology/29.2.445}
 
+Berman, R. G. and Aranovich, L. Ya. (1996) Optimized standard state and solution properties of minerals. I. Model calibration for olivine, orthopyroxene, cordierite, garnet, and ilmenite in the system FeO-MgO-CaO-Al{\s2}O{\s3}-TiO{\s2}-SiO{\s2}. \emph{Contrib. Mineral. Petrol.} \bold{126}, 1-24. \url{https://doi.org/10.1007/s004100050233}
+
 Dayhoff, M. O. and Lippincott, E. R. and Eck, R. V. (1964) Thermodynamic Equilibria In Prebiological Atmospheres. \emph{Science} \bold{146}, 1461--1464. \url{https://doi.org/10.1126/science.146.3650.1461}
 
 Dayhoff, M. O. and Lippincott, E. R., Eck, R. V. and Nagarajan (1967) Thermodynamic Equilibrium In Prebiological Atmospheres of C, H, O, N, P, S, and Cl. Report SP-3040, National Aeronautics and Space Administration.

Modified: pkg/CHNOSZ/tests/testthat/test-berman.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-berman.R	2018-03-28 04:31:38 UTC (rev 310)
+++ pkg/CHNOSZ/tests/testthat/test-berman.R	2018-03-28 06:01:10 UTC (rev 311)
@@ -79,3 +79,12 @@
   # we are less consistent with the reference values at high T
   expect_maxdiff(Kfs$G[3:4], Kfs_G[3:4], 350)
 })
+
+test_that("nonexistent or incomplete user data file is handled properly", {
+  thermo$opt$Berman <<- "XxXxXx.csv"
+  expect_error(berman("calcite"), "the file named in thermo\\$opt\\$Berman \\(XxXxXx.csv\\) does not exist")
+  thermo$opt$Berman <<- system.file("extdata/Berman/testing/BA96.csv", package="CHNOSZ")
+  expect_error(berman("xxx"), "Data for xxx not available. Please add it to")
+  thermo$opt$Berman <<- NA
+  expect_error(berman("xxx"), "Data for xxx not available. Please add it to your_data_file.csv")
+})

Modified: pkg/CHNOSZ/vignettes/obigt.Rmd
===================================================================
--- pkg/CHNOSZ/vignettes/obigt.Rmd	2018-03-28 04:31:38 UTC (rev 310)
+++ pkg/CHNOSZ/vignettes/obigt.Rmd	2018-03-28 06:01:10 UTC (rev 311)
@@ -123,7 +123,7 @@
 
 * Updates included with [SUPCRTBL](http://www.indiana.edu/~hydrogeo/supcrtbl.html) are listed under **Optional Data** / **SUPCRTBL**.
 
-* Data from SUPCRT92 which have been superseded in CHNOSZ by the Berman data are listed under **Optional Data** / **SUPCRT92**.
+* Data from SUPCRT92 which have been superseded by the Berman data are listed under **Optional Data** / **SUPCRT92**.
 
 # Sources of data {.tabset .tabset-fade}
 



More information about the CHNOSZ-commits mailing list