(contours, cloud_mask, georef, image_epsg, settings)
return shoreline
Converts the contours from image coordinates to world coordinates. 
    This function also removes the contours that are too small to be a shoreline 
    (based on the parameter settings['min_length_sl'])

    KV WRL 2018

    Arguments:
    -----------
    contours: np.array or list of np.array
        image contours as detected by the function find_contours
    cloud_mask: np.array
        2D cloud mask with True where cloud pixels are
    georef: np.array
        vector of 6 elements [Xtr, Xscale, Xshear, Ytr, Yshear, Yscale]
    image_epsg: int
        spatial reference system of the image from which the contours were extracted
    settings: dict with the following keys
        'output_epsg': int
            output spatial reference system
        'min_length_sl': float
            minimum length of shoreline contour to be kept (in meters)

    Returns:
    -----------
    shoreline: np.array
        array of points with the X and Y coordinates of the shoreline
Converts the contours from image coordinates to world coordinates. 
    This function also removes the contours that are too small to be a shoreline 
    (based on the parameter settings['min_length_sl'])
Converts the contours from image coordinates to world coordinates . This function also removes the contours that are too small to be a shoreline ( based on the parameter settings [ min_length_sl ] )
def process_shoreline(contours, cloud_mask, georef, image_epsg, settings):
    """
    Converts the contours from image coordinates to world coordinates. 
    This function also removes the contours that are too small to be a shoreline 
    (based on the parameter settings['min_length_sl'])

    KV WRL 2018

    Arguments:
    -----------
    contours: np.array or list of np.array
        image contours as detected by the function find_contours
    cloud_mask: np.array
        2D cloud mask with True where cloud pixels are
    georef: np.array
        vector of 6 elements [Xtr, Xscale, Xshear, Ytr, Yshear, Yscale]
    image_epsg: int
        spatial reference system of the image from which the contours were extracted
    settings: dict with the following keys
        'output_epsg': int
            output spatial reference system
        'min_length_sl': float
            minimum length of shoreline contour to be kept (in meters)

    Returns:
    -----------
    shoreline: np.array
        array of points with the X and Y coordinates of the shoreline

    """

    # convert pixel coordinates to world coordinates
    contours_world = SDS_tools.convert_pix2world(contours, georef)
    # convert world coordinates to desired spatial reference system
    contours_epsg = SDS_tools.convert_epsg(contours_world, image_epsg, settings['output_epsg'])
    # remove contours that have a perimeter < min_length_sl (provided in settings dict)
    # this enables to remove the very small contours that do not correspond to the shoreline
    contours_long = []
    for l, wl in enumerate(contours_epsg):
        coords = [(wl[k,0], wl[k,1]) for k in range(len(wl))]
        a = LineString(coords) # shapely LineString structure
        if a.length >= settings['min_length_sl']:
            contours_long.append(wl)
    # format points into np.array
    x_points = np.array([])
    y_points = np.array([])
    for k in range(len(contours_long)):
        x_points = np.append(x_points,contours_long[k][:,0])
        y_points = np.append(y_points,contours_long[k][:,1])
    contours_array = np.transpose(np.array([x_points,y_points]))

    shoreline = contours_array

    # now remove any shoreline points that are attached to cloud pixels
    if sum(sum(cloud_mask)) > 0:
        # get the coordinates of the cloud pixels
        idx_cloud = np.where(cloud_mask)
        idx_cloud = np.array([(idx_cloud[0][k], idx_cloud[1][k]) for k in range(len(idx_cloud[0]))])
        # convert to world coordinates and same epsg as the shoreline points
        coords_cloud = SDS_tools.convert_epsg(SDS_tools.convert_pix2world(idx_cloud, georef),
                                               image_epsg, settings['output_epsg'])[:,:-1]
        # only keep the shoreline points that are at least 30m from any cloud pixel
        idx_keep = np.ones(len(shoreline)).astype(bool)
        for k in range(len(shoreline)):
            if np.any(np.linalg.norm(shoreline[k,:] - coords_cloud, axis=1) < 30):
                idx_keep[k] = False
        shoreline = shoreline[idx_keep]

    return shoreline
def process_shoreline ( contours , cloud_mask , georef , image_epsg , settings ) : # convert pixel coordinates to world coordinates contours_world = SDS_tools . convert_pix2world ( contours , georef ) # convert world coordinates to desired spatial reference system contours_epsg = SDS_tools . convert_epsg ( contours_world , image_epsg , settings [ 'output_epsg' ] ) # remove contours that have a perimeter < min_length_sl (provided in settings dict) # this enables to remove the very small contours that do not correspond to the shoreline contours_long = [ ] for l , wl in enumerate ( contours_epsg ) : coords = [ ( wl [ k , 0 ] , wl [ k , 1 ] ) for k in range ( len ( wl ) ) ] a = LineString ( coords ) # shapely LineString structure if a . length >= settings [ 'min_length_sl' ] : contours_long . append ( wl ) # format points into np.array x_points = np . array ( [ ] ) y_points = np . array ( [ ] ) for k in range ( len ( contours_long ) ) : x_points = np . append ( x_points , contours_long [ k ] [ : , 0 ] ) y_points = np . append ( y_points , contours_long [ k ] [ : , 1 ] ) contours_array = np . transpose ( np . array ( [ x_points , y_points ] ) ) shoreline = contours_array # now remove any shoreline points that are attached to cloud pixels if sum ( sum ( cloud_mask ) ) > 0 : # get the coordinates of the cloud pixels idx_cloud = np . where ( cloud_mask ) idx_cloud = np . array ( [ ( idx_cloud [ 0 ] [ k ] , idx_cloud [ 1 ] [ k ] ) for k in range ( len ( idx_cloud [ 0 ] ) ) ] ) # convert to world coordinates and same epsg as the shoreline points coords_cloud = SDS_tools . convert_epsg ( SDS_tools . convert_pix2world ( idx_cloud , georef ) , image_epsg , settings [ 'output_epsg' ] ) [ : , : - 1 ] # only keep the shoreline points that are at least 30m from any cloud pixel idx_keep = np . ones ( len ( shoreline ) ) . astype ( bool ) for k in range ( len ( shoreline ) ) : if np . any ( np . linalg . norm ( shoreline [ k , : ] - coords_cloud , axis = 1 ) < 30 ) : idx_keep [ k ] = False shoreline = shoreline [ idx_keep ] return shoreline