-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTempstat_by_country_v1.m
122 lines (98 loc) · 3.06 KB
/
Tempstat_by_country_v1.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
% This m-file calculates CDD and HDD by country using 60-91 temperature
% data. Only gridcells over urban areas are used.
clear all
%% Constants
WD=pwd;
datafolder='Data';
monthname=['jan';'feb';'mar';'apr';'may';'jun';'jul';'aug';'sep';'oct';'nov';'dec'];
monthlength=[31 28 31 30 31 30 31 31 30 31 30 31];
do=0;
tempbal=12;
%% Load Spatial data
load([WD,'\',datafolder,'\countries.mat']);
load([WD,'\',datafolder,'\citygrid.mat']);
citygrid(citygrid==-9999)=NaN;
citygrid(citygrid>0)=1;
courban=citygrid.*countries;
clear countries citygrid
%% Loop for calculating mean tempreature for country using Willmot data
% for i=1980:2008
% for j=1:12
% startdate=datenum([i j 1]);
% avtemp=ImportWillmot_v2(startdate,do);
%
% disp([num2str(i),' ', num2str(monthname(j,:))])
% for k=1:231 %looping through every country
%
% temp=avtemp(courban==k);
% tempstats(k,j,i-1979)=nanmean(temp);
%
% end
%
% end
% end
% clear temp
% load tempstat
% Loop for calculating CDD and HDD
% CDD=zeros(231,29);HDD=CDD;
% for i=1:29 %Years
% for j=1:231 %looping through every country
% for k=1:12 %Months
% temp=abs(tempbal-tempstats(j,k,i));
% if tempstats(j,k,i)>12
% CDD(j,i)=temp*monthlength(k)+CDD(j,i);
% else
% HDD(j,i)=temp*monthlength(k)+HDD(j,i);
% end
% end
%
% end
% end
%% Loop for calculating mean tempreature for country using 61-90 data
for j=1:12
load ([WD,'\Data\temperature\avtemp_',monthname(j,:),'.mat']);
disp(num2str(monthname(j,:)))
for k=1:231 %looping through every country
temp=avtemp(courban==k);
tempstats(k,j)=nanmean(temp);
end
end
clear temp
CDD=zeros(231,12);HDD=CDD;
for j=1:231 %looping through every country
for k=1:12 %Months
temp=abs(tempbal-tempstats(j,k));
if tempstats(j,k)>12
CDD(j,k)=temp*monthlength(k)+CDD(j,k);
else
HDD(j,k)=temp*monthlength(k)+HDD(j,k);
end
end
end
%% plotting
textCountry=importdata([WD,'\Data\CountryID.txt'],';');
index=1;plotnr=1;
for i=1:10
for j=1:5
for k=1:5
subplot(5,5,plotnr),plot(CDD(index,:)),hold on
plot(HDD(index,:),'r')
set(gca,'ylim',[0 1000],'xlim',[1 12],'FontSize',6),axis square
title([textCountry.textdata(index,2),' HDD/CDD= ' num2str(sum(HDD(index,:))/sum(CDD(index,:)))]...
,'fontsize',6)
index=index+1;plotnr=plotnr+1;
if plotnr==26,plotnr=1;pause;hold off;close; end
end
end
end
% plot(CDD(i,:)),hold on
% plot(HDD(i,:),'r')
% set(gca,'ylim',[0 1000],'xlim',[1 12])
% legend('CDD','HDD')
% close
% end
%% Calculating totalpopulation
for k=1:231 %looping through every country
temp=totalpopu(countries==k);
popstats(k,1)=nanmean(temp);
end