# Autogenerated API¶

## High level functions¶

pyseaflux.flux_calculations.flux_bulk(temp_C, salt, pCO2_sea_uatm, pCO2_air_uatm, pres_hPa, kw_cmhr)[source]

Calculates bulk air-sea CO2 fluxes

$FCO_2 = k_w \cdot K_0 \cdot \Delta pCO_2$
Parameters
• temp_C (array) – temperature from OISST in degCelcius with an allowable range of [-2:45]

• salt (array) – salinity from EN4 in PSU. Allowable range [5 : 50]

• pCO2_sea_uatm (array) – partial pressure of CO2 in the sea in micro-atmospheres. Allowable range is [50 : 1000]

• pCO2_air_uatm (array) – partial pressure of CO2 in the air in micro-atmospheres. Allowable range is [50 : 1000].

• press_hPa (array) – atmospheric pressure in hecto-Pascals with allowable range [500:1500]

• kw_cmhr (array) – the gas transfer velocity in (cm/hr). Given the careful choices involved in estimating kw, we require the user to explicitly provide kw. kw can be calculated with pyseaflux.gas_transfer_velocity.<func>. Things to be aware of when calculating kw: wind product and scaling coeffient of gas transfer, resolution resampling, and the formulation (i.e. quadratic, cubic).

Returns

Sea-air CO2 flux where positive is out of the ocean and negative is into the ocean. Units are gC.m-2.day-1 (grams Carbon per metre squared per day). If the input is an xarray.DataArray, then the output will be a data array with fluxes, globally integrated flux, and the area used to integrate the fluxes.

Return type

array

## Conversions of fCO2 - pCO2¶

pyseaflux.fco2_pco2_conversion.fCO2_to_pCO2(fCO2SW_uatm, tempSW_C, pres_hPa=1013.25, tempEQ_C=None, checks=True)[source]

Convert fCO2 to pCO2 in sea water.

If equilibrator temperature is provided, we get a simple approximate for equilibrator $$xCO_2$$ that allows for the virial expansion to be calculated more accurately. If not, then a simple approximation is good enough. See the examples for the differences.

$pCO_2^{sw} = fCO_2^{sw} \div virial(xCO_2^{eq})$

where $$xCO_2^{eq} = fCO_2^{sw} \times \Delta T^{(sw - eq)} \div P^{eq}$$

Parameters
• fCO2SW_uatm (array) – seawater fugacity of CO2 in micro atmospheres

• tempSW_C (array) – sea water temperature in degrees C

• pres_hPa (array, optional) – equilibrator pressure in hecto Pascals. Defaults to 1013.25.

• tempEQ_C (array, optional) – equilibrator temperature in degrees C. Defaults to None.

Returns

partial pressure of CO2 in seawater

Return type

array

Note

In FluxEngine, they account fully solve for the original xCO2 that is used in the calculation of the virial expansion. I use the first estimate of xCO2 (based on fCO2 rather than pCO2). The difference between the two approaches is so small that it is not significant to be concerned. Their correction is more precise, but the difference between their iterative correction and our approximation is on the order of 1e-14 atm (1e-8 uatm).

Examples

>>> fCO2_to_pCO2(380, 8)
381.50806485658234
>>> fCO2_to_pCO2(380, 8, pres_hPa=985)
381.4659553134281
>>> fCO2_to_pCO2(380, 8, pres_hPa=985, tempEQ_C=14)
381.466027968504

pyseaflux.fco2_pco2_conversion.pCO2_to_fCO2(pCO2SW_uatm, tempSW_C, pres_hPa=None, tempEQ_C=None, checks=False)[source]

Convert pCO2 to fCO2 in sea water to account for non-ideal behaviour of CO2

If equilibrator temperature is provided, we get a simple approximate for equilibrator $$xCO_2$$ that allows for the virial expansion to be calculated more accurately. If not, then a simple approximation is probably good enough. See the examples for the differences.

$pCO_2^{sw} = fCO_2^{sw} \times virial(xCO_2^{eq})$

