[CHNOSZ-commits] r578 - in pkg/CHNOSZ: . R inst man vignettes
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Jul 25 05:07:31 CEST 2020
Author: jedick
Date: 2020-07-25 05:07:30 +0200 (Sat, 25 Jul 2020)
New Revision: 578
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/R/diagram.R
pkg/CHNOSZ/inst/NEWS.Rd
pkg/CHNOSZ/man/diagram.Rd
pkg/CHNOSZ/vignettes/multi-metal.Rmd
Log:
Speed up plotting of field boundaries in diagram()
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2020-07-25 01:09:29 UTC (rev 577)
+++ pkg/CHNOSZ/DESCRIPTION 2020-07-25 03:07:30 UTC (rev 578)
@@ -1,6 +1,6 @@
Date: 2020-07-25
Package: CHNOSZ
-Version: 1.3.6-51
+Version: 1.3.6-52
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-25 01:09:29 UTC (rev 577)
+++ pkg/CHNOSZ/R/diagram.R 2020-07-25 03:07:30 UTC (rev 578)
@@ -24,7 +24,7 @@
# sizes
cex=par("cex"), cex.names=1, cex.axis=par("cex"),
# line styles
- lty=NULL, lty.cr=NULL, lty.aq=NULL, lwd=par("lwd"), dotted=NULL,
+ lty=NULL, lwd=par("lwd"), dotted=NULL,
spline.method=NULL, contour.method="edge", levels=NULL,
# colors
col=par("col"), col.names=par("col"), fill=NULL,
@@ -180,7 +180,6 @@
## identify predominant species
predominant <- NA
- linesout <- NA
H2O.predominant <- NULL
if(plotvar %in% c("loga.equil", "alpha", "A/(2.303RT)") & type!="saturation") {
pv <- plotvals
@@ -524,47 +523,28 @@
}
# the categories (species/groups/etc) on the plot
zvals <- na.omit(unique(as.vector(predominant)))
- # initialize list to output line coordinates
- linesout <- list()
- iout <- 1
- # take each possible pair of species
+ # loop over species
for(i in 1:(length(zvals)-1)) {
- for(j in (i+1):length(zvals)) {
- z <- predominant
- # draw contours only for this pair
- z[!z %in% c(zvals[i], zvals[j])] <- NA
- # give them neighboring values (so we get one contour line)
- z[z==zvals[i]] <- 0
- z[z==zvals[j]] <- 1
- # use contourLines() instead of contour() in order to get line coordinates 20181029
- cLines <- contourLines(xs, ys, z, levels=0.5)
- if(length(cLines) > 0) {
- # loop in case contourLines returns multiple lines
- for(k in 1:length(cLines)) {
- # draw the lines
- mylty <- lty
- if(!is.null(lty.cr)) {
- # use lty.cr for cr-cr boundaries 20190530
- if(all(grepl("cr", eout$species$state[c(zvals[i], zvals[j])]))) mylty <- lty.cr
- }
- if(!is.null(lty.aq)) {
- # use lty.aq for aq-aq boundaries 20190531
- if(all(grepl("aq", eout$species$state[c(zvals[i], zvals[j])]))) mylty <- lty.aq
- }
- lines(cLines[[k]][2:3], lty=mylty, col=col, lwd=lwd)
- # keep the x and y values (list components 2 and 3)
- linesout[[iout]] <- cLines[[k]][[2]]
- names(linesout)[iout] <- paste0("x", k, "_", zvals[i], ".", zvals[j])
- linesout[[iout+1]] <- cLines[[k]][[3]]
- names(linesout)[iout+1] <- paste0("y", k, "_", zvals[i], ".", zvals[j])
- iout <- iout + 2
- }
+ # get the "z" values
+ z <- predominant
+ # assign values to get one contour line between this species and all others
+ i0 <- z==zvals[i]
+ i1 <- z!=zvals[i]
+ z[i0] <- 0
+ z[i1] <- 1
+ # use contourLines() instead of contour() in order to get line coordinates 20181029
+ cLines <- contourLines(xs, ys, z, levels=0.5)
+ if(length(cLines) > 0) {
+ # loop in case contourLines returns multiple lines
+ for(k in 1:length(cLines)) {
+ # draw the lines
+ mylty <- lty
+ lines(cLines[[k]][2:3], lty=mylty, col=col, lwd=lwd)
}
- }
+ }
+ # mask species to prevent double-plotting contour lines
+ predominant[i0] <- NA
}
- # https://stackoverflow.com/questions/34570860/adding-na-to-make-all-list-elements-equal-length 20181029
- # for compatibility with R 3.1.0, don't use lengths() here 20190302
- lapply(linesout, `length<-`, max(sapply(linesout, length)))
}
## label plot function
plot.names <- function(out, xs, ys, xlim, ylim, names, srt, min.area) {
@@ -704,7 +684,7 @@
# font metric state and subsequent errors adding e.g. subscripted text to plot)
if(length(na.omit(unique(as.vector(zs)))) > 1) {
if(!is.null(dotted)) plot.line(zs, xlim.calc, ylim.calc, dotted, col, lwd, xrange=xrange)
- else linesout <- contour.lines(predominant, xlim.calc, ylim.calc, lty=lty, col=col, lwd=lwd)
+ else contour.lines(predominant, xlim.calc, ylim.calc, lty=lty, col=col, lwd=lwd)
}
# re-draw the tick marks and axis lines in case the fill obscured them
has.color <- FALSE
@@ -738,10 +718,8 @@
outstuff <- list(plotvar = plotvar, plotvals = plotvals, names = names, predominant = predominant, predominant.values = predominant.values)
# 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)
- out <- c(eout, outstuff)
- if(!identical(predominant, NA) & is.null(dotted)) out <- c(out, list(lines=linesout))
- out <- c(out, out2D)
- return(invisible(out))
+ out <- c(eout, outstuff, out2D)
+ invisible(out)
}
find.tp <- function(x) {
Modified: pkg/CHNOSZ/inst/NEWS.Rd
===================================================================
--- pkg/CHNOSZ/inst/NEWS.Rd 2020-07-25 01:09:29 UTC (rev 577)
+++ pkg/CHNOSZ/inst/NEWS.Rd 2020-07-25 03:07:30 UTC (rev 578)
@@ -9,7 +9,7 @@
\newcommand{\s}{\ifelse{latex}{\eqn{_{#1}}}{\ifelse{html}{\out{<sub>#1</sub>}}{#1}}}
\newcommand{\S}{\ifelse{latex}{\eqn{^{#1}}}{\ifelse{html}{\out{<sup>#1</sup>}}{^#1}}}
-\section{Changes in CHNOSZ version 1.3.6-51 (2020-07-25)}{
+\section{Changes in CHNOSZ version 1.3.6-52 (2020-07-25)}{
\subsection{MAJOR CHANGES}{
\itemize{
@@ -175,6 +175,9 @@
\code{multi-metal.Rmd} vignette to compute the Pourbaix energy
(Δ\emph{G}\s{pbx}) for a metastable material.
+ \item Remove the \samp{lty.aq} and \samp{lty.cr} arguments from
+ \code{diagram()}.
+
}
}
Modified: pkg/CHNOSZ/man/diagram.Rd
===================================================================
--- pkg/CHNOSZ/man/diagram.Rd 2020-07-25 01:09:29 UTC (rev 577)
+++ pkg/CHNOSZ/man/diagram.Rd 2020-07-25 03:07:30 UTC (rev 578)
@@ -21,7 +21,7 @@
# character sizes
cex = par("cex"), cex.names = 1, cex.axis = par("cex"),
# line styles
- lty = NULL, lty.cr = NULL, lty.aq = NULL, lwd = par("lwd"), dotted = NULL,
+ lty = NULL, lwd = par("lwd"), dotted = NULL,
spline.method = NULL, contour.method = "edge", levels = NULL,
# colors
col = par("col"), col.names = par("col"), fill = NULL,
@@ -58,8 +58,6 @@
\item{cex.names}{numeric, character expansion factor to be used for names of species on plots}
\item{cex.axis}{numeric, character expansion factor for names of axes}
\item{lty}{numeric, line types to be used in plots}
- \item{lty.cr}{numeric, line types for cr-cr boundaries (between two minerals)}
- \item{lty.aq}{numeric, line types for aq-aq boundaries (between two aqueous species)}
\item{lwd}{numeric, line width}
\item{dotted}{numeric, how often to skip plotting points on predominance field boundaries (to gain the effect of dotted or dashed boundary lines)}
\item{spline.method}{character, method used in \code{\link{splinefun}}}
@@ -131,7 +129,6 @@
If \code{alpha} is TRUE, the fractional degrees of formation (ratios of activities to total activity) are plotted.
Or, setting \code{alpha} to \samp{balance} allows the activities to be multiplied by the number of the balancing component; this is useful for making \dQuote{percent carbon} diagrams where the species differ in carbon number.
The line type and line width can be controlled with \code{lty} and \code{lwd}, respectively.
-Set \code{lty.cr} to 0 to disable drawing lines between minerals (to show equal-activity lines for only aqueous species), or set \code{lty.aq} to 0 to disable drawing lines between aqueous species.
To connect the points with splines instead of lines, set \code{spline.method} to one of the methods in \code{\link{splinefun}}.
}
Modified: pkg/CHNOSZ/vignettes/multi-metal.Rmd
===================================================================
--- pkg/CHNOSZ/vignettes/multi-metal.Rmd 2020-07-25 01:09:29 UTC (rev 577)
+++ pkg/CHNOSZ/vignettes/multi-metal.Rmd 2020-07-25 03:07:30 UTC (rev 578)
@@ -343,7 +343,7 @@
stopifnot(round(eV_atom, 3) == 0.411)
```
-This is very close to the value of 0.412 eV/atom for the energy above the hull for [triclinic FeVO~4~ on the MP website](https://materialsproject.org/materials/mp-504509/), showing that we successfully made a round-trip starting with the input formation energies (eV/atom) from the MP website, to Gibbs energy (J/mol) in the OBIGT database, and back out to energy above the hull (eV/atom).
+This is nearly equal to the value of 0.412 eV/atom for the energy above the hull for [triclinic FeVO~4~ on the MP website](https://materialsproject.org/materials/mp-504509/), showing that we successfully made a round-trip starting with the input formation energies (eV/atom) from the MP website, to Gibbs energy (J/mol) in the OBIGT database, and back out to energy above the hull (eV/atom).
The concept of using the stable minerals and aqueous species to calculate reaction energetics is formalized in the `mosaic()` function, which is described next.
Because this example modified the thermodynamic data for some minerals that are used below, we should restore the default OBIGT database before proceeding to the next section.
More information about the CHNOSZ-commits
mailing list