NREL-erad 0.0.0a0__py3-none-any.whl → 1.0.0__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.
- erad/__init__.py +1 -0
- erad/constants.py +20 -20
- erad/cypher_queries/load_data_v1.cypher +211 -211
- erad/data/World_Earthquakes_1960_2016.csv +23410 -23410
- erad/db/assets/critical_infras.py +170 -170
- erad/db/assets/distribution_lines.py +101 -101
- erad/db/credential_model.py +20 -20
- erad/db/disaster_input_model.py +23 -23
- erad/db/inject_earthquake.py +52 -52
- erad/db/inject_flooding.py +53 -53
- erad/db/neo4j_.py +162 -162
- erad/db/utils.py +13 -13
- erad/exceptions.py +68 -68
- erad/metrics/check_microgrid.py +208 -208
- erad/metrics/metric.py +178 -178
- erad/programs/backup.py +61 -61
- erad/programs/microgrid.py +44 -44
- erad/scenarios/abstract_scenario.py +102 -102
- erad/scenarios/common.py +92 -92
- erad/scenarios/earthquake_scenario.py +161 -161
- erad/scenarios/fire_scenario.py +160 -160
- erad/scenarios/flood_scenario.py +493 -493
- erad/scenarios/flows.csv +671 -0
- erad/scenarios/utilities.py +75 -75
- erad/scenarios/wind_scenario.py +89 -89
- erad/utils/ditto_utils.py +252 -252
- erad/utils/hifld_utils.py +147 -147
- erad/utils/opendss_utils.py +357 -357
- erad/utils/overpass.py +76 -76
- erad/utils/util.py +178 -178
- erad/visualization/plot_graph.py +218 -218
- {NREL_erad-0.0.0a0.dist-info → nrel_erad-1.0.0.dist-info}/METADATA +65 -61
- nrel_erad-1.0.0.dist-info/RECORD +42 -0
- {NREL_erad-0.0.0a0.dist-info → nrel_erad-1.0.0.dist-info}/WHEEL +1 -2
- {NREL_erad-0.0.0a0.dist-info → nrel_erad-1.0.0.dist-info/licenses}/LICENSE.txt +28 -28
- NREL_erad-0.0.0a0.dist-info/RECORD +0 -42
- NREL_erad-0.0.0a0.dist-info/top_level.txt +0 -1
erad/scenarios/utilities.py
CHANGED
@@ -1,76 +1,76 @@
|
|
1
|
-
from shapely.geometry import MultiPolygon, Point, LineString
|
2
|
-
from shapely.ops import nearest_points
|
3
|
-
import matplotlib.pyplot as plt
|
4
|
-
import scipy.stats as stats
|
5
|
-
import geopy.distance
|
6
|
-
import numpy as np
|
7
|
-
import stateplane
|
8
|
-
|
9
|
-
|
10
|
-
class GeoUtilities:
|
11
|
-
|
12
|
-
@property
|
13
|
-
def identify_stateplane_projection(self) -> str:
|
14
|
-
""" Automatically identifies stateplane projection ID """
|
15
|
-
x = self.centroid.x
|
16
|
-
y = self.centroid.y
|
17
|
-
return stateplane.identify(x, y)
|
18
|
-
|
19
|
-
def in_polygon(self, point : Point) -> bool:
|
20
|
-
return self.multipolygon.contains(point)
|
21
|
-
|
22
|
-
def distance_from_boundary(self, point : Point) -> float:
|
23
|
-
""" Calculates distance of a point to polygon boundary. Correct calculations require conversion to cartesian coordinates"""
|
24
|
-
if self.multipolygon.contains(point):
|
25
|
-
p1, p2 = nearest_points(self.boundary, point)
|
26
|
-
else:
|
27
|
-
p1, p2 = nearest_points(self.multipolygon, point)
|
28
|
-
coords_1 = (p1.y, p1.x)
|
29
|
-
coords_2 = (p2.y, p2.x)
|
30
|
-
return geopy.distance.geodesic(coords_1, coords_2).km
|
31
|
-
|
32
|
-
def distance_from_centroid(self, point : Point):
|
33
|
-
""" Calculates distance of a point to polygon centroid. Correct calculations require conversion to cartesian coordinates """
|
34
|
-
coords_1 = (self.centroid.y, self.centroid.x)
|
35
|
-
coords_2 = (point.y, point.x)
|
36
|
-
return geopy.distance.geodesic(coords_1, coords_2).km
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
class ProbabilityFunctionBuilder:
|
41
|
-
"""Class containing utility fuctions for sceario definations."""
|
42
|
-
|
43
|
-
|
44
|
-
def __init__(self, dist, params):
|
45
|
-
"""Constructor for BaseScenario class.
|
46
|
-
|
47
|
-
Args:
|
48
|
-
dist (str): Name of teh distribution. Should follow Scipy naming convention
|
49
|
-
params (list): A list of parameters for the chosen distribution function. See Scipy.stats documentation
|
50
|
-
"""
|
51
|
-
|
52
|
-
self.dist = getattr(stats, dist)
|
53
|
-
self.params = params
|
54
|
-
return
|
55
|
-
|
56
|
-
def sample(self):
|
57
|
-
"""Sample the distribution """
|
58
|
-
return self.dist.rvs(*self.params, size=1)[0]
|
59
|
-
|
60
|
-
def plot_cdf(self, x:np.linspace, ax =None, label="") -> None:
|
61
|
-
"""Plot the cumalative distribution fuction"""
|
62
|
-
cdf = self.dist.cdf
|
63
|
-
if ax is None:
|
64
|
-
plt.plot(x,cdf(x, *self.params), label=label)
|
65
|
-
else:
|
66
|
-
ax.plot(x,cdf(x, *self.params), label=label)
|
67
|
-
|
68
|
-
|
69
|
-
def probability(self, value: float) -> float:
|
70
|
-
"""Calculates survival probability of a given asset.
|
71
|
-
|
72
|
-
Args:
|
73
|
-
value (float): value for vetor of interest. Will change with scenarions
|
74
|
-
"""
|
75
|
-
cdf = self.dist.cdf
|
1
|
+
from shapely.geometry import MultiPolygon, Point, LineString
|
2
|
+
from shapely.ops import nearest_points
|
3
|
+
import matplotlib.pyplot as plt
|
4
|
+
import scipy.stats as stats
|
5
|
+
import geopy.distance
|
6
|
+
import numpy as np
|
7
|
+
import stateplane
|
8
|
+
|
9
|
+
|
10
|
+
class GeoUtilities:
|
11
|
+
|
12
|
+
@property
|
13
|
+
def identify_stateplane_projection(self) -> str:
|
14
|
+
""" Automatically identifies stateplane projection ID """
|
15
|
+
x = self.centroid.x
|
16
|
+
y = self.centroid.y
|
17
|
+
return stateplane.identify(x, y)
|
18
|
+
|
19
|
+
def in_polygon(self, point : Point) -> bool:
|
20
|
+
return self.multipolygon.contains(point)
|
21
|
+
|
22
|
+
def distance_from_boundary(self, point : Point) -> float:
|
23
|
+
""" Calculates distance of a point to polygon boundary. Correct calculations require conversion to cartesian coordinates"""
|
24
|
+
if self.multipolygon.contains(point):
|
25
|
+
p1, p2 = nearest_points(self.boundary, point)
|
26
|
+
else:
|
27
|
+
p1, p2 = nearest_points(self.multipolygon, point)
|
28
|
+
coords_1 = (p1.y, p1.x)
|
29
|
+
coords_2 = (p2.y, p2.x)
|
30
|
+
return geopy.distance.geodesic(coords_1, coords_2).km
|
31
|
+
|
32
|
+
def distance_from_centroid(self, point : Point):
|
33
|
+
""" Calculates distance of a point to polygon centroid. Correct calculations require conversion to cartesian coordinates """
|
34
|
+
coords_1 = (self.centroid.y, self.centroid.x)
|
35
|
+
coords_2 = (point.y, point.x)
|
36
|
+
return geopy.distance.geodesic(coords_1, coords_2).km
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
class ProbabilityFunctionBuilder:
|
41
|
+
"""Class containing utility fuctions for sceario definations."""
|
42
|
+
|
43
|
+
|
44
|
+
def __init__(self, dist, params):
|
45
|
+
"""Constructor for BaseScenario class.
|
46
|
+
|
47
|
+
Args:
|
48
|
+
dist (str): Name of teh distribution. Should follow Scipy naming convention
|
49
|
+
params (list): A list of parameters for the chosen distribution function. See Scipy.stats documentation
|
50
|
+
"""
|
51
|
+
|
52
|
+
self.dist = getattr(stats, dist)
|
53
|
+
self.params = params
|
54
|
+
return
|
55
|
+
|
56
|
+
def sample(self):
|
57
|
+
"""Sample the distribution """
|
58
|
+
return self.dist.rvs(*self.params, size=1)[0]
|
59
|
+
|
60
|
+
def plot_cdf(self, x:np.linspace, ax =None, label="") -> None:
|
61
|
+
"""Plot the cumalative distribution fuction"""
|
62
|
+
cdf = self.dist.cdf
|
63
|
+
if ax is None:
|
64
|
+
plt.plot(x,cdf(x, *self.params), label=label)
|
65
|
+
else:
|
66
|
+
ax.plot(x,cdf(x, *self.params), label=label)
|
67
|
+
|
68
|
+
|
69
|
+
def probability(self, value: float) -> float:
|
70
|
+
"""Calculates survival probability of a given asset.
|
71
|
+
|
72
|
+
Args:
|
73
|
+
value (float): value for vetor of interest. Will change with scenarions
|
74
|
+
"""
|
75
|
+
cdf = self.dist.cdf
|
76
76
|
return cdf(value, *self.params)
|
erad/scenarios/wind_scenario.py
CHANGED
@@ -1,89 +1,89 @@
|
|
1
|
-
from erad.constants import FIRE_HISTORIC_GEODATAFRAME_PATH, DATA_FOLDER
|
2
|
-
from shapely.geometry import MultiPolygon, Point, LineString
|
3
|
-
from erad.scenarios.utilities import ProbabilityFunctionBuilder
|
4
|
-
from erad.scenarios.abstract_scenario import BaseScenario
|
5
|
-
from erad.exceptions import FeatureNotImplementedError
|
6
|
-
from erad.scenarios.utilities import GeoUtilities
|
7
|
-
import matplotlib.pyplot as plt
|
8
|
-
from datetime import datetime
|
9
|
-
import geopandas as gpd
|
10
|
-
import numpy as np
|
11
|
-
import random
|
12
|
-
import pyproj
|
13
|
-
import os
|
14
|
-
|
15
|
-
from erad.scenarios.common import AssetTypes
|
16
|
-
from erad.scenarios.utilities import ProbabilityFunctionBuilder
|
17
|
-
|
18
|
-
|
19
|
-
class WindScenario(BaseScenario, GeoUtilities):
|
20
|
-
"""Base class for FireScenario. Extends BaseScenario and GeoUtilities
|
21
|
-
|
22
|
-
Attributes:
|
23
|
-
multipolygon (MultiPolygon): MultiPolygon enclosing wild fire regions
|
24
|
-
probability_model (dict): Dictionary mapping asset types to probability funcitons
|
25
|
-
timestamp (datetime): Scenario occurance time
|
26
|
-
"""
|
27
|
-
|
28
|
-
fragility_curves = {
|
29
|
-
#Extending energy system modelling to include extreme weather risks and application to hurricane events in Puerto Rico
|
30
|
-
AssetTypes.substation.name : ProbabilityFunctionBuilder("lognorm", [0.8, 10, 5]),
|
31
|
-
AssetTypes.solar_panels.name : ProbabilityFunctionBuilder("lognorm", [0.8, 10, 5]),
|
32
|
-
AssetTypes.buried_lines.name : ProbabilityFunctionBuilder("lognorm", [0.8, 10, 5]),
|
33
|
-
AssetTypes.wind_turbines.name : ProbabilityFunctionBuilder("
|
34
|
-
#AssetTypes.battery_storage.name : ProbabilityFunctionBuilder("lognorm", [0.8, 10, 5]),
|
35
|
-
#AssetTypes.transmission_poles.name : ProbabilityFunctionBuilder("lognorm", [0.8, 10, 5]),
|
36
|
-
AssetTypes.distribution_poles.name : ProbabilityFunctionBuilder("lognorm", [0.8, 10, 5]),
|
37
|
-
# AssetTypes.transmission_overhead_lines.name : ProbabilityFunctionBuilder("lognorm", [0.8, 10, 5]),
|
38
|
-
AssetTypes.distribution_overhead_lines.name : ProbabilityFunctionBuilder("beta", [0.8, 10, 5]),
|
39
|
-
}
|
40
|
-
|
41
|
-
def __init__(self, multipolygon : MultiPolygon , probability_model : dict, timestamp : datetime) -> None:
|
42
|
-
"""Constructor for FireScenario.
|
43
|
-
|
44
|
-
Args:
|
45
|
-
multipolygon (MultiPolygon): MultiPolygon enclosing wild fire regions
|
46
|
-
probability_model (dict): Dictionary mapping asset types to probability funcitons
|
47
|
-
timestamp (datetime): Scenario occurance time
|
48
|
-
"""
|
49
|
-
|
50
|
-
super(WindScenario, self).__init__(multipolygon, probability_model, timestamp)
|
51
|
-
return
|
52
|
-
|
53
|
-
@property
|
54
|
-
def area(self) -> float:
|
55
|
-
"""Method to calculate area of affected region."""
|
56
|
-
geod = pyproj.Geod(ellps="WGS84")
|
57
|
-
area = abs(geod.geometry_area_perimeter(self.polygon)[0])
|
58
|
-
return area
|
59
|
-
|
60
|
-
@property
|
61
|
-
def polygon(self) -> MultiPolygon:
|
62
|
-
"""Method to return polygon for the affected region."""
|
63
|
-
return self.multipolygon
|
64
|
-
|
65
|
-
@property
|
66
|
-
def boundary(self) -> LineString:
|
67
|
-
"""Method to return boundary for the affected region."""
|
68
|
-
return self.multipolygon.boundary
|
69
|
-
|
70
|
-
@property
|
71
|
-
def centroid(self) -> Point:
|
72
|
-
"""Method to return the centroid of the affected region."""
|
73
|
-
return self.polygon.centroid
|
74
|
-
|
75
|
-
def increment_time(self):
|
76
|
-
"""Method to increment simulation time for time evolviong scenarios."""
|
77
|
-
raise FeatureNotImplementedError()
|
78
|
-
|
79
|
-
def calculate_survival_probability(self, assets : dict, timestamp : datetime, plot: bool) -> dict:
|
80
|
-
"""Method to calculate survival probaility of asset types.
|
81
|
-
|
82
|
-
Args:
|
83
|
-
assets (dict): The dictionary of all assets and their corresponding asset types
|
84
|
-
plot (bool): Set to true to plot the fire survival model
|
85
|
-
"""
|
86
|
-
return assets
|
87
|
-
|
88
|
-
|
89
|
-
|
1
|
+
from erad.constants import FIRE_HISTORIC_GEODATAFRAME_PATH, DATA_FOLDER
|
2
|
+
from shapely.geometry import MultiPolygon, Point, LineString
|
3
|
+
from erad.scenarios.utilities import ProbabilityFunctionBuilder
|
4
|
+
from erad.scenarios.abstract_scenario import BaseScenario
|
5
|
+
from erad.exceptions import FeatureNotImplementedError
|
6
|
+
from erad.scenarios.utilities import GeoUtilities
|
7
|
+
import matplotlib.pyplot as plt
|
8
|
+
from datetime import datetime
|
9
|
+
import geopandas as gpd
|
10
|
+
import numpy as np
|
11
|
+
import random
|
12
|
+
import pyproj
|
13
|
+
import os
|
14
|
+
|
15
|
+
from erad.scenarios.common import AssetTypes
|
16
|
+
from erad.scenarios.utilities import ProbabilityFunctionBuilder
|
17
|
+
|
18
|
+
|
19
|
+
class WindScenario(BaseScenario, GeoUtilities):
|
20
|
+
"""Base class for FireScenario. Extends BaseScenario and GeoUtilities
|
21
|
+
|
22
|
+
Attributes:
|
23
|
+
multipolygon (MultiPolygon): MultiPolygon enclosing wild fire regions
|
24
|
+
probability_model (dict): Dictionary mapping asset types to probability funcitons
|
25
|
+
timestamp (datetime): Scenario occurance time
|
26
|
+
"""
|
27
|
+
|
28
|
+
fragility_curves = {
|
29
|
+
#Extending energy system modelling to include extreme weather risks and application to hurricane events in Puerto Rico
|
30
|
+
AssetTypes.substation.name : ProbabilityFunctionBuilder("lognorm", [0.8, 10, 5]),
|
31
|
+
AssetTypes.solar_panels.name : ProbabilityFunctionBuilder("lognorm", [0.8, 10, 5]),
|
32
|
+
AssetTypes.buried_lines.name : ProbabilityFunctionBuilder("lognorm", [0.8, 10, 5]),
|
33
|
+
AssetTypes.wind_turbines.name : ProbabilityFunctionBuilder("norm", [0.8, 10, 5]),
|
34
|
+
#AssetTypes.battery_storage.name : ProbabilityFunctionBuilder("lognorm", [0.8, 10, 5]),
|
35
|
+
#AssetTypes.transmission_poles.name : ProbabilityFunctionBuilder("lognorm", [0.8, 10, 5]),
|
36
|
+
AssetTypes.distribution_poles.name : ProbabilityFunctionBuilder("lognorm", [0.8, 10, 5]),
|
37
|
+
# AssetTypes.transmission_overhead_lines.name : ProbabilityFunctionBuilder("lognorm", [0.8, 10, 5]),
|
38
|
+
AssetTypes.distribution_overhead_lines.name : ProbabilityFunctionBuilder("beta", [0.8, 10, 5]),
|
39
|
+
}
|
40
|
+
|
41
|
+
def __init__(self, multipolygon : MultiPolygon , probability_model : dict, timestamp : datetime) -> None:
|
42
|
+
"""Constructor for FireScenario.
|
43
|
+
|
44
|
+
Args:
|
45
|
+
multipolygon (MultiPolygon): MultiPolygon enclosing wild fire regions
|
46
|
+
probability_model (dict): Dictionary mapping asset types to probability funcitons
|
47
|
+
timestamp (datetime): Scenario occurance time
|
48
|
+
"""
|
49
|
+
|
50
|
+
super(WindScenario, self).__init__(multipolygon, probability_model, timestamp)
|
51
|
+
return
|
52
|
+
|
53
|
+
@property
|
54
|
+
def area(self) -> float:
|
55
|
+
"""Method to calculate area of affected region."""
|
56
|
+
geod = pyproj.Geod(ellps="WGS84")
|
57
|
+
area = abs(geod.geometry_area_perimeter(self.polygon)[0])
|
58
|
+
return area
|
59
|
+
|
60
|
+
@property
|
61
|
+
def polygon(self) -> MultiPolygon:
|
62
|
+
"""Method to return polygon for the affected region."""
|
63
|
+
return self.multipolygon
|
64
|
+
|
65
|
+
@property
|
66
|
+
def boundary(self) -> LineString:
|
67
|
+
"""Method to return boundary for the affected region."""
|
68
|
+
return self.multipolygon.boundary
|
69
|
+
|
70
|
+
@property
|
71
|
+
def centroid(self) -> Point:
|
72
|
+
"""Method to return the centroid of the affected region."""
|
73
|
+
return self.polygon.centroid
|
74
|
+
|
75
|
+
def increment_time(self):
|
76
|
+
"""Method to increment simulation time for time evolviong scenarios."""
|
77
|
+
raise FeatureNotImplementedError()
|
78
|
+
|
79
|
+
def calculate_survival_probability(self, assets : dict, timestamp : datetime, plot: bool) -> dict:
|
80
|
+
"""Method to calculate survival probaility of asset types.
|
81
|
+
|
82
|
+
Args:
|
83
|
+
assets (dict): The dictionary of all assets and their corresponding asset types
|
84
|
+
plot (bool): Set to true to plot the fire survival model
|
85
|
+
"""
|
86
|
+
return assets
|
87
|
+
|
88
|
+
|
89
|
+
|