where $$xCO_2^{eq} = fCO_2^{sw} \times \Delta T^{(sw - eq)} \div P^{eq}$$

Parameters
• fCO2SW_uatm (array) – seawater fugacity of CO2 in micro atmospheres

• tempSW_C (array) – sea water temperature in degrees C

• pres_hPa (array, optional) – equilibrator pressure in hecto Pascals. Defaults to 1013.25.

• tempEQ_C (array, optional) – equilibrator temperature in degrees C. Defaults to None.

Returns

fugacity of CO2 in seawater

Return type

array

Note

In FluxEngine, they account for the change in xCO2. This error is so small that it is not significant to be concerned about it. Their correction is more precise, but the difference between their iterative correction and our approximation is less than 1e-14 atm (or 1e-8 uatm).

Examples

>>> pCO2_to_fCO2(380, 8)
378.49789637942064
>>> pCO2_to_fCO2(380, 8, pres_hPa=985)
378.53967828231225
>>> pCO2_to_fCO2(380, 8, pres_hPa=985, tempEQ_C=14)
378.53960618459695

pyseaflux.fco2_pco2_conversion.virial_coeff(temp_K, pres_atm, xCO2_mol=None, checks=False)[source]

Calculate the ideal gas correction factor for converting pCO2 to fCO2.

Based on the Lewis and Wallace 1998 Correction.

Parameters
• temp_K (array) – temperature in degrees Kelvin

• pres_atm (array) – atmospheric pressure in atmospheres

• xCO2_mol (array, optional) – mole fraction of CO2, can also be p/fCO2 if xCO2 not available. Can also be None which makes a small difference. See examples.

Returns

the factor to multiply/divide with pCO2/fCO2. Unitless

\begin{align}\begin{aligned}fCO_2 = pCO_2 \times \text{virial expansion}\\pCO_2 = fCO_2 \div \text{virial expansion}\end{aligned}\end{align}

Return type

array

Examples

From Dickson et al. (2007)

>>> 350 * virial_coeff(298.15, 1)  # CO2 [uatm] * correction factor
348.8836492182758


References

Weiss, R. (1974). Carbon dioxide in water and seawater: the solubility of a non-ideal gas. Marine Chemistry, 2(3), 203–215. https://doi.org/10.1016/0304-4203(74)90015-2

Compared with the Seacarb package in R

## Gas Transfer Velocity¶

Modulates the magnitude of the flux between the atmosphere and the ocean.

pyseaflux.gas_transfer_velocity.k_Ho06(wind_second_moment, temp_C)[source]

Calculates the gas transfer coeffcient for CO2 using the formulation of Ho et al. (2006)

The gas transfer velocity is for the QuickSCAT satellite wind product. Note that using this function for any other wind product is stricktly speaking not correct.

$k_{600} = 0.266 \cdot U^2$

The parameterization is based on the SOLAS Air-Sea Gas Exchange (SAGE) experiment.

Parameters
• wind_ms (array) – wind speed in m/s

• temp_C (array) – temperature in degrees C

Returns

gas transfer velocity (k600) in cm/hr

Return type

kw (array)

References

Ho, D. T., Law, C. S., Smith, M. J., Schlosser, P., Harvey, M., & Hill, P. (2006). Measurements of air-sea gas exchange at high wind speeds in the Southern Ocean: Implications for global parameterizations. Geophysical Research Letters, 33(16), 1–6. https://doi.org/10.1029/2006GL026817

pyseaflux.gas_transfer_velocity.k_Li86(wind_ms, temp_C)[source]

Calculates the gas transfer coeffcient for CO2 using the formulation of Liss and Merlivat (1986)

Note

This is an old parameterization and we recommend using updated parameterisations that are calculated based on the wind product you choose to use. We include this parameterisation based purely for legacy purposes.

Parameters
• wind_ms (array) – wind speed in m/s

• temp_C (array) – temperature in degrees C

Returns

gas transfer velocity (k600) in cm/hr

Return type

kw (array)

References

