[CHNOSZ-commits] r570 - in pkg/CHNOSZ: . R inst man vignettes
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Jul 21 04:13:10 CEST 2020
Author: jedick
Date: 2020-07-21 04:13:09 +0200 (Tue, 21 Jul 2020)
New Revision: 570
Added:
pkg/CHNOSZ/R/flatten.R
pkg/CHNOSZ/man/flatten.Rd
Removed:
pkg/CHNOSZ/R/combine.R
pkg/CHNOSZ/man/combine.Rd
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/NAMESPACE
pkg/CHNOSZ/inst/NEWS.Rd
pkg/CHNOSZ/vignettes/mklinks.sh
pkg/CHNOSZ/vignettes/multi-metal.Rmd
Log:
Rename combine() to flatten()
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2020-07-21 01:42:22 UTC (rev 569)
+++ pkg/CHNOSZ/DESCRIPTION 2020-07-21 02:13:09 UTC (rev 570)
@@ -1,6 +1,6 @@
Date: 2020-07-21
Package: CHNOSZ
-Version: 1.3.6-43
+Version: 1.3.6-44
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/NAMESPACE
===================================================================
--- pkg/CHNOSZ/NAMESPACE 2020-07-21 01:42:22 UTC (rev 569)
+++ pkg/CHNOSZ/NAMESPACE 2020-07-21 02:13:09 UTC (rev 570)
@@ -59,7 +59,7 @@
"CHNOSZ", "thermo", "reset", "OBIGT", "retrieve", "AkDi", "moles",
"lNaCl", "lS", "lT", "lP", "lTP", "lex",
# added 20200716 or later
- "duplex", "combine"
+ "duplex", "flatten"
)
# Load shared objects
Deleted: pkg/CHNOSZ/R/combine.R
===================================================================
--- pkg/CHNOSZ/R/combine.R 2020-07-21 01:42:22 UTC (rev 569)
+++ pkg/CHNOSZ/R/combine.R 2020-07-21 02:13:09 UTC (rev 570)
@@ -1,138 +0,0 @@
-# CHNOSZ/duplex.R
-# Combine diagrams for two metals
-# 20200713 first version jmd
-
-# Function to combine two diagrams (simple overlay, no interaction) 20200717
-# -- makes new "species" from all combinations of those in d1 and d2
-combine <- function(d1, d2) {
- check_d1_d2(d1, d2)
-
- # Index all combinations of species in d1 and d2
- i1 <- 1:nrow(d1$species)
- i2 <- 1:nrow(d2$species)
- combs <- expand.grid(i1, i2)
-
- # Get species rows for each combination
- s1 <- d1$species[combs[, 1], ]
- s2 <- d2$species[combs[, 2], ]
- # Make a new species data frame
- nbasis <- nrow(d1$basis)
- species <- s1[, 1:nbasis] + s2[, 1:nbasis]
- ispecies <- paste(s1$ispecies, s2$ispecies, sep = ",")
- logact <- paste(s1$logact, s2$logact, sep = ",")
- state <- paste(s1$state, s2$state, sep = ",")
- # Use names from diagram()
- if(is.expression(d1$names) & is.expression(d2$names)) {
- name <- lapply(1:nrow(combs), function(i) bquote(.(d1$names[[combs[i, 1]]])+.(d2$names[[combs[i, 2]]])))
- name <- unlist(lapply(name, deparse, width.cutoff = 500, control = NULL))
- } else if(is.expression(d1$names)) {
- name <- lapply(1:nrow(combs), function(i) bquote(.(d1$names[[combs[i, 1]]])+.(d2$names[combs[i, 2]])))
- name <- unlist(lapply(name, deparse, width.cutoff = 500, control = NULL))
- } else if(is.expression(d2$names)) {
- name <- lapply(1:nrow(combs), function(i) bquote(.(d1$names[combs[i, 1]])+.(d2$names[[combs[i, 2]]])))
- name <- unlist(lapply(name, deparse, width.cutoff = 500, control = NULL))
- } else name <- paste(d1$names[combs[, 1]], d2$names[combs[, 2]], sep="+")
- if(length(name) != nrow(combs)) stop("deparse()-ing expressions gives unequal length; try diagram(., format.names = FALSE)")
- species <- cbind(species, ispecies, logact, state, name)
-
- # Get affinities for each combination
- v1 <- d1$values[combs[, 1]]
- v2 <- d2$values[combs[, 2]]
- values <- Map("+", v1, v2)
- # Assign -Inf affinity where a species isn't predominant
- for(i in seq_along(values)) {
- i1 <- combs[i, 1]
- i2 <- combs[i, 2]
- ip1 <- d1$predominant == i1
- ip2 <- d2$predominant == i2
- ip12 <- ip1 & ip2
- values[[i]][!ip12] <- -Inf
- }
-
- # Use d1 as a template for the new affinity object
- anew <- d1[1:11]
- # Insert combined results
- anew$species <- species
- anew$values <- values
- # We don't have sout (results from subcrt()) for the combined "species"
- anew$sout <- NULL
- anew
-}
-
-# Function to make a new "affinity" object from two diagrams 20200713
-# -- uses *secondary* balancing coefficients to combine the diagrams
-duplex <- function(d1, d2, balance = NULL) {
- check_d1_d2(d1, d2)
-
- # Combine the species data frames
- species <- rbind(d1$species, d2$species)
- # Combine the sout objects (results from subcrt())
- only2 <- !d2$sout$species$ispecies %in% d1$sout$species$ispecies
- sout <- d1$sout
- sout$species <- rbind(sout$species, d2$sout$species[only2, ])
- sout$out <- c(sout$out, d2$sout$out[only2])
- # Combine the affinity values divided by the *primary*
- # balancing coefficients ("plotvals" from diagram())
- values <- c(d1$plotvals, d2$plotvals)
-
- # Use d1 as a template for the new affinity object
- anew <- d1[1:11]
- # Insert combined results
- anew$species <- species
- anew$sout <- sout
- anew$values <- values
-
- # Figure out the *secondary* balancing coefficients
- n.balance <- balance(anew, balance = balance)$n.balance
- # In the Fe-Cu-S-O-H example all the coefficients on H+ are negative
- if(all(n.balance < 0)) n.balance <- -n.balance
- n1 <- nrow(d1$species)
- n.balance.1 <- n.balance[1:n1]
- n.balance.2 <- n.balance[(n1+1):length(n.balance)]
-
- # Make empty matrices to hold affinities and balancing coefficients
- a1 <- d1$values[[1]]
- a1[] <- NA
- b2 <- a2 <- b1 <- a1
- # Get the affinities (per mole of species, not divided by any balancing coefficients)
- # and the secondary balancing coefficients for the predominant species in each diagram
- p1 <- d1$predominant
- for(ip in unique(as.vector(p1))) {
- a1[p1 == ip] <- d1$values[[ip]][p1 == ip]
- b1[p1 == ip] <- n.balance.1[ip]
- }
- p2 <- d2$predominant
- for(ip in unique(as.vector(p2))) {
- a2[p2 == ip] <- d2$values[[ip]][p2 == ip]
- b2[p2 == ip] <- n.balance.2[ip]
- }
- # Divide the affinities by the secondary balancing coefficients
- ab1 <- a1 / b1
- ab2 <- a2 / b2
- # Identify the species with the highest affinity (predominant in the *secondary* reactions)
- i1 <- ab1 > ab2
- # Suppress non-predominant species at each grid point
- for(i in 1:n1) anew$values[[i]][!i1] <- -Inf
- for(i in (n1+1):length(n.balance)) anew$values[[i]][i1] <- -Inf
-
- anew
-
-}
-
-### unexported function ###
-
-# Check that d1 and d2 can be combined
-# Extracted from duplex() 20200717
-check_d1_d2 <- function(d1, d2) {
- # Check that the basis species are the same
- if(!identical(d1$basis, d2$basis)) stop("basis species in objects 'd1' and 'd2' are not identical")
- # Check that the variables and their values are the same
- if(!identical(d1$vars, d2$vars)) stop("variable names in objects 'd1' and 'd2' are not identical")
- if(!identical(d1$vals, d2$vals)) stop("variable values in objects 'd1' and 'd2' are not identical")
- # Check that T and P are the same
- if(!identical(d1$T, d2$T)) stop("temperatures in objects 'd1' and 'd2' are not identical")
- if(!identical(d1$P, d2$P)) stop("pressures in objects 'd1' and 'd2' are not identical")
- # Check that we have plotvals and predominant (from diagram())
- if(is.null(d1$plotvals) | is.null(d1$predominant)) stop("object 'd1' is missing 'plotvals' or 'predominant' components (not made by diagram()?)")
- if(is.null(d2$plotvals) | is.null(d2$predominant)) stop("object 'd2' is missing 'plotvals' or 'predominant' components (not made by diagram()?)")
-}
Copied: pkg/CHNOSZ/R/flatten.R (from rev 569, pkg/CHNOSZ/R/combine.R)
===================================================================
--- pkg/CHNOSZ/R/flatten.R (rev 0)
+++ pkg/CHNOSZ/R/flatten.R 2020-07-21 02:13:09 UTC (rev 570)
@@ -0,0 +1,138 @@
+# CHNOSZ/flatten.R
+# Combine diagrams for two metals
+# 20200713 first version jmd
+
+# Function to combine two diagrams (simple overlay, no interaction) 20200717
+# -- makes new "species" from all combinations of those in d1 and d2
+flatten <- function(d1, d2) {
+ check_d1_d2(d1, d2)
+
+ # Index all combinations of species in d1 and d2
+ i1 <- 1:nrow(d1$species)
+ i2 <- 1:nrow(d2$species)
+ combs <- expand.grid(i1, i2)
+
+ # Get species rows for each combination
+ s1 <- d1$species[combs[, 1], ]
+ s2 <- d2$species[combs[, 2], ]
+ # Make a new species data frame
+ nbasis <- nrow(d1$basis)
+ species <- s1[, 1:nbasis] + s2[, 1:nbasis]
+ ispecies <- paste(s1$ispecies, s2$ispecies, sep = ",")
+ logact <- paste(s1$logact, s2$logact, sep = ",")
+ state <- paste(s1$state, s2$state, sep = ",")
+ # Use names from diagram()
+ if(is.expression(d1$names) & is.expression(d2$names)) {
+ name <- lapply(1:nrow(combs), function(i) bquote(.(d1$names[[combs[i, 1]]])+.(d2$names[[combs[i, 2]]])))
+ name <- unlist(lapply(name, deparse, width.cutoff = 500, control = NULL))
+ } else if(is.expression(d1$names)) {
+ name <- lapply(1:nrow(combs), function(i) bquote(.(d1$names[[combs[i, 1]]])+.(d2$names[combs[i, 2]])))
+ name <- unlist(lapply(name, deparse, width.cutoff = 500, control = NULL))
+ } else if(is.expression(d2$names)) {
+ name <- lapply(1:nrow(combs), function(i) bquote(.(d1$names[combs[i, 1]])+.(d2$names[[combs[i, 2]]])))
+ name <- unlist(lapply(name, deparse, width.cutoff = 500, control = NULL))
+ } else name <- paste(d1$names[combs[, 1]], d2$names[combs[, 2]], sep="+")
+ if(length(name) != nrow(combs)) stop("deparse()-ing expressions gives unequal length; try diagram(., format.names = FALSE)")
+ species <- cbind(species, ispecies, logact, state, name)
+
+ # Get affinities for each combination
+ v1 <- d1$values[combs[, 1]]
+ v2 <- d2$values[combs[, 2]]
+ values <- Map("+", v1, v2)
+ # Assign -Inf affinity where a species isn't predominant
+ for(i in seq_along(values)) {
+ i1 <- combs[i, 1]
+ i2 <- combs[i, 2]
+ ip1 <- d1$predominant == i1
+ ip2 <- d2$predominant == i2
+ ip12 <- ip1 & ip2
+ values[[i]][!ip12] <- -Inf
+ }
+
+ # Use d1 as a template for the new affinity object
+ anew <- d1[1:11]
+ # Insert combined results
+ anew$species <- species
+ anew$values <- values
+ # We don't have sout (results from subcrt()) for the combined "species"
+ anew$sout <- NULL
+ anew
+}
+
+# Function to make a new "affinity" object from two diagrams 20200713
+# -- uses *secondary* balancing coefficients to combine the diagrams
+duplex <- function(d1, d2, balance = NULL) {
+ check_d1_d2(d1, d2)
+
+ # Combine the species data frames
+ species <- rbind(d1$species, d2$species)
+ # Combine the sout objects (results from subcrt())
+ only2 <- !d2$sout$species$ispecies %in% d1$sout$species$ispecies
+ sout <- d1$sout
+ sout$species <- rbind(sout$species, d2$sout$species[only2, ])
+ sout$out <- c(sout$out, d2$sout$out[only2])
+ # Combine the affinity values divided by the *primary*
+ # balancing coefficients ("plotvals" from diagram())
+ values <- c(d1$plotvals, d2$plotvals)
+
+ # Use d1 as a template for the new affinity object
+ anew <- d1[1:11]
+ # Insert combined results
+ anew$species <- species
+ anew$sout <- sout
+ anew$values <- values
+
+ # Figure out the *secondary* balancing coefficients
+ n.balance <- balance(anew, balance = balance)$n.balance
+ # In the Fe-Cu-S-O-H example all the coefficients on H+ are negative
+ if(all(n.balance < 0)) n.balance <- -n.balance
+ n1 <- nrow(d1$species)
+ n.balance.1 <- n.balance[1:n1]
+ n.balance.2 <- n.balance[(n1+1):length(n.balance)]
+
+ # Make empty matrices to hold affinities and balancing coefficients
+ a1 <- d1$values[[1]]
+ a1[] <- NA
+ b2 <- a2 <- b1 <- a1
+ # Get the affinities (per mole of species, not divided by any balancing coefficients)
+ # and the secondary balancing coefficients for the predominant species in each diagram
+ p1 <- d1$predominant
+ for(ip in unique(as.vector(p1))) {
+ a1[p1 == ip] <- d1$values[[ip]][p1 == ip]
+ b1[p1 == ip] <- n.balance.1[ip]
+ }
+ p2 <- d2$predominant
+ for(ip in unique(as.vector(p2))) {
+ a2[p2 == ip] <- d2$values[[ip]][p2 == ip]
+ b2[p2 == ip] <- n.balance.2[ip]
+ }
+ # Divide the affinities by the secondary balancing coefficients
+ ab1 <- a1 / b1
+ ab2 <- a2 / b2
+ # Identify the species with the highest affinity (predominant in the *secondary* reactions)
+ i1 <- ab1 > ab2
+ # Suppress non-predominant species at each grid point
+ for(i in 1:n1) anew$values[[i]][!i1] <- -Inf
+ for(i in (n1+1):length(n.balance)) anew$values[[i]][i1] <- -Inf
+
+ anew
+
+}
+
+### unexported function ###
+
+# Check that d1 and d2 can be combined
+# Extracted from duplex() 20200717
+check_d1_d2 <- function(d1, d2) {
+ # Check that the basis species are the same
+ if(!identical(d1$basis, d2$basis)) stop("basis species in objects 'd1' and 'd2' are not identical")
+ # Check that the variables and their values are the same
+ if(!identical(d1$vars, d2$vars)) stop("variable names in objects 'd1' and 'd2' are not identical")
+ if(!identical(d1$vals, d2$vals)) stop("variable values in objects 'd1' and 'd2' are not identical")
+ # Check that T and P are the same
+ if(!identical(d1$T, d2$T)) stop("temperatures in objects 'd1' and 'd2' are not identical")
+ if(!identical(d1$P, d2$P)) stop("pressures in objects 'd1' and 'd2' are not identical")
+ # Check that we have plotvals and predominant (from diagram())
+ if(is.null(d1$plotvals) | is.null(d1$predominant)) stop("object 'd1' is missing 'plotvals' or 'predominant' components (not made by diagram()?)")
+ if(is.null(d2$plotvals) | is.null(d2$predominant)) stop("object 'd2' is missing 'plotvals' or 'predominant' components (not made by diagram()?)")
+}
Modified: pkg/CHNOSZ/inst/NEWS.Rd
===================================================================
--- pkg/CHNOSZ/inst/NEWS.Rd 2020-07-21 01:42:22 UTC (rev 569)
+++ pkg/CHNOSZ/inst/NEWS.Rd 2020-07-21 02:13:09 UTC (rev 570)
@@ -48,8 +48,9 @@
\subsection{NEW FEATURES}{
\itemize{
- \item Add function \strong{combine()} for combining diagrams for different
- systems (i.e., simple overlay with labels for species from both systems).
+ \item Add function \strong{flatten()} for combining two diagrams for
+ different systems (i.e., simple overlay with labels for species from both
+ systems).
\item Add function \strong{duplex()} for making a new diagram by secondary
balancing between two systems.
Deleted: pkg/CHNOSZ/man/combine.Rd
===================================================================
--- pkg/CHNOSZ/man/combine.Rd 2020-07-21 01:42:22 UTC (rev 569)
+++ pkg/CHNOSZ/man/combine.Rd 2020-07-21 02:13:09 UTC (rev 570)
@@ -1,74 +0,0 @@
-\encoding{UTF-8}
-\name{combine}
-\alias{combine}
-\alias{duplex}
-\title{Combine Diagrams}
-\description{
- Combine two diagrams for different systems by simple overlay or using a secondary balancing constraint.
-}
-
-\usage{
- combine(d1, d2)
- duplex(d1, d2, balance = NULL)
-}
-
-\arguments{
- \item{d1}{list, output of \code{\link{diagram}} for first system}
- \item{d2}{list, output of \code{diagram} for second system}
- \item{balance}{character or numeric, specification of secondary balancing coefficients}
-}
-
-\details{
-
-These functions both make a new \code{\link{affinity}} object from two diagrams.
-In essence, \code{combine} identifies the intersection of predominance fields for all possible combinations of species (without interaction between the systems), while \code{duplex} creates a new diagram by comparing the affinities of reactions between species in both systems.
-Both functions mask the non-predominant species by assigning them -Inf values of affinity, so the result can be used to make a new diagram that shows the combined system.
-
-\code{combine} makes a simple overlay of two diagrams using new "species" generated from all combinations of those in \code{d1} and \code{d2}.
-The new names are formed from the \code{names} used in the source diagrams; for example if "Cp" and "Py" are predominant minerals at the same position in diagrams 1 and 2, the field for the combined diagram will be labeled "Cp+Py".
-The resulting affinities are simply the sum of affinities of the two species; they are assigned values of -Inf wherever one of the species is not predominant in either of the diagrams.
-
-Diagrams for different systems likely use different \emph{primary} balancing coefficients, such as balancing on different metals.
-\code{duplex} uses \emph{secondary} balancing coefficients, specified acording to \code{balance} (see \code{\link{equilibrate}} for a description of this argument), to determine the reactions between the species in the two systems.
-The affinities of these reactions are then used \emph{only} to identify the predominant species at each grid point.
-The \emph{returned} value of affinity are carried forward from those used to make the source diagrams (\samp{plotvals} in \code{d1} and \code{d2}), and therefore reflect the primary balancing coefficients.
-The returned values are assigned -Inf wherever that species is determined to not predominate according to the secondary balancing.
-
-\code{combine} yields finite values of affinity for only a single species at any grid point, the final diagram can be made with any setting of \code{balance}.
-However, for \code{duplex}, \code{balance} in the final diagram should be set to \samp{1} in order to preserve the primary balancing coefficients.
-
-}
-
-\value{
-A list object with the same structure as the output from \code{\link{affinity}}, so it can be used as input to \code{diagram}.
-}
-
-\seealso{
-A longer example is in the vignette \viglink{multi-metal}.
-}
-
-\examples{\dontshow{opar <- par(no.readonly = TRUE)}
-par(mfrow = c(2, 2))
-# Define basis species with Fe and Cu
-basis(c("Fe+2", "Cu+", "hydrogen sulfide", "oxygen", "H2O", "H+"))
-xlab <- ratlab("Fe+2", "Cu+")
-# Calculate diagram for only Fe-bearing minerals
-species(c("pyrite", "pyrrhotite", "magnetite", "hematite"))
-aFe <- affinity("Fe+2" = c(0, 12), O2 = c(-40, -16), T = 400, P = 2000)
-dFe <- diagram(aFe, xlab = xlab, main = "Fe-S-O-H")
-# Calculate diagram for only Cu-bearing minerals
-species(c("covellite", "chalcocite", "tenorite", "cuprite"))
-aCu <- affinity(aFe) # argument recall
-dCu <- diagram(aCu, xlab = xlab, main = "Cu-S-O-H")
-### combine() diagram
-ac <- combine(dFe, dCu)
-diagram(ac, xlab = xlab, main = "Cu-Fe-S-O-H with combine()")
-### duplex() diagram
-ad <- duplex(dFe, dCu)
-diagram(ad, xlab = xlab, balance = 1, main = "Cu-Fe-S-O-H with duplex()")
-db <- describe.basis(ibasis = 3)
-leg <- lex(lTP(400, 2000), db)
-legend("bottomleft", legend = leg, bty = "n")
-\dontshow{par(opar)}}
-
-\concept{Extended workflow}
Copied: pkg/CHNOSZ/man/flatten.Rd (from rev 569, pkg/CHNOSZ/man/combine.Rd)
===================================================================
--- pkg/CHNOSZ/man/flatten.Rd (rev 0)
+++ pkg/CHNOSZ/man/flatten.Rd 2020-07-21 02:13:09 UTC (rev 570)
@@ -0,0 +1,74 @@
+\encoding{UTF-8}
+\name{flatten}
+\alias{flatten}
+\alias{duplex}
+\title{Combine Diagrams}
+\description{
+ Combine two diagrams for different systems by flattening them or using a secondary balancing constraint.
+}
+
+\usage{
+ flatten(d1, d2)
+ duplex(d1, d2, balance = NULL)
+}
+
+\arguments{
+ \item{d1}{list, output of \code{\link{diagram}} for first system}
+ \item{d2}{list, output of \code{diagram} for second system}
+ \item{balance}{character or numeric, specification of secondary balancing coefficients}
+}
+
+\details{
+
+These functions both make a new \code{\link{affinity}} object from two diagrams.
+\code{flatten} identifies the intersection of predominance fields for all possible combinations of species (without interaction between the systems), while \code{duplex} creates a new diagram by comparing the affinities of reactions between species in both systems.
+Both functions mask the non-predominant species by assigning them -Inf values of affinity, so the result can be used to make a new diagram that shows the combined system.
+
+\code{flatten} makes a simple overlay of two diagrams using new "species" generated from all combinations of those in \code{d1} and \code{d2}.
+The new names are formed from the \code{names} used in the source diagrams; for example if "Cp" and "Py" are predominant minerals at the same position in diagrams 1 and 2, the field for the flattened diagram will be labeled "Cp+Py".
+The resulting affinities are simply the sum of affinities of the two species; they are assigned values of -Inf wherever one of the species is not predominant in either of the diagrams.
+
+Diagrams for different systems likely use different \emph{primary} balancing coefficients, such as balancing on different metals.
+\code{duplex} uses \emph{secondary} balancing coefficients, specified acording to \code{balance} (see \code{\link{equilibrate}} for a description of this argument), to determine the reactions between the species in the two systems.
+The affinities of these reactions are then used \emph{only} to identify the predominant species at each grid point.
+The \emph{returned} value of affinity are carried forward from those used to make the source diagrams (\samp{plotvals} in \code{d1} and \code{d2}), and therefore reflect the primary balancing coefficients.
+The returned values are assigned -Inf wherever that species is determined to not predominate according to the secondary balancing.
+
+Because \code{flatten} yields finite values of affinity for only a single species at any grid point, the final diagram can be made with any setting of \code{balance}.
+However, for \code{duplex}, \code{balance} in the final diagram should be set to \samp{1} in order to preserve the primary balancing coefficients.
+
+}
+
+\value{
+A list object with the same structure as the output from \code{\link{affinity}}, so it can be used as input to \code{diagram}.
+}
+
+\seealso{
+A longer example is in the vignette \viglink{multi-metal}.
+}
+
+\examples{\dontshow{opar <- par(no.readonly = TRUE)}
+par(mfrow = c(2, 2))
+# Define basis species with Fe and Cu
+basis(c("Fe+2", "Cu+", "hydrogen sulfide", "oxygen", "H2O", "H+"))
+xlab <- ratlab("Fe+2", "Cu+")
+# Calculate diagram for only Fe-bearing minerals
+species(c("pyrite", "pyrrhotite", "magnetite", "hematite"))
+aFe <- affinity("Fe+2" = c(0, 12), O2 = c(-40, -16), T = 400, P = 2000)
+dFe <- diagram(aFe, xlab = xlab, main = "Fe-S-O-H")
+# Calculate diagram for only Cu-bearing minerals
+species(c("covellite", "chalcocite", "tenorite", "cuprite"))
+aCu <- affinity(aFe) # argument recall
+dCu <- diagram(aCu, xlab = xlab, main = "Cu-S-O-H")
+### flatten() diagram
+ac <- flatten(dFe, dCu)
+diagram(ac, xlab = xlab, main = "Cu-Fe-S-O-H with flatten()")
+### duplex() diagram
+ad <- duplex(dFe, dCu)
+diagram(ad, xlab = xlab, balance = 1, main = "Cu-Fe-S-O-H with duplex()")
+db <- describe.basis(ibasis = 3)
+leg <- lex(lTP(400, 2000), db)
+legend("bottomleft", legend = leg, bty = "n")
+\dontshow{par(opar)}}
+
+\concept{Extended workflow}
Modified: pkg/CHNOSZ/vignettes/mklinks.sh
===================================================================
--- pkg/CHNOSZ/vignettes/mklinks.sh 2020-07-21 01:42:22 UTC (rev 569)
+++ pkg/CHNOSZ/vignettes/mklinks.sh 2020-07-21 02:13:09 UTC (rev 570)
@@ -110,9 +110,9 @@
# add links to multi-metal.html 20200716
sed -i 's/affinity()/<a href="..\/html\/affinity.html">affinity()<\/a>/g' multi-metal.html
-sed -i 's/combine()/<a href="..\/html\/combine.html">combine()<\/a>/g' multi-metal.html
+sed -i 's/flatten()/<a href="..\/html\/flatten.html">flatten()<\/a>/g' multi-metal.html
sed -i 's/diagram()/<a href="..\/html\/diagram.html">diagram()<\/a>/g' multi-metal.html
sed -i 's/mosaic()/<a href="..\/html\/mosaic.html">mosaic()<\/a>/g' multi-metal.html
sed -i 's/equilibrate()/<a href="..\/html\/equilibrate.html">equilibrate()<\/a>/g' multi-metal.html
-sed -i 's/duplex()/<a href="..\/html\/combine.html">duplex()<\/a>/g' multi-metal.html
+sed -i 's/duplex()/<a href="..\/html\/flatten.html">duplex()<\/a>/g' multi-metal.html
sed -i 's/ratlab()/<a href="..\/html\/util.expression.html">ratlab()<\/a>/g' multi-metal.html
Modified: pkg/CHNOSZ/vignettes/multi-metal.Rmd
===================================================================
--- pkg/CHNOSZ/vignettes/multi-metal.Rmd 2020-07-21 01:42:22 UTC (rev 569)
+++ pkg/CHNOSZ/vignettes/multi-metal.Rmd 2020-07-21 02:13:09 UTC (rev 570)
@@ -74,11 +74,11 @@
Basic diagrams in CHNOSZ are made for reactions that are *balanced on an element* (see [Equilibrium in CHNOSZ](equilibrium.html)) and therefore represent minerals or aqueous species that all have one element, often a metal, in common.
The package documentation has many examples of diagrams for a single metal appearing in different minerals or complexed with different ligands, but a common request is to make diagrams for multiple metals.
This vignette describes some methods for constructing diagrams for multi-metal minerals and other multi-element systems.
-The methods are **simple overlay**, **mosaic series**, and **secondary balancing**.
+The methods are **flattening**, **mosaic series**, and **secondary balancing**.
-## Simple Overlay
+## Flattening
-Simple overlay refers to independent calculations for two different systems that are displayed on the same diagram.
+Flattening or simple overlay refers to independent calculations for two different systems that are displayed on the same diagram.
Although it is easy to make such a diagram, there is no interaction between the systems.
This example starts with a log*f*~O<sub>2</sub>~--pH base diagram for the C-O-H system then overlays a diagram for S-O-H.
@@ -86,7 +86,7 @@
This allows calculations to be run at the same conditions for a different system.
This feature is also used in other examples in this vignette.
-```{r overlay, echo = 1:8, eval = FALSE}
+```{r flatten, echo = 1:8, eval = FALSE}
par(mfrow = c(1, 2))
basis("CHNOS+")
species(c("CH4", "CO2", "HCO3-", "CO3-2"))
@@ -95,14 +95,14 @@
species(c("H2S", "HS-", "HSO4-", "SO4-2"))
aS <- affinity(aC) # argument recall
dS <- diagram(aS, add = TRUE, col = 4, col.names = 4)
-aCS <- combine(dC, dS)
+aCS <- flatten(dC, dS)
diagram(aCS)
legend("topright", legend = lTP(25, 1))
```
-The second diagram is just like the first, except the function `combine()` is used to label the fields with names of species from both systems and we add a legend to indicate the temperature and pressure.
+The second diagram is just like the first, except the function `flatten()` is used to label the fields with names of species from both systems, and a legend is added to indicate the temperature and pressure.
-```{r overlay, echo = 9:11, results = "hide", message = FALSE, fig.width = 10, fig.height = 5, out.width = "100%"}
+```{r flatten, echo = 9:11, results = "hide", message = FALSE, fig.width = 10, fig.height = 5, out.width = "100%"}
```
Note that these are predominance diagrams, so they show only the species with highest activity; there is in fact a distribution of activities of aqueous species that is not visible here.
@@ -176,7 +176,7 @@
## Mosaic Series 2
-The results of a mosaic series can also processed with `combine()` to label each region with the minerals from both systems.
+The results of a mosaic series can also processed with `flatten()` to label each region with the minerals from both systems.
For this example, the speciation of aqueous sulfur is not considered.
```{r series2, results = "hide", message = FALSE, fig.width = 6, fig.height = 4, out.width = "100%", pngquant = pngquant}
@@ -194,8 +194,8 @@
T = 125, predominant = list(dFe$predominant))
abbrv <- info(species()$ispecies)$abbrv
dCu <- diagram(mCu$A.species, names = abbrv)
-# Combine the diagrams and adjust labels
-aFeCu <- combine(dFe, dCu)
+# Flatten the diagrams and adjust labels
+aFeCu <- flatten(dFe, dCu)
names <- aFeCu$species$name
srt <- rep(0, length(names))
srt[names %in% c("Mt+Cu", "Hm+Cu")] <- 90
@@ -289,11 +289,11 @@
```
Now comes the secondary balancing, where all reactions, not only that between bornite and chalcopyrite, are balanced on H^+^.
-We first combine the affinities for the Fe- or Cu-bearing minerals to make diagram D.
+We first duplex the diagrams for the Fe- or Cu-bearing minerals to make diagram D.
Note that after secondary balancing with `duplex()`, the argument `balance = 1` should be used in `diagram()` to prevent further balancing.
This is because `duplex()` preserves the primary balancing for Fe- and Cu-bearing minerals (internally the "plotvals" components of `dFe` and `dCu`).
-Then we combine diagrams D and C to make the final diagram in E.
+Then we duplex diagrams D and C to make the final diagram in E.
The fields in this diagram are labeled with mineral abbreviations from the OBIGT database.
```{r duplex, eval = FALSE, echo = 33:43}
```
More information about the CHNOSZ-commits
mailing list