-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindWeatherImpact.py
More file actions
128 lines (101 loc) · 4.98 KB
/
findWeatherImpact.py
File metadata and controls
128 lines (101 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import numpy as np
import pandas as pd
import os
from util.mainHelper import weatherImpact,createLevelsAlt,findWeatherLevel
n=2 # Number of weather scenarios to simulate
network = "P3R" # Network identifier
directories = [f"./{network}/Rain/nodes/", f"./{network}/Wind/nodes/"] # Directories containing data
fileNames = [f for f in os.listdir(directories[0]) if os.path.isfile(os.path.join(directories[0], f))] # List of filenames in the first directory
# Normalization Levels for Weather Data
windSeverityLevels = createLevelsAlt(0,120,10)
rainSeverityLevels = createLevelsAlt(0,6,10)
# Process files for nodes
for name in fileNames:
alpha = {
"elevation nodes": [0.4, 0.6],
"vegetation": [0.8, 0.2]
}
rainDf = pd.read_csv(directories[0] + name) # Load rain data
windDf = pd.read_csv(directories[1] + name) # Load wind data
rainDf.drop(["Unnamed: 0"], axis=1, inplace=True) # Remove extra index column if present in rain data
windDf.drop(["Unnamed: 0"], axis=1, inplace=True) # Remove extra index column if present in wind data
# Calculate max and min values for rain and wind datasets
maxValuesRain = np.array(rainDf.max(axis=1))
maxValuesWind = np.array(windDf.max(axis=1))
minValuesRain = np.array(rainDf.min(axis=1))
minValuesWind = np.array(windDf.min(axis=1))
# Initialize arrays to store scores and vectors in
weatherVector = np.zeros((2, 767, n))
score_wind = np.zeros((2, 767))
score_rain = np.zeros((2, 767))
# Loop through each node to find the normalized weather value
for i in range(767):
score_wind[0,i] = findWeatherLevel(minValuesWind[i],windSeverityLevels)
score_wind[1,i] = findWeatherLevel(maxValuesWind[i],windSeverityLevels)
score_rain[0,i] = findWeatherLevel(minValuesRain[i],rainSeverityLevels)
score_rain[1,i] = findWeatherLevel(maxValuesRain[i],rainSeverityLevels)
# Create the normalized weather vector
weatherVector[0,:] = np.linspace(score_wind[0,:], score_wind[1,:], num=n).T
weatherVector[1,:] = np.linspace(score_rain[0,:], score_rain[1,:], num=n).T
# Compute weather impact for both interpolated points
wi1 = weatherImpact(alpha, weatherVector[:,:,0])
wi2 = weatherImpact(alpha, weatherVector[:,:,1])
# Create dictionary to hold final weather impact ranges
wi = {
"elevation nodes": [],
"vegetation": []
}
# Combine data for low and high scenarios
for feature in wi:
for low, high in zip(wi1[feature], wi2[feature]):
wi[feature].append(((np.round(low,3), np.round(high,3))))
# Create DataFrame and save to CSV
events = pd.DataFrame(wi)
pd.DataFrame.to_csv(events, f'./{network}/WI/nodes/{name}')
# Process files for edges (similar steps as nodes)
directories = [f"./{network}/Rain/edges/", f"./{network}/Wind/edges/"]
fileNames = [f for f in os.listdir(directories[0]) if os.path.isfile(os.path.join(directories[0], f))]
# Process files for edges
for name in fileNames:
alpha = {
"vegetation edges": [0.7, 0.3],
"length": [0.9, 0.1],
}
rainDf = pd.read_csv(directories[0] + name)
windDf = pd.read_csv(directories[1] + name)
# Removing both types of unnamed columns that might have been erroneously created
rainDf.drop(["Unnamed: 0.1", "Unnamed: 0"], axis=1, inplace=True)
windDf.drop(["Unnamed: 0.1", "Unnamed: 0"], axis=1, inplace=True)
# Calculate max and min values for rain and wind datasets
maxValuesRain = rainDf.max(axis=1)
maxValuesWind = windDf.max(axis=1)
minValuesRain = rainDf.min(axis=1)
minValuesWind = windDf.min(axis=1)
# Initialize arrays to store scores and vectors in
weatherVector = np.zeros((2, 766, n))
score_wind = np.zeros((2, 766))
score_rain = np.zeros((2, 766))
# Loop through each edge to find the normalized weather value
for i in range(766):
score_wind[0,i] = findWeatherLevel(minValuesWind[i],windSeverityLevels)
score_wind[1,i] = findWeatherLevel(maxValuesWind[i],windSeverityLevels)
score_rain[0,i] = findWeatherLevel(minValuesRain[i],rainSeverityLevels)
score_rain[1,i] = findWeatherLevel(maxValuesRain[i],rainSeverityLevels)
# Create the normalized weather vector
weatherVector[0,:] = np.linspace(score_wind[0,:], score_wind[1,:], num=n).T
weatherVector[1,:] = np.linspace(score_rain[0,:], score_rain[1,:], num=n).T
# Compute weather impact for both interpolated points
wi1 = weatherImpact(alpha, weatherVector[:,:,0])
wi2 = weatherImpact(alpha, weatherVector[:,:,1])
# Create dictionary to hold final weather impact ranges
wi = {
"vegetation edges": [],
"length": []
}
# Combine data for low and high scenarios
for feature in wi:
for low, high in zip(wi1[feature], wi2[feature]):
wi[feature].append((np.round(low,3), np.round(high,3)))
# Create DataFrame and save to CSV
events = pd.DataFrame(wi)
pd.DataFrame.to_csv(events, f'./{network}/WI/edges/{name}')