Skip to content

Commit 215e145

Browse files
committed
Updated Create_network.m and scenario length in code
1 parent d3df0b3 commit 215e145

12 files changed

+82
-94
lines changed

Dataset Creation/Create_network.m

+71-63
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,64 @@
1515

1616
% Shuffle the values retaining the same instance from the file above
1717
Active_Loads = Active_Power.arr(:, 1:48);
18+
PV = Active_Power.arr(:, 56:60);
19+
% Each scenario corresponds to a minute of time and we want to create
20+
% scenarios for every 5 seconds of the recorded loads by interpolating them
21+
timestep = 60/5;
22+
23+
curr_gran = 1:1:length(Active_Loads);
24+
end_gran = 1:(1/timestep):length(Active_Loads);
25+
Int_Active_Loads = zeros(length(end_gran),48);
26+
Int_PV = zeros(length(end_gran),5);
27+
for i=1:48
28+
Int_Active_Loads(:,i) = interpn(curr_gran,Active_Loads(:,i),end_gran,'makima');
29+
end
30+
for i=1:5
31+
Int_PV(:,i) = interpn(curr_gran,PV(:,i),end_gran,'makima');
32+
end
1833

19-
% Check for non-positive or very low values in Active_Loads and convert them to mean
34+
% Check for non-positive or very low values in Int_Active_Loads and convert them to mean
2035
for i=1:48
21-
for j=1:44580
22-
if Active_Loads(j,i)<=10
23-
Active_Loads(j,i) = mean(Active_Loads(:,i));
36+
for j=1:length(Int_Active_Loads)
37+
if j==1
38+
if Int_Active_Loads(j,i)<=10
39+
Int_Active_Loads(j,i) = mean(Int_Active_Loads(:,i));
40+
end
41+
elseif Int_Active_Loads(j,i)<=10
42+
Int_Active_Loads(j,i) = Int_Active_Loads(j-1,i);
2443
end
2544
end
2645
end
2746

28-
Reactive_Loads = Active_Loads * tan(acos(PF_load));
29-
PV = Active_Power.arr(:, 56:60);
30-
random_idx = randperm(size(Active_Loads,1));
31-
Shuffled_Active_Loads = Active_Loads(random_idx,:);
32-
Shuffled_PV = PV(random_idx,:);
47+
% Check for non-positive or very low values in Int_PV_Loads and convert them to mean
48+
for i=1:5
49+
for j=1:length(Int_PV)
50+
if Int_PV(j,i)<0
51+
Int_PV(j,i) = 0;
52+
end
53+
end
54+
end
55+
56+
Int_Reactive_Loads = Int_Active_Loads * tan(acos(PF_load));
3357

58+
Per_Fault=[3715,9535,9535,9535,1022,1022,1022,2384,2384,2384,817,1225];
59+
Int_Per_Fault=12*Per_Fault;
60+
Int_Per_Fault(12)=Int_Per_Fault(12)-11;
3461
% Specify every possible fault we are going to simulate
3562
Scenario.Name = {'Healthy','A-G','B-G','C-G','A-B','B-C','A-C','A-B-G','B-C-G','A-C-G','A-B-C','A-B-C-G'};
3663

37-
% For each scenario make a cell containing loads and PVs
38-
Load1 = {Shuffled_Active_Loads(1:3715, :), Shuffled_PV(1:3715, :)};
39-
Load2 = {Shuffled_Active_Loads(3716:13250, :), Shuffled_PV(3716:13250, :)};
40-
Load3 = {Shuffled_Active_Loads(13251:22785, :), Shuffled_PV(13251:22785, :)};
41-
Load4 = {Shuffled_Active_Loads(22786:32320, :), Shuffled_PV(22786:32320, :)};
42-
Load5 = {Shuffled_Active_Loads(32321:33342, :), Shuffled_PV(32321:33342, :)};
43-
Load6 = {Shuffled_Active_Loads(33343:34364, :), Shuffled_PV(33343:34364, :)};
44-
Load7 = {Shuffled_Active_Loads(34365:35386, :), Shuffled_PV(34365:35386, :)};
45-
Load8 = {Shuffled_Active_Loads(35387:37770, :), Shuffled_PV(35387:37770, :)};
46-
Load9 = {Shuffled_Active_Loads(37771:40154, :), Shuffled_PV(37771:40154, :)};
47-
Load10= {Shuffled_Active_Loads(40155:42538, :), Shuffled_PV(40155:42538, :)};
48-
Load11= {Shuffled_Active_Loads(42539:43355, :), Shuffled_PV(42539:43355, :)};
49-
Load12= {Shuffled_Active_Loads(43356:44580, :), Shuffled_PV(43356:44580, :)};
50-
51-
Scenario.Loads = {Load1, Load2, Load3, Load4, Load5, Load6, Load7, Load8, Load9, Load10, Load11, Load12};
64+
Load = cell(length(Int_Active_Loads),3);
65+
for i=1:length(Int_Active_Loads)
66+
if i~=length(Int_Active_Loads)
67+
Load_i={Int_Active_Loads(i,:),Int_Active_Loads(i+1,:),Int_PV(i,:)};
68+
else
69+
Load_i={Int_Active_Loads(i,:),Int_Active_Loads(i,:),Int_PV(i,:)};
70+
end
71+
Load(i,:)=Load_i;
72+
end
73+
74+
random_idx = randperm(length(Int_Active_Loads));
75+
Load = Load(random_idx,:);
5276

