(im_list)
return im_list_flt
Removes duplicates from the EE collection of Sentinel-2 images (many duplicates)
    Finds the images that were acquired at the same time but have different utm zones.

    KV WRL 2018

    Arguments:
    -----------
    im_list: list
        list of images in the collection

    Returns:
    -----------
    im_list_flt: list
        filtered list of images
Removes duplicates from the EE collection of Sentinel-2 images (many duplicates)
    Finds the images that were acquired at the same time but have different utm zones.
Removes duplicates from the EE collection of Sentinel - 2 images ( many duplicates ) Finds the images that were acquired at the same time but have different utm zones .
def filter_S2_collection(im_list):
    """
    Removes duplicates from the EE collection of Sentinel-2 images (many duplicates)
    Finds the images that were acquired at the same time but have different utm zones.

    KV WRL 2018

    Arguments:
    -----------
    im_list: list
        list of images in the collection

    Returns:
    -----------
    im_list_flt: list
        filtered list of images
    """

    # get datetimes
    timestamps = [datetime.fromtimestamp(_['properties']['system:time_start']/1000,
                                         tz=pytz.utc) for _ in im_list]
    # get utm zone projections
    utm_zones = np.array([int(_['bands'][0]['crs'][5:]) for _ in im_list])
    if len(np.unique(utm_zones)) == 1:
        return im_list
    else:
        utm_zone_selected =  np.max(np.unique(utm_zones))
        # find the images that were acquired at the same time but have different utm zones
        idx_all = np.arange(0,len(im_list),1)
        idx_covered = np.ones(len(im_list)).astype(bool)
        idx_delete = []
        i = 0
        while 1:
            same_time = np.abs([(timestamps[i]-_).total_seconds() for _ in timestamps]) < 60*60*24
            idx_same_time = np.where(same_time)[0]
            same_utm = utm_zones == utm_zone_selected
            # get indices that have the same time (less than 24h apart) but not the same utm zone
            idx_temp = np.where([same_time[j] == True and same_utm[j] == False for j in idx_all])[0]
            idx_keep = idx_same_time[[_ not in idx_temp for _ in idx_same_time]]
            # if more than 2 images with same date and same utm, drop the last ones
            if len(idx_keep) > 2:
               idx_temp = np.append(idx_temp,idx_keep[-(len(idx_keep)-2):])
            for j in idx_temp:
                idx_delete.append(j)
            idx_covered[idx_same_time] = False
            if np.any(idx_covered):
                i = np.where(idx_covered)[0][0]
            else:
                break
        # update the collection by deleting all those images that have same timestamp
        # and different utm projection
        im_list_flt = [x for k,x in enumerate(im_list) if k not in idx_delete]

    return im_list_flt
def filter_S2_collection ( im_list ) : # get datetimes timestamps = [ datetime . fromtimestamp ( _ [ 'properties' ] [ 'system:time_start' ] / 1000 , tz = pytz . utc ) for _ in im_list ] # get utm zone projections utm_zones = np . array ( [ int ( _ [ 'bands' ] [ 0 ] [ 'crs' ] [ 5 : ] ) for _ in im_list ] ) if len ( np . unique ( utm_zones ) ) == 1 : return im_list else : utm_zone_selected = np . max ( np . unique ( utm_zones ) ) # find the images that were acquired at the same time but have different utm zones idx_all = np . arange ( 0 , len ( im_list ) , 1 ) idx_covered = np . ones ( len ( im_list ) ) . astype ( bool ) idx_delete = [ ] i = 0 while 1 : same_time = np . abs ( [ ( timestamps [ i ] - _ ) . total_seconds ( ) for _ in timestamps ] ) < 60 * 60 * 24 idx_same_time = np . where ( same_time ) [ 0 ] same_utm = utm_zones == utm_zone_selected # get indices that have the same time (less than 24h apart) but not the same utm zone idx_temp = np . where ( [ same_time [ j ] == True and same_utm [ j ] == False for j in idx_all ] ) [ 0 ] idx_keep = idx_same_time [ [ _ not in idx_temp for _ in idx_same_time ] ] # if more than 2 images with same date and same utm, drop the last ones if len ( idx_keep ) > 2 : idx_temp = np . append ( idx_temp , idx_keep [ - ( len ( idx_keep ) - 2 ) : ] ) for j in idx_temp : idx_delete . append ( j ) idx_covered [ idx_same_time ] = False if np . any ( idx_covered ) : i = np . where ( idx_covered ) [ 0 ] [ 0 ] else : break # update the collection by deleting all those images that have same timestamp # and different utm projection im_list_flt = [ x for k , x in enumerate ( im_list ) if k not in idx_delete ] return im_list_flt