CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-seawater

Python implementation of the CSIRO seawater toolbox for calculating properties of sea water using EOS-80 equation of state

Pending
Overview
Eval results
Files

core-eos80.mddocs/

Core EOS-80 Functions

Fundamental equation of state calculations for seawater based on the UNESCO 1983 algorithms. These functions provide the essential relationships between salinity, temperature, pressure, and density that form the foundation of oceanographic calculations.

Capabilities

Density Calculations

Core density calculations using the EOS-80 equation of state.

def dens(s, t, p):
    """
    Density of seawater using the EOS-80 equation of state.
    
    Parameters:
    - s: array_like, salinity [psu (PSS-78)]
    - t: array_like, temperature [°C (ITS-90)]
    - p: array_like, pressure [db]
    
    Returns:
    - array_like: density [kg/m³]
    """

def dens0(s, t):
    """
    Density of seawater at atmospheric pressure.
    
    Parameters:
    - s: array_like, salinity [psu (PSS-78)]
    - t: array_like, temperature [°C (ITS-90)]
    
    Returns:
    - array_like: density at atmospheric pressure [kg/m³]
    """

def pden(s, t, p, pr=0):
    """
    Potential density of seawater.
    
    Parameters:
    - s: array_like, salinity [psu (PSS-78)]
    - t: array_like, temperature [°C (ITS-90)]
    - p: array_like, pressure [db]
    - pr: array_like, reference pressure [db], default 0
    
    Returns:
    - array_like: potential density [kg/m³]
    """

Temperature Calculations

Temperature transformations and potential temperature calculations.

def ptmp(s, t, p, pr=0):
    """
    Potential temperature of seawater.
    
    Parameters:
    - s: array_like, salinity [psu (PSS-78)]
    - t: array_like, in-situ temperature [°C (ITS-90)]
    - p: array_like, pressure [db]
    - pr: array_like, reference pressure [db], default 0
    
    Returns:
    - array_like: potential temperature [°C (ITS-90)]
    """

def temp(s, pt, p, pr=0):
    """
    In-situ temperature from potential temperature.
    
    Parameters:
    - s: array_like, salinity [psu (PSS-78)]
    - pt: array_like, potential temperature [°C (ITS-90)]
    - p: array_like, pressure [db]
    - pr: array_like, reference pressure [db], default 0
    
    Returns:
    - array_like: in-situ temperature [°C (ITS-90)]
    """

def adtg(s, t, p):
    """
    Adiabatic temperature gradient.
    
    Parameters:
    - s: array_like, salinity [psu (PSS-78)]
    - t: array_like, temperature [°C (ITS-90)]
    - p: array_like, pressure [db]
    
    Returns:
    - array_like: adiabatic temperature gradient [°C/db]
    """

Pressure and Depth

Conversions between pressure and depth.

def pres(depth, lat):
    """
    Pressure from depth using Fofonoff and Millard (1983).
    
    Parameters:
    - depth: array_like, depth [m]
    - lat: array_like, latitude [decimal degrees]
    
    Returns:
    - array_like: pressure [db]
    """

def dpth(p, lat):
    """
    Depth from pressure using Fofonoff and Millard (1983).
    
    Parameters:
    - p: array_like, pressure [db]
    - lat: array_like, latitude [decimal degrees]
    
    Returns:
    - array_like: depth [m]
    """

Salinity Calculations

Salinity calculations from conductivity measurements.

def salt(r, t, p):
    """
    Salinity from conductivity ratio using PSS-78.
    
    Parameters:
    - r: array_like, conductivity ratio (C/C[35,15,0])
    - t: array_like, temperature [°C (ITS-90)]
    - p: array_like, pressure [db]
    
    Returns:
    - array_like: salinity [psu (PSS-78)]
    """

Sound Velocity

Sound velocity in seawater.

def svel(s, t, p):
    """
    Sound velocity in seawater using Chen and Millero (1977).
    
    Parameters:
    - s: array_like, salinity [psu (PSS-78)]
    - t: array_like, temperature [°C (ITS-90)]
    - p: array_like, pressure [db]
    
    Returns:
    - array_like: sound velocity [m/s]
    """

