7. API Documentation
The following API documentation is automatically generated from the source code.
7.1. Subpackages
7.2. infrarisk.src.network_recovery module
- class infrarisk.src.network_recovery.NetworkRecovery(network, sim_step, pipe_close_policy='repair', pipe_closure_delay=None, line_close_policy='sensor_based_line_isolation', line_closure_delay=None)
Bases:
objectGenerate a disaster and recovery object for storing simulation-related information and settings.
- add_additional_end_events(repair_order, extra_hours=8)
Add events post-recovery to the event table.
- Parameters:
repair_order (list) – list of components to be repaired
extra_hours (integer, optional) – Number of hours post-recovery to be simulated, defaults to 8
- add_disruption_to_event_table()
Schedules the events until the initial disruption events.
- add_recovery_to_event_table(component, recovery_start, recovery_time)
Adds the recovery time to the event table.
- Parameters:
component (string) – The component name
recovery_start (integer) – The start time of the recovery in seconds
recovery_time (integer) – The duration of the recovery in seconds
- calculate_recovery_start_end(links_to_repair, repair_order)
Calculates the start and end times for the repair of the links.
- Parameters:
links_to_repair (list) – The list of components to be repaired
repair_order (list) – The list of components to be repaired in the order in which they are to be repaired
- Returns:
The component name, start time and durationof the repair of the links
- Return type:
list
- calculate_recovery_time(component)
Calculates the recovery time of the given component.
- Parameters:
component (string) – Component whose recovery time is to be calculated.
- Returns:
Recovery time of the component in seconds.
- Return type:
float
- calculate_travel_time_and_path(component, crew)
Calculates the travel time and path for a component and crew.
- Parameters:
component (string) – The component for which the travel time and path is to be calculated
crew (infrarisk.src.repair_crew.WaterRepairCrew or infrarisk.src.repair_crew.PowerRepairCrew or infrarisk.src.repair_crew.TranspoRepairCrew) – The crew for which the travel time and path is to be calculated
- Returns:
The nearest node, travel time to that node for the crew and path for the component and crew
- Return type:
list
- check_route_accessibility(failed_transpo_link_en_route)
Checks when the failed transportation links along a route are repaired and the possible start time.
- Parameters:
failed_transpo_link_en_route (list) – List of transportation links along the route.
- Returns:
Accessibility and possible start time of the route.
- Return type:
[bool, int]
- fail_transpo_link(link_compon)
Fails the given transportation link by changing the free-flow travel time to a very large value.
- Parameters:
link_compon (string) – Name of the transportation link.
- get_event_table()
Returns the event table.
- Returns:
The event table.
- Return type:
pandas.DataFrame
- remove_previous_water_controls()
Removes all previous pump controls
- reset_networks()
Resets the IntegratedNetwork object within NetworkRecovery object.
- restore_transpo_link(link_compon)
Restores the disrupted transportation link by changing the free flow travel time to the original value.
- Parameters:
link_compon (string) – Name of the transportation link.
- schedule_recovery(repair_order)
Generates the unexpanded event table consisting of disruptions and repair actions.
- Parameters:
repair_order (list of strings.) – The repair order considered in the current simulation.
- set_initial_crew_start()
Sets the initial start times at which the respective infrastructure crews start from their locations post-disaster.
- switch_closure_allowed(compons_to_repair, switch)
Check if a switch closure is possible. Depends on whether a switch needs to be open to isolate any component whose repair is not yet performed
- Parameters:
compons_to_repair (list) – List of components to be repaired excluding the component under consideration.
switch (string) – Switch component
- Returns:
True if switch closure is allowed, False otherwise.
- Return type:
bool
- update_directly_affected_components(time_stamp, next_sim_time)
Updates the operational performance of directly impacted infrastructure components by the external event.
- Parameters:
time_stamp (integer) – Current time stamp in the event table in seconds.
next_sim_time (integer) – Next time stamp in the event table in seconds.
- update_traffic_model(run_user_equilibrium=False)
Updates the static traffic assignment model based on current network conditions.
- Parameters:
run_user_equilibrium (bool) – If True, runs user equilibrium before updating the traffic assignment model.
- infrarisk.src.network_recovery.add_pipe_leak(wn, leak_junc, area, discharge_coeff=0.75, start_time=None, end_time=None)
Adds a leak to a junction.
- Parameters:
wn (wntr.network.WaterNetworkModel) – Water network object.
leak_junc (string) – Name of the junction where the leak is to be added.
area (float) – Area of the leak in m^2.
discharge_coeff (float) – Discharge coefficient of the leak.
start_time (integer) – Time at which the leak must start in seconds.
end_time (integer) – Time at which the leak must end in seconds.
- infrarisk.src.network_recovery.get_nearest_time_step(time_stamp, time_step)
Returns the nearest time step to the given time stamp.
- Parameters:
time_stamp (integer) – Time stamp in seconds.
time_step (integer) – Time step in seconds.
- infrarisk.src.network_recovery.link_close_event(wn, pipe_name, time_stamp, state)
Closes a pipe.
- Parameters:
wn (wntr.network.WaterNetworkModel) – Water network object.
pipe_name (string) – Name of the pipe.
time_stamp (integer) – Time stamp at which the pipe must be closed in seconds.
state (string) – The state of the object.
- Returns:
The modified wntr network object after pipe splits.
- Return type:
wntr.network.WaterNetworkModel
- infrarisk.src.network_recovery.link_open_event(wn, pipe_name, time_stamp, state)
Opens a pipe.
- Parameters:
wn (wntr.network.WaterNetworkModel) – Water network object.
pipe_name (string) – Name of the pipe.
time_stamp (integer) – Time stamp at which the pipe must be opened in seconds.
state (string) – The state of the object.
- Returns:
The modified wntr network object after pipe splits.
- Return type:
wntr.network.WaterNetworkModel
- infrarisk.src.network_recovery.pipe_leak_node_generator(network)
Splits the directly affected pipes to induce leak during simulations.
- Parameters:
network (infrarisk.src.physical.integrated_network.IntegratedNetwork) – Integrated infrastructure network object
- infrarisk.src.network_recovery.pump_outage_event(wn, pump_name, start_time, end_time)
7.3. infrarisk.src.optimizer module
- class infrarisk.src.optimizer.BruteForceOptimizer(prediction_horizon=None)
Bases:
OptimizerA Brute Force Optimizer class
- Parameters:
Optimizer (Optimizer abstract class.) – An optimizer class.
- find_optimal_recovery(simulation)
Identifies the optimal recovery strategy using the Model Predictive Control principle.
- Parameters:
simulation (infrarisk.src.simulation.NetworkSimulation) – The infrastructure network simulation object.
- get_optimization_log()
Returns the optimization log.
- Returns:
A table consisting of the AUC values from the network simulations.
- Return type:
pandas.DataFrame
- get_repair_permutations(simulation)
Returns all possible permutations of the repair order.
- Parameters:
simulation (infrarisk.src.simulation.NetworkSimulation) – An integrated infrastructure network simulation object.
- Returns:
A nested list of all possible repair permutations for the given list of components.
- Return type:
list
- get_trackers()
Returns the time, power consumption ratio and water consumption ratio values.
- Returns:
lists: list
- class infrarisk.src.optimizer.Optimizer(prediction_horizon=None)
Bases:
ABCThe Optimizer class defines an interface to a discrete optimizer or can be implemented as such. This optimizer takes a network object and a prediction horizon and should compute the best steps of the length of the prediction_horizon
- abstract find_optimal_recovery(simulation)
- abstract get_optimization_log()
- abstract get_trackers()
7.4. infrarisk.src.plots module
Functions to generate infrastructure network plots and result plots.
- infrarisk.src.plots.integrate(x, y)
Calculates the area under a curve
- Parameters:
x (list) – An array of the x values of the curve
y (list) – An array of the y values of the curve
- Returns:
The area under the curve
- Return type:
float
- infrarisk.src.plots.plot_bokeh_from_integrated_graph(G, title, extent=[(1000, 1000), (8000, 6600)], basemap=False)
Converts the integrated network into a Bokeh interactive plot.
- Parameters:
G (networkx.Graph) – Integrated network on which the simulation is to be performed.
title (string) – Title of the plot.
extent (list, optional) – Extent of the plot as a list of tuple in the format [(xmin, xmax), (ymin, ymax)], defaults to [(1000, 8000), (1000, 6600)]
- infrarisk.src.plots.plot_bokeh_lines(p, x, y, infra, link_layer, link_category, ids, line_dash='-', color='black', alpha=1)
Plots the links on the map.
- Parameters:
p (bokeh.plotting.figure.Figure) – The bokeh figure object.
x (list) – The x coordinates of the links.
y (list) – The y coordinates of the links.
infra (string) – The infrastructure type of the links.
link_layer (string) – The link layer of the links.
link_category (string) – The link category of the links.
ids (list) – The link ids.
line_dash (string) – The line dash style of the links.
color (string) – The color of the links.
alpha (float) – The alpha value of the links.
- Returns:
The bokeh figure object.
- Return type:
bokeh.plotting.figure.Figure
- infrarisk.src.plots.plot_disruptions_and_crews(integrated_network, basemap=False)
Generate a plot of the number of disruptions and crews for each strategy.
- Parameters:
integrated_network (infrarisk.src.physical.integrated_network.IntegratedNetwork) – The integrated network object
basemap (bool, optional) – Whether to include a basemap, defaults to False
- infrarisk.src.plots.plot_interdependent_effects(resilience_metrics, metric, title=True)
Plots the interdependent effects of the water and power systems.
- Parameters:
resilience_metrics (infrarisk.src.resilience_metrics.WeightedResilienceMetric) – The object in which simulation results are stored.
metric (string) – The metric to be plotted.
title (bool, optional) – Whether to show the title, defaults to True
- infrarisk.src.plots.plot_network_impact_map(resilience_metrics, integrated_network, strategy, node_prefix, infra='power', time_index=None)
Plots the impact of the disruption on the network.
- Parameters:
resilience_metrics (infrarisk.src.resilience_metrics.WeightedResilienceMetric) – The object in which simulation results are stored.
integrated_network (infrarisk.src.integrated_network.IntegratedNetwork) – The integrated network.
strategy (string) – The strategy used to restore the network.
node_prefix (string) – The prefix of the nodes to be considered.
infra (string, optional) – The infrastructure to be considered, defaults to “power”. Other option is “water”.
time_index (int, optional) – The time index to be considered, defaults to None. If not None, plot the network impact map at the given time index.
- infrarisk.src.plots.plot_power_net(net)
Generates the power systems plot.
- Parameters:
net (pandapowerNet) – The power systems network.
- infrarisk.src.plots.plot_region_impact_map(resilience_metrics, sa_dict, strategy, extends)
Plot the impact map of the region.
- Parameters:
resilience_metrics (: infrarisk.src.resilience_metrics.WeightedResilienceMetric) – The object in which simulation results are stored
sa_dict (dictionary of geopandas.GeoDataFrame) – The power and water socioeconomic impact dictionary
strategy (string) – The name of the recovery strategy
extends (tuple) – The extends of the region
- infrarisk.src.plots.plot_repair_curves(network_recovery, scatter=False)
Generates the direct impact and repair level plots for the failed components.
- Parameters:
network_recovery (infrarisk.src.network_recovery.NetworkRecovery) – The disrupt_generator.DisruptionAndRecovery object.
scatter (bool, optional) – scatter plot, defaults to False
- infrarisk.src.plots.plot_transpo_net(transpo_folder)
Generates the transportation network plot.
- Parameters:
transpo_folder (string) – Location of the transport model (.tntp files).
- infrarisk.src.plots.plot_water_net(wn)
Generates the water network plot.
- Parameters:
wn (wntr.network.WaterNetworkModel) – The water network.
7.5. infrarisk.src.recovery_strategies module
- class infrarisk.src.recovery_strategies.CentralityStrategy(integrated_network)
Bases:
objectBased on betweenness centrality of the components multiplied by capacity. Break ties randomly.
- get_repair_order()
Returns the repair sequence based on the principle of betweenness centrality.
- Returns:
A list of component names in the order of repair action.
- Return type:
list
- set_repair_order()
Identifies the repair sequence based on the betweenness centrality measure. For methodology, please refer to networkx package documentation.
- class infrarisk.src.recovery_strategies.CrewDistanceStrategy(integrated_network)
Bases:
objectBased on the distance between the component and the crew location. Break ties randomly.
- get_repair_order()
Returns the repair sequence based on the distance from the initial crew location.
- Returns:
A list of component names in the order of repair action.
- Return type:
list
- set_repair_order()
Identifies the repair sequence based on the distance from crew location.
- class infrarisk.src.recovery_strategies.HandlingCapacityStrategy(integrated_network)
Bases:
objectBased on the predetermined priority for different components
- get_repair_order()
Returns the repair sequence based on the distance from the initial crew location.
- Returns:
A list of component names in the order of repair action.
- Return type:
list
- set_repair_order()
Identifies the repair sequence based on the maximum quantity of resource flow handled.
- class infrarisk.src.recovery_strategies.JointStrategy
Bases:
objectOptimized strategy. Capture interdependencies somehow if exist. Not an immediate priority
- class infrarisk.src.recovery_strategies.ZoneBasedStrategy(integrated_network, zones_shp)
Bases:
objectBased on the zone in which the components are located.
- get_repair_order()
Returns the repair sequence based on the distance from the initial crew location.
- Returns:
A list of component names in the order of repair action.
- Return type:
list
- set_repair_order()
Identifies the repair sequence based on the zone of the component.
7.6. infrarisk.src.repair_crews module
Repair crew classes
- class infrarisk.src.repair_crews.PowerRepairCrew(name=None, init_loc=None, crew_size=None)
Bases:
objectPower network repair crew class
- get_crew_loc()
Returns the current location of the crew (transport junction).
- Returns:
Name of the current location of the crew
- Return type:
string
- get_next_trip_start()
Returns the next trip start time for the crew in seconds.
- Parameters:
time (integer) – Start time of the next trip start
- reset_locs()
Resets the current location of the crew.
- set_crew_loc(loc)
Sets the current location of the crew (transport junction name).
- Parameters:
loc (string) – Name of the current location of the crew
- set_next_trip_start(time)
Sets the next trip start time for the crew in seconds.
- Parameters:
time (integer) – Start time of the next trip start
- class infrarisk.src.repair_crews.TranspoRepairCrew(name=None, init_loc=None, crew_size=None)
Bases:
objectTraffic network repair crew class
- get_crew_loc()
Returns the current location of the crew (transport node name).
- Returns:
Name of the current location of the crew
- Return type:
string
- get_next_trip_start()
Returns the next trip start time for the crew in seconds.
- Parameters:
time (integer) – Start time of the next trip start
- reset_locs()
Resets the current location of the crew.
- set_crew_loc(loc)
Sets the current location of the crew (transport node name).
- Parameters:
loc (string) – Name of the current location of the crew
- set_next_trip_start(time)
Sets the next trip start time for the crew in seconds.
- Parameters:
time (integer) – Start time of the next trip start
- class infrarisk.src.repair_crews.WaterRepairCrew(name=None, init_loc=None, crew_size=None)
Bases:
objectWater network repair crew class
- get_crew_loc()
Returns the current location of the crew (transport junction name).
- Returns:
Name of the current location of the crew
- Return type:
string
- get_next_trip_start()
Returns the next trip start time for the crew in seconds.
- Parameters:
time (integer) – Start time of the next trip start
- reset_locs()
Resets the current location of the crew.
- set_crew_loc(loc)
Sets the current location of the crew (transport junction name).
- Parameters:
loc (string) – Name of the current location of the crew
- set_next_trip_start(time)
Sets the next trip start time for the crew.
- Parameters:
time (integer) – Start time of the next trip start in seconds
7.7. infrarisk.src.resilience_metrics module
Resilience metric classes to be used for optimizing recovery actions.
- class infrarisk.src.resilience_metrics.WeightedResilienceMetric
Bases:
objectA class that consists of methods to calculate and store weighted ILOS estimates without
- calculate_node_details(network_recovery, wn_results)
Calculates the node head, deamand and pressure and stores them to respective tables.
- Parameters:
network_recovery (infrarisk.src.network_recovery.NetworkRecovery) – The network recovery object
wn_results (dictionary) – The water network simulation results for the current time interval
- calculate_power_load(network_recovery, sim_time)
Calculates the power flow in loads and motor pumps.
- Parameters:
network_recovery (infrarisk.src.network_recovery.NetworkRecovery) – The network recovery object.
sim_time (integer) – The simulation time when the data is collected in seconds.
- calculate_power_resmetric(network_recovery)
Calculates the power network performance timelines (pcs and ecs).
- Parameters:
network_recovery (infrarisk.src.network_recovery.NetworkRecovery) – The network recovery object
- calculate_pump_energy(wn_object)
Calculates the energy consumed by each pump in kWhr in the network and stores the values in a dictionary.
- Parameters:
wn_object (wntr.network.WaterNetworkModel) – The water network model.
- calculate_pump_flow(network_recovery, wn_results)
Calculates the flowrates in pumps and stores the values to a table.
- Parameters:
network_recovery (infrarisk.src.network_recovery.NetworkRecovery) – The network recovery object.
wn_results (dictionary) – The water network simulation results for the current time interval
- calculate_pump_status(network_recovery, wn_results)
Calculates the status of pumps and stores the values to a table.
- Parameters:
network_recovery (infrarisk.src.network_recovery.NetworkRecovery) – The network recovery object.
wn_results (dictionary) – The water network simulation results for the current time interval.
- calculate_transpo_resmetric(tn)
- calculate_water_lost(network_recovery, wn_results)
Calculates the flows through pipe leaks and stores it to a table.
- Parameters:
network_recovery (infrarisk.src.network_recovery.NetworkRecovery) – The network recovery object
wn_results (dictionary) – The water network simulation results for the current time interval
- calculate_water_resmetrics(network_recovery)
Calculates the water network performance timelines (pcs and ecs).
- Parameters:
network_recovery (infrarisk.src.network_recovery.NetworkRecovery) – The network recovery object
- get_weighted_auc_metrics()
Returns the weighted auc metrics.
- Returns:
list of acs and pcs weighted auc values
- Return type:
list
- integrate(x, y)
Calculates the area under a curve
- Parameters:
x (list) – An array of the x values of the curve
y (list) – An array of the y values of the curve
- Returns:
The area under the curve
- Return type:
float
- set_weighted_auc_metrics()
Calculates the water, power, and weighted auc values.
7.8. infrarisk.src.simulation module
Functions to implement the various steps of the interdependent infrastructure network simulations.
- class infrarisk.src.simulation.NetworkSimulation(network_recovery)
Bases:
objectA class to perform simulation of interdependent effects.
- expand_event_table()
Creates the pivot tables (for functional state and performance level) corresponding to the event table.
- get_components_repaired()
Returns the list of components that are already repaired.
- Returns:
list of components which are already repaired.
- Return type:
list
- get_components_to_repair()
Returns the remaining components to be repaired.
- Returns:
The list of components
- Return type:
list
- get_sim_times(network_recovery)
Returns the unique simulation times scheduled by the event table.
- Parameters:
network_recovery (infrarisk.src.network_recovery.NetworkRecovery) – A integrated infrastructure network recovery object.
- Returns:
Unique simulation time stamps
- Return type:
list
- simulate_interdependent_effects(network_recovery_original)
Simulates the interdependent effect based on the initial disruptions and subsequent repair actions.
- Parameters:
network_recovery_original (infrarisk.src.network_recovery.NetworkRecovery) – A integrated infrastructure network recovery object.
- Returns:
lists of time stamps and resilience values of power and water supply.
- Return type:
- update_repaired_components(component)
Update the lists of repaired and to be repaired components.
- Parameters:
component (string) – The name of the component that was recently repaired.
- write_results(file_dir, resilience_metrics)
Writes the results to csv files.
- Parameters:
file_dir (string) – The directory in which the simulation contents are to be saved.
resilience_metrics (infrarisk.src.resilience_metrics.WeightedResilienceMetric) – The object in which simulation related data are stored.