#!/usr/bin/env python # coding: utf-8 # # Converting conditions and pH scales # # *Based on **CO2SYSExample2.m** for MATLAB by Steven van Heuven.* # # A sample is measured in the lab to have a pH of 7.8 on the Total scale at 25 °C under atmospheric pressure. # # 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? # # Additional properties: # # * Alkalinity = 2400 μmol/kg # * Salinity = 35 # * Total silicate = 50 μmol/kg # * Total phosphate = 50 μmol/kg # # ## Define conditions # # 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: # In[1]: # Define input and output conditions kwargs = dict( par1_type = 1, # The first parameter supplied is of type "1", which means "alkalinity" par1 = 2400, # value of the first parameter par2_type = 3, # The second parameter supplied is of type "3", which means "pH" par2 = 7.8, # value of the second parameter salinity = 35, # Salinity of the sample temperature = 25, # Temperature at input conditions temperature_out = 2, # Temperature at output conditions pressure = 0, # Pressure at input conditions pressure_out = 4000, # Pressure at output conditions total_silicate = 50, # Concentration of silicate in the sample (in umol/kg) total_phosphate = 2, # Concentration of phosphate in the sample (in umol/kg) opt_pH_scale = 1, # pH scale at which the input pH is reported ("1" means "Total Scale") opt_k_carbonic = 4, # Choice of H2CO3 and HCO3- dissociation constants K1 and K2 ("4" means "Mehrbach refit") opt_k_bisulfate = 1, # Choice of HSO4- dissociation constant KSO4 ("1" means "Dickson") opt_total_borate = 1, # Choice of boron:sal ("1" means "Uppstrom") ) print('Conditions have been defined!') # ## Run PyCO2SYS # # Next, we run PyCO2SYS to solve the marine carbonate system under the input and output conditions and calculate related variables: # In[2]: # Import PyCO2SYS import PyCO2SYS as pyco2 # Run PyCO2SYS results = pyco2.sys(**kwargs) # Extract and print out the result pH_insitu_SWS = results['pH_sws_out'] print('The in situ pH on the Seawater scale was: {:.3f}'.format(pH_insitu_SWS)) # See [the documentation](https://pyco2sys.readthedocs.io/en/latest/co2sys_nd/) for more detailed information about the arguments and results of PyCO2SYS.