Skip to content

Commit

Permalink
added recazl, stlabx, tparch (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewAnnex committed Apr 22, 2022
1 parent e766fed commit 6c3a70d
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 1 deletion.
72 changes: 72 additions & 0 deletions src/spiceypy/spiceypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10381,6 +10381,41 @@ def rdtext(
return stypes.to_python_string(line), bool(eof.value)


@spice_error_check
def recazl(
rectan: Union[ndarray, Iterable[float]], azccw: bool, elplsz: bool
) -> Tuple[float, float, float]:
"""
Convert rectangular coordinates of a point to range, azimuth and
elevation.

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

:param rectan: Rectangular coordinates of a point.
:param azccw: Flag indicating how Azimuth is measured.
:param elplsz: Flag indicating how Elevation is measured.
:return:
Distance of the point from the origin,
Azimuth in radians,
Elevation in radians.
"""
_rectan = stypes.to_double_vector(rectan)
_azccw = ctypes.c_int(azccw)
_elplsz = ctypes.c_int(elplsz)
_range = ctypes.c_double(0)
_az = ctypes.c_double(0)
_el = ctypes.c_double(0)
libspice.recazl_c(
_rectan,
_azccw,
_elplsz,
ctypes.byref(_range),
ctypes.byref(_az),
ctypes.byref(_el),
)
return _range.value, _az.value, _el.value


@spice_error_check
def reccyl(rectan: Union[ndarray, Iterable[float]]) -> Tuple[float, float, float]:
"""
Expand Down Expand Up @@ -13516,6 +13551,28 @@ def stelab(pobj: ndarray, vobs: ndarray) -> ndarray:
return stypes.c_vector_to_python(appobj)


@spice_error_check
def stlabx(pobj: ndarray, vobs: ndarray) -> ndarray:
"""
Correct the position of a target for the stellar aberration
effect on radiation transmitted from a specified observer to
the target.

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

:param pobj: Position of an object with respect to the observer.
:param vobs:
Velocity of the observer with respect
to the Solar System barycenter.
:return: Corrected position of the object.
"""
_pobj = stypes.to_double_vector(pobj)
_vobs = stypes.to_double_vector(vobs)
_corpos = stypes.empty_double_vector(3)
libspice.stlabx_c(_pobj, _vobs, _corpos)
return stypes.c_vector_to_python(_corpos)


@spice_error_check
@spice_found_exception_thrower
def stpool(
Expand Down Expand Up @@ -14245,6 +14302,21 @@ def tkvrsn(item: str) -> str:
return stypes.to_python_string(libspice.tkvrsn_c(item))


@spice_error_check
def tparch(type: str) -> None:
"""
Restrict the set of strings that are recognized by SPICE time
parsing routines to those that have standard values for all time
components.

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

:param type: String: Use "YES" to restrict time inputs.
"""
_type = stypes.string_to_char_p(type)
libspice.tparch_c(_type)


@spice_error_check
def tparse(instring: str, lenout: int = _default_len_out) -> Tuple[float, str]:
"""
Expand Down
101 changes: 101 additions & 0 deletions src/spiceypy/tests/test_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6480,6 +6480,77 @@ def rdtext_helper(filename, expected_line, expected_done):
cleanup_kernel(xRDTEXT)


def test_recazl():
d = spice.dpr()
npt.assert_array_almost_equal(
spice.recazl([0.0, 0.0, 0.0], False, False), [0.000, 0.0, 0.000], 3
)
npt.assert_array_almost_equal(
spice.recazl([1.0, 0.0, 0.0], False, False), [1.000, 0.0, 0.000], 3
)
npt.assert_array_almost_equal(
spice.recazl([0.0, 1.0, 0.0], False, False), [1.000, 270.0 / d, 0.000], 3
)
npt.assert_array_almost_equal(
spice.recazl([0.0, 0.0, 1.0], False, False), [1.000, 0.0, -90.000 / d], 3
)
npt.assert_array_almost_equal(
spice.recazl([-1.0, 0.0, 0.0], False, False), [1.000, 180.0 / d, 0.000], 3
)
npt.assert_array_almost_equal(
spice.recazl([0.0, -1.0, 0.0], False, False), [1.000, 90.0 / d, 0.000], 3
)
npt.assert_array_almost_equal(
spice.recazl([0.0, 0.0, -1.0], False, False), [1.000, 0.0, 90.000 / d], 3
)
npt.assert_array_almost_equal(
spice.recazl([1.0, 1.0, 0.0], False, False), [1.414, 315.0 / d, 0.000], 3
)
npt.assert_array_almost_equal(
spice.recazl([1.0, 0.0, 1.0], False, False), [1.414, 0.0, -45.000 / d], 3
)
npt.assert_array_almost_equal(
spice.recazl([0.0, 1.0, 1.0], False, False), [1.414, 270.0 / d, -45.000 / d], 3
)
npt.assert_array_almost_equal(
spice.recazl([1.0, 1.0, 1.0], False, False), [1.732, 315.0 / d, -35.264 / d], 3
)

npt.assert_array_almost_equal(
spice.recazl([0.0, 0.0, 0.0], True, True), [0.000, 0.0, 0.000], 3
)
npt.assert_array_almost_equal(
spice.recazl([1.0, 0.0, 0.0], True, True), [1.000, 0.0, 0.000], 3
)
npt.assert_array_almost_equal(
spice.recazl([0.0, 1.0, 0.0], True, True), [1.000, 90.0 / d, 0.000], 3
)
npt.assert_array_almost_equal(
spice.recazl([0.0, 0.0, 1.0], True, True), [1.000, 0.0, 90.000 / d], 3
)
npt.assert_array_almost_equal(
spice.recazl([-1.0, 0.0, 0.0], True, True), [1.000, 180.0 / d, 0.000], 3
)
npt.assert_array_almost_equal(
spice.recazl([0.0, -1.0, 0.0], True, True), [1.000, 270.0 / d, 0.000], 3
)
npt.assert_array_almost_equal(
spice.recazl([0.0, 0.0, -1.0], True, True), [1.000, 0.0, -90.000 / d], 3
)
npt.assert_array_almost_equal(
spice.recazl([1.0, 1.0, 0.0], True, True), [1.414, 45.0 / d, 0.000], 3
)
npt.assert_array_almost_equal(
spice.recazl([1.0, 0.0, 1.0], True, True), [1.414, 0.0, 45.000 / d], 3
)
npt.assert_array_almost_equal(
spice.recazl([0.0, 1.0, 1.0], True, True), [1.414, 90.0 / d, 45.000 / d], 3
)
npt.assert_array_almost_equal(
spice.recazl([1.0, 1.0, 1.0], True, True), [1.732, 45.0 / d, 35.264 / d], 3
)


def test_reccyl():
expected1 = np.array([0.0, 0.0, 0.0])
expected2 = np.array([1.0, 90.0 * spice.rpd(), 0.0])
Expand Down Expand Up @@ -8722,6 +8793,23 @@ def test_stelab():
npt.assert_array_almost_equal(expected_cortarg, cortarg)


def test_stlabx():
IDOBS = 399
IDTARG = 301
UTC = "July 4 2004"
FRAME = "J2000"
spice.furnsh(CoreKernels.testMetaKernel)
et = spice.str2et(UTC)
sobs = spice.spkssb(IDOBS, et, FRAME)
pos, ltime = spice.spkapo(IDTARG, et, FRAME, sobs, "XLT")
# note the values below won't match due to the different kernels used
expected_pos = [201809.933536, -260878.049826, -147716.077987]
npt.assert_array_almost_equal(pos, expected_pos, 1)
pcorr = spice.stlabx(pos, sobs[3:6])
expected_pcorr = [201782.730972, -260894.375627, -147724.405897]
npt.assert_array_almost_equal(pcorr, expected_pcorr, 1)


def test_stpool():
kernel = os.path.join(cwd, "stpool_t.ker")
cleanup_kernel(kernel)
Expand Down Expand Up @@ -9152,6 +9240,19 @@ def test_tkvrsn():
assert version == "CSPICE_N0067"


def test_tparch():
spice.tparch("NO")
spice.tparch("YES")
a, e = spice.tparse("FEB 34, 1993")
assert "The day of the month specified for the month of February was 3.40E+01." in e
spice.tparch("NO")
a, e = spice.tparse("FEB 34, 1993")
assert (
"The day of the month specified for the month of February was 3.40E+01."
not in e
)


def test_tparse():
actual_one, error_one = spice.tparse("1996-12-18T12:28:28")
assert actual_one == -95815892.0
Expand Down
12 changes: 11 additions & 1 deletion src/spiceypy/utils/libspicehelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,14 @@
libspice.rav2xf_c.argtypes = [(c_double * 3) * 3, (c_double * 3), (c_double * 6) * 6]
libspice.raxisa_c.argtypes = [(c_double * 3) * 3, (c_double * 3), c_double_p]
libspice.rdtext_c.argtypes = [c_char_p, c_int, c_char_p, c_int_p]
libspice.recazl_c.argtypes = [
(c_double * 3),
c_int,
c_int,
c_double_p,
c_double_p,
c_double_p,
]
libspice.reccyl_c.argtypes = [(c_double * 3), c_double_p, c_double_p, c_double_p]
libspice.recgeo_c.argtypes = [
(c_double * 3),
Expand Down Expand Up @@ -2033,7 +2041,8 @@
c_int_p,
]
libspice.ssize_c.argtypes = [c_int, s_cell_p]
libspice.stelab_c.argtypes = [(c_double * 3), (c_double * 3)]
libspice.stelab_c.argtypes = [(c_double * 3), (c_double * 3), (c_double * 3)]
libspice.stlabx_c.argtypes = [(c_double * 3), (c_double * 3), (c_double * 3)]
libspice.stpool_c.argtypes = [
c_char_p,
c_int,
Expand Down Expand Up @@ -2146,6 +2155,7 @@
libspice.tkfram_.argtypes = [c_int_p, (c_double * 3) * 3, c_int_p, c_int_p]
libspice.tkvrsn_c.argtypes = [c_char_p]
libspice.tkvrsn_c.restype = c_char_p
libspice.tparch_c.argtypes = [c_char_p]
libspice.tparse_c.argtypes = [c_char_p, c_int, c_double_p, c_char_p]
libspice.tpictr_c.argtypes = [c_char_p, c_int, c_int, c_char_p, c_int_p, c_char_p]
libspice.trace_c.argtypes = [(c_double * 3) * 3]
Expand Down

0 comments on commit 6c3a70d

Please sign in to comment.