fockez
fockez

Reputation: 11

comtypes ndarray with ASCOM safearray problem

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. The description from comtypes doc is below: By default, comtypes converts SAFEARRAY output arguments to tuples of python objects on an item-by-item basis. When dealing with large SAFEARRAYs, this conversion can be costly. Comtypes provides a the safearray_as_ndarray context manager (from comtypes.safearray) for modifying this behavior to return a NumPy array. This altered behavior is to put an ndarray over a copy of the SAFEARRAY’s memory, which is faster than calling into python for each item. When this fails, a NumPy array can still be created on an item-by-item basis. The context manager is thread-safe, in that usage of the context manager on one thread does not affect behavior on other threads.

Thanks.

Upvotes: 1

Views: 273

Answers (0)

Related Questions