Thermodynamic Properties

Thermodynamic properties of seawater.

def cp(s, t, p):
    """
    Heat capacity of seawater.
    
    Parameters:
    - s: array_like, salinity [psu (PSS-78)]
    - t: array_like, temperature [°C (ITS-90)]
    - p: array_like, pressure [db]
    
    Returns:
    - array_like: specific heat capacity [J/(kg·°C)]
    """

def alpha(s, t, p, *, pt=False):
    """
    Thermal expansion coefficient of seawater.
    
    Parameters:
    - s: array_like, salinity [psu (PSS-78)]
    - t: array_like, temperature [°C (ITS-90)]
    - p: array_like, pressure [db]
    - pt: bool, use potential temperature if True
    
    Returns:
    - array_like: thermal expansion coefficient [1/°C]
    """

def beta(s, t, p, *, pt=False):
    """
    Saline contraction coefficient of seawater.
    
    Parameters:
    - s: array_like, salinity [psu (PSS-78)]
    - t: array_like, temperature [°C (ITS-90)]
    - p: array_like, pressure [db]
    - pt: bool, use potential temperature if True
    
    Returns:
    - array_like: saline contraction coefficient [1/psu]
    """

def aonb(s, t, p, *, pt=False):
    """
    Ratio of thermal expansion to saline contraction coefficients.
    
    Parameters:
    - s: array_like, salinity [psu (PSS-78)]
    - t: array_like, temperature [°C (ITS-90)]
    - p: array_like, pressure [db]
    - pt: bool, use potential temperature if True
    
    Returns:
    - array_like: alpha/beta ratio [psu·°C⁻¹]
    """

Gravity and Freezing Point

Gravity variations and freezing point calculations.

def g(lat, z=0):
    """
    Acceleration due to gravity as a function of latitude.
    
    Parameters:
    - lat: array_like, latitude [decimal degrees]
    - z: array_like, height above sea level [m], default 0
    
    Returns:
    - array_like: acceleration due to gravity [m/s²]
    """

def fp(s, p):
    """
    Freezing point of seawater.
    
    Parameters:
    - s: array_like, salinity [psu (PSS-78)]
    - p: array_like, pressure [db]
    
    Returns:
    - array_like: freezing point temperature [°C (ITS-90)]
    """

Usage Examples

Basic Property Calculations

import seawater as sw
import numpy as np

# Define typical oceanographic conditions
s = 35.0  # salinity in psu
t = 15.0  # temperature in °C
p = 100.0  # pressure in decibars

# Calculate fundamental properties
density = sw.dens(s, t, p)
potential_temp = sw.ptmp(s, t, p)
sound_vel = sw.svel(s, t, p)

print(f"Density: {density:.3f} kg/m³")
print(f"Potential temperature: {potential_temp:.3f} °C")
print(f"Sound velocity: {sound_vel:.2f} m/s")

Profile Analysis

import seawater as sw
import numpy as np

# Create a typical ocean profile
pressure = np.array([0, 50, 100, 200, 500, 1000])  # db
temperature = np.array([20, 18, 15, 10, 5, 3])     # °C
salinity = np.full_like(pressure, 35.0)             # psu

# Calculate profile properties
density = sw.dens(salinity, temperature, pressure)
pot_temp = sw.ptmp(salinity, temperature, pressure)
pot_density = sw.pden(salinity, temperature, pressure)

# Display results
for i in range(len(pressure)):
    print(f"P: {pressure[i]:4.0f} db, "
          f"T: {temperature[i]:5.1f} °C, "
          f"θ: {pot_temp[i]:5.2f} °C, "
          f"ρ: {density[i]:7.3f} kg/m³")

Install with Tessl CLI

npx tessl i tessl/pypi-seawater

docs

auxiliary.md

core-eos80.md

geostrophic.md

index.md

support.md

tile.json