Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions gsw/_fixed_wrapped_ufuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,50 @@
from ._wrapped_ufuncs import *

_p_from_z = p_from_z


def p_from_z(z, lat, geo_strf_dyn_height=0, sea_surface_geopotential=0):
if numpy.ma.any(numpy.ma.asarray(z) > 5):
raise ValueError(f"z should be generally negative; found max(z) = {numpy.ma.max(z)}")
return _p_from_z(z, lat, geo_strf_dyn_height, sea_surface_geopotential)


p_from_z.__doc__ = _p_from_z.__doc__

_z_from_p = z_from_p


def z_from_p(p, lat, geo_strf_dyn_height=0, sea_surface_geopotential=0):
return _z_from_p(p, lat, geo_strf_dyn_height, sea_surface_geopotential)


z_from_p.__doc__ = _z_from_p.__doc__

_gibbs = gibbs


def gibbs(ns, nt, np, SA, t, p):
params = {"ns": ns, "nt": nt, "np": np}
for k, v in params.items():
u = numpy.unique(v)
if u.min() < 0 or u.max() > 2 or u.dtype.kind != "i":
raise ValueError("ns, nt, np must contain integers 0, 1, or 2;"
f" found {k}={v}")
raise ValueError(f"ns, nt, np must contain integers 0, 1, or 2; found {k}={v}")
return _gibbs(ns, nt, np, SA, t, p)


gibbs.__doc__ = _gibbs.__doc__


_gibbs_ice = gibbs_ice


def gibbs_ice(nt, np, t, p):
params = {"nt": nt, "np": np}
for k, v in params.items():
u = numpy.unique(v)
if u.min() < 0 or u.max() > 2 or u.dtype.kind != "i":
raise ValueError("nt, np must contain integers 0, 1, or 2;"
f" found {k}={v}")
raise ValueError(f"nt, np must contain integers 0, 1, or 2; found {k}={v}")
return _gibbs_ice(nt, np, t, p)


gibbs_ice.__doc__ = _gibbs_ice.__doc__
2 changes: 1 addition & 1 deletion gsw/_wrapped_ufuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4302,7 +4302,7 @@ def p_from_z(z, lat, geo_strf_dyn_height, sea_surface_geopotential):
Parameters
----------
z : array-like
Depth, positive up, m
Height, positive up (so z = -depth), m
lat : array-like
Latitude, -90 to 90 degrees
geo_strf_dyn_height : array-like
Expand Down
35 changes: 35 additions & 0 deletions gsw/tests/test_fixups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Tests of function modifications by _fixed_wrapped_ufuncs.py
"""

import numpy as np
import pytest

import gsw

zvals_ok = [
-5500,
np.linspace(-100, 0, 11),
np.nan,
[np.nan, -100],
np.ma.masked_invalid([np.nan, -100]),
]

zvals_bad = [
5500,
np.linspace(0, 100, 11),
[np.nan, 100],
np.ma.masked_invalid([np.nan, 100]),
]


@pytest.mark.parametrize("z", zvals_ok)
def test_p_from_z_ok(z):
# smoke test: doesn't raise an exception
gsw.p_from_z(z, 30)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that this is fine b/c we don't expect it to fail and, if it fails the test runner will stop with an exception. Maybe we can integrate it more with pytest with a patter like this?

try:
    gsw.p_from_z(z, 30)
except Exception as e:
        pytest.fail(f"Failed test_p_from_z_ok.\n{e}.")

Or an expected result comparison?



@pytest.mark.parametrize("z", zvals_bad)
def test_p_from_z_bad(z):
with pytest.raises(ValueError):
gsw.p_from_z(z, 30)
2 changes: 1 addition & 1 deletion tools/docstring_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
pt = "Potential temperature referenced to a sea pressure, degrees C",
rho = "Seawater density (not anomaly) in-situ, e.g., 1026 kg/m^3.",
t_Ih = "In-situ temperature of ice (ITS-90), degrees C",
z = "Depth, positive up, m",
z = "Height, positive up (so z = -depth), m",
SA_bulk = "bulk Absolute Salinity of the seawater and ice mixture, g/kg",
w_Ih =
"""mass fraction of ice: the mass of ice divided by the
Expand Down
Loading