quatrope / astroalign

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

_generate_invariants requires at least 5 sources to work, find_transform only 3. #36

Closed RosCarraro closed 4 years ago

RosCarraro commented 5 years ago

I'm trying to run find_transform on a target image with 4 sources. The check on target_controlp is passed because there are at least 3 sources, but when it enters _generate_invariants the indx variable is forced to length=5(>4), since NUM_NEAREST_NEIGHBORS=5, and there is no check on this. Then the arrange function is not able to find the fifth source. I'm attaching a screenshot of the errors. image

martinberoiz commented 5 years ago

Yes, this is definitely a bug. I originally intended this to work with 3 sources or more. I will add a new test for low number of sources and try to implement a solution, but it might take a while. I'm afraid that for low number of sources I will have to treat it as a separate case.

leliel12 commented 5 years ago

i think a "warning" can be a solution

El mié., 11 sept. 2019 a las 13:32, Martin Beroiz (notifications@github.com) escribió:

Yes, this is definitely a bug. I originally intended this to work with 3 sources or more. I will add a new test for low number of sources and try to implement a solution, but it might take a while. I'm afraid that for low number of sources I will have to treat it as a separate case.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/toros-astro/astroalign/issues/36?email_source=notifications&email_token=AACJAAWITSTNSEKK5J2JXB3QJEMSPA5CNFSM4IVV7EZ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6PC7IA#issuecomment-530460576, or mute the thread https://github.com/notifications/unsubscribe-auth/AACJAAUW3NE43OFYWJOXJITQJEMSPANCNFSM4IVV7EZQ .

-- Juan B Cabral

RosCarraro commented 5 years ago

So does this mean that if being able to change NUM_NEAREST_NEIGHBORS to len(sources) if len(sources)<5 would not solve the problem? This would be too bad because most of my data has a low number of sources :(

I was trying to do this in _generate_invariants but I have some scope problem: image

martinberoiz commented 5 years ago

Instead of tweaking the source code, you can try changing the value before you call register, like this:

import astroalign as aa
aa.NUM_NEAREST_NEIGHBORS = 3 # (or 4)
aligned = aa.register(source, target)

but I can't guarantee it will work.

The example you gave won't work because you're modifying the variable num instead of the variable NUM_NEAREST_NEIGHBORS.

martinberoiz commented 5 years ago

Hi,

I released a new version that partially deals with few sources. So far it's tested when the input is a list of the (x, y) positions of the sources, as opposed to passing the image. It's tested for 3, 4, 5... sources.

Passing the image array can still cause problems since it seems to be picking up fake sources from the noisy background.

Maybe give it a try and see if this fixes your issue. I'll keep the issue open until I fix this completely.

martinberoiz commented 4 years ago

The new release 2.1 should work with few sources on the image. Please feel free to reopen this issue or open a new one if you still find problems.

Check the new documentation out