BCDA-APS / apstools

various tools for use with Bluesky at the APS
https://bcda-aps.github.io/apstools/latest/
Other
16 stars 9 forks source link

RuntimeError from listdevice() #990

Closed prjemian closed 2 weeks ago

prjemian commented 3 months ago

image

prjemian commented 1 month ago

RuntimeError: Invalid array size (0, 0, 0) - Is that an unprimed area detector?

prjemian commented 1 month ago

Perhaps the best way past this is to wrap https://github.com/BCDA-APS/apstools/blob/4a152d0894c9395045eaea6ad00b7721163dfc15/apstools/utils/device_info.py#L231 with try..except and return a value. But what value to return? The error message (Invalid array size (0, 0, 0))? Something more terse?

prjemian commented 1 month ago

If this is an unprimed area detector situation, it is harder to re-create the initial conditions. Need to take an existing AD and change its image parameters so that the ophyd object will raise the exception.

Adding a unit test here could be contrived and possibly not realistic. Need to create a Device with a Signal that triggers the exception.

prjemian commented 1 month ago

Ran again with this code change and an unprimed area detector. Error is now:

In [5]: listdevice(adsimdet)
Subscription value callback exception (EpicsSignal(read_pv='ad:image1:ArrayData', name='adsimdet_image_array_data', parent='adsimdet_image', value=array([], dtype=uint8), timestamp=631152000.0, auto_monitor=True, string=False, write_pv='ad:image1:ArrayData', limits=False, put_complete=False))
Traceback (most recent call last):
  File "/home/prjemian/.conda/envs/bluesky_2024_2/lib/python3.11/site-packages/ophyd/ophydobj.py", line 492, in inner
    cb(*args, **kwargs)
  File "/home/prjemian/.conda/envs/bluesky_2024_2/lib/python3.11/site-packages/ophyd/signal.py", line 696, in _derived_value_callback
    value = self.inverse(value)
            ^^^^^^^^^^^^^^^^^^^
  File "/home/prjemian/.conda/envs/bluesky_2024_2/lib/python3.11/site-packages/ophyd/areadetector/base.py", line 123, in inverse
    raise RuntimeError(f"Invalid array size {self.derived_shape}")
RuntimeError: Invalid array size (0, 0, 0)

Still an exception from ophyd.areadetector.base from the subscription, but this time listdevice() completed.

prjemian commented 1 month ago

Summary

We can suppress that exception from causing listdevice() to fail but the same code raises an exception in the DETECTOR.image.shaped_image callback. The exception is raised in areadetector.base when the image shape tuple is all zeroes. That is an indicator of an area detector IOC that has just started and no image has been passed from the cam to the image plugin.