LSSTDESC / snmachine

Machine learning code for photometric supernova classification
BSD 3-Clause "New" or "Revised" License
9 stars 5 forks source link

Add method to find bad coadds #260

Open Catarina-Alves opened 2 years ago

Catarina-Alves commented 2 years ago

In previous versions of SNANA (before March/2022), the simlibs coadds were not working properly; not all the observations in the same night of the same passband were coadded. I made a function to check if a sndata dataset suffers from this issue. It would be great to add it to the base class in sndata.

Code:

def find_bad_coadd(dataset):
    obj_names = dataset.object_names[:3]
    pbs = dataset.filter_set
    number_obs_per_night = []
    for i in np.arange(len(obj_names)):
        obj = obj_names[i]
        obj_data = dataset.data[obj]

        for pb in pbs:
            is_pb = obj_data['filter'] == pb
            obj_data_pb = obj_data[is_pb]
            obj_mjd_pb = np.array(obj_data_pb['mjd'])

            time_diff = obj_mjd_pb[1:] - obj_mjd_pb[:-1]
            index_change_night = np.where(time_diff >.5)[0] + 1

            number_obs_per_night_obj = np.zeros(len(index_change_night) + 1)
            number_obs_per_night_obj[0] = index_change_night[0]
            number_obs_per_night_obj[1:-1] = index_change_night[1:] - index_change_night[:-1]
            number_obs_per_night_obj[-1] = len(obj_mjd_pb) - index_change_night[-1]

            # we expect one visit per night in each passband, so subtract it
            number_obs_per_night_obj -= 1
            if np.sum(number_obs_per_night_obj) > 0:
                print(obj, pb)
                print(number_obs_per_night_obj)
                sys.exit('It should have only one visit per night in each filter.')
    print('No repeats')