(output)
Function to remove from the output dictionnary entries containing shorelines for 
    the same date and satellite mission. This happens when there is an overlap between 
    adjacent satellite images.

    Arguments:
    -----------
        output: dict
            contains output dict with shoreline and metadata

    Returns:
    -----------
        output_no_duplicates: dict
            contains the updated dict where duplicates have been removed
Function to remove from the output dictionnary entries containing shorelines for 
    the same date and satellite mission. This happens when there is an overlap between 
    adjacent satellite images.
Function to remove from the output dictionnary entries containing shorelines for the same date and satellite mission . This happens when there is an overlap between adjacent satellite images .
def remove_duplicates(output):
    """
    Function to remove from the output dictionnary entries containing shorelines for 
    the same date and satellite mission. This happens when there is an overlap between 
    adjacent satellite images.

    Arguments:
    -----------
        output: dict
            contains output dict with shoreline and metadata

    Returns:
    -----------
        output_no_duplicates: dict
            contains the updated dict where duplicates have been removed

    """

    # nested function
    def duplicates_dict(lst):
        "return duplicates and indices"
        def duplicates(lst, item):
                return [i for i, x in enumerate(lst) if x == item]
        return dict((x, duplicates(lst, x)) for x in set(lst) if lst.count(x) > 1)

    dates = output['dates']
    # make a list with year/month/day
    dates_str = [_.strftime('%Y%m%d') for _ in dates]
    # create a dictionnary with the duplicates
    dupl = duplicates_dict(dates_str)
    # if there are duplicates, only keep the first element
    if dupl:
        output_no_duplicates = dict([])
        idx_remove = []
        for k,v in dupl.items():
            idx_remove.append(v[0])
        idx_remove = sorted(idx_remove)
        idx_all = np.linspace(0, len(dates_str)-1, len(dates_str))
        idx_keep = list(np.where(~np.isin(idx_all,idx_remove))[0])
        for key in output.keys():
            output_no_duplicates[key] = [output[key][i] for i in idx_keep]
        print('%d duplicates' % len(idx_remove))
        return output_no_duplicates
    else:
        print('0 duplicates')
        return output
def remove_duplicates ( output ) : # nested function def duplicates_dict ( lst ) : "return duplicates and indices" def duplicates ( lst , item ) : return [ i for i , x in enumerate ( lst ) if x == item ] return dict ( ( x , duplicates ( lst , x ) ) for x in set ( lst ) if lst . count ( x ) > 1 ) dates = output [ 'dates' ] # make a list with year/month/day dates_str = [ _ . strftime ( '%Y%m%d' ) for _ in dates ] # create a dictionnary with the duplicates dupl = duplicates_dict ( dates_str ) # if there are duplicates, only keep the first element if dupl : output_no_duplicates = dict ( [ ] ) idx_remove = [ ] for k , v in dupl . items ( ) : idx_remove . append ( v [ 0 ] ) idx_remove = sorted ( idx_remove ) idx_all = np . linspace ( 0 , len ( dates_str ) - 1 , len ( dates_str ) ) idx_keep = list ( np . where ( ~ np . isin ( idx_all , idx_remove ) ) [ 0 ] ) for key in output . keys ( ) : output_no_duplicates [ key ] = [ output [ key ] [ i ] for i in idx_keep ] print ( '%d duplicates' % len ( idx_remove ) ) return output_no_duplicates else : print ( '0 duplicates' ) return output