Skip to content
Merged
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
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# gsw documentation build configuration file, created by
# sphinx-quickstart on Mon Mar 13 15:27:45 2017.
Expand Down Expand Up @@ -56,6 +55,7 @@
# |version| and |release|, also used in various other places throughout the
# built documents.
import gsw

version = release = gsw.__version__

# The language for content autogenerated by Sphinx. Refer to documentation
Expand Down
19 changes: 5 additions & 14 deletions gsw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,12 @@
"""


from ._fixed_wrapped_ufuncs import *

from .stability import *
from .geostrophy import *
from .utility import *
from . import geostrophy
from . import utility
from . import stability
from . import density
from . import energy
from . import conversions

from . import ice

from . import conversions, density, energy, geostrophy, ice, stability, utility
from ._fixed_wrapped_ufuncs import * # noqa
from .conversions import t90_from_t68
from .geostrophy import * # noqa
from .stability import * # noqa
from .utility import * # noqa

try:
from ._version import __version__
Expand Down
21 changes: 11 additions & 10 deletions gsw/_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import numpy as np


def masked_to_nan(arg):
"""
Convert a masked array to a float ndarray with nans; ensure
Expand Down Expand Up @@ -104,7 +105,7 @@ def indexer(shape, axis, order='C'):
else:
index_position = list(range(ndim))

for k in range(kmax):
for _k in range(kmax):
yield tuple(inds)

for i in index_position:
Expand Down Expand Up @@ -158,8 +159,8 @@ def __init__(self, *args, **kwargs):
def __getattr__(self, name):
try:
return self[name]
except KeyError:
raise AttributeError("'Bunch' object has no attribute '%s'" % name)
except KeyError as err:
raise AttributeError(f"'Bunch' object has no attribute {name}. {err}")

def __setattr__(self, name, value):
self[name] = value
Expand Down Expand Up @@ -208,7 +209,7 @@ def from_pyfile(self, filename):
# Python 3 the scoping for list comprehensions would
# lead to a NameError. Wrapping the code in a function
# fixes this.
d = dict()
d = {}
lines = ["def _temp_func():\n"]
with open(filename) as f:
lines.extend([" " + line for line in f])
Expand All @@ -232,12 +233,12 @@ def update_values(self, *args, **kw):
already in the Bunch instance will raise a KeyError.
"""
strict = kw.pop("strict", False)
newkw = dict()
newkw = {}
for d in args:
newkw.update(d)
newkw.update(kw)
self._check_strict(strict, newkw)
dsub = dict([(k, v) for (k, v) in newkw.items() if k in self])
dsub = {k: v for (k, v) in newkw.items() if k in self}
self.update(dsub)

def update_None(self, *args, **kw):
Expand All @@ -246,13 +247,13 @@ def update_None(self, *args, **kw):
will be updated only if it is None.
"""
strict = kw.pop("strict", False)
newkw = dict()
newkw = {}
for d in args:
newkw.update(d)
newkw.update(kw)
self._check_strict(strict, newkw)
dsub = dict([(k, v) for (k, v) in newkw.items()
if k in self and self[k] is None])
dsub = {k: v for (k, v) in newkw.items()
if k in self and self[k] is None}
self.update(dsub)

def _check_strict(self, strict, kw):
Expand All @@ -264,4 +265,4 @@ def _check_strict(self, strict, kw):
ek = list(self.keys())
ek.sort()
raise KeyError(
"Update keys %s don't match existing keys %s" % (bk, ek))
f"Update keys {bk} don't match existing keys {ek}")
59 changes: 29 additions & 30 deletions gsw/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,37 @@
'z_from_p',
]

from ._utilities import match_args_return

