Skip to content

AID file not created due to "Comparison star or VSP AUID not found" #1367

@ivenzor

Description

@ivenzor

In some cases the AID file creation may be skipped due to the following exception: Comparison star or VSP AUID not found

Although the exception is raised within the stellar_variability function, the bug actually originates from the backtrack section of the Aperture Photometry process.

Here’s evidence:

comp_stars [[462, 335], [416, 190], [401, 215], [494, 327], [581, 286], [529, 331], [611, 220], [558, 330]]
vsp_list [[558, 330], [416, 190]]
vsp_num [1, 7]
ref_flux {1: {'myfit': <api.elca.lc_fitter object at 0x000001A75B14F050>, 'pos': [416, 190]}, 7: {'myfit': <api.elca.lc_fitter object at 0x000001A75B14D430>, 'pos': [558, 330]}}

Initially, ref_flux is correctly populated with keys 1 and 7. However, during the backtrack logic, an incorrect key is added. The following log shows key 0 being added to ref_flux:

backtrack is True
temp_ref_flux {1: {'myfit': <api.elca.lc_fitter object at 0x000001A75B1178F0>, 'pos': [416, 190]}, 7: None}
j 6
ref_flux BEFORE {1: {'myfit': <api.elca.lc_fitter object at 0x000001A75B117C80>, 'pos': [416, 190]}, 7: {'myfit': <api.elca.lc_fitter object at 0x000001A75B117CB0>, 'pos': [558, 330]}}
ref_flux AFTER {1: {'myfit': <api.elca.lc_fitter object at 0x000001A75B117C80>, 'pos': [416, 190]}, 7: {'myfit': <api.elca.lc_fitter object at 0x000001A75B117CB0>, 'pos': [558, 330]}, 0: {'myfit': <api.elca.lc_fitter object at 0x000001A75B1178F0>, 'pos': [416, 190]}}

Later, the choose_comp_star_variability function selects this invalid key 0. This causes it to look up the star at index 0 in the comp_stars list, which is [462, 335]. Since this star is not in the vsp_list, the exception is raised.

The bug is caused by using enumerate() on the dictionary's values, which generates a new index instead of using the dictionary's actual key. The problematic code:

                                for i, value in enumerate(temp_ref_flux.values()):
                                    if value is not None and i != j:
                                        ref_flux[i] = value

The proposed fix is to iterate over the dictionary's items directly to preserve the correct keys:

                                for key, value in temp_ref_flux.items():
                                    if value is not None and key != j:
                                        ref_flux[key] = value

This would ensures that only valid comparison star indices are ever used as keys in ref_flux. After applying this change, the pipeline completed successfully and the AID file was created.

The intermittent nature of this bug is due to the fact that the backtrack block is not always executed, and even when it is, the bug's symptom only appears if the vsp_num indices do not happen to match the enumerate indices.

If you are ok I can go ahead and create the PR.
@tamimfatahi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions