# Path: urbanaccess/utils.py
# def log(message, level=None, name=None, filename=None):
#     """
#     Write a message to the log file and/or print to the console.
# 
#     Parameters
#     ----------
#     message : string
#         the content of the message to log
#     level : int, optional
#         one of the logger.level constants
#     name : string, optional
#         name of the logger
#     filename : string, optional
#         name of the log file
# 
#     Returns
#     -------
#     None
#     """
# 
#     if level is None:
#         level = lg.INFO
#     if name is None:
#         name = config.settings.log_name
#     if filename is None:
#         filename = config.settings.log_filename
# 
#     if config.settings.log_file:
#         # get the current logger or create a new one then log message at
#         # requested level
#         logger = _get_logger(level=level, name=name, filename=filename)
#         if level == lg.DEBUG:
#             logger.debug(message)
#         elif level == lg.INFO:
#             logger.info(message)
#         elif level == lg.WARNING:
#             logger.warning(message)
#         elif level == lg.ERROR:
#             logger.error(message)
# 
#     # if logging to console is turned on, convert message to ascii and print
#     #  to the console only
#     if config.settings.log_console:
#         # capture current stdout, then switch it to the console, print the
#         # message, then switch back to what had been the stdout
#         # this prevents logging to notebook - instead, it goes to console
#         standard_out = sys.stdout
#         sys.stdout = sys.__stdout__
# 
#         # convert message to ascii for proper console display in windows
#         # terminals
#         message = unicodedata.normalize('NFKD', str(message)).encode(
#             'ascii', errors='replace').decode()
#         print(message)
#         sys.stdout = standard_out
#     # otherwise print out standard statement
#     else:
#         print(message)


import time
import pandana
from osmnet.load import network_from_bbox
from pandana import Network
from urbanaccess.utils import log

    # remove low connectivity nodes and return cleaned nodes and edges
    if remove_lcn:
        log('Checking for low connectivity nodes...')
        pandana_net = Network(nodes['x'], nodes['y'],
                              edges['from'], edges['to'], edges[['distance']])
        lcn = pandana_net.low_connectivity_nodes(impedance=10000, count=10,
                                                 imp_name='distance')
        log(
            '{:,} out of {:,} nodes ({:.2f} percent of total) were '
            'identified as having low connectivity and have '
            'been removed.'.format(len(lcn), len(nodes),
                                   (len(lcn) / len(nodes)) * 100))

        rm_nodes = set(lcn)

        nodes_to_keep = ~nodes.index.isin(rm_nodes)
        edges_to_keep = ~(
            edges['from'].isin(rm_nodes) | edges['to'].isin(rm_nodes))

        nodes = nodes.loc[nodes_to_keep]
        edges = edges.loc[edges_to_keep]

        log('Completed OSM data download and graph node and edge table '
            'creation in {:,.2f} seconds'.format(time.time() - start_time))

        return nodes, edges

    else:


# Path: urbanaccess/utils.py
# def log(message, level=None, name=None, filename=None):
#     """
#     Write a message to the log file and/or print to the console.
# 
#     Parameters
#     ----------
#     message : string
#         the content of the message to log
#     level : int, optional
#         one of the logger.level constants
#     name : string, optional
#         name of the logger
#     filename : string, optional
#         name of the log file
# 
#     Returns
#     -------
#     None
#     """
# 
#     if level is None:
#         level = lg.INFO
#     if name is None:
#         name = config.settings.log_name
#     if filename is None:
#         filename = config.settings.log_filename
# 
#     if config.settings.log_file:
#         # get the current logger or create a new one then log message at
#         # requested level
#         logger = _get_logger(level=level, name=name, filename=filename)
#         if level == lg.DEBUG:
#             logger.debug(message)
#         elif level == lg.INFO:
#             logger.info(message)
#         elif level == lg.WARNING:
#             logger.warning(message)
#         elif level == lg.ERROR:
#             logger.error(message)
# 
#     # if logging to console is turned on, convert message to ascii and print
#     #  to the console only
#     if config.settings.log_console:
#         # capture current stdout, then switch it to the console, print the
#         # message, then switch back to what had been the stdout
#         # this prevents logging to notebook - instead, it goes to console
#         standard_out = sys.stdout
#         sys.stdout = sys.__stdout__
# 
#         # convert message to ascii for proper console display in windows
#         # terminals
#         message = unicodedata.normalize('NFKD', str(message)).encode(
#             'ascii', errors='replace').decode()
#         print(message)
#         sys.stdout = standard_out
#     # otherwise print out standard statement
#     else:
#         print(message)


# Path: urbanaccess/osm/load.py
import time
import pandana
from osmnet.load import network_from_bbox
from pandana import Network
from urbanaccess.utils import log


    # remove low connectivity nodes and return cleaned nodes and edges
    if remove_lcn:
        log('Checking for low connectivity nodes...')
        pandana_net = Network(nodes['x'], nodes['y'],
                              edges['from'], edges['to'], edges[['distance']])
        lcn = pandana_net.low_connectivity_nodes(impedance=10000, count=10,
                                                 imp_name='distance')
        log(
            '{:,} out of {:,} nodes ({:.2f} percent of total) were '
            'identified as having low connectivity and have '
            'been removed.'.format(len(lcn), len(nodes),
                                   (len(lcn) / len(nodes)) * 100))

        rm_nodes = set(lcn)

        nodes_to_keep = ~nodes.index.isin(rm_nodes)
        edges_to_keep = ~(
            edges['from'].isin(rm_nodes) | edges['to'].isin(rm_nodes))

        nodes = nodes.loc[nodes_to_keep]
        edges = edges.loc[edges_to_keep]

        log('Completed OSM data download and graph node and edge table '
            'creation in {:,.2f} seconds'.format(time.time() - start_time))

        return nodes, edges

    else:


        log('Completed OSM data download and graph node and edge table '