quatrope / astroalign

A tool to align astronomical images based on asterism matching
MIT License
140 stars 44 forks source link

fix IndexError #68

Closed dubai03nsr closed 2 years ago

dubai03nsr commented 3 years ago

Calling find_transform sometimes yields an unexpected IndexError: arrays used as indices must be of integer (or boolean) type on line 556 test_points = data[test_idxs, :]. To resolve the IndexError, I cast test_idxs using .astype(int) on line 554.

Among the cases I have tested, the cases that would have yielded IndexError now yield MaxIterError (List of matching triangles exhausted before an acceptable transformation was found) after my fix. Regardless, resolving the unexpected IndexError would make debugging much more user-friendly.

Below is a program that would have yielded IndexError.

import astroalign as aa

source = [(1, 2), (3, 4), (5, 6), (8, 9)]
target = [(2, 2), (4, 4), (6, 6), (10, 9)]
transf, (source_list, target_list) = aa.find_transform(source, target)
martinberoiz commented 3 years ago

Thanks for catching this bug! I did some testing and the problem is not really that test_idxs is not of integer type, but that test_idxs is actually the empty array.

It has to do with the algorithm having a single triangle match and no other triangles to test against (that's why test_idxs is empty).

I tested your solution for the given example, but it still doesn't work for me (it gets stuck a few steps after for the same reason).

I'm looking into this, will try a solution and add a unit testing for this case.

martinberoiz commented 2 years ago

A fix to this bug is merged to master now.