Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit abce476

Browse files
committedApr 16, 2025·
lots of refactoring and some fixes, questionable solution for booleans, switched to explicit casting to ensure numpy arrays and not memviews are returned. I think this could be resulting in some slowdowns
1 parent 2b2e20c commit abce476

File tree

4 files changed

+751
-824
lines changed

4 files changed

+751
-824
lines changed
 

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
.zip
77
*.pyc
88
*.so
9+
.vscode/
910

1011
# Spice Kernels
1112
*.bsp

‎src/spiceypy/benchmarks/test_cyice.py

Lines changed: 136 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,61 @@ def setup_module(module):
8585
def test_cyice_b1900_correctness():
8686
assert cyice.b1900() == 2415020.31352
8787

88+
8889
@pytest.mark.parametrize('function', [cyice.b1900, spice.b1900], ids=get_module_name)
8990
@pytest.mark.parametrize('grouped_benchmark', ["b1900"], indirect=True)
9091
def test_perf_b1900(function, grouped_benchmark):
9192
grouped_benchmark(function)
9293

9394

94-
def test_cyice_convrt_correctness():
95-
assert cyice.convrt(300.0, "statute_miles", "km") == 482.80320
95+
@pytest.mark.parametrize('function', [cyice.ckgp, spice.ckgp], ids=get_module_name)
96+
@pytest.mark.parametrize('grouped_benchmark', ["ckgp"], indirect=True)
97+
def test_perf_ckgp(function, grouped_benchmark, load_cassini_kernels):
98+
ckid = -82000
99+
cover = 267832537952.0
100+
grouped_benchmark(function, ckid, cover, 256, "J2000")
101+
res = function(ckid, cover, 256, "J2000")
102+
cmat, clkout = res[0], res[1]
103+
assert clkout == 267832537952.0
104+
assert isinstance(cmat, np.ndarray)
105+
expected_cmat = [
106+
[0.5064665782997639365, -0.75794210739897316387, 0.41111478554891744963],
107+
[-0.42372128242505308071, 0.19647683351734512858, 0.88422685364733510927],
108+
[-0.7509672961490383436, -0.6220294331642198804, -0.22164725216433822652],
109+
]
110+
npt.assert_array_almost_equal(cmat, expected_cmat)
111+
112+
113+
@pytest.mark.parametrize('function', [cyice.ckgpav, spice.ckgpav], ids=get_module_name)
114+
@pytest.mark.parametrize('grouped_benchmark', ["ckgpav"], indirect=True)
115+
def test_perf_ckgpav(function, grouped_benchmark, load_cassini_kernels):
116+
ckid = -82000
117+
cover = 267832537952.0
118+
grouped_benchmark(function, ckid, cover, 256, "J2000")
119+
res = function(ckid, cover, 256, "J2000")
120+
cmat, avout, clkout = res[0], res[1], res[2]
121+
assert clkout == 267832537952.0
122+
assert isinstance(cmat, np.ndarray)
123+
assert isinstance(avout, np.ndarray)
124+
expected_cmat = [
125+
[0.5064665782997639365, -0.75794210739897316387, 0.41111478554891744963],
126+
[-0.42372128242505308071, 0.19647683351734512858, 0.88422685364733510927],
127+
[-0.7509672961490383436, -0.6220294331642198804, -0.22164725216433822652],
128+
]
129+
expected_avout = [
130+
-0.00231258422150853885,
131+
-0.00190333614370416515,
132+
-0.00069657429072504716,
133+
]
134+
npt.assert_array_almost_equal(cmat, expected_cmat)
135+
npt.assert_array_almost_equal(avout, expected_avout)
96136

97137

98138
@pytest.mark.parametrize('function', [cyice.convrt, spice.convrt], ids=get_module_name)
99139
@pytest.mark.parametrize('grouped_benchmark', ["convrt"], indirect=True)
100140
def test_perf_convrt(function, grouped_benchmark):
101141
grouped_benchmark(function, 1.0, "parsecs", "lightyears")
142+
assert function(300.0, "statute_miles", "km") == 482.80320
102143

103144

104145
@pytest.mark.parametrize('function', [cyice.convrt_v, spice.convrt], ids=get_module_name)
@@ -120,11 +161,14 @@ def test_perf_deltet(function, grouped_benchmark, load_core_kernels):
120161
def test_perf_deltet_v(function, grouped_benchmark, load_core_kernels):
121162
ets_2004 = np.repeat(spice.str2et("Jan 1 2004"), 100)
122163
grouped_benchmark(function, ets_2004, "ET")
164+
res = function(ets_2004, "ET")
165+
assert isinstance(res, np.ndarray)
123166

124167

125168
def test_cyice_et2utc_v_correctness(load_core_kernels):
126169
et = -527644192.5403653
127170
output = cyice.et2utc_v(np.array([et] * 100), "J", 6)
171+
assert isinstance(output, list)
128172
assert np.array_equal(
129173
output,
130174
np.array(["JD 2445438.006415"] * 100),
@@ -155,6 +199,8 @@ def test_perf_etcal(function, grouped_benchmark):
155199
def test_perf_etcal_v(function, grouped_benchmark):
156200
data = np.arange(10000.0, dtype=float)
157201
grouped_benchmark(function, data)
202+
res = function(data)
203+
assert isinstance(res, np.ndarray)
158204

159205

160206
@pytest.mark.parametrize('function', [cyice.failed, spice.failed], ids=get_module_name)
@@ -172,13 +218,36 @@ def test_perf_fovray(function, grouped_benchmark, load_cassini_kernels):
172218
et = spice.str2et("2013 FEB 25 11:50:00 UTC")
173219
raydir = np.array([0.0, 0.0, 1.0])
174220
grouped_benchmark(function, "CASSINI_ISS_NAC", raydir, frame, "S", "CASSINI", et)
221+
assert function("CASSINI_ISS_NAC", raydir, frame, "S", "CASSINI", et)
222+
223+
224+
@pytest.mark.parametrize('function', [cyice.fovray_v], ids=get_module_name)
225+
@pytest.mark.parametrize('grouped_benchmark', ["fovray_v"], indirect=True)
226+
def test_perf_fovray_v(function, grouped_benchmark, load_cassini_kernels):
227+
# core of test
228+
ets = np.repeat(spice.str2et("2013 FEB 25 11:50:00 UTC"), 100)
229+
raydir = np.array([0.0, 0.0, 1.0])
230+
grouped_benchmark(function, "CASSINI_ISS_NAC", raydir, "CASSINI_ISS_NAC", "S", "CASSINI", ets)
231+
res = function("CASSINI_ISS_NAC", raydir, "CASSINI_ISS_NAC", "S", "CASSINI", ets)
232+
assert isinstance(res, np.ndarray)
233+
assert res.dtype == np.bool
175234

176235

177236
@pytest.mark.parametrize('function', [cyice.fovtrg, spice.fovtrg], ids=get_module_name)
178237
@pytest.mark.parametrize('grouped_benchmark', ["fovtrg"], indirect=True)
179-
def test_perf_fovray(function, grouped_benchmark, load_cassini_kernels):
238+
def test_perf_fovtrg(function, grouped_benchmark, load_cassini_kernels):
180239
et = spice.str2et("2013 FEB 25 11:50:00 UTC")
181-
grouped_benchmark(function, "CASSINI_ISS_NAC","Enceladus", "Ellipsoid", "IAU_ENCELADUS", "LT+S","CASSINI", et)
240+
grouped_benchmark(function, "CASSINI_ISS_NAC", "Enceladus", "Ellipsoid", "IAU_ENCELADUS", "LT+S","CASSINI", et)
241+
242+
243+
@pytest.mark.parametrize('function', [cyice.fovtrg_v], ids=get_module_name)
244+
@pytest.mark.parametrize('grouped_benchmark', ["fovtrg_v"], indirect=True)
245+
def test_perf_fovtrg_v(function, grouped_benchmark, load_cassini_kernels):
246+
ets = np.repeat(spice.str2et("2013 FEB 25 11:50:00 UTC"), 100)
247+
grouped_benchmark(function, "CASSINI_ISS_NAC","Enceladus", "Ellipsoid", "IAU_ENCELADUS", "LT+S","CASSINI", ets)
248+
res = function( "CASSINI_ISS_NAC","Enceladus", "Ellipsoid", "IAU_ENCELADUS", "LT+S","CASSINI", ets)
249+
assert isinstance(res, np.ndarray)
250+
assert res.dtype == np.bool
182251

183252

184253
@pytest.mark.parametrize('function', [cyice.lspcn, spice.lspcn], ids=get_module_name)
@@ -217,6 +286,7 @@ def test_cyice_spkcvt_correctness(load_earth_kernels):
217286
1.11355285621839659171e01,
218287
])
219288
npt.assert_almost_equal(lt, expected_lt)
289+
assert isinstance(state, np.ndarray)
220290
npt.assert_array_almost_equal(state, expected_state, decimal=6)
221291

