How to use the wntr.graphics.plot_network function in wntr

To help you get started, we’ve selected a few wntr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github USEPA / WNTR / examples / fragility_curves.py View on Github external
wntr.graphics.plot_network(wn, link_attribute=pga,title='Peak Ground Acceleration (g)',
                           node_size=0, link_width=2)
  
# Define fragility curve  
FC = wntr.scenario.FragilityCurve()
FC.add_state('Minor', 1, {'Default': lognorm(0.5,scale=0.3)})
FC.add_state('Major', 2, {'Default': lognorm(0.5,scale=0.7)}) 
wntr.graphics.plot_fragility_curve(FC, xlabel='Peak Ground Acceleration (g)')

# Draw damage state for each pipe
pipe_PEDS = FC.cdf_probability(pga)
pipe_damage_state = FC.sample_damage_state(pipe_PEDS)
pipe_damage_state_map = FC.get_priority_map()
val = pipe_damage_state.map(pipe_damage_state_map)
custom_cmp = wntr.graphics.custom_colormap(3, ['grey', 'royalblue', 'darkorange'])
wntr.graphics.plot_network(wn, link_attribute=val, node_size=0, link_width=2,
                           link_cmap=custom_cmp, title='Damage state: 0=None, 1=Minor, 2=Major')
github USEPA / WNTR / examples / water_quality_simulation.py View on Github external
# Run age scenario and plot results
wn.options.quality.mode = 'AGE'
results = sim.run_sim()
AGE_at_5hr = results.node['quality'].loc[5*3600,:]/3600.0 # convert to hours
wntr.graphics.plot_network(wn, node_attribute=AGE_at_5hr, node_size=20, 
                      title='Water age (hrs), time = 5 hours')
AGE_at_node = results.node['quality'].loc[:,'208']/3600.0
plt.figure()
AGE_at_node.plot(title='Water age, node 208')

# Run trace scenario and plot results
wn.options.quality.mode = 'TRACE'
wn.options.quality.trace_node = '111'
results = sim.run_sim()
TRACE_at_5hr = results.node['quality'].loc[5*3600,:]
wntr.graphics.plot_network(wn, node_attribute=TRACE_at_5hr, node_size=20, 
                      title='Trace percent, time = 5 hours')
TRACE_at_node = results.node['quality'].loc[:,'208']
plt.figure()
TRACE_at_node.plot(title='Trace percent, node 208')

# Run a hydraulic simulation only
wn.options.quality.mode = 'NONE'
results = sim.run_sim()

# To run water quality simulation with pressure dependent demands, 
# reset demands in the water network using demands computed using the 
# WNTRSimulator.
sim = wntr.sim.WNTRSimulator(wn)
results = sim.run_sim()
wn.assign_demand(results.node['demand'], 'PDD')
sim = wntr.sim.EpanetSimulator(wn)
github USEPA / WNTR / examples / resilience_metrics.py View on Github external
shat.append(entropy[1])
    plt.figure()
    plt.plot(shat)
    plt.ylabel('System Entropy')
    plt.xlabel('Time, hr')
    print("Entropy")
    print("  Mean: " + str(np.mean(shat)))
    print("  Max: " + str(np.nanmax(shat)))
    print("  Min: " + str(np.nanmin(shat)))

    # Compute water service availability, for each junction
    expected_demand = wntr.metrics.expected_demand(wn)
    demand = results.node['demand'].loc[:,wn.junction_name_list]
    wsa = wntr.metrics.water_service_availability(expected_demand.sum(axis=0), 
                                                  demand.sum(axis=0))
    wntr.graphics.plot_network(wn, node_attribute=wsa, node_size=40, node_range=[0,1], 
                               title='Water service availability, averaged over times')
github USEPA / WNTR / examples / fragility_curves.py View on Github external
# Create a water network model
inp_file = 'networks/Net3.inp'
wn = wntr.network.WaterNetworkModel(inp_file)

# Define the earthquake
wn = wntr.morph.node.scale_node_coordinates(wn, 1000)
epicenter = (32000,15000) # x,y location
magnitude = 7 # Richter scale
depth = 10000 # m, shallow depth
earthquake = wntr.scenario.Earthquake(epicenter, magnitude, depth)

# Compute PGA
R = earthquake.distance_to_epicenter(wn, element_type=wntr.network.Pipe)
pga = earthquake.pga_attenuation_model(R)  
wntr.graphics.plot_network(wn, link_attribute=pga,title='Peak Ground Acceleration (g)',
                           node_size=0, link_width=2)
  
# Define fragility curve  
FC = wntr.scenario.FragilityCurve()
FC.add_state('Minor', 1, {'Default': lognorm(0.5,scale=0.3)})
FC.add_state('Major', 2, {'Default': lognorm(0.5,scale=0.7)}) 
wntr.graphics.plot_fragility_curve(FC, xlabel='Peak Ground Acceleration (g)')

# Draw damage state for each pipe
pipe_PEDS = FC.cdf_probability(pga)
pipe_damage_state = FC.sample_damage_state(pipe_PEDS)
pipe_damage_state_map = FC.get_priority_map()
val = pipe_damage_state.map(pipe_damage_state_map)
custom_cmp = wntr.graphics.custom_colormap(3, ['grey', 'royalblue', 'darkorange'])
wntr.graphics.plot_network(wn, link_attribute=val, node_size=0, link_width=2,
                           link_cmap=custom_cmp, title='Damage state: 0=None, 1=Minor, 2=Major')
