Gibbs Seawater (GSW)

raw JSON →
3.6.21 verified Sat May 09 auth: no python

GSW is a Python implementation of the Thermodynamic Equation of Seawater (TEOS-10) for oceanographic computations. Current version 3.6.21, requires Python >=3.11. It provides over 200 functions for oceanographic variables, including density, salinity, sound speed, potential temperature, etc. Release cadence is sporadic, following updates to the TEOS-10 algorithms.

pip install gsw
error ImportError: No module named gsw
cause gsw not installed or Python environment not activated.
fix
Run 'pip install gsw' in the correct environment.
error TypeError: ufunc '...' not supported for the input types
cause Inputs are not numpy arrays or have incompatible dtypes (e.g., strings).
fix
Ensure all inputs are numeric numpy arrays: e.g., SP = np.array([34, 35], dtype=float).
error ValueError: Invalid input: pressure must be non-negative
cause Negative pressure values are not physically meaningful for ocean depths.
fix
Check data; pressure must be >=0 dbar. For surface pressure use 0.
gotcha GSW functions expect numpy arrays; passing plain Python lists may raise errors in some operations.
fix Convert inputs to numpy arrays (e.g., np.array([...])).
breaking gsw 3.0+ dropped support for Python <3.11. If you are on an older Python version, pin to gsw<3.0.
fix Upgrade Python to 3.11+ or install gsw==2.x with pip install 'gsw<3'.
deprecated Some older function names (e.g., gsw.rho, gsw.alpha) have been renamed to use TEOS-10 standard names (e.g., gsw.rho_t_exact, gsw.alpha_wrt_CT_exact).
fix Check the documentation for the exact function name; the old names are still available but may be removed in future.
gotcha Pressure must be in dbar (decibars), not in Pa. Many newcomers mistakenly pass pressure in Pa.
fix Convert Pa to dbar by dividing by 10000.

Compute absolute salinity and conservative temperature from practical salinity and pressure.

import numpy as np
import gsw

# Example: compute absolute salinity from practical salinity
SP = np.array([35.0, 35.5, 36.0])
p = np.array([0, 10, 100])  # pressure in dbar
lon = np.array([-150, -150, -150])
lat = np.array([30, 30, 30])

SA = gsw.SA_from_SP(SP, p, lon, lat)
print(SA)

# Example: conservative temperature from potential temperature (0 dbar reference)
CT = gsw.CT_from_pt(SA, 15.0)
print(CT)