Skip to content

Commit

Permalink
Checkpoint commit: continuing reorganization of the package
Browse files Browse the repository at this point in the history
  • Loading branch information
efiring committed Apr 1, 2017
1 parent a751cb9 commit 2fbe54a
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Thumbs.db

# Things specific to this project #
###################################
*.list

# Documentation generated files #
#################################
13 changes: 11 additions & 2 deletions gsw/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#from ._gsw_ufuncs import *
"""
Python implementation of the Gibbs SeaWater (GSW) Oceanographic
Toolbox of TEOS-10.
"""


from ._wrapped_ufuncs import *
from ._pyfunctions import *

from .stability import *
from . import stability

from . import conversions
33 changes: 33 additions & 0 deletions gsw/conversions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
Conversions involving temperature, salinity, entropy, pressure,
and height.
"""
from ._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,
z_from_p,
)
18 changes: 18 additions & 0 deletions gsw/_pyfunctions.py → gsw/stability.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
"""
Vertical stability functions.
These work with ndarrays of profiles; use the `axis` keyword
argument to specify the axis along which pressure varies.
For example, the default, following the Matlab versions, is
`axis=0`, meaning the pressure varies along the first dimension.
Use `axis=-1` if pressure varies along the last dimension--that
is, along a row, as the column index increases, in the 2-D case.
Docstrings are not yet available; they will be added later via
an automated mechanism.
"""


import numpy as np

from ._utilities import match_args_return, axis_slicer
Expand Down Expand Up @@ -44,6 +60,7 @@ def Nsquared(SA, CT, p, lat=None, axis=0):

return N2, p_mid


@match_args_return
def Turner_Rsubrho(SA, CT, p, axis=0):
SA = np.clip(SA, 0, 50)
Expand All @@ -70,6 +87,7 @@ def Turner_Rsubrho(SA, CT, p, axis=0):

return Tu, Rsubrho, p_mid


@match_args_return
def IPV_vs_fNsquared_ratio(SA, CT, p, p_ref=0, axis=0):
SA = np.clip(SA, 0, 50)
Expand Down
1 change: 1 addition & 0 deletions tools/_utilities.py
24 changes: 24 additions & 0 deletions tools/categories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Use 'wrapped_ufuncs.list' and the function names from parsing
Matlab to generate lists of wrapped functions in categories.
"""

from matlab_parser import get_sigdicts_by_subdir

sigdicts = get_sigdicts_by_subdir()
with open('wrapped_ufuncs.list') as f:
lines = f.readlines()
uflist = [name.strip() for name in lines]

def write_basic_conversions():
out = []
nlist = [n for n in uflist if 'from' in n]
for name in nlist:
if not('ice' in name or 'freezing' in name or 'exact' in name):
try:
out.append(sigdicts['toolbox'][name]['name'])
except KeyError:
pass
out.append('')
with open('basic_conversions.list', 'w') as f:
f.write(',\n'.join(out))
9 changes: 8 additions & 1 deletion tools/matlab_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
r"\((?P<input>.*)\)")


def list_functions(matdir=gsw_matlab_dir):
def list_functions(matdir=gsw_matlab_dir, subdir=''):
rawlist = glob.glob(os.path.join(matdir, '*.m'))
signatures = []
rejects = []
Expand Down Expand Up @@ -65,6 +65,13 @@ def get_complete_sigdict():
return to_sigdict(get_all_signatures())


def get_sigdicts_by_subdir():
out = dict(toolbox=to_sigdict(list_functions()[0]))
for subdir in gsw_matlab_subdirs:
out[subdir] = to_sigdict(list_functions(subdir=subdir)[0])
return out


def variables_from_signatures(signatures):
inputs = set()
outputs = set()
Expand Down

0 comments on commit 2fbe54a

Please sign in to comment.