def move_to_next_pixel(fdr, row, col):
    """ Given fdr (flow direction array), row (current row index), col (current col index).
     return the next downstream neighbor as row, col pair

    See How Flow Direction works
    http://desktop.arcgis.com/en/arcmap/latest/tools/spatial-analyst-toolbox/how-flow-direction-works.htm

    D8 flow direction grid

    | 32 |  64  | 128 |
    | 16 |  X   |  1  |
    |  8 |  4   |  2  |

    """
    # get the fdr pixel value (x,y)
    value = fdr[row, col]

    # Update the row, col based on the flow direction
    if value == 1:
        col += 1
    elif value == 2:
        col += 1
        row += 1
    elif value == 4:
        row += 1
    elif value == 8:
        row += 1
        col -= 1
    elif value == 16:
        col -= 1
    elif value == 32:
        row -= 1
        col -= 1
    elif value == 64:
        row -= 1
    elif value == 128:
        row -= 1
        col += 1
    else:
        # Indetermine flow direction, sink. Do not move.
        row = row
        col = col
    return (row, col)