NREL-erad 0.0.0a0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. NREL_erad-0.0.0a0.dist-info/LICENSE.txt +29 -0
  2. NREL_erad-0.0.0a0.dist-info/METADATA +61 -0
  3. NREL_erad-0.0.0a0.dist-info/RECORD +42 -0
  4. NREL_erad-0.0.0a0.dist-info/WHEEL +5 -0
  5. NREL_erad-0.0.0a0.dist-info/top_level.txt +1 -0
  6. erad/__init__.py +0 -0
  7. erad/constants.py +20 -0
  8. erad/cypher_queries/load_data_v1.cypher +212 -0
  9. erad/data/World_Earthquakes_1960_2016.csv +23410 -0
  10. erad/db/__init__.py +0 -0
  11. erad/db/assets/__init__.py +0 -0
  12. erad/db/assets/critical_infras.py +171 -0
  13. erad/db/assets/distribution_lines.py +101 -0
  14. erad/db/credential_model.py +20 -0
  15. erad/db/disaster_input_model.py +23 -0
  16. erad/db/inject_earthquake.py +52 -0
  17. erad/db/inject_flooding.py +53 -0
  18. erad/db/neo4j_.py +162 -0
  19. erad/db/utils.py +14 -0
  20. erad/exceptions.py +68 -0
  21. erad/metrics/__init__.py +0 -0
  22. erad/metrics/check_microgrid.py +208 -0
  23. erad/metrics/metric.py +178 -0
  24. erad/programs/__init__.py +0 -0
  25. erad/programs/backup.py +62 -0
  26. erad/programs/microgrid.py +45 -0
  27. erad/scenarios/__init__.py +0 -0
  28. erad/scenarios/abstract_scenario.py +103 -0
  29. erad/scenarios/common.py +93 -0
  30. erad/scenarios/earthquake_scenario.py +161 -0
  31. erad/scenarios/fire_scenario.py +160 -0
  32. erad/scenarios/flood_scenario.py +494 -0
  33. erad/scenarios/utilities.py +76 -0
  34. erad/scenarios/wind_scenario.py +89 -0
  35. erad/utils/__init__.py +0 -0
  36. erad/utils/ditto_utils.py +252 -0
  37. erad/utils/hifld_utils.py +147 -0
  38. erad/utils/opendss_utils.py +357 -0
  39. erad/utils/overpass.py +76 -0
  40. erad/utils/util.py +178 -0
  41. erad/visualization/__init__.py +0 -0
  42. erad/visualization/plot_graph.py +218 -0
