Skip to content

Commit

Permalink
Add bodeul (#389)
Browse files Browse the repository at this point in the history
* Add capability to call routine bodeul
  • Loading branch information
jeanlucmargot committed Oct 21, 2020
1 parent eab502a commit 7b5fe29
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions appveyor/cspice.def
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ EXPORTS appndc_c
bodc2n_c
bodc2s_c
boddef_c
bodeul_
bodfnd_c
bodn2c_c
bods2c_c
Expand Down
30 changes: 30 additions & 0 deletions spiceypy/spiceypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,36 @@ def bltfrm(frmcls: int, out_cell: Optional[SpiceCell] = None) -> SpiceCell:
return out_cell


@spice_error_check
def bodeul(body: int, et: float) -> Tuple[float, float, float, float]:
"""
Return the Euler angles needed to compute the transformation from
inertial to body-fixed coordinates for any body in the kernel
pool.
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/FORTRAN/spicelib/bodeul.html
:param body: NAIF ID code of body.
:param et: Epoch of transformation in seconds past J2000 TDB.
:return:
Right ascension of the (IAU) north pole in radians.
Declination of the (IAU) north pole of the body in radians.
Prime meridian rotation angle in radians.
Angle between the prime meridian and longitude of longest axis in radians.
"""
body = ctypes.c_int(body)
et = ctypes.c_double(et)
ra = ctypes.c_double()
dec = ctypes.c_double()
w = ctypes.c_double()
lam = ctypes.c_double()
libspice.bodeul_(
ctypes.byref(body), ctypes.byref(et),
ctypes.byref(ra), ctypes.byref(dec), ctypes.byref(w), ctypes.byref(lam)
)
return ra.value, dec.value, w.value, lam.value


@spice_error_check
@spice_found_exception_thrower
def bodc2n(code: int, lenout: int = _default_len_out) -> Tuple[str, bool]:
Expand Down
31 changes: 31 additions & 0 deletions spiceypy/tests/test_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,37 @@ def test_boddef():
spice.kclear()


def test_bodeul():
spice.kclear()
spice.furnsh(CoreKernels.testMetaKernel)
# define body-fixed unit vectors
xbf = [1.0, 0.0, 0.0]
ybf = [0.0, 1.0, 0.0]
zbf = [0.0, 0.0, 1.0]
# get the reference rotation matrix from pxform at et=0.0
ref_rotate = spice.pxform("IAU_VENUS", "J2000", 0.0)
# transform bf vectors to inertial coordinates
xin = spice.mxv(ref_rotate, xbf)
yin = spice.mxv(ref_rotate, ybf)
zin = spice.mxv(ref_rotate, zbf)
# obtain reference RA and DEC of north pole
ref_range, ref_ra, ref_dec = spice.recrad(zin)
# compute location of node
node = spice.ucrss(zbf, zin)
# obtain reference angle of prime meridian
xproj = spice.vdot(node, xin)
yproj = spice.vdot(node, yin)
ref_w = -np.arctan2(yproj, xproj)
ref_lam = 0
# hopefully obtain the same angles with call to bodeul at et=0.0
ra, dec, w, lam = spice.bodeul(299, 0.0)
npt.assert_almost_equal(ra, ref_ra, decimal=4)
npt.assert_almost_equal(dec, ref_dec, decimal=4)
npt.assert_almost_equal(w, ref_w, decimal=4)
npt.assert_almost_equal(lam, ref_lam, decimal=4)
spice.kclear()


def test_bodfnd():
spice.kclear()
spice.furnsh(CoreKernels.testMetaKernel)
Expand Down
1 change: 1 addition & 0 deletions spiceypy/utils/libspicehelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
libspice.bodc2n_c.argtypes = [c_int, c_int, c_char_p, c_int_p]
libspice.bodc2s_c.argtypes = [c_int, c_int, c_char_p]
libspice.boddef_c.argtypes = [c_char_p, c_int]
libspice.bodeul_.argtypes = [c_int_p, c_double_p, c_double_p, c_double_p, c_double_p, c_double_p]
libspice.badkpv_c.argtypes = [c_char_p, c_char_p, c_char_p, c_int, c_int, c_char]
libspice.badkpv_c.restype = c_int
libspice.bltfrm_c.argtypes = [c_int, s_cell_p]
Expand Down

0 comments on commit 7b5fe29

Please sign in to comment.