Liss, P. S., & Merlivat, L. (1986). The Role of Air-Sea Exchange in Geochemical Cycling (Vol. 1983, Issue June 1983). D. Reidel Publishing Company.

pyseaflux.gas_transfer_velocity.k_Mc01(wind_ms, temp_C)[source]

Calculates the gas transfer coeffcient for CO2 using the formulation of McGillis et al. (2001)

The gas transfer velocity has been scaled for in-situ short term wind products. Note that using this function for any other wind product is not correct.

$k_{660} = 3.3 + 0.026 \cdot U^3$
Parameters
• wind_ms (array) – wind speed in m/s

• temp_C (array) – temperature in degrees C

Returns

gas transfer velocity (k660) in cm/hr

Return type

kw (array)

References

McGillis, W. R., Edson, J. B., Ware, J. D., Dacey, J. W. H., Hare, J. E., Fairall, C. W., & Wanninkhof, R. H. (2001). Carbon dioxide flux techniques performed during GasEx-98. Marine Chemistry, 75(4), 267–280. https://doi.org/10.1016/S0304-4203(01)00042-1

pyseaflux.gas_transfer_velocity.k_Ni00(wind_ms, temp_C)[source]

Calculates the gas transfer coeffcient for CO2 using the formulation of Nightingale et al (2000)

$k_{600} = 0.333 \cdot U + 0.222 \cdot U^2$
Parameters
• wind_ms (array) – wind speed in m/s

• temp_C (array) – temperature in degrees C

Returns

gas transfer velocity (k600) in cm/hr

Return type

kw (array)

References

Nightingale, P. D., Malin, G., Law, C. S., Watson, A. J., Liss, P. S., Liddicoat, M. I., Boutin, J., & Upstill-Goddard, R. C. (2000). In situ evaluation of air-sea gas exchange parameterizations using novel conservative and volatile tracers. In Global Biogeochemical Cycles (Vol. 14, Issue 1, p. 373). https://doi.org/10.1029/1999GB900091

pyseaflux.gas_transfer_velocity.k_Sw07(wind_second_moment, temp_C)[source]

Calculates the gas transfer coeffcient for CO2 using the formulation Wanninkhof (1992) rescaled by Sweeny et al (2007)

The gas transfer velocity has been scaled for the NCEP/NCAR reanalysis 1 product. Note that using this function for any other wind product is not correct.

$k_{660} = 0.27 \cdot U^2$
Parameters
• wind_second_moment (array) – wind speed squared in m2/s2. Note that the second moment should be calculated at the native resolution of the wind to avoid losses of variability when taking the square product.

• temp_C (array) – temperature in degrees C

Returns

gas transfer velocity (k660) in cm/hr

Return type

kw (array)

References

Sweeney, C., Gloor, E., Jacobson, A. R., Key, R. M., McKinley, G. A., Sarmiento, J. L., & Wanninkhof, R. H. (2007). Constraining global air-sea gas exchange for CO2 with recent bomb 14C measurements. Global Biogeochemical Cycles, 21(2). https://doi.org/10.1029/2006GB002784

pyseaflux.gas_transfer_velocity.k_Wa09(wind_ms, temp_C)[source]

Calculates the gas transfer coeffcient for CO2 using the formulation of Wanninkhof et al. (2009)

The gas transfer velocity has been scaled for the Cross-Calibrated Multi- Platform (CCMP) Winds product. Note that using this function for any other wind product is not correct.

$k_{660} = 3.0 + 0.1 \cdot U + 0.064 \cdot U^2 + 0.011 \cdot U^3$
Parameters
• wind_ms (array) – wind speed in m/s

• temp_C (array) – temperature in degrees C

Returns

gas transfer velocity (k660) in cm/hr

Return type

kw (array)

References

Wanninkhof, R. H., Asher, W. E., Ho, D. T., Sweeney, C., & McGillis, W. R. (2009). Advances in Quantifying Air-Sea Gas Exchange and Environmental Forcing*. Annual Review of Marine Science, 1(1), 213–244. https://doi.org/10.1146/annurev.marine.010908.163742

pyseaflux.gas_transfer_velocity.k_Wa14(wind_second_moment, temp_C)[source]

Calculates the gas transfer coeffcient for CO2 using the formulation of Wanninkhof et al. (2014)

The gas transfer velocity has been scaled for the Cross-Calibrated Multi- Platform (CCMP) Winds product. Note that using this function for any other wind product is not correct.

$k_{660} = 0.251 \cdot U^2$
Parameters
• wind_second_moment (array) – wind speed squared in m2/s2. Note that the second moment should be calculated at the native resolution of the wind to avoid losses of variability when taking the square product.

• temp_C (array) – temperature in degrees C

Returns

gas transfer velocity (k660) in cm/hr

Return type

kw (array)

References

Wanninkhof, R. H. (2014). Relationship between wind speed and gas exchange over the ocean revisited. Limnology and Oceanography: Methods, 12(JUN), 351–362. https://doi.org/10.4319/lom.2014.12.351

pyseaflux.gas_transfer_velocity.k_Wa92(wind_second_moment, temp_C)[source]

Calculates the gas transfer coeffcient for CO2 using the formulation of Wanninkhof (1992)

Note

This is an old parameterization and we recommend using updated parameterisations that are calculated based on the wind product you choose to use. We include this parameterisation based purely for legacy purposes.

The gas transfer velocity is scaled from instantaneous wind speeds. The study applies a correction to the scaling (0.39) based on instantaneous wind speeds to lower it to 0.31. This correction is based on the variability of wind.

$k_{660} = 0.31 \cdot U^2$
Parameters
• wind_second_moment (array) – wind speed squared in m2/s2. Note that the

• the (second moment should be calculated at the native resolution of) –

• product. (wind to avoid losses of variability when taking the square) –

• temp_C (array) – temperature in degrees C

Returns

gas transfer velocity (k660) in cm/hr

Return type

kw (array)

References

Wanninkhof, R. H. (1992). Relationship between wind speed and gas exchange over the ocean. Journal of Geophysical Research, 97(C5), 7373. https://doi.org/10.1029/92JC00188

pyseaflux.gas_transfer_velocity.k_Wa99(wind_ms, temp_C)[source]

Calculates the gas transfer coeffcient for CO2 using the formulation of Wanninkhof and McGillis (1999)

The gas transfer velocity has been scaled for in-situ short term wind products. Note that using this function for any other wind product is not correct.

$k_{600} = 0.0283 \cdot U^3$
Parameters
• wind_ms (array) – wind speed in m/s

• temp_C (array) – temperature in degrees C

Returns

gas transfer velocity (k600) in cm/hr

Return type

kw (array)

References

Wanninkhof, R. H., & McGillis, W. R. (1999). A cubic relationship between air-sea CO2 exchange and wind speed. Geophysical Research Letters, 26(13), 1889–1892. https://doi.org/10.1029/1999GL900363

pyseaflux.gas_transfer_velocity.schmidt_number(temp_C)[source]

Calculates the Schmidt number as defined by Jahne et al. (1987) and listed in Wanninkhof (2014) Table 1.

Parameters

temp_C (array) – temperature in degrees C

Returns

Schmidt number (dimensionless)

Return type

array

Examples

>>> schmidt_number(20)  # from Wanninkhof (2014)
668.344


References

Jähne, B., Heinz, G., & Dietrich, W. (1987). Measurement of the diffusion coefficients of sparingly soluble gases in water. Journal of Geophysical Research: Oceans, 92(C10), 10767–10776. https://doi.org/10.1029/JC092iC10p10767

## CO2 solubility in seawater¶

pyseaflux.solubility.solubility_weiss1974(salt, temp_K, press_atm=1, checks=True)[source]

Calculates the solubility of CO2 in sea water

Used in the calculation of air-sea CO2 fluxes. We use the formulation by Weiss (1974) summarised in Wanninkhof (2014).

Parameters
• salt (array) – salinity in PSU

• temp_K (array) – temperature in deg Kelvin

