Skip to content

Commit 581141e

Browse files
committed
fixes for various bugs and typos identified
1 parent 7e88390 commit 581141e

3 files changed

Lines changed: 134 additions & 80 deletions

File tree

src/spiceypy/spiceypy.py

Lines changed: 57 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -22,64 +22,60 @@
2222
SOFTWARE.
2323
"""
2424

25+
import ctypes
26+
import functools
2527
import warnings
2628
from contextlib import contextmanager
2729
from datetime import datetime, timezone
28-
import functools
29-
import ctypes
30-
from typing import Callable, Iterator, Iterable, Optional, Tuple, Union, Sequence
31-
30+
from typing import Callable, Iterable, Iterator, Optional, Sequence, Tuple, Union
3231

3332
import numpy
3433
from numpy import ndarray, str_
3534

36-
37-
from .utils import support_types as stypes
38-
from .utils.libspicehelper import libspice, cspice_flavor
39-
from .utils.exceptions import (
40-
SpiceyError,
41-
SpiceyPyError,
42-
NotFoundError,
43-
SpiceyPyIOError,
44-
SpiceyPyMemoryError,
45-
SpiceyPyTypeError,
46-
SpiceyPyKeyError,
47-
SpiceyPyIndexError,
48-
SpiceyPyRuntimeError,
49-
SpiceyPyZeroDivisionError,
50-
SpiceyPyValueError,
51-
dynamically_instantiate_spiceyerror
52-
)
35+
from . import config
5336
from .found_catcher import (
37+
found_check,
5438
found_check_off,
5539
found_check_on,
56-
found_check,
57-
no_found_check,
5840
get_found_catch_state,
41+
no_found_check,
5942
spice_found_exception_thrower,
6043
)
61-
from . import config
62-
44+
from .utils import support_types as stypes
6345
from .utils.callbacks import (
46+
UDBAIL,
47+
UDFUNB,
6448
UDFUNC,
6549
UDFUNS,
66-
UDFUNB,
67-
UDSTEP,
6850
UDREFN,
51+
UDREPF,
6952
UDREPI,
7053
UDREPU,
71-
UDREPF,
72-
UDBAIL,
73-
SpiceUDFUNS,
54+
UDSTEP,
7455
SpiceUDFUNB,
56+
SpiceUDFUNS,
7557
)
76-
58+
from .utils.exceptions import (
59+
NotFoundError,
60+
SpiceyError,
61+
SpiceyPyError,
62+
SpiceyPyIndexError,
63+
SpiceyPyIOError,
64+
SpiceyPyKeyError,
65+
SpiceyPyMemoryError,
66+
SpiceyPyRuntimeError,
67+
SpiceyPyTypeError,
68+
SpiceyPyValueError,
69+
SpiceyPyZeroDivisionError,
70+
dynamically_instantiate_spiceyerror,
71+
)
72+
from .utils.libspicehelper import cspice_flavor, libspice
7773
from .utils.support_types import (
78-
Cell_Char,
7974
Cell_Bool,
80-
Cell_Time,
75+
Cell_Char,
8176
Cell_Double,
8277
Cell_Int,
78+
Cell_Time,
8379
Ellipse,
8480
Plane,
8581
SpiceCell,
@@ -2516,7 +2512,7 @@ def dasdc(handle: int) -> None:
25162512
@spice_error_check
25172513
def dasec(
25182514
handle: int, bufsiz: int = _default_len_out, buflen: int = _default_len_out
2519-
) -> Tuple[int, Iterable[str], int]:
2515+
) -> Tuple[int, Iterable[str], bool]:
25202516
"""
25212517
Extract comments from the comment area of a binary DAS file.
25222518

@@ -2544,7 +2540,7 @@ def dasec(
25442540
ctypes.byref(buffer),
25452541
ctypes.byref(done),
25462542
)
2547-
return n.value, stypes.c_vector_to_python(buffer), done.value
2543+
return n.value, stypes.c_vector_to_python(buffer), bool(done.value)
25482544

25492545

