spacetelescope / catkit2

Package for controlling testbed hardware.
https://spacetelescope.github.io/catkit2/
BSD 3-Clause "New" or "Revised" License
5 stars 0 forks source link

Array shape error in submit_data #140

Closed THD2-team closed 11 months ago

THD2-team commented 11 months ago

Hi, During our work with the AlliedVision camera's service, we had an issue with the array shape when submitting the data to the data stream (with submit_data). To check if the shape was good, we printed the shape of the array that we submitted and compared it to the data stream size defined in make_data_stream and it looks equals: "[1088, 1456]" for make_data_stream and "(1088, 1456, 1)" for the numpy.ndarray submitted. When adding a one value dimension to match the last one in the shape of the numpy.array to test, another error appears saying there is a dimension missmatch.

Here the exact error message we have with make_data_stream argument "[1088, 1456]", which is the sensor size:

Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 232, in 'calling callback function'
  File "C:\Users\thd\miniconda3\envs\catkit2_TEST\lib\site-packages\vimba\camera.py", line 991, in __frame_cb_wrapper
    raise e
  File "C:\Users\thd\miniconda3\envs\catkit2_TEST\lib\site-packages\vimba\camera.py", line 983, in __frame_cb_wrapper
    context.frames_handler(self, frame)
  File "allied_vision_camera.py", line 94, in frame_handler
    self.images.submit_data( frame.as_numpy_ndarray().astype('float32') )
RuntimeError: Incompatible array shape.
Function Run in C:\Users\thd\repos\catkit2\catkit_core\Service.cpp:156
THD2-team commented 11 months ago

nevermind, issue resolved with np.squeeze, thanks a lot @ivalaginja.

ehpor commented 11 months ago

To clarify a little bit: the DataStream.submit_data() is very strict on the memory structure of the data that you're trying to submit. Inside the submit_data() there is just a memcpy() happening that copies memory from Numpy into the DataStream. This is for speed reasons, where any slowdown should be visible explicitly in the Python code rather than implicitly by converting the incoming array to the right format. That avoids having unexpected slowdowns. In your case, the squeeze does not take very long (read: microseconds), but you could imagine allowing dtype conversions or non-contiguous arrays, which would take way longer.