diff --git a/spiceypy/spiceypy.py b/spiceypy/spiceypy.py index bc048fec..c32537ea 100644 --- a/spiceypy/spiceypy.py +++ b/spiceypy/spiceypy.py @@ -9085,7 +9085,7 @@ def oscltx(state, et, mu): mu = ctypes.c_double(mu) elts = stypes.emptyDoubleVector(20) libspice.oscltx_c(state, et, mu, elts) - return stypes.cVectorToPython(elts)[0:11] + return stypes.cVectorToPython(elts[0:11]) ################################################################################ diff --git a/spiceypy/utils/support_types.py b/spiceypy/utils/support_types.py index f18f6ac6..ea08c837 100644 --- a/spiceypy/utils/support_types.py +++ b/spiceypy/utils/support_types.py @@ -155,6 +155,12 @@ def emptyIntVector(n): return (c_int * n)() +def emptyBoolVector(n): + if isinstance(n, c_int): + n = n.value + return (c_bool * n)() + + def cVectorToPython(x): """ Convert the c vector data into the correct python data type @@ -163,11 +169,11 @@ def cVectorToPython(x): :return: """ if isinstance(x[0], bool): - return numpy.frombuffer(x, dtype=numpy.bool).copy() + return numpy.fromiter(x, numpy.bool, count=len(x)) elif isinstance(x[0], int): - return numpy.frombuffer(x, dtype=numpy.int32).copy() + return numpy.fromiter(x, numpy.int_, count=len(x)) elif isinstance(x[0], float): - return numpy.frombuffer(x, dtype=numpy.float64).copy() + return numpy.fromiter(x, numpy.float64, count=len(x)) elif isinstance(x[0].value, bytes): return [toPythonString(y) for y in x] @@ -254,7 +260,7 @@ def from_ndarray(self, param): # return param.data_as(POINTER(c_double)) # the above older method does not work with # functions which take vectors of known size - return numpc.as_ctypes(param) + return numpy.ctypeslib.as_ctypes(param) # Cast from array.array objects def from_array(self, param): @@ -287,11 +293,11 @@ def from_tuple(self, param): # Cast from a numpy array def from_ndarray(self, param): - return numpc.as_ctypes(param) + return numpy.ctypeslib.as_ctypes(param) # Cast from a numpy matrix def from_matrix(self, param): - return numpc.as_ctypes(param) + return numpy.ctypeslib.as_ctypes(param) class IntArrayType: @@ -318,8 +324,10 @@ def from_tuple(self, param): # Cast from a numpy array def from_ndarray(self, param): - # cspice always uses a int size half as big as the float, ie int32 if a float64 system default - return numpc.as_ctypes(param.astype(numpy.int32)) + # return param.data_as(POINTER(c_int)) + # not sure if long is same as int, it should be.. + # return numpy.ctypeslib.as_ctypes(param) + return self.from_param(param.tolist()) # Cast from array.array objects def from_array(self, param): @@ -352,13 +360,11 @@ def from_tuple(self, param): # Cast from a numpy array def from_ndarray(self, param): - # cspice always uses a int size half as big as the float, ie int32 if a float64 system default - return numpc.as_ctypes(param.astype(numpy.int32)) + return numpy.ctypeslib.as_ctypes(param) # Cast from a numpy matrix def from_matrix(self, param): - # cspice always uses a int size half as big as the float, ie int32 if a float64 system default - return numpc.as_ctypes(param.astype(numpy.int32)) + return numpy.ctypeslib.as_ctypes(param) class BoolArrayType: