{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# EQ3_Batch user options"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# input\n",
    "input_filename <- \"input_example.csv\"\n",
    "\n",
    "# redox options:\n",
    "redox_flag  <-  0              # -3, -2, -1, 0, or 1 (see EQ3 documentation for more info)\n",
    "redox_aux <- \"Fe+3\"            # ignored unless redox_flag is 1. Input species, e.g. \"Fe+3\"\n",
    "default_logfO2 <- -6           # what is the default logfO2 if a redox value can't be found?\n",
    "\n",
    "# aqueous block options\n",
    "exclude <- c(\"Year\", \"Area\", \"Temperature\")   # which columns in input file to exclude from aqueous block?\n",
    "suppress <- c(\"N2,AQ\", \"CN-\", \"S2-2\",\"N2H5+\",\"N2O2-2\")  # which species to suppress in aqueous block?\n",
    "\n",
    "# charge balance options\n",
    "charge_balance_on <- \"none\"    # \"none\" for no charge balance. Otherwise, \"H+\" or \"Na+\", etc.\n",
    "\n",
    "# EQ3_Batch options\n",
    "suppress_missing <- TRUE       # suppress the formation of an aqueous species if it is missing a value in the input file?\n",
    "verbose <- 1                   # 2 for all messages, 1 for errors or warnings only, 0 for silent\n",
    "csv_filename <- \"input_processed.csv\" # filename of input summary?\n",
    "create_join <- TRUE            # join all forms of output together into one csv?\n",
    "filename_join <- \"final_report.csv\" # name of final joined output\n",
    "\n",
    "# AquaMine options\n",
    "run_AquaMine <- TRUE              # Run AquaMine after EQ3 output files are generated?\n",
    "AM_output_type <- \"log_activity\"  # Can be \"molality\", \"log_molality\", \"log_gamma\", or \"log_activity\"\n",
    "\n",
    "# MineralMine options\n",
    "run_MineralMine <- TRUE           # Run MineralMine after EQ3 output files are generated?\n",
    "MM_output_type <- \"affinity\"      # Can be \"logQoverK\" or \"affinity\"\n",
    "\n",
    "# RedoxMine options\n",
    "run_RedoxMine <- TRUE           # Run RedoxMine after EQ3 output files are generated?\n",
    "RM_output_type <- \"Eh\"      # Can be \"Eh\", \"pe\", \"logfO2\", or \"Ah\"\n",
    "\n",
    "# MiscMine options\n",
    "run_MiscMine <- TRUE      # Run MiscMine after EQ3 output files are generated? Mines ionic strength and charge balance results.\n",
    "\n",
    "#db <- \"tde\" # which thermo database to use? Default is 'jus'."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Create EQ3 input files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1] \"Warning: no 'logfO2' column found. Attempting to find a 'O2,AQ' column to estimate logfO2 at sample temperature and pressure...\"\n",
      "[1] \"Warning: non-numeric O2,AQ value in sample Crater Hills Geyser. Resorting to using Log fO2 (log bars) with a value of -6\"\n",
      "[1] \"Done! Took 1.3 seconds.\"\n"
     ]
    }
   ],
   "source": [
    "source(\"/Users/graysonboyer/Batch_EQ3_demo/scripts/preprocess_for_EQ3.r\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Run EQ3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "calling EQ3 on Ambergris.3i using jus\n",
      "calling EQ3 on Bison.Pool.3i using jus\n",
      "calling EQ3 on Crater.Hills.Geyser.3i using jus\n",
      "calling EQ3 on Gas.Crack.3i using jus\n",
      "calling EQ3 on MLS.Source.3i using jus\n",
      "calling EQ3 on Snail.3i using jus\n",
      "calling EQ3 on Spray.Geyser.Source.3i using jus\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1] \"runEQ3Batch finished! Took 3 seconds.\"\n"
     ]
    }
   ],
   "source": [
    "source(\"/Users/graysonboyer/Batch_EQ3_demo/scripts/runEQ3Batch.r\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Datamine output files (optional)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1] \"AquaMine finished! Took 1.4 seconds.\"\n"
     ]
    }
   ],
   "source": [
    "if(run_AquaMine){source(\"/Users/graysonboyer/Batch_EQ3_demo/scripts/AquaMine.r\")}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1] \"MineralMine finished! Took 0.4 seconds.\"\n"
     ]
    }
   ],
   "source": [
    "if(run_MineralMine){source(\"/Users/graysonboyer/Batch_EQ3_demo/scripts/MineralMine.r\")}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1] \"RedoxMine finished! Took 0.2 seconds.\"\n"
     ]
    }
   ],
   "source": [
    "if(run_RedoxMine){source(\"/Users/graysonboyer/Batch_EQ3_demo/scripts/RedoxMine.r\")}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1] \"MiscMine finished! Took 0.2 seconds.\"\n"
     ]
    }
   ],
   "source": [
    "if(run_MiscMine){source(\"/Users/graysonboyer/Batch_EQ3_demo/scripts/MiscMine.r\")}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1] \"Join finished! Took 0.1 seconds.\"\n"
     ]
    }
   ],
   "source": [
    "if(create_join){source(\"/Users/graysonboyer/Batch_EQ3_demo/scripts/DataJoin.r\")}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>Sample</th><th scope=col>Year_NA</th><th scope=col>Area_</th><th scope=col>H+_pH</th><th scope=col>Temperature_degC</th><th scope=col>HCO3-_Molality</th><th scope=col>O2,AQ_Molality</th><th scope=col>HS-_Molality</th><th scope=col>SiO2,AQ_Molality</th><th scope=col>METHANE,AQ_Molality</th><th scope=col>⋯</th><th scope=col>O2_AQ/H2O</th><th scope=col>IS (molal)</th><th scope=col>stoichiometric IS (molal)</th><th scope=col>Sigma(mz) cations</th><th scope=col>Sigma(mz) anions</th><th scope=col>Total charge</th><th scope=col>Mean charge</th><th scope=col>Charge imbalance</th><th scope=col>%CI of total</th><th scope=col>%CI of mean</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>Bison Pool         </td><td>2014               </td><td>YNP                </td><td>7.640              </td><td>92.2               </td><td>0.005690           </td><td>9.38e-06           </td><td>3.49e-06           </td><td>0.00627            </td><td>0                  </td><td>⋯                  </td><td>0.631              </td><td>0.0139775          </td><td>0.0140618          </td><td>0.01378783         </td><td>-0.01378922        </td><td>0.02757705         </td><td>0.01378853         </td><td>-1.386903e-06      </td><td>-0.0050            </td><td>-0.0101            </td></tr>\n",
       "\t<tr><td>Spray Geyser Source</td><td>2012               </td><td>YNP                </td><td>8.021              </td><td>92.9               </td><td>0.005410           </td><td>3.13e-06           </td><td>3.62e-06           </td><td>0.00503            </td><td>0                  </td><td>⋯                  </td><td>0.594              </td><td>0.0129728          </td><td>0.0130779          </td><td>0.01272892         </td><td>-0.01271861        </td><td>0.02544754         </td><td>0.01272377         </td><td> 1.031011e-05      </td><td> 0.0405            </td><td> 0.0810            </td></tr>\n",
       "\t<tr><td>Crater Hills Geyser</td><td>2012               </td><td>YNP                </td><td>3.327              </td><td>89.0               </td><td>0.000117           </td><td>0.00e+00           </td><td>1.74e-05           </td><td>0.01440            </td><td>0                  </td><td>⋯                  </td><td>   NA              </td><td>0.0375123          </td><td>0.0420697          </td><td>0.03367785         </td><td>-0.03290374        </td><td>0.06658159         </td><td>0.03329079         </td><td> 7.741091e-04      </td><td> 1.1626            </td><td> 2.3253            </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll}\n",
       " Sample & Year\\_NA & Area\\_ & H+\\_pH & Temperature\\_degC & HCO3-\\_Molality & O2,AQ\\_Molality & HS-\\_Molality & SiO2,AQ\\_Molality & METHANE,AQ\\_Molality & ⋯ & O2\\_AQ/H2O & IS (molal) & stoichiometric IS (molal) & Sigma(mz) cations & Sigma(mz) anions & Total charge & Mean charge & Charge imbalance & \\%CI of total & \\%CI of mean\\\\\n",
       "\\hline\n",
       "\t Bison Pool          & 2014                & YNP                 & 7.640               & 92.2                & 0.005690            & 9.38e-06            & 3.49e-06            & 0.00627             & 0                   & ⋯                   & 0.631               & 0.0139775           & 0.0140618           & 0.01378783          & -0.01378922         & 0.02757705          & 0.01378853          & -1.386903e-06       & -0.0050             & -0.0101            \\\\\n",
       "\t Spray Geyser Source & 2012                & YNP                 & 8.021               & 92.9                & 0.005410            & 3.13e-06            & 3.62e-06            & 0.00503             & 0                   & ⋯                   & 0.594               & 0.0129728           & 0.0130779           & 0.01272892          & -0.01271861         & 0.02544754          & 0.01272377          &  1.031011e-05       &  0.0405             &  0.0810            \\\\\n",
       "\t Crater Hills Geyser & 2012                & YNP                 & 3.327               & 89.0                & 0.000117            & 0.00e+00            & 1.74e-05            & 0.01440             & 0                   & ⋯                   &    NA               & 0.0375123           & 0.0420697           & 0.03367785          & -0.03290374         & 0.06658159          & 0.03329079          &  7.741091e-04       &  1.1626             &  2.3253            \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "Sample | Year_NA | Area_ | H+_pH | Temperature_degC | HCO3-_Molality | O2,AQ_Molality | HS-_Molality | SiO2,AQ_Molality | METHANE,AQ_Molality | ⋯ | O2_AQ/H2O | IS (molal) | stoichiometric IS (molal) | Sigma(mz) cations | Sigma(mz) anions | Total charge | Mean charge | Charge imbalance | %CI of total | %CI of mean | \n",
       "|---|---|---|\n",
       "| Bison Pool          | 2014                | YNP                 | 7.640               | 92.2                | 0.005690            | 9.38e-06            | 3.49e-06            | 0.00627             | 0                   | ⋯                   | 0.631               | 0.0139775           | 0.0140618           | 0.01378783          | -0.01378922         | 0.02757705          | 0.01378853          | -1.386903e-06       | -0.0050             | -0.0101             | \n",
       "| Spray Geyser Source | 2012                | YNP                 | 8.021               | 92.9                | 0.005410            | 3.13e-06            | 3.62e-06            | 0.00503             | 0                   | ⋯                   | 0.594               | 0.0129728           | 0.0130779           | 0.01272892          | -0.01271861         | 0.02544754          | 0.01272377          |  1.031011e-05       |  0.0405             |  0.0810             | \n",
       "| Crater Hills Geyser | 2012                | YNP                 | 3.327               | 89.0                | 0.000117            | 0.00e+00            | 1.74e-05            | 0.01440             | 0                   | ⋯                   |    NA               | 0.0375123           | 0.0420697           | 0.03367785          | -0.03290374         | 0.06658159          | 0.03329079          |  7.741091e-04       |  1.1626             |  2.3253             | \n",
       "\n",
       "\n"
      ],
      "text/plain": [
       "  Sample              Year_NA Area_ H+_pH Temperature_degC HCO3-_Molality\n",
       "1 Bison Pool          2014    YNP   7.640 92.2             0.005690      \n",
       "2 Spray Geyser Source 2012    YNP   8.021 92.9             0.005410      \n",
       "3 Crater Hills Geyser 2012    YNP   3.327 89.0             0.000117      \n",
       "  O2,AQ_Molality HS-_Molality SiO2,AQ_Molality METHANE,AQ_Molality ⋯ O2_AQ/H2O\n",
       "1 9.38e-06       3.49e-06     0.00627          0                   ⋯ 0.631    \n",
       "2 3.13e-06       3.62e-06     0.00503          0                   ⋯ 0.594    \n",
       "3 0.00e+00       1.74e-05     0.01440          0                   ⋯    NA    \n",
       "  IS (molal) stoichiometric IS (molal) Sigma(mz) cations Sigma(mz) anions\n",
       "1 0.0139775  0.0140618                 0.01378783        -0.01378922     \n",
       "2 0.0129728  0.0130779                 0.01272892        -0.01271861     \n",
       "3 0.0375123  0.0420697                 0.03367785        -0.03290374     \n",
       "  Total charge Mean charge Charge imbalance %CI of total %CI of mean\n",
       "1 0.02757705   0.01378853  -1.386903e-06    -0.0050      -0.0101    \n",
       "2 0.02544754   0.01272377   1.031011e-05     0.0405       0.0810    \n",
       "3 0.06658159   0.03329079   7.741091e-04     1.1626       2.3253    "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "head(master_df, 3)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "R [conda env:py36andR]",
   "language": "R",
   "name": "conda-env-py36andR-r"
  },
  "language_info": {
   "codemirror_mode": "r",
   "file_extension": ".r",
   "mimetype": "text/x-r-source",
   "name": "R",
   "pygments_lexer": "r",
   "version": "3.3.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}