Skip to content

Commit

Permalink
Added TANGPT wrapper and test. (#451)
Browse files Browse the repository at this point in the history
* Added wrapper for TANGPT.

Co-authored-by: Andrew Annex <ama6fy@virginia.edu>
  • Loading branch information
marcsit and AndrewAnnex committed Jul 5, 2022
1 parent c2fecee commit 10708db
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 1 deletion.
81 changes: 81 additions & 0 deletions src/spiceypy/spiceypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14924,6 +14924,87 @@ def szpool(name: str) -> Tuple[int, bool]:
################################################################################
# T

@spice_error_check
def tangpt(
method: str,
target: str,
et: float,
fixref: str,
abcorr: str,
corloc: str,
obsrvr: str,
dref: str,
dvec: Union[ndarray, Iterable[float]],
) -> Tuple[ndarray, float, float, ndarray, float, ndarray]:
"""
Compute, for a given observer, ray emanating from the observer,
and target, the "tangent point": the point on the ray nearest
to the target's surface. Also compute the point on the target's
surface nearest to the tangent point.

The locations of both points are optionally corrected for light
time and stellar aberration.

The surface shape is modeled as a triaxial ellipsoid.

https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/tangpt_c.html

:param method: Computation method.
:param target: Name of target body.
:param et: Epoch in ephemeris seconds past J2000 TDB.
:param fixref: Body-fixed, body-centered target body frame.
:param abcorr: Aberration correction.
:param corloc: Aberration correction locus: "TANGENT POINT" or
"SURFACE POINT".
:param obsrvr: Name of observing body.
:param dref: Reference frame of ray direction vector.
:param dvec: Ray direction vector.
:return: "Tangent point": point on ray nearest to surface, Altitude of
tangent point above surface, Distance of tangent point from observer,
Point on surface nearest to tangent point, Epoch associated with
correction locus, Vector from observer to surface point `srfpt'.
"""
_method = stypes.string_to_char_p(method)
_target = stypes.string_to_char_p(target)
_et = ctypes.c_double(et)
_fixref = stypes.string_to_char_p(fixref)
_abcorr = stypes.string_to_char_p(abcorr)
_corloc = stypes.string_to_char_p(corloc)
_obsrvr = stypes.string_to_char_p(obsrvr)
_dref = stypes.string_to_char_p(dref)
_dvec = stypes.to_double_vector(dvec)
tanpt = stypes.empty_double_vector(3)
alt = ctypes.c_double(0)
_range = ctypes.c_double(0)
srfpt = stypes.empty_double_vector(3)
trgepc = ctypes.c_double(0)
srfvec = stypes.empty_double_vector(3)
libspice.tangpt_c(
_method,
_target,
_et,
_fixref,
_abcorr,
_corloc,
_obsrvr,
_dref,
_dvec,
tanpt,
ctypes.byref(alt),
ctypes.byref(_range),
srfpt,
ctypes.byref(trgepc),
srfvec
)
return (
stypes.c_vector_to_python(tanpt),
alt.value,
_range.value,
stypes.c_vector_to_python(srfpt),
trgepc.value,
stypes.c_vector_to_python(srfvec)
)


@spice_error_check
def termpt(
Expand Down
28 changes: 28 additions & 0 deletions src/spiceypy/tests/test_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9494,6 +9494,34 @@ def test_szpool():
assert spice.szpool("MAXLIN") == 15000


def test_tangpt():
spice.reset()
spice.furnsh(
[CoreKernels.lsk, CoreKernels.pck, CoreKernels.spk,
CassiniKernels.satSpk, CassiniKernels.cassTourSpk,
ExtraKernels.earthHighPerPck, ExtraKernels.earthStnSpk]
)
locus = "TANGENT POINT"
sc = "CASSINI"
target = "SATURN"
obsrvr = "DSS-14"
fixref = "IAU_SATURN"
rayfrm = "J2000"
et = spice.str2et("2013-FEB-13 11:21:20.213872 (TDB)")
raydir, raylt = spice.spkpos(
sc, et, rayfrm, "NONE", obsrvr
)
tanpt, alt, range, srfpt, trgepc, srfvec = spice.tangpt(
"ELLIPSOID", target, et, fixref, "NONE", locus, obsrvr,
rayfrm, raydir
)
npt.assert_array_almost_equal(tanpt, [-113646.428171, 213634.489363, -222709.965702], decimal=5)
assert alt == pytest.approx(271285.892825)
assert range == pytest.approx(1425243487.098913)
npt.assert_array_almost_equal(srfpt, [-21455.320586, 40332.076698, -35458.506180], decimal=5)
assert trgepc == pytest.approx(414026480.213872)


def test_termpt():
spice.reset()
spice.furnsh(CoreKernels.spk)
Expand Down
18 changes: 17 additions & 1 deletion src/spiceypy/utils/libspicehelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2265,7 +2265,23 @@

########################################################################################################################
# T

libspice.tangpt_c.argtypes = [
c_char_p,
c_char_p,
c_double,
c_char_p,
c_char_p,
c_char_p,
c_char_p,
c_char_p,
(c_double * 3),
(c_double * 3),
c_double_p,
c_double_p,
(c_double * 3),
c_double_p,
(c_double * 3),
]
libspice.termpt_c.argtypes = [
c_char_p,
c_char_p,
Expand Down

0 comments on commit 10708db

Please sign in to comment.