Thursday, 14 July 2016

What have we been working on?

Mikulov - a lovely town in southern Moravia

Sampling local production in Mikulov

GCDkit is a permanent work in progress, and lots of things evolve! In May 2016, we (Vojtech and Jeff) met for a week in Moravia, locked ourselves in a room and coded from morning to evening. A pity considering the touristic resources, and the view from our room (rest assured that we did sample some of the better options however), but a huge success in terms of writing code!

So, here is a quick list of what we've been up to: you may regard it as a list of features that will be included in GCDkit, sooner or latter (to be honest, latter is more likely than sooner).

Interfaces and connections

  • We spent some effort towards making GCDkit truly platform independent. As we all know, GCDkit so far is a purely Windows-specific application; this is largely (only) due to the choice of using Windows-specific menu and interface functions (the menus that appear at the top of the R console). With help and incentive from some correspondents (Jesse Reimink, then at U. Alberta and now at DTM), we worked hard to make GCDkit usable under other systems. To some point, this can now be done. Jesse had GCDkit running under MacOS, and we had it functional in Linux (well, in an emulator). Of course, you should not expect it to be perfectly stable, and probably not 100% functional either. And obviously the menu system is missing; you have to run it purely from command line. Still, it works and it may be included in the distributed version in the not-so-far future.

GCDkit Development in Linux (Ubuntu)

  • As soon as GCDkit will become (mostly) platform independent and (mostly) usable without the Windows R GUI, nothing should theoretically stop us (or you) from developing other user interfaces. We explored the possibility, for instance, to run a Python application that would call R/GCDkit. Don't hold your breath, though.
  • An additional benefit of a Python/R connection is that QGIS -- the main open source alternative for GIS -- supports Python plugins. There is therefore a long-term possibility for calling a fully interactive GCDkit session from QGIS, and therefore do GCDkit processing on geographic data.
  • A simpler aternative is to use QGIS processing toolbox. As a proof of concept we managed, for instance, to load a shapefile (a geographic layer containing points with analyses) into GCDkit, calculate a CIPW norm, and return another geographic layer containing the normative values that you may then use in normal GIS way (for instance colour by proportion of a normative mineral, etc).

Running a GCDkit "geo-algorithm" from QGIS.


One of our main goals was to work on the long overdue modelling code. After several false starts, we had something to show during the last workshop in Krakow. This time, we totally overhauled the code, and now wrote something we believe is a rather flexible and powerful framework. From a user perspective, you'll be able to do something like that (don't try it on your system, it is not distributed, and it is very likely to change anyway!):

######## Direct melting of an avg Archaean basalt

# Define the mineral proportions
min.props.mod1<-c(0.6,0.4) # sum must be = 1

# Calculate the model
mod1<-pmDirectBatch(c0.lab="avg Arch basalt",min.prop=min.props.mod1,ff=0.7,"mins",mjr.set=mjrs,"kds",trc.set=trcs)

# Add more info (calculating every 0.1 here)
petroCalc(mod1,0.1) # Calculate every 0.1

# Extract the data for plotting

# Prepare a plot (just the real data)

# Add the model curve
Under the hood, we have defined a "PetroModel" class that stores all the information on a model, and several functions to calculate it. With such an object-oriented approach, the nice thing is that we can very easily expand the possibilities. Since we defined the "overplot" function for the main class for instance, we need no additional work to plot a model curve on a graph -- and this will remain true for direct or reverse models, or even for more complex ones including accessories saturation, variable D values, etc., should we decide to include these at some point.

There is no user interface so far, and no real plans to develop one. At the moment one has to resort to the command line and type the functions in, but it is not so difficult. Eventually, we will think of something perhaps using Python (cf. above), or Shiny.

Again, this is not released. It is our next main goal, but will take a bit more time to polish and package (and probably publish !).

Phase equilibria

During the Prague Goldschmidt conference last year, we presented an abstract demonstrating how we could read a PERPLE_X output and further process it to calculate trace elements compositions in the melt. Actually, this is a long standing idea (I [Jeff] started working on it using a monster of an Excel spreadsheet back in 2005, and we started writing this code during a chilly spring in Southern France in 2013). We did spend some work on that, too, tweaking and fixing the code once more (this nasty monazite saturation routine...), and thinking about a publication -- you're not likely to see this code soon and certainly not before we publish.

And more...

Well, we also spent some time discussing grant applications for funding our efforts, and celebrating the success of "ouR" book... We also considered plans to link our work with the very nice job done by Matt Mayne on something called RCrust. And, indeed, we enjoyed a lovely walk in the woods around Valtice.

Book Review

ou"R" book has been reviewed by H. Rollinson, who wrote this essentially nice piece in "Elements". We are very grateful for the positive feedback !

Tuesday, 12 July 2016

Troubles with Windows 10

We have been recently flooded by  email reports of those of you who could not start the GCDkit installer on Windows 10. Strangely, the other versions of the system seem unaffected. We have examined the problem and, as it seems, it consists in the sudden change in security policy of Microsoft, requiring all installation programs to have a valid security certificate.

