-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPecanStreet_Low2HighRes.m
172 lines (110 loc) · 5.94 KB
/
PecanStreet_Low2HighRes.m
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
function [NewResFile] = PecanStreet_Low2HighRes(OriginalResolution,NewResolution,ProcessingType,WeatherFileLoad_Full)
%% Weather Data - Low Resolution to High Resolution - Zero Order Hold
[R,C] = size(WeatherFileLoad_Full);
FileRes=OriginalResolution;
Delta_T_Hour_OriginalRes=OriginalResolution/60; % Time Step in Hours
Delta_T_Hour_NewRes=NewResolution/60; % Time Step in Hours
WeatherFileLoad_Full(:,4+1:end)=WeatherFileLoad_Full(:,4+1:end)/Delta_T_Hour_OriginalRes; % kWh -> kW
%% Creating New Resolution File
if (ProcessingType==1) % Full File to be Processed
% Getting Start and End DateTime
StartDay=WeatherFileLoad_Full(1,1);
StartMonth=WeatherFileLoad_Full(1,2);
StartYear=WeatherFileLoad_Full(1,3);
StartTime=WeatherFileLoad_Full(1,4);
[ StartHr,StartMin,StartSec ] = DeciToHM( StartTime ); % Decimal Time to HMS
EndDay=WeatherFileLoad_Full(R,1);
EndMonth=WeatherFileLoad_Full(R,2);
EndYear=WeatherFileLoad_Full(R,3);
EndTime=WeatherFileLoad_Full(R,4);
[ EndHr,EndMin,EndSec ] = DeciToHM( EndTime ); % Decimal Time to HMS
elseif (ProcessingType==2) % Part of the File to be Processed we take User Input
% Getting Start and End DateTime
StartDay=1;
StartMonth=1;
StartYear=2017;
StartTime=0;
[ StartHr,StartMin,StartSec ] = DeciToHM( StartTime ); % Decimal Time to HMS
EndDay=31;
EndMonth=12;
EndYear=2017;
EndTime=23.5;
[ EndHr,EndMin,EndSec ] = DeciToHM( EndTime ); % Decimal Time to HMS
end
[ ~,StartIndex,EndIndex ] = DateTimeSeriesSlicer(WeatherFileLoad_Full,1,OriginalResolution,StartYear,EndYear,StartMonth,EndMonth,StartDay,EndDay,0,EndTime);
% Creating DateTime Object
Start_DateTime=datetime(StartYear,StartMonth,StartDay,StartHr,StartMin,StartSec);
End_DateTime=datetime(EndYear,EndMonth,EndDay,EndHr,EndMin,EndSec);
% Creating New Resolution Duration
NewResolution_Duration=duration(0,NewResolution,0);
% While Loop for New Resolution File
NewResFile=zeros(1,C); % Initializing5
DateTimeArray=Start_DateTime; % Initializing
Counter_NewTime=1; % Initilizing
Counter_OldTime=StartIndex; % Initializing
while (DateTimeArray(Counter_NewTime)<=End_DateTime)
if (Counter_OldTime==1)
% Decomposing New DateTime
Day=DateTimeArray(Counter_NewTime).Day;
Month=DateTimeArray(Counter_NewTime).Month;
Year=DateTimeArray(Counter_NewTime).Year;
Hour=DateTimeArray(Counter_NewTime).Hour;
Minute=DateTimeArray(Counter_NewTime).Minute;
Second=DateTimeArray(Counter_NewTime).Second;
% Converting HMS to Decimal Time
[ Time ] = HMToDeci( Hour,Minute,Second );
% Updating NewRes File with OldRes File
NewResFile(Counter_NewTime,:)=horzcat([Day,Month,Year,Time],WeatherFileLoad_Full(Counter_OldTime,5:end));
% Incrementing Counter
Counter_OldTime=Counter_OldTime+1 ;
else
% Getting Current and Previous OldRes File DateTime
CurrentDay=WeatherFileLoad_Full(Counter_OldTime,1);
CurrentMonth=WeatherFileLoad_Full(Counter_OldTime,2);
CurrentYear=WeatherFileLoad_Full(Counter_OldTime,3);
CurrentTime=WeatherFileLoad_Full(Counter_OldTime,4);
[ CurrentHr,CurrentMin,CurrentSec ] = DeciToHM( CurrentTime ); % Converting Decimal Time to HMS
PreviousDay=WeatherFileLoad_Full(Counter_OldTime-1,1);
PreviousMonth=WeatherFileLoad_Full(Counter_OldTime-1,2);
PreviousYear=WeatherFileLoad_Full(Counter_OldTime-1,3);
PreviousTime=WeatherFileLoad_Full(Counter_OldTime-1,4);
[ PreviousHr,PreviousMin,PreviousSec ] = DeciToHM( PreviousTime ); % Converting Decimal Time to HMS
% Converting To DateTime Object
CurrentDateTime_OldResFile=datetime(CurrentYear,CurrentMonth,CurrentDay,CurrentHr,CurrentMin,CurrentSec);
PreviousDateTime_OldResFile=datetime(PreviousYear,PreviousMonth,PreviousDay,PreviousHr,PreviousMin,PreviousSec);
if ((DateTimeArray(Counter_NewTime)<=CurrentDateTime_OldResFile)&&(DateTimeArray(Counter_NewTime)>PreviousDateTime_OldResFile))
% Decomposing New DateTime
Day=DateTimeArray(Counter_NewTime).Day;
Month=DateTimeArray(Counter_NewTime).Month;
Year=DateTimeArray(Counter_NewTime).Year;
Hour=DateTimeArray(Counter_NewTime).Hour;
Minute=DateTimeArray(Counter_NewTime).Minute;
Second=DateTimeArray(Counter_NewTime).Second;
% Converting HMS to Decimal Time
[ Time ] = HMToDeci( Hour,Minute,Second );
% Updating NewRes File with OldRes File
NewResFile(Counter_NewTime,:)=horzcat([Day,Month,Year,Time],WeatherFileLoad_Full(Counter_OldTime,5:end));
else
% Incrementing Counter
Counter_OldTime=Counter_OldTime+1 ;
% Decomposing New DateTime
Day=DateTimeArray(Counter_NewTime).Day;
Month=DateTimeArray(Counter_NewTime).Month;
Year=DateTimeArray(Counter_NewTime).Year;
Hour=DateTimeArray(Counter_NewTime).Hour;
Minute=DateTimeArray(Counter_NewTime).Minute;
Second=DateTimeArray(Counter_NewTime).Second;
% Converting HMS to Decimal Time
[ Time ] = HMToDeci( Hour,Minute,Second );
% Updating NewRes File with OldRes File
NewResFile(Counter_NewTime,:)=horzcat([Day,Month,Year,Time],WeatherFileLoad_Full(Counter_OldTime,5:end));
end
end
% Creating Next New Resolution DateTime
DateTimeArray(Counter_NewTime+1)=DateTimeArray(Counter_NewTime)+NewResolution_Duration;
% Incrementing Counter
Counter_NewTime=Counter_NewTime+1 ;
end
% Converting kW -> kWh
NewResFile(:,4+1:end)=NewResFile(:,4+1:end)*Delta_T_Hour_NewRes;
end