@@ -0,0 +1,218 @@
1
+ """ Module for handling graph plots. """
2
+
3
+ # standard imports
4
+ import os
5
+ import abc
6
+ from typing import List, Dict
7
+
8
+ # third-party libraries
9
+ import networkx as nx
10
+ import plotly.graph_objects as go
11
+ from dotenv import load_dotenv
12
+
13
+ # internal libraries
14
+ from erad.utils.util import path_validation
15
+
16
+ load_dotenv()
17
+
18
+
19
+ class AbstractGraphPlot(abc.ABC):
20
+ """Abstract interface for developing subclass to plot network graph."""
21
+
22
+ @abc.abstractmethod
23
+ def add_network_data(self, *args, **kwargs):
24
+ """Abstract method for adding network data."""
25
+
26
+ @abc.abstractmethod
27
+ def prepare_plot(self, *args, **kwargs):
28
+ """Abstract method for preparing and showing teh plot"""
29
+
30
+
31
+ class PloltyGraph(AbstractGraphPlot):
32
+ """Class for managing graph plot using Plotly.
33
+
34
+ Attributes:
35
+ access_token (str): MapBox API token
36
+ style (str): MapBox style
37
+ zoom_level (int): Zoom level for the plot
38
+ data (List): Stores the data to be fed to plotly for plotting
39
+ scatter_data (Dict): Stores longitudes and latitudes of nodes
40
+ from network
41
+ fig (go.Figure): Plotly graph objects figure instance
42
+ """
43
+
44
+ def __init__(
45
+ self,
46
+ access_token: str = None,
47
+ style: str = "carto-darkmatter",
48
+ zoom_level: int = 13,
49
+ ) -> None:
50
+ """Constructor for `PlotlyGraph` Subclass.
51
+
52
+ Args:
53
+ access_token (str): MapBox API token
54
+ style (str): MapBox style
55
+ zoom_level (int): Zoom level for the plot
56
+ """
57
+
58
+ if access_token:
59
+ self.access_token = access_token
60
+ else:
61
+ self.access_token = os.getenv("MAPBOX_API_KEY")
62
+ self.style = style
63
+ self.zoom_level = zoom_level
64
+
65
+ self.data = []
66
+
67
+ def _get_map_centre(self, longitudes: List[float], latitudes: List[float]):
68
+ """Returns map center."""
69
+ return {
70
+ "lon": sum(longitudes) / len(longitudes),
71
+ "lat": sum(latitudes) / len(latitudes),
72
+ }
73
+
74
+ def add_network_data(
75
+ self,
76
+ network: nx.Graph,
77
+ latitude_property: str = "lat",
78
+ longitude_property: str = "long",
79
+ node_color: str = "blue",
80
+ line_color: str = "red",
81
+ ) -> None:
82
+ """Method to add network data to plot data.
83
+
84
+ Args:
85
+ network (nx.Graph): Networkx graph instance
86
+ latitude_property (str): Property name to be
87
+ used as latitude
88
+ longitude_property (str): Property name to be
89
+ used as longitude
90
+ node_color (str): Color name to be used to plot
91
+ nodes
92
+ line_color (str): Color name to be used to plot
93
+ line segments
94
+ """
95
+
96
+ # Add nodes
97
+ self.scatter_data = {"latitudes": [], "longitudes": []}
98
+
99
+ for node in network.nodes.data():
100
+
101
+ # Storing the lat lons in scatter data
102
+ # container
103
+ self.scatter_data["latitudes"].append(node[1][latitude_property])
104
+ self.scatter_data["longitudes"].append(node[1][longitude_property])
105
+
106
+ # Stroing the edge data in container
107
+ line_data = {"latitudes": [], "longitudes": []}
108
+ node_data = {node[0]: node[1] for node in network.nodes.data()}
109
+
110
+ for edge in network.edges():
111
+ line_data["latitudes"].extend(
112
+ [
113
+ node_data[edge[0]][latitude_property],
114
+ node_data[edge[1]][latitude_property],
115
+ None,
116
+ ]
117
+ )
118
+
119
+ line_data["longitudes"].extend(
120
+ [
121
+ node_data[edge[0]][longitude_property],
122
+ node_data[edge[1]][longitude_property],
123
+ None,
124
+ ]
125
+ )
126
+
127
+ # Adding plots to plotly graph object
128
+ self.data.append(
129
+ go.Scattermapbox(
130
+ mode="markers",
131
+ lon=self.scatter_data["longitudes"],
132
+ lat=self.scatter_data["latitudes"],
133
+ marker={"size": 5, "color": node_color},
134
+ )
135
+ )
136
+
137
+ self.data.append(
138
+ go.Scattermapbox(
139
+ mode="markers+lines",
140
+ lon=line_data["longitudes"],
141
+ lat=line_data["latitudes"],
142
+ marker={"size": 0},
143
+ line={"color": line_color},
144
+ )
145
+ )
146
+
147
+ def add_scatter_points(
148
+ self,
149
+ latitudes: List[float],
150
+ longitudes: List[float],
151
+ color: str = "yellow",
152
+ size: int = 5,
153
+ ) -> None:
154
+ """Method for scatter points to plot data.
155
+
156
+ Args:
157
+ latitudes (List[float]): List of latitude points
158
+ longitudes (List[float]): List of longitude points
159
+ color (str): Color to be used for scatter points
160
+ size (int): Size of scatter points
161
+ """
162
+
163
+ self.data.append(
164
+ go.Scattermapbox(
165
+ mode="markers",
166
+ lon=longitudes,
167
+ lat=latitudes,
168
+ marker={"size": size, "color": color},
169
+ )
170
+ )
171
+
172
+ def add_polygon(
173
+ self,
174
+ latitudes: List[float],
175
+ longitudes: List[float],
176
+ fill: str = "toself",
177
+ ) -> None:
178
+ """Method for adding polygon to the plot.
179
+
180
+ Args:
181
+ latitudes (List[float]): List of latitude points
182
+ longitudes (List[float]): List of longitude points
183
+ fill (str): Accepted fill value by plotly
184
+ """
185
+ self.data.append(
186
+ go.Scattermapbox(
187
+ lon=longitudes, lat=latitudes, fill=fill, mode="lines"
188
+ )
189
+ )
190
+
191
+ def prepare_plot(self, show: bool = True):
192
+ """Method to prepare and show the plot.
193
+
194
+ Args:
195
+ show (bool): True if want to see the plot.
196
+ """
197
+ self.fig = go.Figure(data=self.data)
198
+ self.fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
199
+ self.fig.update_mapboxes(
200
+ {
201
+ "accesstoken": self.access_token,
202
+ "style": self.style,
203
+ "center": self._get_map_centre(
204
+ self.scatter_data["longitudes"],
205
+ self.scatter_data["latitudes"],
206
+ ),
207
+ "zoom": self.zoom_level,
208
+ }
209
+ )
210
+
211
+ if show:
212
+ self.fig.show()
213
+
214
+ def html_export(self, html_file_path: str):
215
+ """Method for exporting plot as HTML file."""
216
+ path_validation(html_file_path)
217
+ self.fig.write_html(html_file_path)
218
+