from ._fixed_wrapped_ufuncs import (
adiabatic_lapse_rate_from_CT,
C_from_SP,
CT_from_enthalpy,
CT_from_entropy,
CT_from_pt,
CT_from_rho,
CT_from_t,
deltaSA_from_SP,
entropy_from_pt,
entropy_from_t,
pt0_from_t,
pt_from_CT,
pt_from_entropy,
pt_from_t,
SA_from_rho,
SA_from_SP,
SA_from_Sstar,
SP_from_C,
SP_from_SA,
SP_from_SK,
SP_from_SR,
SP_from_Sstar,
SR_from_SP,
Sstar_from_SA,
Sstar_from_SP,
t_from_CT,
p_from_z,
z_from_p,
C_from_SP,
CT_from_enthalpy,
CT_from_entropy,
CT_from_pt,
CT_from_rho,
CT_from_t,
SA_from_rho,
SA_from_SP,
SA_from_Sstar,
SP_from_C,
SP_from_SA,
SP_from_SK,
SP_from_SR,
SP_from_Sstar,
SR_from_SP,
Sstar_from_SA,
Sstar_from_SP,
adiabatic_lapse_rate_from_CT,
deltaSA_from_SP,
entropy_from_pt,
entropy_from_t,
p_from_z,
pt0_from_t,
pt_from_CT,
pt_from_entropy,
pt_from_t,
t_from_CT,
z_from_p,
)
from ._utilities import match_args_return


@match_args_return
Expand Down
32 changes: 16 additions & 16 deletions gsw/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
in their own "energy" module.
"""
from ._wrapped_ufuncs import (
specvol,
alpha,
beta,
alpha_on_beta,
specvol_alpha_beta,
specvol_anom_standard,
rho,
rho_alpha_beta,
rho_t_exact,
sigma0,
sigma1,
sigma2,
sigma3,
sigma4,
sound_speed,
kappa,
alpha,
alpha_on_beta,
beta,
kappa,
rho,
rho_alpha_beta,
rho_t_exact,
sigma0,
sigma1,
sigma2,
sigma3,
sigma4,
sound_speed,
specvol,
specvol_alpha_beta,
specvol_anom_standard,
)
32 changes: 16 additions & 16 deletions gsw/freezing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
"""

from ._wrapped_ufuncs import (
CT_freezing,
CT_freezing_first_derivatives,
CT_freezing_first_derivatives_poly,
CT_freezing_poly,
pot_enthalpy_ice_freezing,
pot_enthalpy_ice_freezing_first_derivatives,
pot_enthalpy_ice_freezing_first_derivatives_poly,
pot_enthalpy_ice_freezing_poly,
pressure_freezing_CT,
SA_freezing_from_CT,
SA_freezing_from_CT_poly,
SA_freezing_from_t,
SA_freezing_from_t_poly,
t_freezing,
t_freezing_first_derivatives,
t_freezing_first_derivatives_poly,
CT_freezing,
CT_freezing_first_derivatives,
CT_freezing_first_derivatives_poly,
CT_freezing_poly,
SA_freezing_from_CT,
SA_freezing_from_CT_poly,
SA_freezing_from_t,
SA_freezing_from_t_poly,
pot_enthalpy_ice_freezing,
pot_enthalpy_ice_freezing_first_derivatives,
pot_enthalpy_ice_freezing_first_derivatives_poly,
pot_enthalpy_ice_freezing_poly,
pressure_freezing_CT,
t_freezing,
t_freezing_first_derivatives,
t_freezing_first_derivatives_poly,
)
21 changes: 9 additions & 12 deletions gsw/geostrophy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np

from . import _gsw_ufuncs
from ._utilities import match_args_return, indexer
from ._utilities import indexer, match_args_return
from .conversions import z_from_p

