Skip to content

Commit

Permalink
Name order_constit option "PE" to match array name
Browse files Browse the repository at this point in the history
  • Loading branch information
efiring committed Mar 10, 2021
1 parent 0347bba commit 9dc3e00
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
10 changes: 7 additions & 3 deletions tests/test_order_constit.py
Expand Up @@ -42,9 +42,9 @@
@pytest.mark.parametrize("conf_int", ["none", "linear", "MC"])
def test_order(conf_int):

orders = ["energy", "frequency", opts0["constit"]]
orders = [None, "PE", "frequency", opts0["constit"]]
if conf_int != "none":
orders.append("snr")
orders.append("SNR")
elevs = []
ts_elevs = []
vels = []
Expand All @@ -64,10 +64,14 @@ def test_order(conf_int):
assert (ts_vels[i].u == ts_vels[0].u).all()
assert (ts_vels[i].v == ts_vels[0].v).all()

# Is None equivalent to "PE"? (Just a spot check.)
assert (elevs[0].name == elevs[1].name).all()
assert (elevs[0].A == elevs[1].A).all()


def test_invalid_snr():
opts = opts0.copy()
opts["conf_int"] = "none"
opts["order_constit"] = "snr"
opts["order_constit"] = "SNR"
with pytest.raises(ValueError):
solve(time, time_series, lat=45, **opts)
20 changes: 9 additions & 11 deletions utide/_solve.py
Expand Up @@ -105,15 +105,13 @@ def validate_infer(infer, is_2D):


def validate_order_constit(arg, have_snr):
available = ["energy", "frequency"]
available = ["PE", "frequency"]
if have_snr:
available.append("snr")
available.append("SNR")
if arg is None:
return "energy"
if isinstance(arg, str):
arg = arg.lower()
if arg in available:
return arg
return "PE"
if isinstance(arg, str) and arg in available:
return arg
if not isinstance(arg, str) and np.iterable(arg):
return arg # TODO: add checking of its elements
raise ValueError(
Expand Down Expand Up @@ -186,8 +184,8 @@ def solve(t, u, v=None, lat=None, **opts):
amp_ratios and phase_offsets have length N for a scalar
time series, or 2N for a vector series.
order_constit : {'energy', 'SNR', 'frequency', sequence}, optional
The default is 'energy' order, returning results ordered from
order_constit : {'PE', 'SNR', 'frequency', sequence}, optional
The default is 'PE' (percent energy) order, returning results ordered from
high energy to low.
The 'SNR' order is from high signal-to-noise ratio to low, and is
available only if `conf_int` is not 'none'. The
Expand Down Expand Up @@ -440,7 +438,7 @@ def _solv1(tin, uin, vin, lat, **opts):


def _reorder(coef, opt):
if opt["ordercnstit"] == "energy":
if opt["ordercnstit"] == "PE":
# Default: order by decreasing energy.
if "PE" not in coef:
coef["PE"] = _PE(coef)
Expand All @@ -449,7 +447,7 @@ def _reorder(coef, opt):
elif opt["ordercnstit"] == "frequency":
ind = coef["aux"]["frq"].argsort()

elif opt["ordercnstit"] == "snr":
elif opt["ordercnstit"] == "SNR":
# If we are here, we should be guaranteed to have SNR already.
ind = coef["SNR"].argsort()[::-1]
else:
Expand Down

0 comments on commit 9dc3e00

Please sign in to comment.