Skip to content

Commit 96e8e39

Browse files
authored
more n67 function 3 (#447)
* added lgresp, lgrint, qderiv * added 3.10 to build matrix
1 parent ba8d027 commit 96e8e39

File tree

6 files changed

+124
-30
lines changed

6 files changed

+124
-30
lines changed

.github/workflows/ci-build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
matrix:
1616
os: [ubuntu-latest, macos-latest, windows-latest]
17-
python-version: [ 3.6, 3.7, 3.8, 3.9 ]
17+
python-version: [ '3.6', '3.7', '3.8', '3.9', '3.10' ]
1818
steps:
1919
- name: Setup 🔬🍦🏗️
2020
if: ${{ matrix.os == 'windows-latest' }}

.github/workflows/publish-to-test-and-live-pypi.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
steps:
1616
- name: Checkout 🌶️ 🥧
1717
uses: actions/checkout@v2
18-
- name: Set up Python 🐍 3.8
18+
- name: Set up Python 🐍 3.9
1919
uses: actions/setup-python@v2
2020
with:
21-
python-version: 3.8
21+
python-version: 3.9
2222
- name: Display Python 🐍
2323
run: python -c "import sys; print(sys.version)"
2424
- name: Install dependencies

cspice.def

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ EXPORTS appndc_c
5757
ckw03_c
5858
ckw05_c
5959
clearc_c
60+
cleard_c
6061
cleari_c
6162
clight_c
6263
clpool_c

src/spiceypy/spiceypy.py

+94-27
Original file line numberDiff line numberDiff line change
@@ -8288,6 +8288,76 @@ def ldpool(filename: str) -> None:
82888288
libspice.ldpool_c(filename)
82898289

82908290

8291+
@spice_error_check
8292+
def lgresp(first: float, step: float, yvals: ndarray, x: float) -> float:
8293+
"""
8294+
Evaluate a Lagrange interpolating polynomial for a specified
8295+
set of coordinate pairs whose first components are equally
8296+
spaced, at a specified abscissa value.
8297+
8298+
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/lgresp_c.html
8299+
8300+
:param first: First abscissa value.
8301+
:param step: Step Size.
8302+
:param yvals: Ordinate Values.
8303+
:param x: Point at which to interpolate the polynomial.
8304+
:return: The function returns the value at `x' of the unique polynomial of degree n-1 that fits the points in the plane defined by `first', `step', and `yvals'.
8305+
"""
8306+
n = ctypes.c_int(len(yvals))
8307+
_first = ctypes.c_double(first)
8308+
_step = ctypes.c_double(step)
8309+
_yvals = stypes.to_double_vector(yvals)
8310+
_x = ctypes.c_double(x)
8311+
return libspice.lgresp_c(n, _first, _step, _yvals, _x)
8312+
8313+
8314+
@spice_error_check
8315+
def lgrind(
8316+
xvals: Sequence[float], yvals: Sequence[float], x: float
8317+
) -> Tuple[float, float]:
8318+
"""
8319+
Evaluate a Lagrange interpolating polynomial for a specified
8320+
set of coordinate pairs, at a specified abscissa value.
8321+
Return the value of both polynomial and derivative.
8322+
8323+
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/lgrind_c.html
8324+
8325+
:param xvals: Abscissa values.
8326+
:param yvals: Ordinate values.
8327+
:param x: Point at which to interpolate the polynomial.
8328+
:return: Polynomial value at x, Polynomial derivative at x.
8329+
"""
8330+
n = ctypes.c_int(len(xvals))
8331+
xvals = stypes.to_double_vector(xvals)
8332+
yvals = stypes.to_double_vector(yvals)
8333+
work = stypes.empty_double_vector(n.value * 2)
8334+
x = ctypes.c_double(x)
8335+
p = ctypes.c_double(0)
8336+
dp = ctypes.c_double(0)
8337+
libspice.lgrind_c(n, xvals, yvals, work, x, p, dp)
8338+
return p.value, dp.value
8339+
8340+
8341+
@spice_error_check
8342+
def lgrint(xvals: ndarray, yvals: ndarray, x: float) -> float:
8343+
"""
8344+
Evaluate a Lagrange interpolating polynomial for a specified
8345+
set of coordinate pairs, at a specified abscissa value.
8346+
8347+
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/lgrint_c.html
8348+
8349+
:param xvals: Abscissa values.
8350+
:param yvals: Ordinate values.
8351+
:param x: Point at which to interpolate the polynomial.
8352+
:return: The function returns the value at `x' of the unique polynomial of degree n-1 that fits the points in the plane defined by `xvals' and `yvals'.
8353+
"""
8354+
n = ctypes.c_int(len(xvals))
8355+
_xvals = stypes.to_double_vector(xvals)
8356+
_yvals = stypes.to_double_vector(yvals)
8357+
_x = ctypes.c_double(x)
8358+
return libspice.lgrint_c(n, _xvals, _yvals, _x)
8359+
8360+
82918361
@spice_error_check
82928362
def limbpt(
82938363
method: str,
@@ -8377,33 +8447,6 @@ def limbpt(
83778447
)
83788448

83798449

8380-
@spice_error_check
8381-
def lgrind(
8382-
xvals: Sequence[float], yvals: Sequence[float], x: float
8383-
) -> Tuple[float, float]:
8384-
"""
8385-
Evaluate a Lagrange interpolating polynomial for a specified
8386-
set of coordinate pairs, at a specified abscissa value.
8387-
Return the value of both polynomial and derivative.
8388-
8389-
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/lgrind_c.html
8390-
8391-
:param xvals: Abscissa values.
8392-
:param yvals: Ordinate values.
8393-
:param x: Point at which to interpolate the polynomial.
8394-
:return: Polynomial value at x, Polynomial derivative at x.
8395-
"""
8396-
n = ctypes.c_int(len(xvals))
8397-
xvals = stypes.to_double_vector(xvals)
8398-
yvals = stypes.to_double_vector(yvals)
8399-
work = stypes.empty_double_vector(n.value * 2)
8400-
x = ctypes.c_double(x)
8401-
p = ctypes.c_double(0)
8402-
dp = ctypes.c_double(0)
8403-
libspice.lgrind_c(n, xvals, yvals, work, x, p, dp)
8404-
return p.value, dp.value
8405-
8406-
84078450
@spice_error_check
84088451
def lmpool(cvals: Union[ndarray, Iterable[str]]) -> None:
84098452
"""
@@ -10259,6 +10302,30 @@ def qcktrc(tracelen: int = _default_len_out) -> str:
1025910302
return stypes.to_python_string(tracestr)
1026010303

1026110304

10305+
@spice_error_check
10306+
def qderiv(f0: ndarray, f2: ndarray, delta: float) -> ndarray:
10307+
"""
10308+
Estimate the derivative of a function by finding the derivative
10309+
of a quadratic approximating function. This derivative estimate
10310+
is equivalent to that found by computing the average of forward
10311+
and backward differences.
10312+
10313+
https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/qderiv_c.html
10314+
10315+
:param f0: Function values at left endpoint.
10316+
:param f2: Function values at right endpoint.
10317+
:param delta: Separation of abscissa points.
10318+
:return: Derivative vector.
10319+
"""
10320+
_ndim = ctypes.c_int(len(f0))
10321+
_f0 = stypes.to_double_vector(f0)
10322+
_f2 = stypes.to_double_vector(f2)
10323+
_delta = ctypes.c_double(delta)
10324+
_dfdt = stypes.empty_double_vector(_ndim)
10325+
libspice.qderiv_c(_ndim, _f0, _f2, _delta, _dfdt)
10326+
return stypes.c_vector_to_python(_dfdt)
10327+
10328+
1026210329
@spice_error_check
1026310330
def qdq2av(q: ndarray, dq: Union[ndarray, Iterable[float]]) -> ndarray:
1026410331
"""

src/spiceypy/tests/test_wrapper.py

+21
Original file line numberDiff line numberDiff line change
@@ -5257,12 +5257,25 @@ def test_ldpool():
52575257
cleanup_kernel(kernel)
52585258

52595259

5260+
def test_lgresp():
5261+
yvals = [-2.0, -8.0, 26.0, 148.0]
5262+
a = spice.lgresp(-1.0, 2.0, yvals, 2.0)
5263+
assert a == pytest.approx(1.0)
5264+
5265+
52605266
def test_lgrind():
52615267
p, dp = spice.lgrind([-1.0, 0.0, 1.0, 3.0], [-2.0, -7.0, -8.0, 26.0], 2.0)
52625268
assert p == pytest.approx(1.0)
52635269
assert dp == pytest.approx(16.0)
52645270

52655271

5272+
def test_lgrint():
5273+
xvals = [-1.0, 0.0, 1.0, 3.0]
5274+
yvals = [-2.0, -7.0, -8.0, 26.0]
5275+
a = spice.lgrint(xvals, yvals, 2.0)
5276+
assert a == pytest.approx(1.0)
5277+
5278+
52665279
def test_limbpt():
52675280
spice.furnsh(CoreKernels.spk)
52685281
spice.furnsh(ExtraKernels.marsSpk)
@@ -6358,6 +6371,14 @@ def test_qcktrc():
63586371
spice.reset()
63596372

63606373

6374+
def test_qderiv():
6375+
delta = 1.0e-3
6376+
f0 = [(2.0 - delta) ** 2.0]
6377+
f2 = [(2.0 + delta) ** 2.0]
6378+
dfdt = spice.qderiv(f0, f2, delta)
6379+
assert 4 - dfdt[0] < 1e-12
6380+
6381+
63616382
def test_qdq2av():
63626383
angle = [-20.0 * spice.rpd(), 50.0 * spice.rpd(), -60.0 * spice.rpd()]
63636384
m = spice.eul2m(angle[2], angle[1], angle[0], 3, 1, 3)

src/spiceypy/utils/libspicehelper.py

+5
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,8 @@
12561256
]
12571257
libspice.lcase_c.argtypes = [c_char_p, c_int, c_char_p]
12581258
libspice.ldpool_c.argtypes = [c_char_p]
1259+
libspice.lgresp_c.argtypes = [c_int, c_double, c_double, c_double_p, c_double]
1260+
libspice.lgresp_c.restype = c_double
12591261
libspice.lgrind_c.argtypes = [
12601262
c_int,
12611263
c_double_p,
@@ -1265,6 +1267,8 @@
12651267
c_double_p,
12661268
c_double_p,
12671269
]
1270+
libspice.lgrint_c.argtypes = [c_int, c_double_p, c_double_p, c_double]
1271+
libspice.lgrint_c.restype = c_double
12681272
libspice.limbpt_c.argtypes = [
12691273
c_char_p,
12701274
c_char_p,
@@ -1489,6 +1493,7 @@
14891493

14901494
libspice.q2m_c.argtypes = [c_double * 4, (c_double * 3) * 3]
14911495
libspice.qcktrc_c.argtypes = [c_int, c_char_p]
1496+
libspice.qderiv_c.argtypes = [c_int, c_double_p, c_double_p, c_double, c_double_p]
14921497
libspice.qdq2av_c.argtypes = [c_double * 4, c_double * 4, c_double * 3]
14931498
libspice.qxq_c.argtypes = [c_double * 4, c_double * 4, c_double * 4]
14941499

0 commit comments

Comments
 (0)