i4Ds / Karabo-Pipeline

The Karabo Pipeline can be used as Digital Twin for SKA
https://i4ds.github.io/Karabo-Pipeline/
MIT License
11 stars 4 forks source link

`SourceDetectionResult.detect_sources_in_image()` does not fail when no sources are detected. #210

Closed kenfus closed 1 year ago

kenfus commented 1 year ago
Also note that I found out that Karabo wasn’t handling correctly the case where it can’t detect any
source. Indeed when Karabo perform the detection, It then extract the pixel coordinates using
indexes (If I did understand the source code right). But this extraction expects to obtain an array that
is 2-dimesionnal (one list of ‘x’ coordinates and one of ‘y’ coordinates). But when there is no sources
detected, we obtain simply an empty array (represented like so ‘[ ]’) and so it has only 1 dimension.
This causes an ‘IndexError’ error when running the function
‘SourceDetectionResult.detect_sources_in_image()’ and that no source is detected.
Lukas113 commented 1 year ago

Currently I can't reproduce this issue because all I got was a PyBDSF error (not IndexError) with no sources and I can't see where an IndexError from Karabo could even occur.

However, I've seen some potential improvements in the current API (e.g. Imager object is not needed in detect_sources_in_dirty_image where the according should belong to the Image object itself.).

I'll therefore rewrite detect_sources_in_dirty_image and make the according adjustments on Image. Afterwards I'll test it against no sources and if there are KaraboErrors I will handle them. However, I think it is best to leave PyBDSF errors as they are and let the user handle them.

Lukas113 commented 1 year ago

The only case where we directly access the detected sources by indices is in karabo.sourcedeection.result.SourceDetectionResult.get_pixel_position_of_sources and karabo.sourcedeection.result.PyBDSFSourceDetectionResult.__transform_bdsf_to_reduced_result_array. The first function is not part of SourceDetectionResult.detect_sources_in_image, but the second is. Therefore I assume this is the location where the error occured. In both cases I would expect an empty np.ndarray and error-free code. As soon as I've rewritten the api as discussed in the comment above, I'll test it and if it is not as expected I intend to rewrite it.

Lukas113 commented 1 year ago

Currently I'm not able to reproduce this issue and therefore have requested the corresponding image from the author of the report.

In addition, as partially mentioned above I've done the following in branch LG_210_detect_sources_in_image: