Skip to content

Commit

Permalink
Try to improve 'minimum between points' alg
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanconn committed Mar 17, 2022
1 parent 8e95caf commit 0a65047
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
3 changes: 1 addition & 2 deletions Ska/Sun/sun.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ def allowed_rolldev(pitch):
:param pitch: Sun pitch angle (deg)
:returns: Roll deviation (deg)
"""
idx0 = np.searchsorted(ROLL_TABLE.val['pitch'], pitch, side='left')
idx1 = np.searchsorted(ROLL_TABLE.val['pitch'], pitch, side='right')
idx0 = idx1 - 1
idx_max = len(ROLL_TABLE.val) - 1
idx0 = np.clip(idx0, 0, idx_max)
idx1 = np.clip(idx1, 0, idx_max)
# These need some bound checking at the edges
val0 = ROLL_TABLE.val['rolldev'][idx0]
val1 = ROLL_TABLE.val['rolldev'][idx1]
out = np.minimum(val0, val1) # works even for a vector input for `pitch`
Expand Down
26 changes: 19 additions & 7 deletions Ska/Sun/tests/test_sun.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@


def test_allowed_rolldev():
assert np.isclose(allowed_rolldev(135), 13.979)
assert np.isclose(allowed_rolldev(138), 14.516)
assert np.isclose(allowed_rolldev(0), 0)
assert np.isclose(allowed_rolldev(40), 0)
assert np.isclose(allowed_rolldev(179.9), 18.748772)
assert np.isclose(allowed_rolldev(180), 0)
assert np.isclose(allowed_rolldev(181), 0)
# Test array of pitchs and allowed roll dev
testarr = [
[135, 13.979],
[138, 14.516],
[0, 0],
[40, 0],
[179.9, 18.748772],
[179.997, 0],
[180, 0],
[181, 0],
[85.49229, 13.677669],
[85.52, 18.756727],
[125.99, 18.748772],
[126, 17.0]]
for pitch, rolldev in testarr:
assert np.isclose(allowed_rolldev(pitch), rolldev)
# Also test with pitch as vector
assert np.allclose(allowed_rolldev(np.array(testarr)[:, 0]),
np.array(testarr)[:, 1])


def test_position():
Expand Down

0 comments on commit 0a65047

Please sign in to comment.