While we are working on the remedy, the only way on Win 10 seems to use the "advanced" setup taking advantage of the R library mechanism.  
There is no need to be afraid of this,  The procedure is as follows:
  • download and install the R 3.2.1 for Windows
  • download the library
  • run the R console in a SDI mode
  • install the library from the R console (Menu Packages > Install package(s) from local zip files...)
  • install the R2HTML, RODBC and sp libraries (Menu Packages > Install package(s)...) [working Internet connection is required]
  • load the GCDkit library (Menu Packages > Load package > GCDkit or type library(GCDkit) into the R Console)
The last step is to be repeated every time you start R GUI a new. 

Alternatively, you can make an shortcut at your Desktop with a text similar to mine (do take care of the correct path):

C:\R\R-3.2.1\bin\i386\Rgui.exe --silent --no-save --sdi

Setting the directory to that with R libraries. In my case it is:


I hope that this will help. Please let us know if there are any further problems. 


Tuesday, 23 February 2016

What is new in GCDkit 4.1 (Chlopskie jadlo)?

On 10 February has been released a new version of GCDkit. Apart from numerous bug fixes, and a great deal of editing to enable running the GCDkit scripts in a batch mode, it brings several new features. Arguably the most interesting include: 
Switching between datasets
  • Datasets can be stored using the function pokeDataset. Or it is done automatically, like for data freshly loaded into the system using the functions loadData and accessVar. Technically they always become components of a list WRCube.
  • Later, the previous datasets can be restored by functions peekDataset or selectDataset.
  • The WRCube can be cleared anytime using the function purgeDatasets; only the most recent copy of the current dataset survives this operation.
  • Function selectAll has been completely rewritten using the dataset switching, i.e. backup copy of data  stored in the WRCube. Variables WR.bak,WRanh.bak,milli.bak and labels.bak are thus not needed anymore.
  • New function figOverplot allows overplotting a reference dataset onto any Figaro-compatible binary plots, ternary plots, or spiderplots. The reference dataset, stored in an arbitrary global variable, can contain either real-world data or a numeric matrix  spanning from petrogenetic modelling.
Futher important changes
  • figCex, plateCex accept now the value NA (no quotes) that means no plotting  of symbols (most useful on spiderplots if only lines are desired).
  • figAddReservoirs checked and reprogrammed; it newly does work for ternary plots,  and is Figaro-compatible for binaries, ternaries and spiders. It also includes a lot of new arguments, mainly plotting parameters.
  • New functions oxide2ppm and ppm2oxide to recast wt.% of the given oxide to ppm of cations
  • Platform-independent functions tk_winDialog and tk_winDialogString written in Tcl/Tk.
  • calcCore does not require global variables anymore, but can use also those from the parental environment.
  • accessVar does not utilize Windows clipboard to transfer data into variables WR and labels anymore

We trust that you will find this new release useful and reasonably stable.

Good luck, Vojtech

Monday, 9 November 2015

GCDkit 4.0 (Great October Revolution) just released!

We are pleased to announce that the new stable version of GCDkit has been just released!
Primarily, it is aimed to accompany our freshly published book (see the previous post). Of course, this brought about numerous small changes to the code, especially in the batch mode.

