[CHNOSZ-commits] r568 - in pkg/CHNOSZ: . R demo inst man vignettes
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Jul 19 16:57:12 CEST 2020
Author: jedick
Date: 2020-07-19 16:57:12 +0200 (Sun, 19 Jul 2020)
New Revision: 568
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/R/diagram.R
pkg/CHNOSZ/demo/DEW.R
pkg/CHNOSZ/demo/contour.R
pkg/CHNOSZ/demo/copper.R
pkg/CHNOSZ/demo/mosaic.R
pkg/CHNOSZ/inst/NEWS.Rd
pkg/CHNOSZ/man/diagram.Rd
pkg/CHNOSZ/vignettes/anintro.Rmd
pkg/CHNOSZ/vignettes/multi-metal.Rmd
Log:
Change default in diagram() to limit.water = NULL
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2020-07-19 11:09:54 UTC (rev 567)
+++ pkg/CHNOSZ/DESCRIPTION 2020-07-19 14:57:12 UTC (rev 568)
@@ -1,6 +1,6 @@
Date: 2020-07-19
Package: CHNOSZ
-Version: 1.3.6-41
+Version: 1.3.6-42
Title: Thermodynamic Calculations and Diagrams for Geochemistry
Authors at R: c(
person("Jeffrey", "Dick", , "j3ffdick at gmail.com", role = c("aut", "cre"),
Modified: pkg/CHNOSZ/R/diagram.R
===================================================================
--- pkg/CHNOSZ/R/diagram.R 2020-07-19 11:09:54 UTC (rev 567)
+++ pkg/CHNOSZ/R/diagram.R 2020-07-19 14:57:12 UTC (rev 568)
@@ -28,7 +28,7 @@
spline.method=NULL, contour.method="edge", levels=NULL,
# colors
col=par("col"), col.names=par("col"), fill=NULL,
- fill.NA="gray80", limit.water=TRUE,
+ fill.NA="gray80", limit.water=NULL,
# field and line labels
names=NULL, format.names=TRUE, bold=FALSE, italic=FALSE,
font=par("font"), family=par("family"), adj=0.5, dy=0, srt=0,
@@ -43,7 +43,7 @@
## check that eout is a valid object
efun <- eout$fun
if(length(efun)==0) efun <- ""
- if(!efun %in% c("affinity", "equilibrate", "solubility")) stop("'eout' is not the output from affinity(), equilibrate(), or solubility()")
+ if(!(efun %in% c("affinity", "equilibrate") | grepl("solubility", efun))) stop("'eout' is not the output from affinity(), equilibrate(), or solubility()")
## 'type' can be:
# 'auto' - property from affinity() (1D) or maximum affinity (affinity 2D) (aout) or loga.equil (eout)
@@ -180,6 +180,7 @@
## identify predominant species
predominant <- NA
linesout <- NA
+ H2O.predominant <- NULL
if(plotvar %in% c("loga.equil", "alpha", "A/(2.303RT)") & type!="saturation") {
pv <- plotvals
# some additional steps for affinity values, but not for equilibrated activities
@@ -192,11 +193,12 @@
}
}
predominant <- which.pmax(pv)
- # clip plot to water stability region
- if(limit.water & nd==2) {
+ # show water stability region
+ if((is.null(limit.water) | isTRUE(limit.water)) & nd==2) {
wl <- water.lines(eout, plot.it=FALSE)
# proceed if water.lines produced calculations for this plot
if(!identical(wl, NA)) {
+ H2O.predominant <- predominant
# for each x-point, find the y-values that are outside the water stability limits
for(i in seq_along(wl$xpoints)) {
ymin <- min(c(wl$y.oxidation[i], wl$y.reduction[i]))
@@ -205,11 +207,11 @@
# the actual calculation
iNA <- eout$vals[[2]] < ymin | eout$vals[[2]] > ymax
# assign NA to the predominance matrix
- predominant[i, iNA] <- NA
+ H2O.predominant[i, iNA] <- NA
} else {
# as above, but x- and y-axes are swapped
iNA <- eout$vals[[1]] < ymin | eout$vals[[1]] > ymax
- predominant[iNA, i] <- NA
+ H2O.predominant[iNA, i] <- NA
}
}
}
@@ -636,8 +638,8 @@
# add a title
if(!is.null(main)) title(main=main)
}
- # colors and curves (predominance), or contours (properties)
if(identical(predominant, NA)) {
+ # no predominance matrix, so we're contouring properties
contour.method <- rep(contour.method, length.out=length(plotvals))
if(type=="saturation") {
# for saturation plot, contour affinity=0 for all species
@@ -665,6 +667,16 @@
}
pn <- list(namesx=NULL, namesy=NULL)
} else {
+ # with a predominance matrix, color fields and make field boundaries
+ if(!is.null(H2O.predominant)) {
+ # isTRUE(limit.water): clip diagram to H2O stability region
+ if(isTRUE(limit.water)) predominant <- H2O.predominant
+ else {
+ # is.null(limit.water): overlay diagram on H2O stability region
+ zs <- t(H2O.predominant[, ncol(H2O.predominant):1])
+ if(!is.null(fill)) fill.color(xs, ys, zs, fill, ngroups)
+ }
+ }
# put predominance matrix in the right order for image() etc
zs <- t(predominant[, ncol(predominant):1])
if(!is.null(fill)) fill.color(xs, ys, zs, fill, ngroups)
@@ -679,6 +691,7 @@
# re-draw the tick marks and axis lines in case the fill obscured them
has.color <- FALSE
if(!identical(unique(fill), "transparent")) has.color <- TRUE
+ if(!is.null(H2O.predominant) & !identical(fill.NA, "transparent")) has.color <- TRUE
if(any(is.na(zs)) & !identical(fill.NA, "transparent")) has.color <- TRUE
if(tplot & !add & has.color) {
thermo.axis()
@@ -688,6 +701,8 @@
out2D <- list(namesx=pn$namesx, namesy=pn$namesy)
} # end if(nd==2)
} # end if(plot.it)
+ # even if plot=FALSE, return the diagram clipped to the water stability region (for testing) 20200719
+ if(isTRUE(limit.water) & !is.null(H2O.predominant)) predominant <- H2O.predominant
outstuff <- list(plotvar=plotvar, plotvals=plotvals, names=names, predominant=predominant)
# include the balance name and coefficients if we diagrammed affinities 20200714
if(eout.is.aout) outstuff <- c(list(balance = balance, n.balance = n.balance), outstuff)
Modified: pkg/CHNOSZ/demo/DEW.R
===================================================================
--- pkg/CHNOSZ/demo/DEW.R 2020-07-19 11:09:54 UTC (rev 567)
+++ pkg/CHNOSZ/demo/DEW.R 2020-07-19 14:57:12 UTC (rev 568)
@@ -108,7 +108,7 @@
# set total C concentration to 0.03 molal
# (from EQ3NR model for eclogite [Supporting Information of SSH14])
e <- equilibrate(a, loga.balance = log10(0.03))
- diagram(e, limit.water = FALSE, fill = fill)
+ diagram(e, fill = fill)
dp <- describe.property(c(" T", " P"), c(T, P), digits=0)
legend("bottomleft", legend=dp, bty="n")
}
Modified: pkg/CHNOSZ/demo/contour.R
===================================================================
--- pkg/CHNOSZ/demo/contour.R 2020-07-19 11:09:54 UTC (rev 567)
+++ pkg/CHNOSZ/demo/contour.R 2020-07-19 14:57:12 UTC (rev 568)
@@ -24,14 +24,14 @@
# calculate affinity with changing basis species
bases <- c("H2S", "HS-", "HSO4-", "SO4-2")
m <- mosaic(bases, pH = c(2, 10, res), O2 = c(-41, -29, res), T = T, P = P, IS = NaCl$IS, blend = blend)
+# show predominance fields
+diagram(m$A.bases, col = "red", col.names = "red", lty = 2, italic = TRUE)
+diagram(m$A.species, add=TRUE, col = "blue", col.names = "blue", lwd = 2, bold = TRUE)
# calculate and plot solubility
s <- solubility(m$A.species)
# convert to ppb
s <- convert(s, "ppb")
-diagram(s, type="loga.balance", levels = c(1, 10, 100, 1000))
-# show predominance fields
-diagram(m$A.bases, add=TRUE, col = "red", col.names = "red", limit.water = FALSE, lty = 2, italic = TRUE)
-diagram(m$A.species, add=TRUE, col = "blue", col.names = "blue", limit.water = FALSE, lwd = 2, bold = TRUE)
+diagram(s, type = "loga.balance", levels = c(1, 10, 100, 1000), add = TRUE)
# add legend and title
dP <- describe.property(c("T", "P"), c(250, 500))
legend("top", dP, bty = "n", inset = c(0, 0.06))
Modified: pkg/CHNOSZ/demo/copper.R
===================================================================
--- pkg/CHNOSZ/demo/copper.R 2020-07-19 11:09:54 UTC (rev 567)
+++ pkg/CHNOSZ/demo/copper.R 2020-07-19 14:57:12 UTC (rev 568)
@@ -40,7 +40,7 @@
# mosaic diagram with speciate glycine as a function of pH
m <- mosaic(bases=Gly, pH=c(0, 16, 500), Eh=c(-0.6, 1.0, 500))
fill <- c(rep("lightgrey", 3), rep("white", 4), rep("lightblue", 4))
-d <- diagram(m$A.species, fill=fill, names=FALSE, xaxs="i", yaxs="i", fill.NA="pink2")
+d <- diagram(m$A.species, fill=fill, names=FALSE, xaxs="i", yaxs="i", fill.NA="pink2", limit.water = TRUE)
# to make the labels look nicer
names <- names[sort(unique(as.numeric(d$predominant)))]
for(i in 1:length(names)) {
@@ -56,13 +56,13 @@
}
# add glycine ionization lines
-d <- diagram(m$A.bases, add=TRUE, col="darkblue", lty=3, names=FALSE, limit.water=FALSE)
+d <- diagram(m$A.bases, add=TRUE, col="darkblue", lty=3, names=FALSE)
text(d$namesx, -0.5, Gly, col="darkblue")
# add water lines and title
water.lines(d)
mtitle(expression("Copper-water-glycine at 25"~degree*"C and 1 bar",
- "After Aksu and Doyle, 2001 (Fig. 2b)"), line=0.5)
+ "After Aksu and Doyle, 2001 (Fig. 2b)"))
# done!
reset()
Modified: pkg/CHNOSZ/demo/mosaic.R
===================================================================
--- pkg/CHNOSZ/demo/mosaic.R 2020-07-19 11:09:54 UTC (rev 567)
+++ pkg/CHNOSZ/demo/mosaic.R 2020-07-19 14:57:12 UTC (rev 568)
@@ -27,15 +27,15 @@
# note curved lines, particularly at the boundaries with siderite
m1 <- mosaic(bases, bases2, pH = pH, Eh = Eh, T = T)
# make a diagram and add water stability lines
-diagram(m1$A.species, lwd = 2)
+diagram(m1$A.species, lwd = 2, limit.water = TRUE)
water.lines(m1$A.species, col = "seagreen", lwd = 1.5)
# show lines for Fe(aq) = 10^-4 M
species(c("Fe+2", "Fe+3"), -4)
m2 <- mosaic(bases, bases2, pH = pH, Eh = Eh, T = T)
-diagram(m2$A.species, add = TRUE, names = FALSE)
+diagram(m2$A.species, add = TRUE, names = FALSE, limit.water = TRUE)
# overlay the sulfur and carbonate basis species predominance fields
-d <- diagram(m1$A.bases, add = TRUE, col = "red", col.names = "red", lty = 3, limit.water = FALSE)
-d <- diagram(m1$A.bases2, add = TRUE, col = "blue", names = FALSE, lty = 3, limit.water = FALSE)
+d <- diagram(m1$A.bases, add = TRUE, col = "red", col.names = "red", lty = 3)
+d <- diagram(m1$A.bases2, add = TRUE, col = "blue", names = FALSE, lty = 3)
text(d$namesx, -0.8, as.expression(sapply(m1$A.bases2$species$name, expr.species)), col = "blue")
# add legend and title
dP <- describe.property(c("T", "P"), c(25, 1))
Modified: pkg/CHNOSZ/inst/NEWS.Rd
===================================================================
--- pkg/CHNOSZ/inst/NEWS.Rd 2020-07-19 11:09:54 UTC (rev 567)
+++ pkg/CHNOSZ/inst/NEWS.Rd 2020-07-19 14:57:12 UTC (rev 568)
@@ -6,7 +6,7 @@
\newcommand{\H2O}{\ifelse{latex}{\eqn{\mathrm{H_{2}O}}}{\ifelse{html}{\out{H<sub>2</sub>O}}{H2O}}}
\newcommand{\Hplus}{\ifelse{latex}{\eqn{\mathrm{H^{+}}}}{\ifelse{html}{\out{H<sup>+</sup>}}{H+}}}
-\section{Changes in CHNOSZ version 1.3.6-41 (2020-07-19)}{
+\section{Changes in CHNOSZ version 1.3.6-42 (2020-07-19)}{
\subsection{MAJOR CHANGES}{
\itemize{
@@ -36,6 +36,12 @@
calculations for different species. To add new species to an existing
system, use \samp{add = TRUE}.
+ \item The new default of \code{NULL} for \strong{limit.water} in
+ \code{diagram()} causes the main diagram to be overlaid on the fields of
+ water stability (white) and instability (gray). Change this to
+ \code{TRUE} to obtain the previous default of masking all parts of the
+ diagram oustide of the water stability field.
+
}
}
@@ -199,7 +205,7 @@
\item TODO: remove stopifnot() from examples.
- \item TODO: change default to diagram(., water.lines= FALSE)
+ \item TODO: get water limits on logfO2-logfS2 diagram (multi-metal.Rmd)
}
}
Modified: pkg/CHNOSZ/man/diagram.Rd
===================================================================
--- pkg/CHNOSZ/man/diagram.Rd 2020-07-19 11:09:54 UTC (rev 567)
+++ pkg/CHNOSZ/man/diagram.Rd 2020-07-19 14:57:12 UTC (rev 568)
@@ -25,7 +25,7 @@
spline.method = NULL, contour.method = "edge", levels = NULL,
# colors
col = par("col"), col.names = par("col"), fill = NULL,
- fill.NA = "gray80", limit.water = TRUE,
+ fill.NA = "gray80", limit.water = NULL,
# field and line labels
names = NULL, format.names = TRUE, bold = FALSE, italic = FALSE,
font = par("font"), family = par("family"), adj = 0.5, dy = 0, srt = 0,
@@ -68,7 +68,7 @@
\item{col.names}{character, colors for labels of species}
\item{fill}{character, colors used to fill predominance fields}
\item{fill.NA}{character, color for grid points with NA values}
- \item{limit.water}{logical, set NA values beyond water stability limits?}
+ \item{limit.water}{NULL or logical, set NA values beyond water stability limits?}
\item{names}{character, names of species for activity lines or predominance fields}
\item{format.names}{logical, apply formatting to chemical formulas?}
\item{bold}{logical, use bold formatting for names?}
@@ -140,10 +140,13 @@
\code{fill} can be any \code{\link{colors}}, or the word \samp{rainbow}, \samp{heat}, \samp{terrain}, \samp{topo}, or \samp{cm}, indicating a palette from \pkg{grDevices}.
Starting with \R version 3.6.0, \code{fill} can be the name of any available HCL color palette, matched in the same way as the \code{palette} argument of \code{hcl.colors}.
-\code{fill.NA} gives the color for empty fields, i.e. points for which NA values are present, possibly by using \code{\link{equilibrate}} at extreme conditions (see \code{test-diagram.Rd}).
-\code{fill.NA} is also used to specify the color outside the water stability limits on Eh-pH or pe-pH diagrams, when \code{limit.water} is TRUE.
-Note that the default for \code{fill.NA} is automatically changed to \samp{transparent} when \code{add} is TRUE.
+\code{fill.NA} gives the color for empty fields, i.e. points at which NA values are present for any species.
+This may occur when there are missing thermodynamic data or the temperature or pressure are not in the range of the equations of state.
+The default for \code{fill.NA} is automatically changed to \samp{transparent} when \code{add} is TRUE.
+\code{fill.NA} is also used for all areas outside the water stability region on Eh-pH and other diagrams when \code{limit.water} is TRUE.
+The default of NULL for \code{limit.water} causes the main diagram to be overlaid on the water stability regions; change this to FALSE to not show the water limits at all.
+
The default line-drawing algorithm uses \code{\link{contourLines}} to obtain smooth-looking diagonal and curved lines, at the expense of not coinciding exactly with the rectangular grid that is used for drawing colors.
\code{lty}, \code{col}, and \code{lwd} can be specified, but limiting the lines via \code{xrange} is not currently supported.
To go back to the old behavior for drawing lines, set \code{dotted} to \samp{0}.
Modified: pkg/CHNOSZ/vignettes/anintro.Rmd
===================================================================
--- pkg/CHNOSZ/vignettes/anintro.Rmd 2020-07-19 11:09:54 UTC (rev 567)
+++ pkg/CHNOSZ/vignettes/anintro.Rmd 2020-07-19 14:57:12 UTC (rev 568)
@@ -664,11 +664,12 @@
```{r EhpH_plot_color, fig.margin=TRUE, fig.width=4, fig.height=4, smallish.mar=TRUE, dpi=dpi, out.width="100%", echo=FALSE, message=FALSE, cache=TRUE, fig.cap="The same plot, with different colors and labels.", pngquant=pngquant, timeit=timeit}
diagram(a, fill = "terrain", lwd = 2, lty = 3,
names = c("hydrogen sulfide", "bisulfide", "bisulfate", "sulfate"),
+ limit.water = TRUE,
tplot = FALSE, main = "sulfur species, 25 °C", bty = "n")
```
The names of species that can be parsed as chemical formulas are formatted with subscripts and superscripts; if this is not desired, set `format.names = FALSE`.
-The default colors for diagrams shown on the screen use R's `heat.colors()` palette.
-Some arguments in <span style="color:green">`diagram()`</span> can be used to control the color, labels, and lines, and title.
+Other arguments in <span style="color:green">`diagram()`</span> can be used to control the line type, color, and width, and field labels and plot title.
+The `limit.water` argument allows clipping the diagram to the water stability region; other areas are colored gray.
The `tplot` argument turns off plot customizations used in CHNOSZ.
Additional arguments are passed to R's plotting functions; here, we use `bty` to remove the box around the plot.
```{r EhpH_plot_color, echo=TRUE, eval=FALSE}
@@ -717,7 +718,7 @@
The key argument is `bases`, which identifies the candidate basis species, starting with the one in the current basis.
The other arguments, like those of <span style="color:green">`affinity()`</span>, specify the ranges of the variables; `res` indicates the grid resolution to use for each variable (the default is 256).
The first call to <span style="color:green">`diagram()`</span> plots the species of interest; the second adds the predominance fields of the basis species.
-We turn off the gray coloring beyond the water stability limits (`limit.water`) but plot dashed blue lines using <span style="color:green">`water.lines()`</span>:
+We also use <span style="color:green">`water.lines()`</span> to draw dashed blue lines at the water stability limits:
```{r copper_mosaic, fig.margin=TRUE, fig.width=4, fig.height=4, dpi=dpi, out.width="100%", message=FALSE, cache=TRUE, fig.cap="Copper minerals and aqueous complexes with chloride, 200 °C.", pngquant=pngquant, timeit=timeit}
T <- 200
@@ -724,9 +725,9 @@
res <- 200
bases <- c("H2S", "HS-", "HSO4-", "SO4-2")
m1 <- mosaic(bases, pH = c(0, 12, res), Eh=c(-1.2, 0.75, res), T=T)
-diagram(m1$A.species, lwd = 2, fill = NA, limit.water = FALSE)
+diagram(m1$A.species, lwd = 2, fill = NA)
diagram(m1$A.bases, add = TRUE, col = "red1", col.names = "red1", lty = 3,
- limit.water = FALSE, italic = TRUE)
+ italic = TRUE)
water.lines(m1$A.species, col = "blue1")
```
@@ -752,10 +753,9 @@
if (names(newvar) == "O2") basis("O2", "gas")
mosaicargs <- c(list(bases), pH = list(c(-2, 12, res)), newvar, T = T)
m1 <- do.call(mosaic, mosaicargs)
- diagram(m1$A.species, lwd = 2, fill = "terrain",
- limit.water = FALSE)
+ diagram(m1$A.species, lwd = 2, fill = "terrain", limit.water = FALSE)
diagram(m1$A.bases, add = TRUE, col = "red1", col.names = "red1", lty = 3,
- limit.water = FALSE, italic = TRUE)
+ italic = TRUE)
water.lines(m1$A.species, col = "blue1")
swap.basis(names(newvar), "e-")
}
@@ -1797,7 +1797,8 @@
res <- 300
a <- affinity(T = c(T, res), H2 = c(-9, -3, res), iprotein = ip)
fill <- ZC.col(ZC(protein.formula(ip)))
-diagram(a, normalize = TRUE, fill = fill, names = as.character(1:5))
+diagram(a, normalize = TRUE, fill = fill, names = as.character(1:5),
+ limit.water = TRUE)
T <- c(93.3, 79.4, 67.5, 65.3, 57.1)
logaH2 <- c(-3.38, -4.14, -5.66, -7.47, -10.02)
lines(T, logaH2, lty = 2, lwd = 2)
Modified: pkg/CHNOSZ/vignettes/multi-metal.Rmd
===================================================================
--- pkg/CHNOSZ/vignettes/multi-metal.Rmd 2020-07-19 11:09:54 UTC (rev 567)
+++ pkg/CHNOSZ/vignettes/multi-metal.Rmd 2020-07-19 14:57:12 UTC (rev 568)
@@ -135,7 +135,7 @@
```
Now we calculate affinities for minerals in the Fe-S-O-H system that take account of the changing aqueous sulfur species in `bases1`.
-The result is used to make different layers of the diagram:
+The result is used to make different layers of the diagram (1 and 2 are both made by the first call to `diagram()`):
1. Water stability region (bounded by the grey area)
2. Predominance fields for the aqueous S species (italic blue text and dashed lines)
@@ -144,15 +144,14 @@
```{r series1_2, eval = FALSE, echo = 1:6}
species(bases2)
mFe <- mosaic(bases1, pH = pH, O2 = O2, T = T)
-diagram(mFe$A.bases, lty = 0, names = NA)
diagram(mFe$A.bases, lty = 2, col = 4, col.names = 4,
- italic = TRUE, add = TRUE, limit.water = FALSE)
-dFe <- diagram(mFe$A.species, add = TRUE, limit.water = FALSE)
+ italic = TRUE)
+dFe <- diagram(mFe$A.species, add = TRUE)
species(c("chalcopyrite", "bornite"))
mCu <- mosaic(list(bases1, bases2), pH = pH, O2 = O2,
T = T, predominant = list(NULL, dFe$predominant))
diagram(mCu$A.species, add = TRUE, col = 2, col.names = 2,
- lwd = 2, bold = TRUE, limit.water = FALSE)
+ lwd = 2, bold = TRUE)
TP <- describe.property(c("T", "P"), c(T, "Psat"))
legend("topright", TP, bty = "n")
title(paste("Cu-Fe-S-O-H; Total S =", 10^logaH2S, "m"))
More information about the CHNOSZ-commits
mailing list