diff --git a/spiceypy/spiceypy.py b/spiceypy/spiceypy.py index c32537ea..bc048fec 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 ea08c837..f18f6ac6 100644 --- a/spiceypy/utils/support_types.py +++ b/spiceypy/utils/support_types.py @@ -155,12 +155,6 @@ 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 @@ -169,11 +163,11 @@ def cVectorToPython(x): :return: """ if isinstance(x[0], bool): - return numpy.fromiter(x, numpy.bool, count=len(x)) + return numpy.frombuffer(x, dtype=numpy.bool).copy() elif isinstance(x[0], int): - return numpy.fromiter(x, numpy.int_, count=len(x)) + return numpy.frombuffer(x, dtype=numpy.int32).copy() elif isinstance(x[0], float): - return numpy.fromiter(x, numpy.float64, count=len(x)) + return numpy.frombuffer(x, dtype=numpy.float64).copy() elif isinstance(x[0].value, bytes): return [toPythonString(y) for y in x] @@ -260,7 +254,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 numpy.ctypeslib.as_ctypes(param) + return numpc.as_ctypes(param) # Cast from array.array objects def from_array(self, param): @@ -293,11 +287,11 @@ def from_tuple(self, param): # Cast from a numpy array def from_ndarray(self, param): - return numpy.ctypeslib.as_ctypes(param) + return numpc.as_ctypes(param) # Cast from a numpy matrix def from_matrix(self, param): - return numpy.ctypeslib.as_ctypes(param) + return numpc.as_ctypes(param) class IntArrayType: @@ -324,10 +318,8 @@ def from_tuple(self, param): # Cast from a numpy array def from_ndarray(self, param): - # 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()) + # 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)) # Cast from array.array objects def from_array(self, param): @@ -360,11 +352,13 @@ def from_tuple(self, param): # Cast from a numpy array def from_ndarray(self, param): - return numpy.ctypeslib.as_ctypes(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)) # Cast from a numpy matrix def from_matrix(self, param): - return numpy.ctypeslib.as_ctypes(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)) class BoolArrayType: