(output, transects, settings)
return cross_dist
Computes the intersection between the 2D shorelines and the shore-normal.
    transects. It returns time-series of cross-shore distance along each transect.
    
    KV WRL 2018       

    Arguments:
    -----------
    output: dict
        contains the extracted shorelines and corresponding metadata
    transects: dict
        contains the X and Y coordinates of each transect
    settings: dict with the following keys
        'along_dist': int
            alongshore distance considered caluclate the intersection
              
    Returns:    
    -----------
    cross_dist: dict
        time-series of cross-shore distance along each of the transects. 
        Not tidally corrected.
Computes the intersection between the 2D shorelines and the shore-normal.
    transects. It returns time-series of cross-shore distance along each transect.
    
    KV WRL 2018
Computes the intersection between the 2D shorelines and the shore - normal . transects . It returns time - series of cross - shore distance along each transect . KV WRL 2018
def compute_intersection(output, transects, settings):
    """
    Computes the intersection between the 2D shorelines and the shore-normal.
    transects. It returns time-series of cross-shore distance along each transect.
    
    KV WRL 2018       

    Arguments:
    -----------
    output: dict
        contains the extracted shorelines and corresponding metadata
    transects: dict
        contains the X and Y coordinates of each transect
    settings: dict with the following keys
        'along_dist': int
            alongshore distance considered caluclate the intersection
              
    Returns:    
    -----------
    cross_dist: dict
        time-series of cross-shore distance along each of the transects. 
        Not tidally corrected.        
    """    
    
    # loop through shorelines and compute the median intersection    
    intersections = np.zeros((len(output['shorelines']),len(transects)))
    for i in range(len(output['shorelines'])):

        sl = output['shorelines'][i]
        
        for j,key in enumerate(list(transects.keys())): 
            
            # compute rotation matrix
            X0 = transects[key][0,0]
            Y0 = transects[key][0,1]
            temp = np.array(transects[key][-1,:]) - np.array(transects[key][0,:])
            phi = np.arctan2(temp[1], temp[0])
            Mrot = np.array([[np.cos(phi), np.sin(phi)],[-np.sin(phi), np.cos(phi)]])
    
            # calculate point to line distance between shoreline points and the transect
            p1 = np.array([X0,Y0])
            p2 = transects[key][-1,:]
            d_line = np.abs(np.cross(p2-p1,sl-p1)/np.linalg.norm(p2-p1))
            # calculate the distance between shoreline points and the origin of the transect
            d_origin = np.array([np.linalg.norm(sl[k,:] - p1) for k in range(len(sl))])
            # find the shoreline points that are close to the transects and to the origin
            # the distance to the origin is hard-coded here to 1 km 
            idx_dist = np.logical_and(d_line <= settings['along_dist'], d_origin <= 1000)
            # find the shoreline points that are in the direction of the transect (within 90 degrees)
            temp_sl = sl - np.array(transects[key][0,:])
            phi_sl = np.array([np.arctan2(temp_sl[k,1], temp_sl[k,0]) for k in range(len(temp_sl))])
            diff_angle = (phi - phi_sl)
            idx_angle = np.abs(diff_angle) < np.pi/2
            # combine the transects that are close in distance and close in orientation
            idx_close = np.where(np.logical_and(idx_dist,idx_angle))[0]     
            
            # in case there are no shoreline points close to the transect 
            if len(idx_close) == 0:
                intersections[i,j] = np.nan
            else:
                # change of base to shore-normal coordinate system
                xy_close = np.array([sl[idx_close,0],sl[idx_close,1]]) - np.tile(np.array([[X0],
                                   [Y0]]), (1,len(sl[idx_close])))
                xy_rot = np.matmul(Mrot, xy_close)
                # compute the median of the intersections along the transect
                intersections[i,j] = np.nanmedian(xy_rot[0,:])
    
    # fill the a dictionnary
    cross_dist = dict([])
    for j,key in enumerate(list(transects.keys())): 
        cross_dist[key] = intersections[:,j]   
    
    # save a .csv file for Excel users
    out_dict = dict([])
    out_dict['dates'] = output['dates']
    for key in transects.keys():
        out_dict['Transect '+ key] = cross_dist[key]
    df = pd.DataFrame(out_dict)
    fn = os.path.join(settings['inputs']['filepath'],settings['inputs']['sitename'],
                      'transect_time_series.csv')
    df.to_csv(fn, sep=',')
    print('Time-series of the shoreline change along the transects saved as:\n%s'%fn)
    
    return cross_dist
def compute_intersection ( output , transects , settings ) : # loop through shorelines and compute the median intersection     intersections = np . zeros ( ( len ( output [ 'shorelines' ] ) , len ( transects ) ) ) for i in range ( len ( output [ 'shorelines' ] ) ) : sl = output [ 'shorelines' ] [ i ] for j , key in enumerate ( list ( transects . keys ( ) ) ) : # compute rotation matrix X0 = transects [ key ] [ 0 , 0 ] Y0 = transects [ key ] [ 0 , 1 ] temp = np . array ( transects [ key ] [ - 1 , : ] ) - np . array ( transects [ key ] [ 0 , : ] ) phi = np . arctan2 ( temp [ 1 ] , temp [ 0 ] ) Mrot = np . array ( [ [ np . cos ( phi ) , np . sin ( phi ) ] , [ - np . sin ( phi ) , np . cos ( phi ) ] ] ) # calculate point to line distance between shoreline points and the transect p1 = np . array ( [ X0 , Y0 ] ) p2 = transects [ key ] [ - 1 , : ] d_line = np . abs ( np . cross ( p2 - p1 , sl - p1 ) / np . linalg . norm ( p2 - p1 ) ) # calculate the distance between shoreline points and the origin of the transect d_origin = np . array ( [ np . linalg . norm ( sl [ k , : ] - p1 ) for k in range ( len ( sl ) ) ] ) # find the shoreline points that are close to the transects and to the origin # the distance to the origin is hard-coded here to 1 km  idx_dist = np . logical_and ( d_line <= settings [ 'along_dist' ] , d_origin <= 1000 ) # find the shoreline points that are in the direction of the transect (within 90 degrees) temp_sl = sl - np . array ( transects [ key ] [ 0 , : ] ) phi_sl = np . array ( [ np . arctan2 ( temp_sl [ k , 1 ] , temp_sl [ k , 0 ] ) for k in range ( len ( temp_sl ) ) ] ) diff_angle = ( phi - phi_sl ) idx_angle = np . abs ( diff_angle ) < np . pi / 2 # combine the transects that are close in distance and close in orientation idx_close = np . where ( np . logical_and ( idx_dist , idx_angle ) ) [ 0 ] # in case there are no shoreline points close to the transect  if len ( idx_close ) == 0 : intersections [ i , j ] = np . nan else : # change of base to shore-normal coordinate system xy_close = np . array ( [ sl [ idx_close , 0 ] , sl [ idx_close , 1 ] ] ) - np . tile ( np . array ( [ [ X0 ] , [ Y0 ] ] ) , ( 1 , len ( sl [ idx_close ] ) ) ) xy_rot = np . matmul ( Mrot , xy_close ) # compute the median of the intersections along the transect intersections [ i , j ] = np . nanmedian ( xy_rot [ 0 , : ] ) # fill the a dictionnary cross_dist = dict ( [ ] ) for j , key in enumerate ( list ( transects . keys ( ) ) ) : cross_dist [ key ] = intersections [ : , j ] # save a .csv file for Excel users out_dict = dict ( [ ] ) out_dict [ 'dates' ] = output [ 'dates' ] for key in transects . keys ( ) : out_dict [ 'Transect ' + key ] = cross_dist [ key ] df = pd . DataFrame ( out_dict ) fn = os . path . join ( settings [ 'inputs' ] [ 'filepath' ] , settings [ 'inputs' ] [ 'sitename' ] , 'transect_time_series.csv' ) df . to_csv ( fn , sep = ',' ) print ( 'Time-series of the shoreline change along the transects saved as:\n%s' % fn ) return cross_dist