{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Converting conditions and pH scales\n", "\n", "*Based on **CO2SYSExample2.m** for MATLAB by Steven van Heuven.*\n", "\n", "A sample is measured in the lab to have a pH of 7.8 on the Total scale at 25 °C under atmospheric pressure.\n", "\n", "What would its pH have been in situ in the ocean: at 2 °C and 4000 dbar pressure (roughly 4000 m depth) on the Seawater scale?\n", "\n", "Additional properties:\n", "\n", " * Alkalinity = 2400 μmol/kg\n", " * Salinity = 35\n", " * Total silicate = 50 μmol/kg\n", " * Total phosphate = 50 μmol/kg\n", " \n", "## Define conditions\n", "\n", "The first step is to define the input and output conditions that we want to use with PyCO2SYS. In this case, we only need a single value for every variable:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Conditions have been defined!\n" ] } ], "source": [ "# Define input and output conditions\n", "kwargs = dict(\n", " par1_type = 1, # The first parameter supplied is of type \"1\", which means \"alkalinity\"\n", " par1 = 2400, # value of the first parameter\n", " par2_type = 3, # The second parameter supplied is of type \"3\", which means \"pH\"\n", " par2 = 7.8, # value of the second parameter\n", " salinity = 35, # Salinity of the sample\n", " temperature = 25, # Temperature at input conditions\n", " temperature_out = 2, # Temperature at output conditions\n", " pressure = 0, # Pressure at input conditions\n", " pressure_out = 4000, # Pressure at output conditions\n", " total_silicate = 50, # Concentration of silicate in the sample (in umol/kg)\n", " total_phosphate = 2, # Concentration of phosphate in the sample (in umol/kg)\n", " opt_pH_scale = 1, # pH scale at which the input pH is reported (\"1\" means \"Total Scale\")\n", " opt_k_carbonic = 4, # Choice of H2CO3 and HCO3- dissociation constants K1 and K2 (\"4\" means \"Mehrbach refit\")\n", " opt_k_bisulfate = 1, # Choice of HSO4- dissociation constant KSO4 (\"1\" means \"Dickson\")\n", " opt_total_borate = 1, # Choice of boron:sal (\"1\" means \"Uppstrom\")\n", ")\n", "print('Conditions have been defined!')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Run PyCO2SYS\n", "\n", "Next, we run PyCO2SYS to solve the marine carbonate system under the input and output conditions and calculate related variables:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The in situ pH on the Seawater scale was: 7.990\n" ] } ], "source": [ "# Import PyCO2SYS\n", "import PyCO2SYS as pyco2\n", "\n", "# Run PyCO2SYS\n", "results = pyco2.sys(**kwargs)\n", "\n", "# Extract and print out the result\n", "pH_insitu_SWS = results['pH_sws_out']\n", "print('The in situ pH on the Seawater scale was: {:.3f}'.format(pH_insitu_SWS))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "See [the documentation](https://pyco2sys.readthedocs.io/en/latest/co2sys_nd/) for more detailed information about the arguments and results of PyCO2SYS." ] } ], "metadata": { "@webio": { "lastCommId": null, "lastKernelId": null }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.4" } }, "nbformat": 4, "nbformat_minor": 4 }