But there also further important improvements, even though many are hiding behind the bonnet.

  •  At last, the package has got its NAMESPACE, which means that it became available for R 3.2 and higher.
  •  Hopefully fixed were the notorious problems with installation pointed out by several users even on this forum. They were apparently occurring when there has been a personal library folder created during the R installation process.  
  • Improved was the help system, which includes a number of illustrative figures now.  
  • Semitransparency of plotting symbols (that can be set through function setTransparency) or fields (e.g., in spiderByGroupFields).Use preferably PDF export to preserve it.
  • New possibility of assigning colours according to values of a variable (assignColVar). 
  • Table of molecular weights from the CIAAW official web site ( has replaced the existing one.  
  • New diagrams:
    • New geotectonic diagrams of Müller et al. (1992) for potassic igneous rocks
    • New Nb/Yb–Th/Yb and Nb/Yb–TiO2 /Yb plots of Pearce (2008) 
  • New plugin:
    • Rutile saturation algorithms of Ryerson & Watson (1987) and Hayden & Watson (2007)
  • File input/output:
    • improved import from GeoRoc, references in the end saved into file, references.txt and shown in a separate window upon load,
    • reading ROC, PEG, CSV files even on 64bit systems,
    • improved merging of files,
    • fixed problems with comments in data files.
  •  Legends:
    • improved appearance of legends, esp. for single colour and/or single plotting symbol,
    • corrected were problems with legends in spider.contour and spiderByGroupFields,
    • fixed were legends in figMulti, in addition their backgrounds became semitransparent.
  •  Calculations:
    • addResults replaces any already existing variables of the given name,
    • printSamples got a new parameter, print=FALSE, that allows to use the function just for calculations, i.e. skipping the printing,
    • millications can be newly calculated from any matrix/vector ,
    • the function groupsByLabel assigns a value (Undefined) to analyses for which the grouping information is missing,
    • calcCore did not work correctly for fractions. For instance, Nb/Ta ratios were Inf for Ta contents that were not determined. This affected scaling of plots etc.,
    • summaryRangesByGroup and strip work correctly even for subsets.
  •  Plotting:
    • new function plateLabelSlots to annotate individual slots by letters, numbers or Roman numerals,
    • binary and plotWithLimits allow linear fits also when some (or both) of the axes is/are logarithmic.
    • contourGroups is more robust now - and works better on datasets with missing values.


Tuesday, 27 October 2015

Book on geochemical modelling of magmatic processes in R/GCDkit

We break the two years of our silence with some news potentially interesting to anyone involved in interpretation of whole-rock geochemical data from igneous rocks. We are pleased to announce that, after two years of intense writing, we have finally published a book:

Janoušek, V., Moyen, J. F., Martin, H., Erban, V. & Farrow, C. M. (2016). Geochemical Modelling of Igneous Processes – Principles and Recipes in R Language. Bringing the Power of R to a Geochemical Community. Springer-Verlag, Berlin, Heidelberg, 346 pp. 

 Abstract from the publisher:
"The aim of this book is to unlock the power of the freeware R language to advanced university students and researchers dealing with whole-rock geochemistry of (meta-) igneous rocks. The first part covers data input/output, calculation of commonly used indexes and plotting in R. The core of the book then focuses on the presentation and practical implementations of modelling techniques used for fingerprinting processes such as partial melting, fractional crystallization, binary mixing or AFC using major-, trace-element and radiogenic isotope data. The reader will be given a firm theoretical basis for forward/reverse modelling, followed by exercises dealing with typical problems likely to be encountered in real life, and their solutions using R. The concluding sections GCDkit for interpretation of whole-rock geochemical data from igneous and metamorphic rocks."
demonstrate, using practical examples, how a researcher can proceed in developing a realistic model simulating natural systems. The appendices outline the fundamentals of the R language and provide a quick introduction to the open-source R-package
In more simple words, this book:
  • Provides basics of R language and its application to geochemical problems,
  • Gives the first comprehensive introduction to the GCDkit system,
  • Explains fundamentals of numerical modelling of igneous processes,
  • Shows not only formulae, but also the successful modelling strategies,
  • Includes numerous worked examples how geochemical modelling helps us to understand geological problems.
And its contents are in the nutshell:

Part I: R/GCDkit at work

  • Loading and Manipulating Data
  • Linking Whole-Rock Chemistry with Mineral Stoichiometry
  • Statistics
  • Classification and Grouping
  • Classical Plots
    (binary, Harker, ternary, spider)
  • Specialized Plots
    (log–log, specialized spiderplots, contour plots, anomaly plots…)
  • Radiogenic Isotopes
    (initial ratios, epsilon values, model ages, isochrons…)

Parts II–IV: Majors, traces, radiogenic isotopes

  • Core of the book; explains fundamentals of each direct and reverse modelling, including the relevant formulae
  • Introduces the numerical solution and its implementation in the R language
  • Includes a number of real numerical problems
  • Each is presented as a numerical receipt with solution in R  (± GCDkit )

Part V: Practical Modelling

  • Choosing an Appropriate Model
    (evidence for crystallization, partial melting, magma mixing and assimilation…)
  • Semi-Quantitative Approach
    (assessing the trace-element compatibility, process identification, mixing test…)
  • Constraining a Model
    (using appropriate strategy, obtaining input parameters for the model, partition coefficients, dealing with accessories…)
  • Numerical Tips and Tricks
    (reducing system, colinearity, breaking minerals to end-members, coupling majors and traces…)
  • Common Sense in Action
    (thermodynamic, rheological  constraints, scale and speed of processes, how well can we distinguish between models, dangerous projections…)

Part VI: Worked Examples

  • Differentiation of a Calc-Alkaline Series: Atacazo-Ninahuilca volcanoes, Ecuador
  • Progressive Melting of a Metasedimentary Sequence: the Saint-Malo Migmatitic Complex, France
  • Appendix A: R Syntax in a Nutshell
  • Appendix B: Introduction to GCDkit
  • Appendix C: Solving Systems of Linear Algebraic Equations in R
Courtesy of the publisher, the Appendices explaining the R syntax and the workings of the GCDkit system, are freely available here.

Sunday, 21 July 2013

Installing GCDkit

Two important point to note – the source of a great many complains :

1) You must install R before installing GCDkit. I repeat – you must install R before GCDkit.

You must install R before GCDkit.

(if you don’t, GCDkit will not start properly and complain about not finding the R Gui file etc.)

(in fact it is possible, but you then need to manually load GCDkit with library(GCDkit), but most regular users will not want to go that route).

2) With the current version of GCDkit (GCDkit 3.0), you must use R2.13.1. Again : you must use R 2.13.1

If you don’t, it’s very likely that GCDkit will not work. Also, note that the current version of R is 2.15.1 at the time of writing; so if you want version 2.13, you will need to look for it on CRAN website.

Sometimes, the simplest information is the most overlooked...