Skip to content

Commit

Permalink
Merge 4127612 into 238feed
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewAnnex committed Apr 14, 2020
2 parents 238feed + 4127612 commit 4c98e38
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 11 deletions.
8 changes: 8 additions & 0 deletions docs/documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ spiceypy.utils.support_types module
:undoc-members:
:show-inheritance:

spiceypy.utils.callbacks module
-----------------------------------

.. automodule:: spiceypy.utils.callbacks
:members:
:undoc-members:
:show-inheritance:

spiceypy.utils.libspice module
------------------------------

Expand Down
3 changes: 2 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
numpy
sphinx_autodoc_typehints
sphinx_autodoc_typehints
sphinx==2.3.1
29 changes: 21 additions & 8 deletions spiceypy/spiceypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from . import config
from .utils.callbacks import SpiceUDFUNS, SpiceUDFUNB
from .utils.callbacks import (
UDFUNC,
UDFUNS,
UDFUNB,
UDSTEP,
Expand Down Expand Up @@ -244,7 +245,7 @@ def cell_bool(cell_size: int) -> SpiceCell:
return stypes.SPICEBOOL_CELL(cell_size)


def cell_time(cell_size):
def cell_time(cell_size) -> SpiceCell:
return stypes.SPICETIME_CELL(cell_size)


Expand Down Expand Up @@ -1366,7 +1367,7 @@ def ckw05(
)


def cleard():
def cleard() -> NotImplementedError:
raise NotImplementedError


Expand Down Expand Up @@ -6767,7 +6768,9 @@ def gftfov(


@spice_error_check
def gfudb(udfuns, udfunb, step, cnfine, result):
def gfudb(
udfuns: UDFUNS, udfunb: UDFUNB, step: float, cnfine: SpiceCell, result: SpiceCell
):
"""
Perform a GF search on a user defined boolean quantity.
Expand All @@ -6785,7 +6788,17 @@ def gfudb(udfuns, udfunb, step, cnfine, result):


@spice_error_check
def gfuds(udfuns, udqdec, relate, refval, adjust, step, nintvls, cnfine, result):
def gfuds(
udfuns: UDFUNS,
udqdec: UDFUNB,
relate: str,
refval: float,
adjust: float,
step: float,
nintvls: int,
cnfine: SpiceCell,
result: SpiceCell,
) -> SpiceCell:
"""
Perform a GF search on a user defined scalar quantity.
Expand Down Expand Up @@ -14099,7 +14112,7 @@ def trcnam(index: int, namlen: int = _default_len_out) -> str:


@spice_error_check
def trcoff():
def trcoff() -> None:
"""
Disable tracing.
Expand Down Expand Up @@ -14236,7 +14249,7 @@ def ucrss(v1: ndarray, v2: ndarray) -> ndarray:
return stypes.c_vector_to_python(vout)


def uddc(udfunc, x, dx):
def uddc(udfunc: UDFUNC, x: float, dx: float) -> bool:
"""
SPICE private routine intended solely for the support of SPICE
routines. Users should not call this routine directly due to the
Expand All @@ -14255,7 +14268,7 @@ def udfunc(et_in):
pos, new_et = spice.spkpos("MERCURY", et_in, "J2000", "LT+S", "MOON")
return new_et
deriv = spice.uddf(udfunc, et, 1.0)
is_negative = spice.uddc(udfunc, et, 1.0)
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/uddc_c.html
Expand All @@ -14272,7 +14285,7 @@ def udfunc(et_in):


@spice_error_check
def uddf(udfunc, x, dx):
def uddf(udfunc: UDFUNC, x: float, dx: float) -> float:
"""
Routine to calculate the first derivative of a caller-specified
function using a three-point estimation.
Expand Down
2 changes: 1 addition & 1 deletion spiceypy/tests/test_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9774,7 +9774,7 @@ def test_uddc():
spice.furnsh(CoreKernels.testMetaKernel)
et = spice.str2et("JAN 1 2009")

@spiceypy.utils.callbacks.SpiceUDFUNS
@spiceypy.utils.callbacks.SpiceUDFUNC
def udfunc(et_in):
pos, new_et = spice.spkpos("MERCURY", et_in, "J2000", "LT+S", "MOON")
return new_et
Expand Down
21 changes: 20 additions & 1 deletion spiceypy/utils/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import functools
from ctypes import c_int, c_double, c_char_p, POINTER, CFUNCTYPE, byref
from .support_types import SpiceCell
from typing import Callable

UDFUNC = CFUNCTYPE(None, c_double, POINTER(c_double))
UDFUNS = CFUNCTYPE(None, c_double, POINTER(c_double))
UDFUNB = CFUNCTYPE(None, UDFUNS, c_double, POINTER(c_int))
UDSTEP = CFUNCTYPE(None, c_double, POINTER(c_double))
Expand All @@ -36,7 +38,24 @@
UDBAIL = CFUNCTYPE(c_int)


def SpiceUDFUNS(f):
def SpiceUDFUNC(f: Callable[[float], float]) -> UDFUNC:
"""
Decorator for wrapping python functions in spice udfunc callback type
:param f: function that has one argument of type float, and returns a float
:type f: builtins.function
:return: wrapped udfunc function
:rtype: builtins.function
"""

@functools.wraps(f)
def wrapping_udfunc(x: float, value: POINTER(c_double)) -> None:
result = f(x)
value[0] = c_double(result)

return UDFUNC(wrapping_udfunc)


def SpiceUDFUNS(f) -> UDFUNS:
"""
Decorator for wrapping python functions in spice udfuns callback type
:param f: function that has one argument of type float, and returns a float
Expand Down

0 comments on commit 4c98e38

Please sign in to comment.