github USEPA / WNTR / examples / resilience_metrics.py View on Github external
G_flowrate_36hrs = wn.get_graph()
    G_flowrate_36hrs.weight_graph(link_attribute=attr)

    # Compute betweenness-centrality at time 36 hours
    bet_cen = nx.betweenness_centrality(G_flowrate_36hrs)
    wntr.graphics.plot_network(wn, node_attribute=bet_cen,
                          title='Betweenness Centrality', node_size=40)
    central_pt_dom = G_flowrate_36hrs.central_point_dominance()
    print("Central point dominance: " + str(central_pt_dom))

    # Compute entropy at time 36, for node 185
    [S, Shat] = wntr.metrics.entropy(G_flowrate_36hrs, sources=None, sinks=['185'])

    # Plot all simple paths between the Lake/River and node 185
    link_count = G_flowrate_36hrs.links_in_simple_paths(sources=['Lake', 'River'], sinks=['185'])
    wntr.graphics.plot_network(wn, link_attribute=link_count, link_width=1,
                            node_attribute = {'River': 1, 'Lake': 1, '185': 1},
                            node_size=30, title='Link count in paths')

    # Calculate entropy for 1 day, all nodes
    shat = []
    G_flowrate_t = wn.get_graph()
    for t in np.arange(0, 24*3600+1,3600):
        attr = results.link['flowrate'].loc[t,:]
        G_flowrate_t.weight_graph(link_attribute=attr)
        entropy = wntr.metrics.entropy(G_flowrate_t)
        shat.append(entropy[1])
    plt.figure()
    plt.plot(shat)
    plt.ylabel('System Entropy')
    plt.xlabel('Time, hr')
    print("Entropy")
github USEPA / WNTR / examples / resilience_metrics.py View on Github external
# wn.add_pattern('SourcePattern', source_pattern)
    wn.add_source('Source1', '121', 'SETPOINT', 1000, 'SourcePattern')

    # Simulate hydraulics and water quality for each scenario
    sim = wntr.sim.EpanetSimulator(wn)
    results_CHEM = sim.run_sim()

    demand = results_CHEM.node['demand'].loc[:,wn.junction_name_list]
    quality = results_CHEM.node['quality'].loc[:,wn.junction_name_list]
    flowrate = results_CHEM.link['flowrate'].loc[:,wn.pipe_name_list] 
    
    MC = wntr.metrics.mass_contaminant_consumed(demand, quality)
    VC = wntr.metrics.volume_contaminant_consumed(demand, quality, 0.001)
    EC = wntr.metrics.extent_contaminant(quality, flowrate, wn, 0.001)

    wntr.graphics.plot_network(wn, node_attribute=MC.sum(axis=0), node_range = [0,1e5], node_size=40,
                          title='Total mass consumed')

    plt.figure()
    EC.plot(title='Extent of contamination')
github USEPA / WNTR / examples / getting_started.py View on Github external
import wntr

# Create a water network model
inp_file = 'networks/Net3.inp'
wn = wntr.network.WaterNetworkModel(inp_file)

# Graph the network
wntr.graphics.plot_network(wn, title=wn.name)

# Simulate hydraulics
sim = wntr.sim.EpanetSimulator(wn)
results = sim.run_sim()

# Plot results on the network
pressure_at_5hr = results.node.loc['pressure',5*3600, :]
wntr.graphics.plot_network(wn, node_attribute=pressure_at_5hr, node_size=30, 
                        title='Pressure at 5 hours')
github USEPA / WNTR / examples / resilience_metrics.py View on Github external
title='Clustering Coefficient', node_size=40)

    # Compute betweenness centrality
    bet_cen = nx.betweenness_centrality(G)
    wntr.graphics.plot_network(wn, node_attribute=bet_cen,
                          title='Betweenness Centrality', node_size=40,
                          node_range=[0, 0.4])
    central_pt_dom = G.central_point_dominance()
    print("Central point dominance: " + str(central_pt_dom))

    # Compute articulation points
    Nap = list(nx.articulation_points(uG))
    Nap = list(set(Nap)) # get the unique nodes in Nap
    Nap_density = float(len(Nap))/uG.number_of_nodes()
    print("Density of articulation points: " + str(Nap_density))
    wntr.graphics.plot_network(wn, node_attribute=Nap, title='Articulation Point',
                          node_size=40, node_range=[0,1])

    # Compute bridges
    bridges = G.bridges()
    wntr.graphics.plot_network(wn, link_attribute=bridges, title='Bridges',
                          link_width=2, link_range=[0,1])
    Nbr_density = float(len(bridges))/G.number_of_edges()
    print("Density of bridges: " + str(Nbr_density))

    # Compute spectral gap
    spectral_gap = G.spectral_gap()
    print("Spectral gap: " + str(spectral_gap))

    # Compute algebraic connectivity
    alg_con = G.algebraic_connectivity()
    print("Algebraic connectivity: " + str(alg_con))