def edges_flux_to_node_flux(G, attribute_name='flux'):
    """Sum all flux from incoming edges for each node in networkx object"""
    node_fluxes = {}
    for node in G.nodes:
        node_flux = sum([edge[2] for edge in list(G.in_edges(node, data=attribute_name)) if edge[2]])
        node_fluxes[node] = node_flux
    return node_fluxes