25502546
@spice_error_check
@@ -3177,7 +3173,7 @@ def dnearp(
31773173
:param c: Length on semi axis parallel to Z axis.
31783174
:return: State of the nearest point on the ellipsoid, Altitude and derivative of altitude
31793175
"""
3180-
_state = stypes.to_double_matrix(state)
3176+
_state = stypes.to_double_vector(state)
31813177
_a = ctypes.c_double(a)
31823178
_b = ctypes.c_double(b)
31833179
_c = ctypes.c_double(c)
@@ -3518,7 +3514,7 @@ def dskd02(
35183514
n = ctypes.c_int(0)
35193515
values = stypes.empty_double_vector(room)
35203516
libspice.dskd02_c(handle, dladsc, item, start, room, ctypes.byref(n), values)
3521-
return stypes.c_vector_to_python(values)
3517+
return stypes.c_vector_to_python(values)[:n.value]
35223518

35233519

35243520
@spice_error_check
@@ -3578,7 +3574,7 @@ def dski02(
35783574
n = ctypes.c_int()
35793575
values = stypes.empty_int_vector(room)
35803576
libspice.dski02_c(handle, dladsc, item, start, room, ctypes.byref(n), values)
3581-
return stypes.c_matrix_to_numpy(values)
3577+
return stypes.c_vector_to_python(values)[:n.value]
35823578

35833579

35843580
@spice_error_check
@@ -3656,7 +3652,7 @@ def dskn02(handle: int, dladsc: SpiceDLADescr, plid: int) -> ndarray:
36563652
:param handle: DSK file handle.
36573653
:param dladsc: DLA descriptor.
36583654
:param plid: Plate ID.
3659-
:return: late's unit normal vector.
3655+
:return: Plate's unit normal vector.
36603656
"""
36613657
handle = ctypes.c_int(handle)
36623658
plid = ctypes.c_int(plid)
@@ -3722,7 +3718,7 @@ def dskp02(handle: int, dladsc: SpiceDLADescr, start: int, room: int) -> ndarray
37223718
n = ctypes.c_int(0)
37233719
plates = stypes.empty_int_matrix(3, room)
37243720
libspice.dskp02_c(handle, dladsc, start, room, ctypes.byref(n), plates)
3725-
return stypes.c_matrix_to_numpy(plates)
3721+
return stypes.c_matrix_to_numpy(plates)[:n.value]
37263722

37273723

37283724
@spice_error_check
@@ -5370,7 +5366,7 @@ def ekuced(
53705366
nvals = ctypes.c_int(nvals)
53715367
dvals = stypes.to_double_vector(dvals)
53725368
isnull = ctypes.c_int(isnull)
5373-
libspice.ekaced_c(handle, segno, recno, column, nvals, dvals, isnull)
5369+
libspice.ekuced_c(handle, segno, recno, column, nvals, dvals, isnull)
53745370

53755371

53765372
@spice_error_check
@@ -5629,23 +5625,23 @@ def errint(marker: str, number: int) -> None:
56295625
libspice.errint_c(marker, number)
56305626

56315627

5632-
def errprt(op: str, lenout: int, inlist: str) -> str:
5628+
def errprt(op: str, lislen: int, inlist: str) -> str:
56335629
"""
56345630
Retrieve or set the list of error message items to be output when an
56355631
error is detected.
56365632

56375633
https://naif.jpl.nasa.gov/pub/naif/misc/toolkit_docs_N0067/C/cspice/errprt_c.html
56385634

56395635
:param op: The operation, "GET" or "SET".
5640-
:param lenout: Length of list for output.
5636+
:param lislen: Length of list for output.
56415637
:param inlist: Specification of error messages to be output.
56425638
:return: A list of error message items.
56435639
"""
5644-
lenout = ctypes.c_int(lenout)
5640+
lislen = ctypes.c_int(lislen)
56455641
op = stypes.string_to_char_p(op)
5646-
inlist = ctypes.create_string_buffer(str.encode(inlist), lenout.value)
5642+
inlist = ctypes.create_string_buffer(str.encode(inlist), lislen.value)
56475643
inlistptr = ctypes.c_char_p(ctypes.addressof(inlist))
5648-
libspice.errdev_c(op, lenout, inlistptr)
5644+
libspice.errprt_c(op, lislen, inlistptr)
56495645
return stypes.to_python_string(inlistptr)
56505646

56515647

@@ -7611,6 +7607,7 @@ def gfudb(
76117607
"""
76127608
step = ctypes.c_double(step)
76137609
libspice.gfudb_c(udfuns, udfunb, step, ctypes.byref(cnfine), ctypes.byref(result))
7610+
return result
76147611

76157612

76167613
@spice_error_check
@@ -8243,7 +8240,7 @@ def inter(a: SpiceCell, b: SpiceCell) -> SpiceCell:
82438240
assert isinstance(a, stypes.SpiceCell)
82448241
assert isinstance(b, stypes.SpiceCell)
82458242
assert a.dtype == b.dtype
8246-
# Next line was redundant with [raise NotImpImplementedError] below
8243+
# Next line was redundant with [raise NotImplementedError] below
82478244
# assert a.dtype == 0 or a.dtype == 1 or a.dtype == 2
82488245
if a.dtype == 0:
82498246
c = stypes.SPICECHAR_CELL(max(a.size, b.size), max(a.length, b.length))
@@ -11323,7 +11320,7 @@ def recsph(rectan: ndarray) -> Tuple[float, float, float]:
1132311320
"""
1132411321
Convert from rectangular coordinates to spherical coordinates.
1132511322

11326-
https://naif.jpl.nasa.gov/pub/naif/misc/toolkit_docs_N0067/C/cspice/recrad_c.html
11323+
https://naif.jpl.nasa.gov/pub/naif/misc/toolkit_docs_N0067/C/cspice/recsph_c.html
1132711324

1132811325
:param rectan: Rectangular coordinates of a point.
1132911326
:return:
@@ -11512,7 +11509,7 @@ def repmct(
1151211509
Replace a marker with the text representation of a
1151311510
cardinal number.
1151411511

11515-
https://naif.jpl.nasa.gov/pub/naif/misc/toolkit_docs_N0067/C/cspice/repmc_c.html
11512+
https://naif.jpl.nasa.gov/pub/naif/misc/toolkit_docs_N0067/C/cspice/repmct_c.html
1151611513

1151711514
:param instr: Input string.
1151811515
:param marker: Marker to be replaced.
@@ -12793,7 +12790,7 @@ def spkcvt(
1279312790
State of target with respect to observer in km and km/sec,
1279412791
One way light time between target and observer.
1279512792
"""
12796-
trgpos = stypes.to_double_vector(trgsta)
12793+
trgsta = stypes.to_double_vector(trgsta)
1279712794
trgepc = ctypes.c_double(trgepc)
1279812795
trgctr = stypes.string_to_char_p(trgctr)
1279912796
trgref = stypes.string_to_char_p(trgref)
@@ -12805,7 +12802,7 @@ def spkcvt(
1280512802
state = stypes.empty_double_vector(6)
1280612803
lt = ctypes.c_double()
1280712804
libspice.spkcvt_c(
12808-
trgpos,
12805+
trgsta,
1280912806
trgepc,
1281012807
trgctr,
1281112808
trgref,
@@ -12822,11 +12819,7 @@ def spkcvt(
1282212819

1282312820
@spice_error_check
1282412821
def spkez(
12825-
targ: int,
12826-
et: float,
12827-
ref: str,
12828-
abcorr: str,
12829-
obs: int
12822+
targ: int, et: float, ref: str, abcorr: str, obs: int
1283012823
) -> Tuple[ndarray, float]:
1283112824
"""
1283212825
Return the state (position and velocity) of a target body
@@ -12857,11 +12850,7 @@ def spkez(
1285712850

1285812851
@spice_error_check
1285912852
def spkezp(
12860-
targ: int,
12861-
et: float,
12862-
ref: str,
12863-
abcorr: str,
12864-
obs: int
12853+
targ: int, et: float, ref: str, abcorr: str, obs: int
1286512854
) -> Tuple[ndarray, float]:
1286612855
"""
1286712856
Return the position of a target body relative to an observing
@@ -12892,11 +12881,7 @@ def spkezp(
1289212881

1289312882
@spice_error_check
1289412883
def spkezr(
12895-
targ: str,
12896-
et: Union[ndarray, float],
12897-
ref: str,
12898-
abcorr: str,
12899-
obs: str
12884+
targ: str, et: Union[ndarray, float], ref: str, abcorr: str, obs: str
1290012885
) -> Union[Tuple[ndarray, float], Tuple[Iterable[ndarray], Iterable[float]]]:
1290112886
"""
1290212887
Return the state (position and velocity) of a target body
@@ -13130,11 +13115,7 @@ def spkpds(
1313013115

1313113116
@spice_error_check
1313213117
def spkpos(
13133-
targ: str,
13134-
et: Union[float, ndarray],
13135-
ref: str,
13136-
abcorr: str,
13137-
obs: str
13118+
targ: str, et: Union[float, ndarray], ref: str, abcorr: str, obs: str
1313813119
) -> Union[Tuple[ndarray, float], Tuple[ndarray, ndarray]]:
1313913120
"""
1314013121
Return the position of a target body relative to an observing
@@ -15613,11 +15594,12 @@ def union(a: SpiceCell, b: SpiceCell) -> SpiceCell:
1561315594
# Next line was redundant with [raise NotImpImplementedError] below
1561415595
# assert a.dtype == 0 or a.dtype == 1 or a.dtype == 2
1561515596
if a.dtype == 0:
15616-
c = stypes.SPICECHAR_CELL(max(a.size, b.size), max(a.length, b.length))
15597+
s = a.size + b.size
15598+
c = stypes.SPICECHAR_CELL(s, s)
1561715599
elif a.dtype == 1:
15618-
c = stypes.SPICEDOUBLE_CELL(max(a.size, b.size))
15600+
c = stypes.SPICEDOUBLE_CELL(a.size + b.size)
1561915601
elif a.dtype == 2:
15620-
c = stypes.SPICEINT_CELL(max(a.size, b.size))
15602+
c = stypes.SPICEINT_CELL(a.size + b.size)
1562115603
else:
1562215604
raise NotImplementedError
1562315605
libspice.union_c(ctypes.byref(a), ctypes.byref(b), ctypes.byref(c))
@@ -16749,7 +16731,7 @@ def wnreld(a: SpiceCell, op: str, b: SpiceCell) -> bool:
1674916731
assert isinstance(b, stypes.SpiceCell)
1675016732
assert a.dtype == 1
1675116733
assert isinstance(op, str)
16752-
op = stypes.string_to_char_p(op.encode(encoding="UTF-8"))
16734+
op = stypes.string_to_char_p(op)
1675316735
return bool(libspice.wnreld_c(ctypes.byref(a), op, ctypes.byref(b)))
1675416736

1675516737

0 commit comments

Comments
 (0)