222292

@@ -255,14 +325,13 @@ def test_perf_sce2c(function, grouped_benchmark, load_voyager_kernels):
255325
grouped_benchmark(function, -32, et)
256326

257327

258-
# @pytest.mark.skip(reason="broken")
259-
# @pytest.mark.parametrize('function', [cyice.sce2s, spice.sce2s])
260-
# def test_perf_sce2s(function, benchmark):
261-
# benchmark.group = 'performance - %s' % get_qualified_name(function)
262-
# spice.furnsh(CoreKernels.testMetaKernel)
263-
# spice.furnsh(ExtraKernels.voyagerSclk)
264-
# et = spice.str2et("1979 JUL 05 21:50:21.23379")
265-
# benchmark(function, -32, et)
328+
@pytest.mark.parametrize('function', [cyice.sce2s, spice.sce2s], ids=get_module_name)
329+
@pytest.mark.parametrize('grouped_benchmark', ["sce2s"], indirect=True)
330+
def test_perf_sce2s(function, grouped_benchmark):
331+
spice.furnsh(CoreKernels.testMetaKernel)
332+
spice.furnsh(ExtraKernels.voyagerSclk)
333+
et = spice.str2et("1979 JUL 05 21:50:21.23379")
334+
grouped_benchmark(function, -32, et)
266335

267336

268337
@pytest.mark.parametrize('function', [cyice.scs2e, spice.scs2e], ids=get_module_name)
@@ -276,72 +345,66 @@ def test_perf_scs2e(function, grouped_benchmark, load_voyager_kernels):
276345
def test_perf_sct2e(function, grouped_benchmark, load_voyager_kernels):
277346
grouped_benchmark(function, -32, 985327965.0)
278347

279-
# # def test_getmsg_cyice_benchmark(benchmark):
280-
# # cyice.reset()
281-
# # spice.sigerr("test error")
282-
# # benchmark(cyice.getmsg, "SHORT", 200)
283-
# # cyice.reset()
284-
285-
286-
# # def test_getmsg_spiceypy_benchmark(benchmark):
287-
# # spice.reset()
288-
# # spice.sigerr("test error")
289-
# # benchmark(spice.getmsg, "SHORT", 200)
290-
# # spice.reset()
291-
292-
293-
# # def test_qcktrc():
294-
# # cyice.reset()
295-
# # spice.chkin("test")
296-
# # spice.chkin("qcktrc")
297-
# # trace = cyice.qcktrc(40)
298-
# # assert trace == "test --> qcktrc"
299-
# # spice.chkout("qcktrc")
300-
# # spice.chkout("test")
301-
# # cyice.reset()
302-
303348

