deepskies / deeplenstronomy

A pipeline for versatile strong lens sample simulations
MIT License
27 stars 7 forks source link

Remove Poisson Resampling of Image Background #59

Closed rmorgan10 closed 2 years ago

rmorgan10 commented 3 years ago

Motivated by Erik Zaborowski and Alex Drlica-Wagner, applying a Poisson resampling to image backgrounds for dataset diversity is not appropriate if the background images have been background-subtracted.

To remedy this behavior, Erik suggests removing the Poisson resampling. To ensure dataset diversity, we should also warn the user if the distribution of background images utilized could prove troublesome.

Consider a function placed in deeplenstronomy.py:

def check_background_indices(idx_list: list):
    """Issue a warning if an element occurs to frequently in the list.

    Calculate number of elements in the list that deviate from a uniform distribution
    by more than 1 standard deviation. If this number is more than 1/3 of the elements
    in the list, print a warning.

    Args:
        idx_list (list): List of background image indices to use.
    """
    values = np.unique(idx_list)
    average_value, std = np.mean(values), np.std(values)
    num_deviating = sum(np.abs(values - average_value) > np.std(values))
    if num_deviating > len(idx_list) / 3:
        print("WARNING: Non-uniform distribution of background images detected, check map.txt file.")

If this function is called on the output of utils.organize_image_backgrounds, then we should be safe to remove the Poisson resampling.