contrib/stack/topsStack/s1_select_ion.py
def check_redundancy(group, threshold=1):
    '''
    threshold: time difference threshold in seconds between two slices in second.
    this routine checks, for a slice, if there are multiple ones.
    '''

    print('\nchecking different copies of same slice')

    safe_removed_indices = []
    ngroup = len(group)
    for i in range(ngroup):
        ngroupi = len(group[i])
        if ngroupi == 1:
            continue
        else:
            for j in range(ngroupi-1):
                for k in range(j+1, ngroupi):
                    if np.absolute((group[i][j].start_date_time - group[i][k].start_date_time).total_seconds()) < threshold and \
                       np.absolute((group[i][j].stop_date_time - group[i][k].stop_date_time).total_seconds()) < threshold:

                        #determine which one to be removed
                        j_version = False
                        k_version = False
                        for l in range(ngroupi):
                            if l != j and l != k:
                                if group[i][j].proc_version == group[i][l].proc_version:
                                    j_version = True
                                if group[i][k].proc_version == group[i][l].proc_version:
                                    k_version = True
                        if j_version == k_version:
                            safe_removed_index = [i, j]
                        else:
                            if j_version == False and k_version == True:
                                safe_removed_index = [i, j]
                            else:
                                safe_removed_index = [i, k]
                        safe_removed_indices.append(safe_removed_index)

                        print('in acquistion {}, the following two slices are the same:'.format(i+1))
                        if safe_removed_index == [i, j]:
                            print(os.path.basename(group[i][j].safe_file) + ' (not to be used)')
                            print(os.path.basename(group[i][k].safe_file))
                        else:
                            print(os.path.basename(group[i][j].safe_file))
                            print(os.path.basename(group[i][k].safe_file) + ' (not to be used)')

    #remove redundant slices
    if safe_removed_indices != []:
        group_new = []
        for i in range(ngroup):
            ngroupi = len(group[i])
            group_new.append([group[i][j] for j in range(ngroupi) if [i,j] not in safe_removed_indices])

        print('slices removed:')
        for index in safe_removed_indices:
            print('%s %3d'%(os.path.basename(group[index[0]][index[1]].safe_file), index[0]+1))

    else:
        group_new = group
        print('no slices removed')

    return group_new

    threshold: time difference threshold in seconds between two slices in second.
    this routine checks, for a slice, if there are multiple ones.
    
time difference threshold in seconds between two slices in second.
this routine checks, for a slice, if there are multiple ones.
time difference threshold in seconds between two slices in second . this routine checks for a slice if there are multiple ones .
def check_redundancy(group, threshold=1):
    print('\nchecking different copies of same slice')
    safe_removed_indices = []
    ngroup = len(group)
    for i in range(ngroup):
        ngroupi = len(group[i])
        if ngroupi == 1:
            continue
        else:
            for j in range(ngroupi-1):
                for k in range(j+1, ngroupi):
                    if np.absolute((group[i][j].start_date_time - group[i][k].start_date_time).total_seconds()) < threshold and \
                       np.absolute((group[i][j].stop_date_time - group[i][k].stop_date_time).total_seconds()) < threshold:
                        j_version = False
                        k_version = False
                        for l in range(ngroupi):
                            if l != j and l != k:
                                if group[i][j].proc_version == group[i][l].proc_version:
                                    j_version = True
                                if group[i][k].proc_version == group[i][l].proc_version:
                                    k_version = True
                        if j_version == k_version:
                            safe_removed_index = [i, j]
                        else:
                            if j_version == False and k_version == True:
                                safe_removed_index = [i, j]
                            else:
                                safe_removed_index = [i, k]
                        safe_removed_indices.append(safe_removed_index)
                        print('in acquistion {}, the following two slices are the same:'.format(i+1))
                        if safe_removed_index == [i, j]:
                            print(os.path.basename(group[i][j].safe_file) + ' (not to be used)')
                            print(os.path.basename(group[i][k].safe_file))
                        else:
                            print(os.path.basename(group[i][j].safe_file))
                            print(os.path.basename(group[i][k].safe_file) + ' (not to be used)')
    if safe_removed_indices != []:
        group_new = []
        for i in range(ngroup):
            ngroupi = len(group[i])
            group_new.append([group[i][j] for j in range(ngroupi) if [i,j] not in safe_removed_indices])
        print('slices removed:')
        for index in safe_removed_indices:
            print('%s %3d'%(os.path.basename(group[index[0]][index[1]].safe_file), index[0]+1))
    else:
        group_new = group
        print('no slices removed')
    return group_new
def check_redundancy ( group , threshold = 1 ) : print ( '\nchecking different copies of same slice' ) safe_removed_indices = [ ] ngroup = len ( group ) for i in range ( ngroup ) : ngroupi = len ( group [ i ] ) if ngroupi == 1 : continue else : for j in range ( ngroupi - 1 ) : for k in range ( j + 1 , ngroupi ) : if np . absolute ( ( group [ i ] [ j ] . start_date_time - group [ i ] [ k ] . start_date_time ) . total_seconds ( ) ) < threshold and np . absolute ( ( group [ i ] [ j ] . stop_date_time - group [ i ] [ k ] . stop_date_time ) . total_seconds ( ) ) < threshold : j_version = False k_version = False for l in range ( ngroupi ) : if l != j and l != k : if group [ i ] [ j ] . proc_version == group [ i ] [ l ] . proc_version : j_version = True if group [ i ] [ k ] . proc_version == group [ i ] [ l ] . proc_version : k_version = True if j_version == k_version : safe_removed_index = [ i , j ] else : if j_version == False and k_version == True : safe_removed_index = [ i , j ] else : safe_removed_index = [ i , k ] safe_removed_indices . append ( safe_removed_index ) print ( 'in acquistion {}, the following two slices are the same:' . format ( i + 1 ) ) if safe_removed_index == [ i , j ] : print ( os . path . basename ( group [ i ] [ j ] . safe_file ) + ' (not to be used)' ) print ( os . path . basename ( group [ i ] [ k ] . safe_file ) ) else : print ( os . path . basename ( group [ i ] [ j ] . safe_file ) ) print ( os . path . basename ( group [ i ] [ k ] . safe_file ) + ' (not to be used)' ) if safe_removed_indices != [ ] : group_new = [ ] for i in range ( ngroup ) : ngroupi = len ( group [ i ] ) group_new . append ( [ group [ i ] [ j ] for j in range ( ngroupi ) if [ i , j ] not in safe_removed_indices ] ) print ( 'slices removed:' ) for index in safe_removed_indices : print ( '%s %3d' % ( os . path . basename ( group [ index [ 0 ] ] [ index [ 1 ] ] . safe_file ) , index [ 0 ] + 1 ) ) else : group_new = group print ( 'no slices removed' ) return group_new
threshold: time difference threshold in seconds between two slices in second.
threshold : time difference threshold in seconds between two slices in second .
'''
    threshold: time difference threshold in seconds between two slices in second.
    this routine checks, for a slice, if there are multiple ones.
    ''' #determine which one to be removed #remove redundant slices
group
threshold