15
15
16
16
% Shuffle the values retaining the same instance from the file above
17
17
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
18
33
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
20
35
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 );
24
43
end
25
44
end
26
45
end
27
46
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 ));
33
57
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 ;
34
61
% Specify every possible fault we are going to simulate
35
62
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' };
36
63
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 ,: );
52
76
53
77
% Fault Resistance - LogNormal Distribution Generator
54
78
% Makes
57
81
mu = log((m ^ 2 )/sqrt(v + m ^ 2 ));
58
82
sigma = sqrt(log(v /(m ^ 2 )+1 ));
59
83
60
- Rs = lognrnd(mu , sigma , 44580 , 1 );
84
+ Rs = lognrnd(mu , sigma , length( Int_Active_Loads ) , 1 );
61
85
62
86
% 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 };
77
87
78
88
% Fault Duration - Weibull Distribution Generator
79
89
80
90
a = 0.3 ; % scale parameter
81
91
b = 1.2 ; % shape parameter
82
92
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 )
85
95
while Fault_Duration(i )<=20e-3
86
96
Fault_Duration(i ) = wblrnd(a , b );
87
97
end
88
98
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 );
90
100
91
101
% 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 ));
112
120
%% Save Scenario structure for exporting
113
121
114
- save(' Int_Scenario.mat' , ' -struct' , ' Scenario' );
122
+ save(' Int_Scenario.mat' , ' -struct' , ' Scenario' );
0 commit comments