def test_check_dup_table(): from pyigm.field.utils import check_dup_table table = create_fake_target_table() isdup, idx, coords = check_dup_table(table) assert np.sum(isdup) == 12 assert all(isdup[:3])
def clean_duplicates(self, table, tol=1*u.arcsec, method='first'): """ Clean duplicates in table based on (ra,dec) coordinates Parameters ---------- table : Table Table to clean duplicates based on (ra, dec) tol : Angle, optional Angular tolerance for considering duplicates method : str, optional Method to use. Current options are: ``'first'``: if duplicates exist keep only the first one Returns ------- cleaned_table : Table A version of `table` without duplicates """ # TODO: add more methods for merging/cleaning duplicates if method not in ['first']: raise RuntimeError('Not ready for this method=`{}`'.format(method)) isdup, idx, dcoord = pfu.check_dup_table(table, tol=tol) dup_inds = np.where(isdup == True)[0] keep = [] if method == 'first': for ii in dup_inds: mtch = np.where(dcoord[ii].separation(dcoord) < tol)[0] keep.append(min(mtch)) first_dup = np.unique(np.array(keep)) no_dup = np.arange(len(idx))[~isdup] clean_inds = np.append(no_dup, first_dup) clean_inds = np.sort(clean_inds) #return return table[clean_inds]