__all__ = ['geo_strf_dyn_height',
Expand Down Expand Up @@ -50,16 +50,15 @@ def geo_strf_dyn_height(SA, CT, p, p_ref=0, axis=0, max_dp=1.0,
"""
interp_methods = {'pchip' : 2, 'linear' : 1}
if interp_method not in interp_methods:
raise ValueError('interp_method must be one of %s'
% (interp_methods.keys(),))
raise ValueError(f'interp_method must be one of {interp_methods.keys()}')
if SA.shape != CT.shape:
raise ValueError('Shapes of SA and CT must match; found %s and %s'
% (SA.shape, CT.shape))
raise ValueError(f'Shapes of SA and CT must match; found {SA.shape} and {CT.shape}')
if p.ndim == 1 and SA.ndim > 1:
if len(p) != SA.shape[axis]:
raise ValueError('With 1-D p, len(p) must be SA.shape[axis];\n'
' found %d versus %d on specified axis, %d'
% (len(p), SA.shape[axis], axis))
raise ValueError(
f'With 1-D p, len(p) must be SA.shape[axis];\n'
f' found {len(p)} versus {SA.shape[axis]} on specified axis, {axis}'
)
ind = [np.newaxis] * SA.ndim
ind[axis] = slice(None)
p = p[tuple(ind)]
Expand Down Expand Up @@ -294,12 +293,10 @@ def geostrophic_velocity(geo_strf, lon, lat, p=0, axis=0):
lon = unwrap(lon)

if lon.shape != lat.shape or lon.ndim != 1:
raise ValueError('lon, lat must be 1-D and matching; found shapes'
' %s and %s' % (lon.shape, lat.shape))
raise ValueError(f'lon, lat must be 1-D and matching; found shapes {lon.shape} and {lat.shape}')

if geo_strf.ndim not in (1, 2):
raise ValueError('geo_strf must be 1-D or 2-d; found shape %s'
% (geo_strf.shape,))
raise ValueError(f'geo_strf must be 1-D or 2-d; found shape {geo_strf.shape}')

laxis = 0 if axis else -1

Expand Down
66 changes: 33 additions & 33 deletions gsw/ice.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@
"""

from ._wrapped_ufuncs import (
adiabatic_lapse_rate_ice,
alpha_wrt_t_ice,
chem_potential_water_ice,
cp_ice,
enthalpy_ice,
entropy_ice,
Helmholtz_energy_ice,
ice_fraction_to_freeze_seawater,
internal_energy_ice,
kappa_const_t_ice,
kappa_ice,
melting_ice_equilibrium_SA_CT_ratio,
melting_ice_equilibrium_SA_CT_ratio_poly,
melting_ice_into_seawater,
melting_ice_SA_CT_ratio,
melting_ice_SA_CT_ratio_poly,
melting_seaice_equilibrium_SA_CT_ratio,
melting_seaice_equilibrium_SA_CT_ratio_poly,
melting_seaice_into_seawater,
melting_seaice_SA_CT_ratio,
melting_seaice_SA_CT_ratio_poly,
pot_enthalpy_from_pt_ice,
pot_enthalpy_from_pt_ice_poly,
pressure_coefficient_ice,
pt0_from_t_ice,
pt_from_pot_enthalpy_ice,
pt_from_pot_enthalpy_ice_poly,
pt_from_t_ice,
rho_ice,
seaice_fraction_to_freeze_seawater,
sound_speed_ice,
specvol_ice,
t_from_pt0_ice,
Helmholtz_energy_ice,
adiabatic_lapse_rate_ice,
alpha_wrt_t_ice,
chem_potential_water_ice,
cp_ice,
enthalpy_ice,
entropy_ice,
ice_fraction_to_freeze_seawater,
internal_energy_ice,
kappa_const_t_ice,
kappa_ice,
melting_ice_equilibrium_SA_CT_ratio,
melting_ice_equilibrium_SA_CT_ratio_poly,
melting_ice_into_seawater,
melting_ice_SA_CT_ratio,
melting_ice_SA_CT_ratio_poly,
melting_seaice_equilibrium_SA_CT_ratio,
melting_seaice_equilibrium_SA_CT_ratio_poly,
melting_seaice_into_seawater,
melting_seaice_SA_CT_ratio,
melting_seaice_SA_CT_ratio_poly,
pot_enthalpy_from_pt_ice,
pot_enthalpy_from_pt_ice_poly,
pressure_coefficient_ice,
pt0_from_t_ice,
pt_from_pot_enthalpy_ice,
pt_from_pot_enthalpy_ice_poly,
pt_from_t_ice,
rho_ice,
seaice_fraction_to_freeze_seawater,
sound_speed_ice,
specvol_ice,
t_from_pt0_ice,
)
2 changes: 1 addition & 1 deletion gsw/stability.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import numpy as np

from ._utilities import match_args_return, axis_slicer
from ._gsw_ufuncs import grav, specvol_alpha_beta
from ._utilities import axis_slicer, match_args_return

__all__ = ['Nsquared',
'Turner_Rsubrho',
Expand Down
Loading