• press_atm (array) – pressure in atmospheres. Used in the solubility correction for water vapour pressure. If not given, assumed that press_atm is 1atm

Returns

solubility of CO2 in seawater ($$K_0$$) in mol/L/atm

Return type

array

Examples

from Weiss (1974) Table 2 but with pH2O correction

>>> solubility_weiss1974(35, 299.15)
0.029285284543519093


## Water vapour pressure¶

pyseaflux.vapour_pressure.dickson2007(salt, temp_K, checks=False)[source]

Water vapour pressure of seawater after Dickson et al. (2007)

Calculates $$pH_2O$$ at a given salinity and temperature using the methods defined in Dickson et al. (2007; CO2 manual)

Parameters
• salt (np.array) – salinity

• temp_K (np.array) – temperature in deg Kelvin

Returns

sea_vapress – sea water vapour pressure in atm

Return type

np.array

Examples

>>> vapress_dickson2007(35, 298.15)  # from Dickson et al. (2007) Ch 5.3.2
0.030698866245809465

pyseaflux.vapour_pressure.weiss1980(salt, temp_K, checks=False)[source]

Water vapour pressure of seawater after Weiss and Price (1980)

For a given salinity and temperature using the methods defined in Weiss (1974)

Parameters
• salt (array) – salinity in PSU

• temp_K (array) – temperature in deg Kelvin

Returns

sea water vapour pressure in atm ($$pH_2O$$)

Return type

array

Examples

>>> vapress_weiss1980(35, 25+273.15)  # tempC + 273.15
0.03065529996317971


References

Weiss, R. (1974). Carbon dioxide in water and seawater: the solubility of a non-ideal gas. Marine Chemistry, 2(3), 203–215. https://doi.org/10.1016/0304-4203(74)90015-2

Weiss, R., & Price, B. a. (1980). Nitrous oxide solubility in water and seawater. Marine Chemistry, 8(4), 347–359. https://doi.org/10.1016/0304-4203(80)90024-9

Not necessarily linked to the marine carbonate system, but are useful.

pyseaflux.auxiliary_equations.pressure_height_correction(pres_hPa, tempSW_C, sensor_height=10.0, checks=True)[source]

Returns exact sea level pressure if the sensor is measuring at height

Parameters
• pres_hPa (array) – Pressure in kiloPascal measured at height

• tempSW_C (array) – Temperature of the seawater in deg C

• sensor_height (float, optional) – the height of the sensor above sea level. Can be negative if you want to convert SLP to sensor height pressure. Defaults to 10.0.

Returns

height corrected pressure

Return type

array

pyseaflux.auxiliary_equations.temperature_correction(temp_in, temp_out)[source]

pCO2 correction factor for temperature changes

Calculate a correction factor for the temperature difference between the intake and equilibrator. This is based on the empirical relationship used in Takahashi et al. 1993.

$pCO_2^{Tout} = pCO_2^{Tin} * T^{factor}$
Parameters
• temp_in (array) – temperature at which original pCO2 is measured (degK or degC)

• temp_out (array) – temperature for which pCO2 should be represented

Returns

a correction factor to be multiplied to pCO2 (unitless)

Return type

array

References

Takahashi, Taro et al. (1993). Seasonal variation of CO2 and nutrients in the high-latitude surface oceans: A comparative study. Global Biogeochemical Cycles, 7(4), 843–878. https://doi.org/10.1029/93GB02263

## Area calculations¶

Calculates the area of pixels for a give grid input.

pyseaflux.area.area_grid(lat, lon, return_dataarray=False)[source]

Calculate the area of each grid cell for given lats and lons

Parameters
• lat (array) – latitudes in decimal degrees of length N

• lon (array) – longitudes in decimal degrees of length M

• return_dataarray (bool, optional) – if True returns xr.DataArray, else array

Returns

area of each grid cell in meters

Return type

array, xr.DataArray

References

Calculate the radius of the earth for a given latitude

Parameters

lat (array, float) – latitude value (-90 : 90)

Returns