304-
# # def test_qcktrc_cyice_benchmark(benchmark):
305-
# # cyice.reset()
306-
# # spice.chkin("test")
307-
# # spice.chkin("qcktrc")
308-
# # benchmark(cyice.qcktrc, 40)
309-
# # spice.chkout("qcktrc")
310-
# # spice.chkout("test")
311-
# # cyice.reset()
349+
@pytest.mark.parametrize('function', [cyice.getmsg, spice.getmsg], ids=get_module_name)
350+
@pytest.mark.parametrize('grouped_benchmark', ["getmsg"], indirect=True)
351+
def test_perf_getmsg(function, grouped_benchmark):
352+
cyice.reset()
353+
spice.sigerr("test error")
354+
grouped_benchmark(function, "SHORT", 200)
355+
cyice.reset()
312356

313357

314-
# # def test_qcktrc_spiceypy_benchmark(benchmark):
315-
# # spice.reset()
316-
# # spice.chkin("test")
317-
# # spice.chkin("qcktrc")
318-
# # benchmark(spice.qcktrc, 40)
319-
# # spice.chkout("qcktrc")
320-
# # spice.chkout("test")
321-
# # spice.reset()
358+
@pytest.mark.parametrize('function', [cyice.qcktrc, spice.qcktrc], ids=get_module_name)
359+
@pytest.mark.parametrize('grouped_benchmark', ["qcktrc"], indirect=True)
360+
def test_perf_qcktrc(function, grouped_benchmark):
361+
cyice.reset()
362+
spice.chkin("test")
363+
spice.chkin("qcktrc")
364+
grouped_benchmark(function, 40)
365+
trace = function(40)
366+
assert trace == "test --> qcktrc"
367+
spice.chkout("qcktrc")
368+
spice.chkout("test")
369+
cyice.reset()
322370

323371

324372
@pytest.mark.parametrize('function', [cyice.spkez, spice.spkez], ids=get_module_name)
325373
@pytest.mark.parametrize('grouped_benchmark', ["spkez"], indirect=True)
326374
def test_perf_spkez(function, grouped_benchmark, load_core_kernels):
327375
et = cyice.str2et("July 4, 2003 11:00 AM PST")
328376
grouped_benchmark(function, 499, et, "J2000", "LT+S", 399)
377+
state, lt = function(499, et, "J2000", "LT+S", 399)
378+
assert isinstance(state, np.ndarray)
329379

330380

381+
@pytest.mark.parametrize('function', [cyice.spkez_v], ids=get_module_name)
382+
@pytest.mark.parametrize('grouped_benchmark', ["spkez_v"], indirect=True)
383+
def test_perf_spkez_v(function, grouped_benchmark, load_core_kernels):
384+
ets = np.repeat(cyice.str2et("July 4, 2003 11:00 AM PST"), 100)
385+
grouped_benchmark(function, 499, ets, "J2000", "LT+S", 399)
386+
state, lts = function(499, ets, "J2000", "LT+S", 399)
387+
assert isinstance(state, np.ndarray)
388+
assert isinstance(lts, np.ndarray)
389+
331390

332391
@pytest.mark.parametrize('function', [cyice.spkezr, spice.spkezr], ids=get_module_name)
333392
@pytest.mark.parametrize('grouped_benchmark', ["spkezr"], indirect=True)
334393
def test_perf_spkezr(function, grouped_benchmark, load_core_kernels):
335394
et = cyice.str2et("July 4, 2003 11:00 AM PST")
336395
grouped_benchmark(function, "Mars", et, "J2000", "LT+S", "Earth")
396+
state, lt = function("Mars", et, "J2000", "LT+S", "Earth")
397+
assert isinstance(state, np.ndarray)
337398

338399

