Skip to content

Commit

Permalink
test: add test for extended doodson
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutterley committed Oct 29, 2024
1 parent 774f35c commit 5d1be55
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pyTMD/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ def _constituent_parameters(c: str, **kwargs):
# return the values for the constituent
return (amplitude, phase, omega, alpha, species)

# Cartright and Tayler (1971) table with 3rd-degree values
# Cartwright and Tayler (1971) table with 3rd-degree values
_ct1971_table_5 = get_data_path(['data','ct1971_tab5.txt'])
# Cartwright and Edden (1973) table with updated values
_ce1973_table_1 = get_data_path(['data','ce1973_tab1.txt'])
Expand Down
105 changes: 90 additions & 15 deletions test/test_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,43 +697,118 @@ def test_doodson():
exp['2q1'] = 125.755
exp['p1'] = 163.555
# long-period species
exp['mm'] = '065.455'
exp['ssa'] = '057.555'
exp['msf'] = '073.555'
exp['mf'] = '075.555'
exp['msqm'] = '093.555'
exp['mtm'] = '085.455'
exp['node'] = '055.565'
exp['mm'] = 065.455
exp['ssa'] = 057.555
exp['msf'] = 073.555
exp['mf'] = 075.555
exp['msqm'] = 093.555
exp['mtm'] = 085.455
exp['node'] = 055.565
# short-period species
exp['m3'] = 355.555
exp['m4'] = 455.555
exp['m6'] = 655.555
exp['m8'] = 855.555
# shallow water species
exp['2so3'] = '3X1.555'
exp['2jp3'] = '3X3.355'
exp['kso3'] = '3X3.555'
exp['2jk3'] = '3X4.355'
exp['2ko3'] = '3X5.555'
# 3rd degree terms
exp["2q1'"] = 125.655
exp["q1'"] = 135.555
exp["o1'"] = 145.655
exp["m1'"] = 155.555
exp["k1'"] = 165.455
exp["j1'"] = 175.555
exp["2n2'"] = 235.655
exp["n2'"] = 245.555
exp["m2'"] = 255.655
exp["l2'"] = 265.555
exp["m3'"] = 355.555
exp['lambda3'] = 363.655
exp["l3"] = 365.455
exp["l3b"] = 365.655
exp["f3"] = 375.555
exp["j3"] = 375.555
exp["s3'"] = 382.555
# get observed values for constituents
obs = doodson_number(exp.keys())
cartwright = doodson_number(exp.keys(), formalism='Cartwright')
# check values
for key,val in exp.items():
assert float(val) == obs[key]
assert val == obs[key]
# check values when entered as string
test = doodson_number(key)
assert float(val) == test
# check conversion to and from Doodson numbers
assert val == test
# check conversion to Doodson numbers
doodson = _to_doodson_number(cartwright[key])
XDO = _to_extended_doodson(cartwright[key])
# check values when entered as Cartwright
assert float(val) == doodson
assert val == doodson
# check values when entered as Doodson
coefficients = _from_doodson_number(val)
extended = _from_extended_doodson(XDO)
assert np.all(cartwright[key] == coefficients)
assert np.all(cartwright[key] == extended)

def test_extended():
"""
Tests the calculation of UKHO Extended Doodson numbers
"""
# expected values
exp = {}
# semi-diurnal species
exp['m2'] = 'BZZZZZZ'
exp['s2'] = 'BBXZZZZ'
exp['n2'] = 'BYZAZZZ'
exp['nu2'] = 'BYBYZZZ'
exp['mu2'] = 'BXBZZZZ'
exp['2n2'] = 'BXZBZZZ'
exp['lambda2'] = 'BAXAZZB'
exp['l2'] = 'BAZYZZB'
exp['k2'] = 'BBZZZZZ'
# diurnal species
exp['m1'] = 'AZZZZZA'
exp['s1'] = 'AAYZZZA'
exp['o1'] = 'AYZZZZY'
exp['oo1'] = 'ACZZZZA'
exp['k1'] = 'AAZZZZA'
exp['q1'] = 'AXZAZZY'
exp['2q1'] = 'AWZBZZY'
exp['p1'] = 'AAXZZZY'
# long-period species
exp['mm'] = 'ZAZYZZZ'
exp['ssa'] = 'ZZBZZZZ'
exp['msf'] = 'ZBXZZZZ'
exp['mf'] = 'ZBZZZZZ'
exp['msqm'] = 'ZDXZZZZ'
exp['mtm'] = 'ZCZYZZZ'
exp['node'] = 'ZZZZAZB'
# short-period species
exp['m3'] = 'CZZZZZZ'
exp['m4'] = 'DZZZZZZ'
exp['n4'] = 'DXZBZZZ'
exp['m6'] = 'FZZZZZZ'
exp['n6'] = 'FWZCZZZ'
exp['m8'] = 'HZZZZZZ'
exp['m10'] = 'JZZZZZZ'
exp['m12'] = 'LZZZZZZ'
# shallow water species
exp['2so3'] = 'CEVZZZA'
exp['2jp3'] = 'CEXXZZA'
exp['kso3'] = 'CEXZZZA'
exp['2jk3'] = 'CEYXZZZ'
exp['2ko3'] = 'CEZZZZA'
# get observed values for constituents
obs = doodson_number(exp.keys(), formalism='Extended')
# check values
for key,val in exp.items():
assert val == obs[key]

def test_parse_tables():
"""
Tests the parsing of tables for tide potential coefficients
"""
# Cartright and Tayler (1971) table with 3rd-degree values
# Cartwright and Tayler (1971) table with 3rd-degree values
# Cartwright and Edden (1973) table with updated values
for table in [_ct1971_table_5, _ce1973_table_1]:
# parse table
Expand Down

0 comments on commit 5d1be55

Please sign in to comment.