Skip to content

[Bug]: Bug with inject_and_recovery when multiple companions are present in the frame #291

Description

@strampelligiovanni

Check Existing Issues

  • Yes, I have checked existing issues to ensure this problem hasn't already been reported.

Instrument or Category

Analysis Tools

Description

When running inject_and_recovery from Analysis.calibrate_contrast , if multiple companions are already present in the frame, I encountered a bug (I believe) where it get stuck in a loop where it's trying to inject 0 canididates, and creates an infinite amount of files.

I'll try to show an example of what's happening, I tested with target 00135300-7441178 from GO-6005 (but it's not the only problematic one).
I'm running the Analysis.calibrate_contrast with multi_injection_spacing=12 (I didn't encounter this problem when running with multi_injection_spacing=None).

in inject_and_recovery - line 2451:

if true_companions is not None:
        for tcomp in true_companions: <---- I have 3 true companion, so the pos_id will restart from 0 when we switch to a new companion
            tcomp_ra, tcomp_de, tcomp_rad = tcomp
            for i in range(Nsep):
                for j in range(Npa):
                    pos_id = i*Npa+j
                    # Convert position to x-y (RA-DEC) offset in pixels
                    inj_ra = injection_seps[i]*np.sin(np.deg2rad(injection_pas[j])) # pixels
                    inj_de = injection_seps[i]*np.cos(np.deg2rad(injection_pas[j])) # pixels
                    # Calculate distance to companion
                    dist = np.sqrt((tcomp_ra-inj_ra)**2+(tcomp_de-inj_de)**2)
                    #Check if too close, if so, lie to the code and say its already injected
                    if dist < tcomp_rad:
                        list_of_injected += [pos_id] <---- [0, 1, 6, 4, 9, 14, 4, 9, 14, 14, 19] this is how the list looks like at the end of the loop, there are repetitions in the Ids since the counter is resetted for each companion

then at line 2570 I eventually get after a few loops:

Ninjected = len(current_injected) = 0

and then at line 2634:

            if len(list_of_injected) == Nsep*Npa: <---- this never checks out because in the list_of_injected there are repeated Ids, so they can't match.
                all_injected = True
            else:
                counter += 1

and so it gets stuck creating an infinite number of 0 injected companions.

I solved in my case changing that if statement to len(np.unique(list_of_injected)) == Nsep*Npa. This allows the cycle to break and exit the loop. Not sure though if this is the correct solution, or if there is an underlyng problem cousing this beheaviour.

Error traceback output

No response

What operating system are you using?

No response

What version of Python are you running?

No response

What Python packages do you have installed?

No response

Additional context or information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions