comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

comtypes ndarray with ASCOM safearray problem

Open fockez opened this issue 5 years ago • 4 comments
trafficstars

It is says that comtypes safearray_as_ndarray context manager will accelerate the reading speed of large array from COM. I tried it with ASCOM camera classes. The ASCOM can return ImageArray int safearray and ImageArrayVariant variant safearray. When using ImageArrayVariant, it can be done successfully, but the time is far more than normal np.array(tuple) way. When using ImageArray, the libarary always get error

File "C:\ProgramData\Anaconda3\lib\site-packages\comtypes_init_.py", line 280, in getattr raise AttributeError(name)

I don't know why. Thanks. I just want to know some fast procedure to get image array from ASCOM.

fockez avatar Feb 03 '20 08:02 fockez

see #205 and #178

jove1 avatar May 15 '20 16:05 jove1

Hi,

running over the same problem. I used numpy 1.21.1 and com types 1.1.10 ans still see the same problem. Recent bumpy still only shows numpy types:

ASCOM camera needs:

<class 'ctypes.c_long'>

but

npsupport.typecodes.values()

still returns:

<class 'numpy.uint16'>, <class 'numpy.intc'>, <class 'numpy.uint32'>, <class 'numpy.int64'>, <class 'numpy.float64'>, <class 'numpy.int16'>, <class 'numpy.uint64'>, <class 'numpy.int8'>, <class 'numpy.uint8'>, <class 'numpy.bool_'>, <class 'numpy.float32'>

Michel

mworion avatar Aug 06 '21 16:08 mworion

Addition in analyse so far: in npsupport the types were correctly added to dict typecodes. At the point in time where you compare your SafeArray type against the dict typecodes it contains only the numpy part. So something is going wrong during runtime.

mworion avatar Aug 06 '21 16:08 mworion

Finally I think I found the cause: in line 311 of SafeArray.py there is a check

self._itemtype_ in list(npsupport.typecodes.values())

as the values are mapped to numpy type, we get always the numpys From my opinion we should check against the keys()

self._itemtype_ in list(npsupport.typecodes.keys())

to make the things right. Any thoughts about this ? Michel

mworion avatar Aug 06 '21 17:08 mworion

@fockez @jove1 @mworion

If the issue remains, please re-open.

junkmd avatar Dec 03 '22 07:12 junkmd