339400
@pytest.mark.parametrize('function', [cyice.spkezr_v, spice.spkezr], ids=get_module_name)
340401
@pytest.mark.parametrize('grouped_benchmark', ["spkezr_v"], indirect=True)
341402
def test_perf_spkezr_v(function, grouped_benchmark, load_core_kernels):
342403
ets = np.full((100,), spice.str2et("July 4, 2003 11:00 AM PST"))
343404
grouped_benchmark(function, "Mars", ets, "J2000", "LT+S", "Earth")
344-
state, lt = function("Mars", ets, "J2000", "LT+S", "Earth")
405+
state, lts = function("Mars", ets, "J2000", "LT+S", "Earth")
406+
assert isinstance(lts, np.ndarray)
407+
assert isinstance(state, np.ndarray)
345408
expected_lt = np.full((100,), 269.6898816177049)
346409
expected_state = np.full(
347410
(100, 6),
@@ -354,7 +417,7 @@ def test_perf_spkezr_v(function, grouped_benchmark, load_core_kernels):
354417
3.001298515816776,
355418
],
356419
)
357-
npt.assert_allclose(lt, expected_lt)
420+
npt.assert_allclose(lts, expected_lt)
358421
npt.assert_allclose(state, expected_state)
359422

360423

@@ -371,13 +434,16 @@ def test_perf_spkpos_v(function, grouped_benchmark, load_core_kernels):
371434
_et = spice.str2et(["July 4, 2003 11:00 AM PST", "July 11, 2003 11:10 AM PST"])
372435
et = np.linspace(_et[0], _et[1], num=100)
373436
grouped_benchmark(function, "Mars", et, "J2000", "LT+S", "Earth")
437+
ptargs, lts = function("Mars", et, "J2000", "LT+S", "Earth")
438+
assert isinstance(ptargs, np.ndarray)
374439

375440

376441
@pytest.mark.parametrize('function', [cyice.str2et, spice.str2et], ids=get_module_name)
377442
@pytest.mark.parametrize('grouped_benchmark', ["str2et"], indirect=True)
378443
def test_perf_str2et(function, grouped_benchmark, load_core_kernels):
379444
grouped_benchmark(function, "Thu Mar 20 12:53:29 PST 1997")
380445

446+
381447
@pytest.mark.parametrize('function', [cyice.str2et_v, spice.str2et], ids=get_module_name)
382448
@pytest.mark.parametrize('grouped_benchmark', ["str2et_v"], indirect=True)
383449
def test_perf_str2et_v(function, grouped_benchmark, load_core_kernels):
@@ -386,6 +452,7 @@ def test_perf_str2et_v(function, grouped_benchmark, load_core_kernels):
386452
grouped_benchmark(function, dates)
387453
expected_ets = np.ones(100) * -87836728.81438904
388454
ets = function(dates)
455+
assert isinstance(ets, np.ndarray)
389456
npt.assert_array_almost_equal(ets, expected_ets)
390457

391458

