-
Notifications
You must be signed in to change notification settings - Fork 0
/
TDA.m
5957 lines (4888 loc) · 267 KB
/
TDA.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%% Info
% Copyright (C) 2017, Navid Haghdadi, [email protected]
% TDA is open source software for assessing existing and proposed new tariffs.
% It offers a range of analyses as described in this document to assist energy
% market stakeholders and the wider community to analyse the impact of different
% tariffs on different user groups. TDA is free software and you can redistribute
% it and/or modify it under the terms of the GNU General Public License as published
% by the Free Software Foundation version 3. For more information about GPL 3 please
% refer to: https://www.gnu.org/licenses/gpl-3.0.en.html.
% --- Main function of the TDA
function TDA
%% ****************** GUI Initialising ***********************
warning('off','all')
% Global Variable h, main handle of the data
global h
h=[];
% If Windows, it will find the folder and work properly
if ispc
h.FolderSel=1;
h.FilesPath='';
% If Mac we need to allocate the TDA folder
else
choice = questdlg('Welcome to TDA! As you are a Mac user, you should first browse the TDA folder in your computer:', ...
'Browse folder','Browse folder','Browse folder');
% Handle response
switch choice
case 'Browse folder'
% Get the folder
h.FilesPath=uigetdir;
h.FolderSel=1;
end
end
% Loading the tariff list (original) and the new tariff list (modified by user)
if ispc
TariffList1=load('Data\AllTariffs.mat','AllTariffs'); % Download original tariffs
try
TariffList2=load('Data\AllTariffs_New.mat','AllTariffs'); % Download new tariffs
catch
TariffList2.AllTariffs=[];
end
else
TariffList1=load([h.FilesPath,'/Data/AllTariffs.mat'],'AllTariffs'); % Download original tariffs
try
TariffList2=load([h.FilesPath,'/Data/AllTariffs_New.mat'],'AllTariffs'); % Download new tariffs
catch
TariffList2.AllTariffs=[];
end
end
% Combining all tariffs
AllTariffsList=[TariffList1.AllTariffs,TariffList2.AllTariffs];
% Removing the original tariffs which has been deleted by user
AllTariffsList(:,~cell2mat({AllTariffsList.Show}))=[];
% Assign the tariffs in to the handle
h.TariffList.AllTariffs=AllTariffsList;
% List of all options for 4 figures
% 1- Load selection figure
h.ListofLoadSelectFigures={'Annual Average Profile', 'Daily Profile(s)','Daily Profile interquartile Range','Daily kWh Histogram','Average Load Duration Curve','Average Peak Day Profile','Monthly Average kWh','Seasonal Daily Pattern'};
% 2- Single variabl figure
h.ListofSingVarFigs={'Average Annual Profile','Daily kWh Histogram','Monthly Average kWh','Seasonal Daily Pattern','Monthly Peak Time','Average Load Duration Curve','Bill Distribution','Bill Box Plot'};
% 3- Dual Variable figures
h.ListofDualVarFigs={'Annual kWh';'Average Demand at ''N'' Network Peaks';'Average Demand at ''N'' Network Monthly Peaks';'Average Demand at Top ''N'' Peaks';'Average Demand at Top ''N'' Monthly Peaks';'Average Daily kWh';'Average Daily Peak';'Bill ($/year)';'Unitised Bill (kW)'}; % Options for plotting in Dual variable figure
% 4- Single case figures
h.ListofSingCaseFigs={'Bill Components'; 'Bill Component Pie Chart';'Daily Profile interquartile Range'}; % Options for plotting in Single case figure
% Number of peaks to be considered
h.ListofTopPeaks=num2cell([1:150]');
% AllDiagrams is the variable which contains all cases (up to 10 case)
h.AllDiagrams=[]; % Container Of all cases (up to 10 cases)
% Load, are not set yet.
h.status.LoadSet=0;
% Import Settings
if ispc
load('Data\Settings.mat');
else
load([h.FilesPath,'/Data/Settings.mat']);
end
% Loading the previous settings saved by the user including:
% Synthetic Network load
h.SyntheticNetwork=SyntheticNetwork;
% Peak time method (based on whole load, filtered load or synthetic network)
h.PeakTimeMethod=PeakTimeMethod;
% Option for ask to name a new case
h.AskForCaseName=AskForCaseName;
% Option for Confirm before exiting
h.Confirm.BeforeExit=Confirm.BeforeExit;
% Option for Confirm before deleting Case
h.Confirm.BeforeDeleting.Case=Confirm.BeforeDeleting.Case;
% Option for Confirm before deleting Load
h.Confirm.BeforeDeleting.Load=Confirm.BeforeDeleting.Load;
% Option for Confirm before deleting Tariff
h.Confirm.BeforeDeleting.Tariff=Confirm.BeforeDeleting.Tariff;
% Option for Confirm before deleting Project
h.Confirm.BeforeDeleting.Project=Confirm.BeforeDeleting.Project;
%% ****************** GUI Elements ***********************
%% GUI Elements: Main Figure
h.MainFigure = figure('Name','TDA (CEEM, UNSW)','NumberTitle','off', ...
'HandleVisibility','on', ...
'Toolbar','none','Menubar','none',...
'Position',[20 50 1200 730 ],...
'CloseRequestFcn',@closeGUI);
% Set Icon
% warning('off', ...
% 'MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame');
% jframe=get(h.MainFigure,'javaframe');
% jIcon=javax.swing.ImageIcon('UNSWLogo_small.png');
% jframe.setFigureIcon(jIcon);
% UNSW and CEEM Logos
h.CEEMAxes = axes('Parent', h.MainFigure, ...
'HandleVisibility','callback', ...
'Units', 'normalized', 'Position',[.01 0.88 0.17 0.12], 'FontSize',8,'Box','on'); % Axes for ceem logo
CEEMIm = imread('CEEMLogo.png');
image(h.CEEMAxes,CEEMIm)
axis(h.CEEMAxes, 'off')
axis(h.CEEMAxes, 'image')
h.UNSWAxes = axes('Parent', h.MainFigure, ...
'HandleVisibility','callback', ...
'Units', 'normalized', 'Position',[.2 0.88 0.1 0.1], 'FontSize',8,'Box','on'); %Axes for UNSW logo
UNSWIm = imread('UNSWLogo.png');
image(h.UNSWAxes,UNSWIm)
axis(h.UNSWAxes, 'off')
axis(h.UNSWAxes, 'image')
%% GUI Elements: Menus
% 1- Project Menu
h.menuProject = uimenu('Label','Project','Parent',h.MainFigure);
% Load project
h.LoadProjMenu=uimenu(h.menuProject,'Label','Load Project');
% update the list of projects based on available projects
updatePrjList
% save and save as puttons
uimenu(h.menuProject,'Label','Save Project','Accelerator','S','Callback', ...
@SaveProj_CB);
uimenu(h.menuProject,'Label','Save Project As','Callback', ...
@SaveProjAs_CB);
% delete projects
h.menuProject_del=uimenu(h.menuProject,'Label','Delete Project');
% update the list of projects for delete
updatePrjList_del
% restart the tool
uimenu(h.menuProject,'Label','Restart Tool','Separator','on','Callback',...
@RestartTool);
% 2- Load Menu
h.menuLoad = uimenu('Label','Load','Parent',h.MainFigure);
% import load
uimenu(h.menuLoad,'Label','Import Load Data', ...
'Callback',@ImpNewLoad_CB);
% delete load
h.menuLoad_del=uimenu(h.menuLoad,'Label','Delete Load Data');
updateLoadList_del
% restart load
uimenu(h.menuLoad,'Label','Restore Original Load Data', 'Callback',@RestoreLoad);
% Maximum Allowed Missing Data (%)
h.menuLoad_Miss=uimenu(h.menuLoad,'Label','Maximum Allowed Missing Data (%)','Separator','On');
h.MissingDataOptions={'0%','1%','2%','5%','10%','20%','30%'};
% Check only the one which has been selected
for n=1:7
h.menuLoad_Miss_Opt{n,1}=uimenu(h.menuLoad_Miss,'Label',h.MissingDataOptions{1,n},...
'checked','Off','Callback',{@ChenageCheckedMiss,n});
end
h.menuLoad_Miss_Opt{4,1}.Checked='On';
% Down sampling the data
h.menuLoad_DownSam=uimenu(h.menuLoad,'Label','Down-sample Users (Random Selection)');
h.DownSamOptions={'100% (full data)','50%','20%','10%','5%','2%','1%'};
for n=1:7
h.menuLoad_DownSam_Opt{n,1}=uimenu(h.menuLoad_DownSam,'Label',h.DownSamOptions{1,n},...
'checked','Off','Callback',{@ChenageCheckedDownSam,n});
end
h.menuLoad_DownSam_Opt{1,1}.Checked='On';
% Options for Network load
h.menuLoad_PT=uimenu(h.menuLoad,'Label','Network Load',...
'Separator','On');
% based on the Aggregation of Whole Load Data
h.menuLoad_PT1=uimenu(h.menuLoad_PT,'Label','Aggregation of Whole Load Data',...
'checked','Off','Callback',{@PeakTimeNew,1});
% based on the Aggregation of Filtered Load Data
h.menuLoad_PT2=uimenu(h.menuLoad_PT,'Label','Aggregation of Filtered Load Data',...
'checked','Off','Callback',{@PeakTimeNew,2});
% based on the Synthetic Network Load
h.menuLoad_PT3=uimenu(h.menuLoad_PT,'Label','Synthetic Network Load',...
'checked','Off','Callback',{@PeakTimeNew,3});
% Create New Synthetic Network Load
h.menuLoad_PT4=uimenu(h.menuLoad_PT,'Label','Create New Synthetic Network Load',...
'Separator','on','Callback',{@PeakTimeNew,4});
% Plot Network Load Pattern
h.menuLoad_PT4=uimenu(h.menuLoad_PT,'Label','Plot Network Load Pattern','Separator','on');
% Plot Network Load which is based on: Based on Whole Dataset
uimenu(h.menuLoad_PT4,'Label','Based on Whole Dataset',...
'Callback',{@PlotNetworkLoad,1});
% Plot Network Load which is based on: Based on Filtered Dataset
uimenu(h.menuLoad_PT4,'Label','Based on Filtered Dataset',...
'Callback',{@PlotNetworkLoad,2});
% Plot Network Load which is based on: Synethetic Network Load
uimenu(h.menuLoad_PT4,'Label','Synethetic Network Load',...
'Callback',{@PlotNetworkLoad,3});
% See what is the method for the network peak and check the option
if h.PeakTimeMethod==1
h.menuLoad_PT1.Checked='On';
elseif h.PeakTimeMethod==2
h.menuLoad_PT2.Checked='On';
else
h.menuLoad_PT3.Checked='On';
end
% 3- Tariff Menu
h.menuTariff = uimenu('Label','Tariff','Parent',h.MainFigure);
% Create New Tariff
h.MenuTariff_cre=uimenu(h.menuTariff,'Label','Create New Tariff');
% Different options for the tariff:
uimenu(h.MenuTariff_cre,'Label','Flat rate','Callback',{@CreateTar,'FR'});
uimenu(h.MenuTariff_cre,'Label','Flat rate Seasonal','Callback',{@CreateTar,'FRSeas'});
uimenu(h.MenuTariff_cre,'Label','Block','Callback',{@CreateTar,'Block'});
uimenu(h.MenuTariff_cre,'Label','Block Quarterly','Callback',{@CreateTar,'Block_Quarterly'});
uimenu(h.MenuTariff_cre,'Label','Time of Use','Callback',{@CreateTar,'TOU'});
uimenu(h.MenuTariff_cre,'Label','Time of Use Seasonal','Callback',{@CreateTar,'TOUSeas'});
uimenu(h.MenuTariff_cre,'Label','Demand Charge','Callback',{@CreateTar,'Demand'});
% Help file of the tariffs
uimenu(h.menuTariff,'Label','Tariff Info','Callback',@HelpTariff);
% Reset the tariff
uimenu(h.menuTariff,'Label','Reset Tariffs','Callback',@ResTar);
% 4- Export Menu
h.menuExport = uimenu('Label','Export','Parent',h.MainFigure);
% Export current figure showing on the panel
uimenu(h.menuExport,'Label','Export Figure','Callback',@ExpCurFig,'Accelerator','E');
% Copy current figure showing on the panel
uimenu(h.menuExport,'Label','Copy Figure','Callback',@CopyCurFig,'Accelerator','C');
% Copy the data of the figure showing on the panel
uimenu(h.menuExport,'Label','Copy Data','Callback',@CopyCurData,'Accelerator','D');
% Export the result of the cases
h.menuExpRes=uimenu(h.menuExport,'Label','Export Results');
% Export all cases
h.menuExport_all=uimenu(h.menuExpRes,'Label','All Cases','Callback',@Exp_AllCases_CB);
% Exporting menu for individual cases will appear when they are being added
% 5- Preferences Menu (specifying the preferences for some options)
h.menuPref.M = uimenu('Label','Preferences','Parent',h.MainFigure);
if h.AskForCaseName
AskForCaseName_C='On';
else
AskForCaseName_C='Off';
end
% Ask To Name New Case
h.menuPref.AskForCaseName=uimenu(h.menuPref.M,'Label','Ask To Name New Case','checked',AskForCaseName_C,'Callback',@AskForCaseName_Callback);
% Check the previously set preference
if h.Confirm.BeforeExit
ConfirmBeforeExit_C='On';
else
ConfirmBeforeExit_C='Off';
end
% Confirm Before Exiting Tool
h.menuPref.Confirm.BeforeExit=uimenu(h.menuPref.M,'Label','Confirm Before Exiting Tool','checked',ConfirmBeforeExit_C,'Callback',@ConfirmBeforeExit_Callback);
% Confirm Before Deleting
h.menuPref.Confirms = uimenu(h.menuPref.M,'Label','Confirm Before Deleting');
% Confirm Before Deleting Case
% Check the previously set preference
if h.Confirm.BeforeDeleting.Case
ConfirmBeforeDeletingCase_C='On';
else
ConfirmBeforeDeletingCase_C='Off';
end
h.menuPref.Confirm.BeforeDeleting.Case=uimenu(h.menuPref.Confirms,'Label','Case','checked',ConfirmBeforeDeletingCase_C,'Callback',@ConfirmBeforeDeletingCase_Callback);
% Confirm Before Deleting Load
% Check the previously set preference
if h.Confirm.BeforeDeleting.Load
ConfirmBeforeDeletingLoad_C='On';
else
ConfirmBeforeDeletingLoad_C='Off';
end
h.menuPref.Confirm.BeforeDeleting.Load=uimenu(h.menuPref.Confirms,'Label','Load','checked',ConfirmBeforeDeletingLoad_C,'Callback',@ConfirmBeforeDeletingLoad_Callback);
% Confirm Before Deleting Project
% Check the previously set preference
if h.Confirm.BeforeDeleting.Project
ConfirmBeforeDeletingProject_C='On';
else
ConfirmBeforeDeletingProject_C='Off';
end
h.menuPref.Confirm.BeforeDeleting.Project=uimenu(h.menuPref.Confirms,'Label','Project','checked',ConfirmBeforeDeletingProject_C,'Callback',@ConfirmBeforeDeletingProject_Callback);
% Confirm Before Deleting Tariff
% Check the previously set preference
if h.Confirm.BeforeDeleting.Tariff
ConfirmBeforeDeletingTariff_C='On';
else
ConfirmBeforeDeletingTariff_C='Off';
end
h.menuPref.Confirm.BeforeDeleting.Tariff=uimenu(h.menuPref.Confirms,'Label','Tariff','checked',ConfirmBeforeDeletingTariff_C,'Callback',@ConfirmBeforeDeletingTariff_Callback);
% 6- Help menu
h.menuHelp = uimenu('Label','Help','Parent',h.MainFigure);
h.menuHelp_About=uimenu(h.menuHelp,'Label','About');
uimenu(h.menuHelp_About,'Label','CEEM','Callback',@About_CEEM_Callback);
uimenu(h.menuHelp_About,'Label','ResearchGate','Callback',@About_RG_Callback);
uimenu(h.menuHelp_About,'Label','GitHub','Callback',@About_GH_Callback);
uimenu(h.menuHelp,'Label','User''s Guide','Callback',@UserGuide_Callback);
uimenu(h.menuHelp,'Label','Check for Update','Callback',@Update_Callback);
uimenu(h.menuHelp,'Label','Feedback','Callback',@Feedback_Callback);
uimenu(h.menuHelp,'Label','Subscribe','Callback',@Subscribe_Callback);
% Project name Text
if isfield(h,'ProjectName')
else
h.ProjectName='Undefined';
end
h.ProjectText = uicontrol(h.MainFigure,'Style','Text',...
'String',['Project Name: ',h.ProjectName], ...
'FontUnits','normalized',...
'Value',1,...
'Units', 'normalized', 'Position',[.75 .95 .25 .03],'TooltipString','Save project if you want to work on this later');
% Functions of the menu options
% Check what missing % is selected
function ChenageCheckedMiss(src,evnt,n2)
for n3=1:size(h.menuLoad_Miss_Opt,1)
h.menuLoad_Miss_Opt{n3,1}.Checked='Off';
end
h.menuLoad_Miss_Opt{n2,1}.Checked='On';
end
% Check what downsampling option is selected
function ChenageCheckedDownSam(src,evnt,n2)
for n3=1:size(h.menuLoad_DownSam_Opt,1)
h.menuLoad_DownSam_Opt{n3,1}.Checked='Off';
end
h.menuLoad_DownSam_Opt{n2,1}.Checked='On';
end
% Check what option is selected:
function AskForCaseName_Callback(src,evnt)
if strcmpi(h.menuPref.AskForCaseName.Checked,'On')
AskForCaseName=0;
h.AskForCaseName=0;
h.menuPref.AskForCaseName.Checked='Off';
else
AskForCaseName=1;
h.AskForCaseName=1;
h.menuPref.AskForCaseName.Checked='On';
end
if ispc
save('Data\Settings','AskForCaseName','-append');
else
save([h.FilesPath,'/Data/Settings'],'AskForCaseName','-append');
end
end
% Check what option is selected:
function ConfirmBeforeExit_Callback(src,evnt)
if strcmpi(h.menuPref.Confirm.BeforeExit.Checked,'On')
Confirm.BeforeExit=0;
h.Confirm.BeforeExit=0;
h.menuPref.Confirm.BeforeExit.Checked='Off';
else
Confirm.BeforeExit=1;
h.Confirm.BeforeExit=1;
h.menuPref.Confirm.BeforeExit.Checked='On';
end
if ispc
save('Data\Settings','Confirm','-append');
else
save([h.FilesPath,'/Data/Settings'],'Confirm','-append');
end
end
% Check what option is selected:
function ConfirmBeforeDeletingCase_Callback(src,evnt)
if strcmpi(h.menuPref.Confirm.BeforeDeleting.Case.Checked,'On')
Confirm.BeforeDeleting.Case=0;
h.Confirm.BeforeDeleting.Case=0;
h.menuPref.Confirm.BeforeDeleting.Case.Checked='Off';
else
Confirm.BeforeDeleting.Case=1;
h.Confirm.BeforeDeleting.Case=1;
h.menuPref.Confirm.BeforeDeleting.Case.Checked='On';
end
if ispc
save('Data\Settings','Confirm','-append');
else
save([h.FilesPath,'/Data/Settings'],'Confirm','-append');
end
end
% Check what option is selected:
function ConfirmBeforeDeletingProject_Callback(src,evnt)
if strcmpi(h.menuPref.Confirm.BeforeDeleting.Project.Checked,'On')
Confirm.BeforeDeleting.Project=0;
h.Confirm.BeforeDeleting.Project=0;
h.menuPref.Confirm.BeforeDeleting.Project.Checked='Off';
else
Confirm.BeforeDeleting.Project=1;
h.Confirm.BeforeDeleting.Project=1;
h.menuPref.Confirm.BeforeDeleting.Project.Checked='On';
end
if ispc
save('Data\Settings','Confirm','-append');
else
save([h.FilesPath,'/Data/Settings'],'Confirm','-append');
end
end
% Check what option is selected:
function ConfirmBeforeDeletingLoad_Callback(src,evnt)
if strcmpi(h.menuPref.Confirm.BeforeDeleting.Load.Checked,'On')
Confirm.BeforeDeleting.Load=0;
h.Confirm.BeforeDeleting.Load=0;
h.menuPref.Confirm.BeforeDeleting.Load.Checked='Off';
else
Confirm.BeforeDeleting.Load=1;
h.Confirm.BeforeDeleting.Load=1;
h.menuPref.Confirm.BeforeDeleting.Load.Checked='On';
end
if ispc
save('Data\Settings','Confirm','-append');
else
save([h.FilesPath,'/Data/Settings'],'Confirm','-append');
end
end
% Check what option is selected:
function ConfirmBeforeDeletingTariff_Callback(src,evnt)
if strcmpi(h.menuPref.Confirm.BeforeDeleting.Tariff.Checked,'On')
Confirm.BeforeDeleting.Tariff=0;
h.Confirm.BeforeDeleting.Tariff=0;
h.menuPref.Confirm.BeforeDeleting.Tariff.Checked='Off';
else
Confirm.BeforeDeleting.Tariff=1;
h.Confirm.BeforeDeleting.Tariff=1;
h.menuPref.Confirm.BeforeDeleting.Tariff.Checked='On';
end
if ispc
save('Data\Settings','Confirm','-append');
else
save([h.FilesPath,'/Data/Settings'],'Confirm','-append');
end
end
% Peak time set
function PeakTimeNew(src,evnt,j)
% if the whole database
if j==1
h.menuLoad_PT1.Checked='on';
h.menuLoad_PT2.Checked='off';
h.menuLoad_PT3.Checked='off';
h.PeakTimeMethod=1;
PeakTimeMethod=h.PeakTimeMethod;
if ispc
save('Data\Settings','PeakTimeMethod','-append');
else
save([h.FilesPath,'/Data/Settings'],'PeakTimeMethod','-append');
end
% if the filtered load
elseif j==2
h.menuLoad_PT1.Checked='off';
h.menuLoad_PT2.Checked='on';
h.menuLoad_PT3.Checked='off';
h.PeakTimeMethod=2;
PeakTimeMethod=h.PeakTimeMethod;
if ispc
save('Data\Settings','PeakTimeMethod','-append');
else
save([h.FilesPath,'/Data/Settings'],'PeakTimeMethod','-append');
end
% if the synethetic load
elseif j==3
if ~isfield(h,'SyntheticNetwork')
DelMsg;msgbox('You have not created any synthetic data yet! Please select "Creat synthetic network load data" to do so!');
else
h.menuLoad_PT1.Checked='off';
h.menuLoad_PT2.Checked='off';
h.menuLoad_PT3.Checked='on';
h.PeakTimeMethod=3;
PeakTimeMethod=h.PeakTimeMethod;
if ispc
save('Data\Settings','PeakTimeMethod','-append');
else
save([h.FilesPath,'/Data/Settings'],'PeakTimeMethod','-append');
end
end
% create a new synthetic load
elseif j==4
choice = questdlg(['Please refer to instructions, section 5.3 (CREATING NEW LOAD DATA) and put the network load data in required format before importing.You can also open the sample file and see the required format or paste in your data into this file and save as a new load file and then load the file when creating the new load data.'], ...
'Create synthetic network load data', ...
'Create now','Open sample file','Cancel','Cancel');
% Handle response
switch choice
case 'Create now'
% locate the file
[h.NewFile_FileName_NL,h.NewFile_PathName_NL,FilterIndex] = uigetfile({'*.xlsx';'*.xls'},'Upload synthetic network load file');
if FilterIndex
DelMsg;msgbox('Loading Data..Please wait!');
% read the file
newNload_rawdata=readtable([h.NewFile_PathName_NL,h.NewFile_FileName_NL]);
if size(newNload_rawdata,2)<2
DelMsg;msgbox('There was a problem in the file. Please make sure you followed the required data format described in the instruction and try again!');
else
% check the file has corret data
if numel(unique(floor(datenum(newNload_rawdata{:,1}))))>366
DelMsg;msgbox('The network load profile should be only one year data. Please make sure you followed the required data format described in the instruction and try again!');
else
% create the synthetic laod
h.SyntheticNetwork=table;
h.SyntheticNetwork.TimeStamp=newNload_rawdata{:,1};
h.SyntheticNetwork.Load=newNload_rawdata{:,2};
SyntheticNetwork=h.SyntheticNetwork;
if ispc
save('Data\Settings.mat','SyntheticNetwork','-append');
else
save([h.FilesPath,'/Data/Settings.mat'],'SyntheticNetwork','-append');
end
DelMsg
choice = questdlg(['The new synthetic load data has been successfully saved! You can plot the netowrk load and monthly peak values.'], ...
'Saved!', ...
'Plot Network Load','OK','OK');
% Handle response
switch choice
case 'Plot Network Load'
PlotNetworkLoad(src,evnt,3)
case 'OK'
DelMsg
end
end
end
end
% open the sample file
case 'Open sample file'
if ispc
copyfile('Data\SampleNLoad_BU.xlsx','SampleNetwork.xlsx');
winopen('SampleNetwork.xlsx')
else
copyfile([h.FilesPath,'/Data/SampleNLoad_BU.xlsx'],[h.FilesPath,'/SampleNetwork.xlsx']);
system(['open ',h.FilesPath,'/SampleNetwork.xlsx'])
end
end
end
end
% plot the netwoke load
function PlotNetworkLoad(src,evnt,k)
GTG=0;
% based on the whole dataset
if k==1
if h.status.LoadSet
LoadNo=find(strcmp(h.AllLoads(:,1),h.CurrentLoad_Name));
PeakLoadForPlot=table;
PeakLoadForPlot.TimeStamp=h.AllLoads{LoadNo,2}.Load.TimeStamp(2:end);
PeakLoadForPlot.Load=h.AllLoads{LoadNo,2}.Load.NetworkLoad(2:end);
NetworkLaodName=h.CurrentLoad_Name;
NetworkLaodName=strrep(NetworkLaodName,'_',' ');
GTG=1;
else
DelMsg;msgbox('No load has been set yet!')
end
% based on the filtered dataset
elseif k==2
if h.status.LoadSet
LoadNo=find(strcmp(h.AllLoads(:,1),h.CurrentLoad_Name));
PeakLoadForPlot=table;
PeakLoadForPlot.TimeStamp=h.AllLoads{LoadNo,2}.Load.TimeStamp(2:end);
PeakLoadForPlot.Load=nanmean(h.AllLoads{LoadNo,2}.Load.kWh(2:end,ismember(h.AllLoads{LoadNo,2}.Load.kWh(1,:),h.FilteredID_demo)),2);
NetworkLaodName=[h.CurrentLoad_Name,'_Filtered'];
NetworkLaodName=strrep(NetworkLaodName,'_',' ');
GTG=1;
else
DelMsg;msgbox('No load has been set yet!')
end
% synthetic network load
else
GTG=1;
PeakLoadForPlot= h.SyntheticNetwork;
NetworkLaodName='Synthetic Network Load';
NetworkLaodName=strrep(NetworkLaodName,'_',' ');
end
% plot the monthly peaks of the load
if GTG
figure;
plot(PeakLoadForPlot.TimeStamp,PeakLoadForPlot.Load)
grid on
xlabel('Time')
ylabel('Power')
title('Network load')
for i=1:12
newtemp1= PeakLoadForPlot.Load(PeakLoadForPlot.TimeStamp.Month==i);
newtemp2= PeakLoadForPlot.TimeStamp(PeakLoadForPlot.TimeStamp.Month==i);
newtemp1(isnan(newtemp1))=0;
hold on
[ind1,ind2]=max(newtemp1);
plot(newtemp2(ind2),ind1,'MarkerSize',10,'Marker','o',...
'LineStyle','none',...
'Color',[1 0 0]);
end
legend('Network load','Monthly peak')
title(['Network load pattern (',NetworkLaodName,')'])
end
end
% update the list of project
function updatePrjList(str,evnt)
child_handles = allchild(h.LoadProjMenu);
try
delete(child_handles)
end
if ispc
ListofPrj=dir('Prj_*');
else
ListofPrj=dir([h.FilesPath,'/Prj_*']);
end
h.PrjList=struct2cell(ListofPrj);
for i=1:size(h.PrjList,2)
h.PrjList{1,i}=h.PrjList{1,i}(5:end-4);
end
for i=1:size(h.PrjList,2)
h.PrjSubList{1,i}= uimenu(h.LoadProjMenu,'Label',[h.PrjList{1,i}],'Callback',{@LoadPrjLis,i});
end
end
% update the list of projects for delet
function updatePrjList_del(str,evnt)
child_handles = allchild(h.menuProject_del);
try
delete(child_handles)
end
if ispc
ListofPrj=dir('Prj_*');
else
ListofPrj=dir([h.FilesPath,'/Prj_*']);
end
h.PrjList=struct2cell(ListofPrj);
for i=1:size(h.PrjList,2)
h.PrjList{1,i}=h.PrjList{1,i}(5:end-4);
end
uimenu(h.menuProject_del,'Label','Delete All','Callback',{@DelPrjLis,-1});
for i=1:size(h.PrjList,2)
uimenu(h.menuProject_del,'Label',[h.PrjList{1,i}],'Callback',{@DelPrjLis,i});
end
end
% update the list of loads for delete
function updateLoadList_del(str,evnt)
child_handles = allchild(h.menuLoad_del);
try
delete(child_handles)
end
if ispc
ListofLoads=dir('Data\LoadData_*');
else
ListofLoads=dir([h.FilesPath,'/Data/LoadData_*']);
end
h.LoadList=struct2cell(ListofLoads);
for i=1:size(h.LoadList,2)
h.LoadList{1,i}=h.LoadList{1,i}(10:end-4);
end
h.SelectLoad_Pup.Value=1;
h.SelectLoad_Pup.String=h.LoadList(1,:);
for i=1:size(h.LoadList,2)
uimenu(h.menuLoad_del,'Label',[h.LoadList{1,i}],'Callback',{@DelLoadLis,i});
end
end
%% GUI Elements: Load Panel
% creat the panel for all options and axes
h.LoadPanel = uipanel('Parent',h.MainFigure,'Title','Select Load:',...
'Units', 'normalized', 'Position',[0.01 .01 0.3 .85],...
'FontWeight','bold',...
'FontSize',10);
% Select load
h.SelectLoad_Pup_text = uicontrol(h.LoadPanel,'Style','Text',...
'String','Select:', ...
'FontUnits','normalized',...
'Value',1,...
'Units', 'normalized', 'Position',[.01 .95 .15 .03],...
'HorizontalAlignment','left');
h.SelectLoad_Pup = uicontrol(h.LoadPanel,'Style','popupmenu',...
'String','N/A', ...
'Value',1,'BackgroundColor','white',...
'FontUnits','normalized',...
'Units', 'normalized', 'Position',[.14 .955 .4 .03]);
h.SetLoad=uicontrol(h.LoadPanel, ...
'Style','pushbutton', 'String','Set',...
'Units', 'normalized', 'Position',[.88 .949 .1 .0369],...
'FontWeight','bold',...
'FontUnits','normalized',...
'Callback', @SetLoad_CB);
h.Line1 = uipanel('Parent',h.LoadPanel,...
'Units', 'normalized', 'Position',[0.02 .935 0.96 .005],...
'BackgroundColor','black','FontSize',10);
% Select user group based on demographic info
h.LoadDemog_text1 = uicontrol(h.LoadPanel,'Style','Text',...
'String','Select user group based on demographic info:', ...
'HorizontalAlignment','left',...
'FontUnits','normalized',...
'FontUnits','normalized',...
'Value',1,...
'FontWeight','bold',...
'Units', 'normalized', 'Position',[.01 .90 0.96 .03]);
% create all the demographic options buttons but invisible until the load
% with demographic info is loaded
for k=1:10
h.Demo_Pup_text{k,1}= uicontrol(h.LoadPanel,'Style','Text',...
'String','N/A', ...
'Value',1,...
'Units', 'normalized', 'Position',[.01 .9-k*0.05 .42 .03],...
'FontWeight','bold',...
'FontUnits','normalized',...
'TooltipString','Filter users group based on this item.',...
'Visible','off',...
'HorizontalAlignment','left');
h.Demo_Pup {k,1}= uicontrol(h.LoadPanel,'Style','popupmenu',...
'String','N/A', ...
'Value',1,'BackgroundColor','white',...
'Visible','off',...
'FontUnits','normalized',...
'Units', 'normalized', 'Position',[.47 .905-k*0.05 .4 .03],...
'Callback', @FilterDemo);
end
h.Demo1_Pup_text_noDemo= uicontrol(h.LoadPanel,'Style','Text',...
'String','Warning: No demographic info exist!', ...
'TooltipString','Please refer to instruction for importing demographic data along with your load data',...
'Value',1,...
'FontUnits','normalized',...
'Units', 'normalized', 'Position',[.01 .8 .95 .04],...
'Visible','off',...
'HorizontalAlignment','left');
% 'FontWeight','bold',...
h.Line2 = uipanel('Parent',h.LoadPanel,...
'Units', 'normalized', 'Position',[0.02 .385 0.96 .005],...
'BackgroundColor','black','FontSize',10);
% Create the load axes
h.LoadAxes = axes('Parent', h.LoadPanel, ...
'HandleVisibility','callback', ...
'Units', 'normalized', 'Position',[.15 0.08 0.75 0.25],...
'FontUnits','normalized',...
'FontSize',8,'Box','on');
% Number of selected users
h.LoadFig_TotNum = uicontrol(h.LoadPanel,'Style','Text',...
'String','No. of users: N/A', ...
'FontUnits','normalized',...
'Value',1,...
'HorizontalAlignment','left',...
'Units', 'normalized', 'Position',[.02 .34 .35 .035]);
% selecting different options to show on the load axes
h.LoadFig_Pup_text = uicontrol(h.LoadPanel,'Style','Text',...
'String','Show:', ...
'Value',1,...
'FontUnits','normalized',...
'HorizontalAlignment','left',...
'Units', 'normalized', 'Position',[.4 .34 .15 .03]);
h.LoadFig_Pup = uicontrol(h.LoadPanel,'Style','popupmenu',...
'String',h.ListofLoadSelectFigures, ...
'BackgroundColor','white',...
'FontUnits','normalized',...
'Units', 'normalized', 'Position',[.55 .345 .4 .03],...
'Callback', @update_LoadSelec_Fig);
%% GUI Elements: Diagram Panel
% creat the panel for all options and axes
h.DiagramPanel = uipanel('Parent',h.MainFigure,...
'Units', 'normalized', 'Position',[0.315 .3+0.035 0.68 .65-0.035],...
'FontSize',10);
% creta the tabs
h.tabg_Diag = uitabgroup('Parent',h.DiagramPanel,'Tag','Loadtabs', ...
'Units','normalized','Position',[0 0 0.7 1]);
% Tab 1: single variable figures:
h.tab1 = uitab('parent',h.tabg_Diag, 'title', 'Single Variable Graphs');
h.SingVarDiag = uipanel('Parent',h.tab1, ...
'Position',[.0 .0 1 1]);
% Axes
h.SingVarAxis = axes('Parent', h.SingVarDiag, ...
'HandleVisibility','callback', ...
'Units', 'normalized', 'Position',[.15 0.25 0.81 0.65],...
'FontSize',8,'Box','on');
h.SingVar_FigType_Text= uicontrol(h.SingVarDiag,'Style','Text',...
'String','Select Figure:', ...
'HorizontalAlignment','left',...
'FontUnits','normalized',...
'FontWeight','bold',...
'Units', 'normalized', 'Position',[.01 .03 .15 .045]);
h.SingVar_FigType_PUP= uicontrol(h.SingVarDiag,'Style','popupmenu',...
'String',h.ListofSingVarFigs, ...
'FontUnits','normalized',...
'Value',1,'BackgroundColor','white',...
'Units', 'normalized', 'Position',[.16 .035 .25 .04],...
'Callback', {@update_SingVar,1});
% Tab 1: Dual variable figures:
h.tab2 = uitab('parent',h.tabg_Diag, 'title', 'Dual Variable Graphs');
h.DualVarDiag = uipanel('Parent',h.tab2, ...
'Position',[.0 .0 1 1]);
h.DualVarAxis = axes('Parent', h.DualVarDiag, ...
'HandleVisibility','callback', ...
'Units', 'normalized', 'Position',[.15 0.25 0.81 0.65],...
'FontSize',8,'Box','on');
% Variable to show in X axes
h.DualVar_FigType_Text_x= uicontrol(h.DualVarDiag,'Style','Text',...
'String','X axis:', ...
'HorizontalAlignment','left',...
'FontUnits','normalized',...
'FontWeight','bold',...
'Units', 'normalized', 'Position',[.03 .09 .08 .045]);
h.DualVar_FigX= uicontrol(h.DualVarDiag,'Style','popupmenu',...
'String',h.ListofDualVarFigs, ...
'Value',1,'BackgroundColor','white',...
'FontUnits','normalized',...
'Units', 'normalized', 'Position',[.12 .095 .25 .045],...
'Callback', {@update_DualVar,1});
% Variable to show in Y axes
h.DualVar_FigType_Text_y= uicontrol(h.DualVarDiag,'Style','Text',...
'String','Y axis:', ...
'HorizontalAlignment','left',...
'FontUnits','normalized',...
'FontWeight','bold',...
'Units', 'normalized', 'Position',[.03 .02 .08 .045]);
h.DualVar_FigY= uicontrol(h.DualVarDiag,'Style','popupmenu',...
'String',h.ListofDualVarFigs, ...
'Value',8,'BackgroundColor','white',...
'FontUnits','normalized',...
'Units', 'normalized', 'Position',[.12 .025 .25 .04],...
'Callback', {@update_DualVar,1});
% if number of peaks needed create the "N" for both X axes:
h.DualVar_XTopPeak_Text= uicontrol(h.DualVarDiag,'Style','Text',...
'String','N=', ...
'HorizontalAlignment','right',...
'FontUnits','normalized',...
'Visible','off',...
'FontWeight','bold',...
'Units', 'normalized', 'Position',[.39 .09 .04 .045]);
h.DualVar_XTopPeak_PB= uicontrol(h.DualVarDiag,'Style','popupmenu',...
'String',h.ListofTopPeaks, ...
'Value',1,'BackgroundColor','white',...
'FontUnits','normalized',...
'Visible','off',...
'Units', 'normalized', 'Position',[.44 .095 .07 .045],...
'Callback', {@update_DualVar,1});
% If one day limit was needed
h.DualVar_XOnePeakPerDay= uicontrol(h.DualVarDiag,'Style','Check',...
'String','One Peak/Day', ...
'HorizontalAlignment','right',...
'FontUnits','normalized',...
'Visible','off',...
'Units', 'normalized', 'Position',[.53 .09 .3 .045],'Callback',{@update_DualVar,1});
% if number of peaks needed create the "N" for both Y axes:
h.DualVar_YTopPeak_Text= uicontrol(h.DualVarDiag,'Style','Text',...
'String','N=', ...
'HorizontalAlignment','right',...
'FontUnits','normalized',...
'Visible','off',...
'FontWeight','bold',...
'Units', 'normalized', 'Position',[.39 .02 .04 .045]);
h.DualVar_YTopPeak_PB= uicontrol(h.DualVarDiag,'Style','popupmenu',...
'String',h.ListofTopPeaks, ...
'Value',1,'BackgroundColor','white',...
'FontUnits','normalized',...
'Visible','off',...
'Units', 'normalized', 'Position',[.44 .025 .07 .045],...
'Callback', {@update_DualVar,1});
% If one day limit was needed
h.DualVar_YOnePeakPerDay= uicontrol(h.DualVarDiag,'Style','Check',...
'String','One Peak/Day', ...
'HorizontalAlignment','right',...
'FontUnits','normalized',...
'Visible','off',...
'Units', 'normalized', 'Position',[.53 .02 .3 .045],'Callback',{@update_DualVar,1});
% Seasons panel:
h.SeasonsPanel = uipanel('Parent',h.DualVarDiag, ...
'Position',[.75 .01 0.245 0.15],'Title','Seasons','Visible','on');
% Summer
h.DualVar_Seasons{1,1}= uicontrol(h.SeasonsPanel,'Style','Check',...
'String','Summer', ...
'HorizontalAlignment','left',...
'FontUnits','normalized',...
'Visible','on',...
'Value',1,...
'Units', 'normalized', 'Position',[0.05 0.1 .48 .35],'Callback',{@update_DualVar,1});
% Autumn
h.DualVar_Seasons{2,1}= uicontrol(h.SeasonsPanel,'Style','Check',...
'String','Autumn', ...
'HorizontalAlignment','left',...
'FontUnits','normalized',...
'Visible','on',...
'Value',1,...
'Units', 'normalized', 'Position',[0.55 0.52 .48 .35],'Callback',{@update_DualVar,1});
% Winter
h.DualVar_Seasons{3,1}= uicontrol(h.SeasonsPanel,'Style','Check',...
'String','Winter', ...
'HorizontalAlignment','left',...
'FontUnits','normalized',...
'Visible','on',...
'Value',1,...
'Units', 'normalized', 'Position',[0.55 0.1 .48 .35],'Callback',{@update_DualVar,1});
% Spring
h.DualVar_Seasons{4,1}= uicontrol(h.SeasonsPanel,'Style','Check',...
'String','Spring', ...
'HorizontalAlignment','left',...
'FontUnits','normalized',...
'Visible','on',...
'Value',1,...
'Units', 'normalized', 'Position',[0.05 0.52 .48 .35],'Callback',{@update_DualVar,1});
% Tab 3: single case figures:
h.tab3 = uitab('parent',h.tabg_Diag, 'title', 'Single Case Graphs');
h.SingCaseDiag = uipanel('Parent',h.tab3, ...
'Position',[.0 .0 1 1]);
h.SingCaseAxis = axes('Parent', h.SingCaseDiag, ...
'HandleVisibility','callback', ...
'Units', 'normalized', 'Position',[.15 0.25 0.81 0.65],...
'FontSize',8,'Box','on');
h.SingCase_SelectCase_Text= uicontrol(h.SingCaseDiag,'Style','Text',...
'String','Select Case: ', ...
'HorizontalAlignment','left',...
'FontUnits','normalized',...
'FontWeight','bold',...
'Units', 'normalized', 'Position',[.03 .1 .15 .045]);
h.SingCase_List= uicontrol(h.SingCaseDiag,'Style','popupmenu',...