5377
% Fault Resistance - LogNormal Distribution Generator
5478
% Makes
@@ -57,58 +81,42 @@
5781
mu = log((m^2)/sqrt(v+m^2));
5882
sigma = sqrt(log(v/(m^2)+1));
5983

60-
Rs = lognrnd(mu, sigma, 44580, 1);
84+
Rs = lognrnd(mu, sigma, length(Int_Active_Loads), 1);
6185

6286
% For each scenario make a cell containing Rs
63-
R1 = Rs(1:3715);
64-
R2 = Rs(3716:13250);
65-
R3 = Rs(13251:22785);
66-
R4 = Rs(22786:32320);
67-
R5 = Rs(32321:33342);
68-
R6 = Rs(33343:34364);
69-
R7 = Rs(34365:35386);
70-
R8 = Rs(35387:37770);
71-
R9 = Rs(37771:40154);
72-
R10= Rs(40155:42538);
73-
R11= Rs(42539:43355);
74-
R12= Rs(43356:44580);
75-
76-
Scenario.Rs = {R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12};
7787

7888
% Fault Duration - Weibull Distribution Generator
7989

8090
a = 0.3; % scale parameter
8191
b = 1.2; % shape parameter
8292

83-
Fault_Duration = wblrnd(a, b, 44580, 1);
84-
for i=1:44580
93+
Fault_Duration = wblrnd(a, b, length(Int_Active_Loads), 1);
94+
for i=1:length(Int_Active_Loads)
8595
while Fault_Duration(i)<=20e-3
8696
Fault_Duration(i) = wblrnd(a, b);
8797
end
8898
end
89-
Fault_Start = Tm + rand(44580,1).*(Ts - Tm - Fault_Duration);
99+
Fault_Start = Tm + rand(length(Int_Active_Loads),1).*(Ts - Tm - Fault_Duration);
90100

91101
% For each scenario make a cell containing Fault_Duration and Fault_Start
92-
T1 = {Fault_Start(1:3715), Fault_Duration(1:3715)};
93-
T2 = {Fault_Start(3716:13250), Fault_Duration(3716:13250)};
94-
T3 = {Fault_Start(13251:22785), Fault_Duration(13251:22785)};
95-
T4 = {Fault_Start(22786:32320), Fault_Duration(22786:32320)};
96-
T5 = {Fault_Start(32321:33342), Fault_Duration(32321:33342)};
97-
T6 = {Fault_Start(33343:34364), Fault_Duration(33343:34364)};
98-
T7 = {Fault_Start(34365:35386), Fault_Duration(34365:35386)};
99-
T8 = {Fault_Start(35387:37770), Fault_Duration(35387:37770)};
100-
T9 = {Fault_Start(37771:40154), Fault_Duration(37771:40154)};
101-
T10= {Fault_Start(40155:42538), Fault_Duration(40155:42538)};
102-
T11= {Fault_Start(42539:43355), Fault_Duration(42539:43355)};
103-
T12= {Fault_Start(43356:44580), Fault_Duration(43356:44580)};
104-
105-
Scenario.Time = {T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12};
106-
107-
% We need 15 (743x108)x1000 matrices to include all 44580 scenarios
108-
% Each matrix constists of ((4x250)=20sec) rows x ((99 V + 9 A) = 108
109-
% features x 743 scenarios = 80244) columns
110-
Scenario.Output = cell(4,743,15);
111-
Scenario.Class = cell(4,743,15);
102+
103+
Scenario.Loads = cell(1,length(Scenario.Name));
104+
Scenario.Time = cell(2,length(Scenario.Name));
105+
Scenario.Rs = cell(1,length(Scenario.Name));
106+
for i=1:12
107+
if i==1
108+
idx_start=1;
109+
else
110+
idx_start=sum(Int_Per_Fault(1:i-1))+1;
111+
end
112+
idx_stop=sum(Int_Per_Fault(1:i));
113+
Scenario.Loads(1,i)={Load(idx_start:idx_stop,:)};
114+
Scenario.Time(:,i)={Fault_Start(idx_start:idx_stop), Fault_Duration(idx_start:idx_stop)};
115+
Scenario.Rs(1,i)={Rs(idx_start:idx_stop)};
116+
end
117+
118+
Scenario.Output = cell(1,length(Int_Active_Loads));
119+
Scenario.Class = cell(1,length(Int_Active_Loads));
112120
%% Save Scenario structure for exporting
113121

114-
save('Int_Scenario.mat', '-struct', 'Scenario');
122+
save('Int_Scenario.mat', '-struct', 'Scenario');

FLITC applications/fault_train_best_models_DMDCWT.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ def shuffle_dataset(dataset, output_class, rs, dur):
6565
x_trn, x_tst, y_trn, y_tst = [], [], [], []
6666
rs_trn, rs_tst, dur_trn, dur_tst = [], [], [], []
6767

68-
scenario_length = [1907, 1907, 1907, 205, 205, 205, 477, 477, 477, 163, 245]
69-
array = np.array(scenario_length) * 3
70-
scenario_length = list(array)
68+
scenario_length = [114420, 114420, 114420, 12264, 12264, 12264, 28608, 28608, 28608, 9804, 14689]
7169

7270
for idx in range(len(scenario_length)):
7371
x_train, x_test, y_train, y_test, rs_train, rs_test, dur_train, dur_test = train_test_split(

FLITC applications/feeder_train_best_models_CWT.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ def shuffle_dataset(dataset, output_class, rs, dur):
5252
x_trn, x_tst, y_trn, y_tst = [], [], [], []
5353
rs_trn, rs_tst, dur_trn, dur_tst = [], [], [], []
5454

55-
scenario_length = [743, 1907, 1907, 1907, 205, 205, 205, 477, 477, 477, 163, 245]
56-
array = np.array(scenario_length) * 3
57-
scenario_length = list(array)
55+
scenario_length = [44580, 114420, 114420, 114420, 12264, 12264, 12264, 28608, 28608, 28608, 9804, 14689]
5856

5957
for idx in range(len(scenario_length)):
6058
x_train, x_test, y_train, y_test, rs_train, rs_test, dur_train, dur_test = train_test_split(

FLITC applications/run_best_models.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
distance_dic = results_dic + r'\Distance_ID'
3535

3636
# Scenario length initialization
37-
scenario_length = [743, 1907, 1907, 1907, 205, 205, 205, 477, 477, 477, 163, 245]
38-
array = np.array(scenario_length) * 3
39-
scenario_length = list(array)
37+
scenario_length = [44580, 114420, 114420, 114420, 12264, 12264, 12264, 28608, 28608, 28608, 9804, 14689]
4038

4139
# LVDG topology recreation
4240
tree, nodes, grid_length = top.create_grid()

Hyperparameter Tuning/Dataset_Parser.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ def create_dataset():
3434
print("Directory is ",directory)
3535

3636
# scenario_length = datapoints for each scenario
37-
scenario_length = [743, 1907, 1907, 1907, 205, 205, 205, 477, 477, 477, 163, 245]
38-
array = np.array(scenario_length) * 3
39-
scenario_length = list(array)
37+
scenario_length = [44580, 114420, 114420, 114420, 12264, 12264, 12264, 28608, 28608, 28608, 9804, 14689]
4038

4139
Name = []
4240
Loads = [[] for _ in range(12)]

Hyperparameter Tuning/Fault_HyperOpt_DMDCWT_not_full_v2.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ def shuffle_dataset(dataset, output_class, rs, dur):
6565
x_trn, x_tst, y_trn, y_tst = [], [], [], []
6666
rs_trn, rs_tst, dur_trn, dur_tst = [], [], [], []
6767

68-
scenario_length = [1907, 1907, 1907, 205, 205, 205, 477, 477, 477, 163, 245]
69-
array = np.array(scenario_length) * 3
70-
scenario_length = list(array)
68+
scenario_length = [114420, 114420, 114420, 12264, 12264, 12264, 28608, 28608, 28608, 9804, 14689]
7169

7270
for idx in range(len(scenario_length)):
7371
x_train, x_test, y_train, y_test, rs_train, rs_test, dur_train, dur_test = train_test_split(

Hyperparameter Tuning/Feeder_HyperOpt_CWT_not_full_v1.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ def shuffle_dataset(dataset, output_class, rs, dur):
4848
x_trn, x_tst, y_trn, y_tst = [], [], [], []
4949
rs_trn, rs_tst, dur_trn, dur_tst = [], [], [], []
5050

51-
scenario_length = [743, 1907, 1907, 1907, 205, 205, 205, 477, 477, 477, 163, 245]
52-
array = np.array(scenario_length) * 3
53-
scenario_length = list(array)
51+
scenario_length = [44580, 114420, 114420, 114420, 12264, 12264, 12264, 28608, 28608, 28608, 9804, 14689]
5452

5553
for idx in range(len(scenario_length)):
5654
x_train, x_test, y_train, y_test, rs_train, rs_test, dur_train, dur_test = train_test_split(

Hyperparameter Tuning/class_encoding.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
Dataset_path = directory + r'\Dataset.joblib'
99

1010
# scenario_length = datapoints for each scenario
11-
scenario_length = [743, 1907, 1907, 1907, 205, 205, 205, 477, 477, 477, 163, 245]
12-
array = np.array(scenario_length) * 3
13-
scenario_length = list(array)
11+
scenario_length = [44580, 114420, 114420, 114420, 12264, 12264, 12264, 28608, 28608, 28608, 9804, 14689]
1412

1513
Dataset = joblib.load(Dataset_path)
1614
names = Dataset['Name']

Hyperparameter Tuning/preprocessing_stage.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ def preprocess():
5656
voltage_int_path = directory + r'\V_int.joblib'
5757
Iabc_path = directory + r'\Iabc.joblib'
5858
class_path = directory + r'\Class.joblib'
59-
scenario_length = [743, 1907, 1907, 1907, 205, 205, 205, 477, 477, 477, 163, 245]
60-
array = np.array(scenario_length) * 3
61-
scenario_length = list(array)
59+
scenario_length = [44580, 114420, 114420, 114420, 12264, 12264, 12264, 28608, 28608, 28608, 9804, 14689]
6260

6361
if not (os.path.exists(dataset_path) and os.path.exists(class_path)):
6462
parser.create_dataset()

Hyperparameter Tuning/reduce_fault_class.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
Fault_Class = np.array(joblib.load(Fault_Class_path))
1313

1414

15-
scenario_length = [1907, 1907, 1907, 205, 205, 205, 477, 477, 477, 163, 245]
16-
array = np.array(scenario_length) * 3
17-
scenario_length = list(array)
15+
scenario_length = [114420, 114420, 114420, 12264, 12264, 12264, 28608, 28608, 28608, 9804, 14689]
1816

1917
Fault_Class_reduced = np.zeros([Fault_Class.shape[0], 7], dtype=int)
2018

Hyperparameter Tuning/sort_distances.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Distance_Class = joblib.load(Distance_Class_path)
99

1010
def distributer(dist_class):
11-
new_class = dist_class[3*743:]
11+
new_class = dist_class[44580:]
1212

1313
return new_class
1414

Hyperparameter Tuning/sort_metadata.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ def sort_meta(dataset):
2222
directory = os.getcwd()
2323

2424
# scenario_length = datapoints for each scenario
25-
scenario_length = [743, 1907, 1907, 1907, 205, 205, 205, 477, 477, 477, 163, 245]
26-
array = np.array(scenario_length) * 3
27-
scenario_length = list(array)
25+
scenario_length = [44580, 114420, 114420, 114420, 12264, 12264, 12264, 28608, 28608, 28608, 9804, 14689]
2826

2927
# Open dataset file
3028
dataset_path = directory + r'\Dataset.joblib'

0 commit comments

Comments
 (0)