@@ -406,6 +473,7 @@ def test_perf_sxform(function, grouped_benchmark, load_core_kernels):
406473
estate = spice.georec(lon, lat, alt, equatr, f)
407474
estate = np.append(estate, [0.0, 0.0, 0.0])
408475
xform = cyice.sxform("IAU_EARTH", "J2000", et)
476+
assert isinstance(xform, np.ndarray)
409477
jstate = np.dot(xform, estate)
410478
expected = np.array(
411479
[
@@ -425,6 +493,8 @@ def test_perf_sxform(function, grouped_benchmark, load_core_kernels):
425493
def test_perf_sxform_v(function, grouped_benchmark, load_core_kernels):
426494
et = np.repeat(spice.str2et("January 1, 1990"), 1000)
427495
grouped_benchmark(function, "IAU_EARTH", "J2000", et)
496+
res = function("IAU_EARTH", "J2000", et)
497+
assert isinstance(res, np.ndarray)
428498

429499

430500
@pytest.mark.parametrize('function', [cyice.tangpt, spice.tangpt], ids=get_module_name)
@@ -451,6 +521,8 @@ def test_perf_tangpt(function, grouped_benchmark, load_core_kernels):
451521
tanpt, alt, range, srfpt, trgepc, srfvec = spice.tangpt(
452522
"ELLIPSOID", target, et, fixref, "NONE", locus, obsrvr, rayfrm, raydir
453523
)
524+
assert isinstance(tanpt, np.ndarray)
525+
assert isinstance(srfpt, np.ndarray)
454526
npt.assert_array_almost_equal(
455527
tanpt, [-113646.428171, 213634.489363, -222709.965702], decimal=5
456528
)
@@ -461,6 +533,7 @@ def test_perf_tangpt(function, grouped_benchmark, load_core_kernels):
461533
)
462534
assert trgepc == pytest.approx(414026480.213872)
463535

536+
464537
@pytest.mark.parametrize('function', [cyice.trgsep, spice.trgsep], ids=get_module_name)
465538
@pytest.mark.parametrize('grouped_benchmark', ["trgsep"], indirect=True)
466539
def test_perf_trgsep(function, grouped_benchmark, load_core_kernels):
@@ -469,11 +542,14 @@ def test_perf_trgsep(function, grouped_benchmark, load_core_kernels):
469542
point_sep = function(et, "MOON", "POINT", "IAU_MOON", "EARTH", "POINT", "IAU_EARTH", "SUN", "LT+S")
470543
assert spice.dpr() * point_sep == pytest.approx(0.15729276)
471544

545+
472546
@pytest.mark.parametrize('function', [cyice.trgsep_v,], ids=get_module_name)
473547
@pytest.mark.parametrize('grouped_benchmark', ["trgsep_v"], indirect=True)
474548
def test_perf_trgsep_v(function, grouped_benchmark, load_core_kernels):
475549
ets = np.repeat(spice.str2et("2007-JAN-11 11:21:20.213872 (TDB)"),100)
476550
grouped_benchmark(function, ets, "MOON", "POINT", "IAU_MOON", "EARTH", "POINT", "IAU_EARTH", "SUN", "LT+S")
551+
res = function(ets, "MOON", "POINT", "IAU_MOON", "EARTH", "POINT", "IAU_EARTH", "SUN", "LT+S")
552+
assert isinstance(res, np.ndarray)
477553

478554

479555
@pytest.mark.parametrize('function', [cyice.unitim, spice.unitim], ids=get_module_name)
@@ -491,17 +567,22 @@ def test_perf_unitim(function, grouped_benchmark, load_core_kernels):
491567
def test_perf_unitim_v(function, grouped_benchmark, load_core_kernels):
492568
ets = np.repeat(spice.str2et("Dec 19 2003"), 100)
493569
grouped_benchmark(function, ets, "ET", "JED")
570+
res = function(ets, "ET", "JED")
571+
assert isinstance(res, np.ndarray)
494572

495573

496574
@pytest.mark.parametrize('function', [cyice.utc2et, spice.utc2et], ids=get_module_name)
497575
@pytest.mark.parametrize('grouped_benchmark', ["utc2et"], indirect=True)
498576
def test_perf_utc2et(function, grouped_benchmark, load_core_kernels):
499577
grouped_benchmark(function, "December 1, 2004 15:04:11")
578+
assert function("December 1, 2004 15:04:11") == 155185515.1831043
500579

501580

502581
@pytest.mark.parametrize('function', [cyice.utc2et_v], ids=get_module_name)
503582
@pytest.mark.parametrize('grouped_benchmark', ["utc2et_v"], indirect=True)
504583
def test_perf_utc2et_v(function, grouped_benchmark, load_core_kernels):
505584
date = "December 1, 2004 15:04:11"
506585
dates = np.array([date] * 100, dtype=np.str_)
507-
grouped_benchmark(function, dates)
586+
grouped_benchmark(function, dates)
587+
res = function(dates)
588+
assert isinstance(res, np.ndarray)

0 commit comments

Comments
 (0)
Please sign in to comment.