<img align="left" width="60%" src="http://www.lsce.ipsl.fr/Css/img/banniere_LSCE_75.png" >
LSCE/IPSL, CEA-CNRS-UVSQ, Gif-sur-Yvette, France
Abstract: This notebook shows how to use the new derivnum
add-on of CO2SYS-Matlab to calculate sensitivities, i.e. partial derivatives that express rates changes of computed CO2 system variables (e.g., H+, $p$CO$_2$, $\Omega_A$) per change in the selected input variable (e.g., $A_\text{T}$, $C_\text{T}$, T, S, $K_1$, $K_2$). It uses CO2SYS-Matlab in octave
, GNU's clone of Matlab. One can simply inspect the HTML version of this file or take advantage of being able to execute its commands interactively in your browser. The latter requires jupyter notebook
and its oct2py
add-on that includes the octavemagic
interface for octave
(see below).
If you are visualizing this after clicking on the link to this file on github, you are visualizing the HTML version of a jupyter notebook. Alternatively, you may run cells interactively and modify them if you have jupyter notebook
installed on your machine. To install that software, just download and the anaconda open software installer for your computing platform (Windows, OS X, or Linux) from https://www.continuum.io/downloads and then follow the easy install instructions at
https://docs.continuum.io/anaconda/install#
Then just download this jupyter notebook
file as well as the 3 routines in the src directory (CO2SYS.m
, errors.m
, and derivnum.m
). Afterwards, you'll only need to install octavemagic
, available in the oct2py
package with the 1-line command in the following section.
oct2py
, with the following command at the Unix prompt:conda install -c conda-forge oct2py=3.6.5
Then launch the notebook as usual with the following command:
jupyter notebook
A new window or tab should appear in your browser, showing the files in the directory from where you launched the above command. Then just click on one of the .ipynb
files, such as this one.
One the notebook file appears in your browser, move to any of its cells with your mouse. Run a cell by clicking on it and hitting Ctrl-Return. Alternatively, type Shift-Return to run a cell and then move to the next one. More information on all the interactive commankds is available in the Jupyter Notebook Quick Start Guide: http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/execute.html
At the top of the notebook, you'll see 8 Tabs (File, Edit, View, Insert, ...). Those tabls provide commands that will allow you to do whatever you like. Under the Help tab you'll find keyboard shortcuts for commands. Alternatively, a cheat sheet for short cuts to commands within jupyter notebook
is available at https://zenodo.org/record/44973/files/ipynb-cheat-sheet.pdf . Or use the command palette after typing Ctrl-Shift-P.
Details on using octavemagic are here: https://ipython.org/ipython-doc/2/config/extensions/octavemagic.html
In [1]:
%load_ext oct2py.ipython
In [2]:
%%octave
addpath ("~/Software/MATLAB/CO2SYS-MATLAB/src")
In [3]:
%%octave
# Standard input for CO2SYS:
# --------------------------
# Input Variables:
PAR1 = 2300; % ALK
PAR2 = 2000; % DIC
PAR1TYPE = 1; % 1=ALK, 2=DIC, 3=pH, 4=pCO2, 5=fCO2
PAR2TYPE = 2; % Same 5 choices as PAR1TYPE
SAL = 35; % Salinity
TEMPIN = 18; % Temperature (input)
TEMPOUT = 25; % Temperature (output)
PRESIN = 0; % Pressure (input)
PRESOUT = PRESIN; % Pressure (output)
# SI = 60; % Total dissolved inorganic silicon (Sit)
# PO4 = 2; % Total dissoloved inorganic Phosphorus (Pt)
SI = 0; % Total dissolved inorganic silicon (Sit)
PO4 = 0; % Total dissoloved inorganic Phosphorus (Pt)
# Input Parameters:
pHSCALEIN = 1; % pH scale (1=total, 2=seawater, 3=NBS, 4=Free)
K1K2CONSTANTS = 10; % set for K1 & K2: 10=Lueker et al. (2000); 14=Millero (2010); 15= Waters et al. (2014)
KSO4CONSTANTS = 1; % KSO4 of Dickson (1990a) & Total dissolved boron (Bt) from Uppström (1974)
In [4]:
%%octave
help derivnum
In [5]:
%%octave
[b, bhead, bunits] = derivnum ('par1', PAR1, PAR2, PAR1TYPE, PAR2TYPE, SAL, TEMPIN, TEMPOUT, PRESIN, PRESOUT,...
SI, PO4,...
pHSCALEIN, K1K2CONSTANTS, KSO4CONSTANTS);
# Print (nicely formatted):
printf("%s %s %s %s %s %s %s %s %s \n", bhead{1:9});
printf("%s %s %s %s %s %s %s %s %s \n", bunits{1:9});
printf("%f %f %f %f %f %f %f %f %f \n", b(1:9));
In [6]:
%%octave
[b, bhead, bunits] = derivnum ('par2', PAR1, PAR2, PAR1TYPE, PAR2TYPE, SAL, TEMPIN, TEMPOUT, PRESIN, PRESOUT,...
SI, PO4,...
pHSCALEIN, K1K2CONSTANTS, KSO4CONSTANTS);
# Print (nicely formatted):
printf("%s %s %s %s %s %s %s %s %s \n", bhead{1:9});
printf("%s %s %s %s %s %s %s %s %s \n", bunits{1:9});
printf("%f %f %f %f %f %f %f %f %f \n", b(1:9));
In [7]:
%%octave
[b, bhead, bunits] = derivnum ('T', PAR1, PAR2, PAR1TYPE, PAR2TYPE, SAL, TEMPIN, TEMPOUT, PRESIN, PRESOUT,...
SI, PO4,...
pHSCALEIN, K1K2CONSTANTS, KSO4CONSTANTS);
# Print (nicely formatted):
printf("%s %s %s %s %s %s %s %s %s \n", bhead{1:9});
printf("%s %s %s %s %s %s %s %s %s \n", bunits{1:9});
printf("%f %f %f %f %f %f %f %f %f \n", b(1:9));
In [8]:
%%octave
[b, bhead, bunits] = derivnum ('S', PAR1, PAR2, PAR1TYPE, PAR2TYPE, SAL, TEMPIN, TEMPOUT, PRESIN, PRESOUT,...
SI, PO4,...
pHSCALEIN, K1K2CONSTANTS, KSO4CONSTANTS);
# Print (nicely formatted):
printf("%s %s %s %s %s %s %s %s %s \n", bhead{1:9});
printf("%s %s %s %s %s %s %s %s %s \n", bunits{1:9});
printf("%f %f %f %f %f %f %f %f %f \n", b(1:9));
In [9]:
%%octave
[b, bhead, bunits] = derivnum ('K1', PAR1, PAR2, PAR1TYPE, PAR2TYPE, SAL, TEMPIN, TEMPOUT, PRESIN, PRESOUT,...
SI, PO4,...
pHSCALEIN, K1K2CONSTANTS, KSO4CONSTANTS);
# Print (nicely formatted):
printf("%s %s %s %s %s %s %s %s %s \n", bhead{1:9});
printf("%s %s %s %s %s %s %s %s %s \n", bunits{1:9});
printf("%f %f %f %f %f %f %f %f %f \n", b(1:9));
In [10]:
%%octave
[b, bhead, bunits] = derivnum ('Kspa', PAR1, PAR2, PAR1TYPE, PAR2TYPE, SAL, TEMPIN, TEMPOUT, PRESIN, PRESOUT,...
SI, PO4,...
pHSCALEIN, K1K2CONSTANTS, KSO4CONSTANTS);
# Print (nicely formatted):
printf("%s %s %s %s %s %s %s %s %s \n", bhead{1:9});
printf("%s %s %s %s %s %s %s %s %s \n", bunits{1:9});
printf("%f %f %f %f %f %f %f %f %f \n", b(1:9));
In [11]:
%%octave
# Standard input for CO2SYS:
# --------------------------
# Input Variables:
PAR1 = 8.1; % pH
PAR2 = 2300; % ALK
PAR1TYPE = 3; % 1=ALK, 2=DIC, 3=pH, 4=pCO2, 5=fCO2
PAR2TYPE = 1; % Same 5 choices as PAR1TYPE
SAL = 35; % Salinity
TEMPIN = 18; % Temperature (input)
TEMPOUT = 25; % Temperature (output)
PRESIN = 0; % Pressure (input)
PRESOUT = PRESIN; % Pressure (output)
SI = 60; % Total dissolved inorganic silicon (Sit)
PO4 = 2; % Total dissoloved inorganic Phosphorus (Pt)
# Input Parameters:
pHSCALEIN = 1; % pH scale (1=total, 2=seawater, 3=NBS, 4=Free)
K1K2CONSTANTS = 15; % set for K1 & K2: 10=Lueker et al. (2000); 14=Millero (2010); 15=Waters et al. (2014)
KSO4CONSTANTS = 1; % KSO4 of Dickson (1990a) & Total dissolved boron (Bt) from Uppstrom (1974)
In [12]:
%%octave
[b, bhead, bunits] = derivnum ('par1', PAR1, PAR2, PAR1TYPE, PAR2TYPE, SAL, TEMPIN, TEMPOUT, PRESIN, PRESOUT,...
SI, PO4,...
pHSCALEIN, K1K2CONSTANTS, KSO4CONSTANTS);
# Print (nicely formatted):
printf("%s %s %s %s %s %s %s %s %s \n", bhead{1:9});
printf("%s %s %s %s %s %s %s %s %s \n", bunits{1:9});
printf("%f %f %f %f %f %f %f %f %f \n", b(1:9));
In [13]:
%%octave
[b, bhead, bunits] = derivnum ('par2', PAR1, PAR2, PAR1TYPE, PAR2TYPE, SAL, TEMPIN, TEMPOUT, PRESIN, PRESOUT,...
SI, PO4,...
pHSCALEIN, K1K2CONSTANTS, KSO4CONSTANTS);
# Print (nicely formatted):
printf("%s %s %s %s %s %s %s %s %s \n", bhead{1:9});
printf("%s %s %s %s %s %s %s %s %s \n", bunits{1:9});
printf("%f %f %f %f %f %f %f %f %f \n", b(1:9));
In [16]:
%%octave
# Standard input for CO2SYS:
# --------------------------
# Input Variables:
PAR1 = 400; % pCO2
PAR2 = 2300; % DIC
PAR1TYPE = 4; % 1=ALK, 2=DIC, 3=pH, 4=pCO2, 5=fCO2
PAR2TYPE = 2; % Same 5 choices as PAR1TYPE
SAL = 35; % Salinity
TEMPIN = 18; % Temperature (input)
TEMPOUT = 25; % Temperature (output)
PRESIN = 0; % Pressure (input)
PRESOUT = PRESIN; % Pressure (output)
SI = 60; % Total dissolved inorganic silicon (Sit)
PO4 = 2; % Total dissoloved inorganic Phosphorus (Pt)
# Input Parameters:
pHSCALEIN = 1; % pH scale (1=total, 2=seawater, 3=NBS, 4=Free)
K1K2CONSTANTS = 15; % set for K1 & K2: 10=Lueker et al. (2000); 14=Millero (2010); 15=Waters et al. (2014)
KSO4CONSTANTS = 1; % KSO4 of Dickson (1990a) & Total dissolved boron (Bt) from Uppstrom (1974)
In [17]:
%%octave
[b, bhead, bunits] = derivnum ('par1', PAR1, PAR2, PAR1TYPE, PAR2TYPE, SAL, TEMPIN, TEMPOUT, ...
PRESIN, PRESOUT, SI, PO4,...
pHSCALEIN, K1K2CONSTANTS, KSO4CONSTANTS);
# Print (nicely formatted):
printf("%s %s %s %s %s %s %s %s %s \n", bhead{1:9});
printf("%s %s %s %s %s %s %s %s %s \n", bunits{1:9});
printf("%f %f %f %f %f %f %f %f %f \n", b(1:9));
In [18]:
%%octave
[b, bhead, bunits] = derivnum ('par2', PAR1, PAR2, PAR1TYPE, PAR2TYPE, SAL, TEMPIN, TEMPOUT,...
PRESIN, PRESOUT, SI, PO4,...
pHSCALEIN, K1K2CONSTANTS, KSO4CONSTANTS);
# Print (nicely formatted):
printf("%s %s %s %s %s %s %s %s %s \n", bhead{1:9});
printf("%s %s %s %s %s %s %s %s %s \n", bunits{1:9});
printf("%f %f %f %f %f %f %f %f %f \n", b(1:9));