Browse Source

Upload files to 'Figure3'

master
Luke Harrington 11 months ago
parent
commit
cb19a47fa3
  1. 248
      Figure3/NComms_Figure3Code.m

248
Figure3/NComms_Figure3Code.m

@ -0,0 +1,248 @@
%----- July 22nd 2021. Code made by Dr Luke Harrington --------------------
%----- This code produces Figure 3 from the NComms analysis. --------------
%--------------------------------------------------------------------------
clear all
% Load files containing all pre-processed hazard, population and GI data
load('DataforNCommsP1.mat');
load('DataforNCommsP2.mat');
%----------------------------
changeyear=1; % 1 is default to look at future SSPs. Can input 0 to look at 2015 data, though code may fall over.
SSPyear=2050; % Year chosen for future data to look at. Needs to be 2050 or 2090
%============================================================
%Here, we need to set up 12 iterations of the key data inputs
%========= DEFAULT = SSP2, 2050, 50th Percentile, ===========
%==== 1/A) 10th pctle; 2/B) 50th pctle; 3/C) 90th pctle; ====
%==== 4/D) 1.5K temp; 5/E) 2.0K temp; 6/F) 3.0K temp; =====
%==== 7/G) SSP1; 8/H) SSP2; 9/I) SSP3; =====
%=== 10/J) Optim Vuln; 11/K) Mod Vuln; 12/L) Pess. Vuln =====
%-------------IMPORTANT VARIABLE SELECTIONS -------------
SNspXX=[1 2 3 2 2 2 2 2 2 2 2 2];
SSPXX=[2 2 2 2 2 2 1 2 3 2 2 2];
VULNXX=[2 2 2 2 2 2 2 2 2 1 2 3];
GMTchoiceXX=[2.0 2.0 2.0 1.5 2.0 3.0 2.0 2.0 2.0 2.0 2.0 2.0];
VL{1}=[0 1.0 3.0 5.0 10]; VH{1}=[0 1.0 5.0 7.0 10]; % OPTIMISTIC VULNERABILITY
VL{2}=[0 1.0 2.0 3.0 10]; VH{2}=[0 1.0 3.0 5.0 10]; % MEDIAN VULNERABILITY
VL{3}=[0 1.0 2.0 3.0 10]; VH{3}=[0 1.0 2.0 3.0 10]; % PESSIMISTIC VULNERABITY
labels={'(a) 10^{th} percentile';'(b) 50^{th} percentile';'(c) 90^{th}'; ...
'(d) 1.5^{o}C of warming';'(e) 2.0^{o}C of warming';'(f) 3.0^{o}C'; ...
'(d) SSP1';'(e) SSP2';'(f) SSP3';'(g) Optimistic'; ...
'(h) Moderate';'(i) Pessimistic'};
subheadings{2}='Climate Model Uncertainty';
subheadings{5}='Emissions Scenario Uncertainty';
subheadings{8}='Socio-economic Uncertainty';
subheadings{11}='Vulnerability Uncertainty';
% PanelPos={[0.06 0.775 0.25 0.165];[0.34 0.775 0.25 0.165];[0.62 0.775 0.25 0.165]; ...
% [0.06 0.54 0.25 0.165];[0.34 0.54 0.25 0.165];[0.62 0.54 0.25 0.165]; ...
% [0.06 0.305 0.25 0.165];[0.34 0.305 0.25 0.165];[0.62 0.305 0.25 0.165]; ...
% [0.06 0.07 0.25 0.165];[0.34 0.07 0.25 0.165];[0.62 0.07 0.25 0.165]};
PanelPos={[0.06 0.68 0.25 0.2];[0.34 0.68 0.25 0.2];[0.62 0.68 0.25 0.2]; ... ...
[0.06 0.54 0.25 0.165];[0.34 0.54 0.25 0.165];[0.62 0.54 0.25 0.165]; ...
[0.06 0.4 0.25 0.2];[0.34 0.4 0.25 0.2];[0.62 0.4 0.25 0.2]; ...
[0.06 0.12 0.25 0.2];[0.34 0.12 0.25 0.2];[0.62 0.12 0.25 0.2]};
%===========================================
%============ NOW, LET's BEGIN =============
for PPP=1:12
SSP=[]; GMTchoice=[]; SNsp=[]; RL=[]; RH=[]; caption=[];
SSP=SSPXX(PPP); % SSP of choice. Can actually be any of SSP 1 to 5.
GMTchoice=GMTchoiceXX(PPP); % nDeg selected.
SNsp=SNspXX(PPP); % If 1/2/3 then look at 10th/50th/90th percentile of S/N data
RL=VL{VULNXX(PPP)};
RH=VH{VULNXX(PPP)};
caption=labels{PPP};
%----------------------------------------------
tntxt={'1.5K ','2.0K ','2.5K ','3.0K '}; ttt={'15';'20';'25';'30'};
%------------
riskcol={[0.5 0.5 0.5];'y';'r';[122/255 1/255 119/255]};
ColorbarChoice='PuBu'; % 'YlOrRd', 'YlOrBr', 'Blues'
%----------------------------------------------
% 1) Need to go through each of the 224 countries
% 2) Check there is Gov Index data (only 169) AND future pop data (only 190)
% 3) If there is (which is true for >97% of global pop), then place relevant data into long 3-variable array of TXx S/N ratios, population & GI
% 4) Then rearrange this into a very large 2-vector array, with one row for
% EACH PERSON IN THE WORLD (or country) considered. Column 1 will be S/N. Column 2 will be the Governance Index
%---------------------------------------------------------------
%========== Okay, now begin ====================================
%----- Step 1: get the S/N and people data ---------------------
SN=[]; ppl=[];
if GMTchoice==1.0
SN=Data10.SNraw{SNsp}; ppl=Data10.ppraw;
elseif GMTchoice==1.5
SN=Data15.SNraw{SNsp}; ppl=Data15.ppraw;
elseif GMTchoice==2.0
SN=Data20.SNraw{SNsp}; ppl=Data20.ppraw;
elseif GMTchoice==2.5
SN=Data25.SNraw{SNsp}; ppl=Data25.ppraw;
elseif GMTchoice==3.0
SN=Data30.SNraw{SNsp}; ppl=Data30.ppraw;
end
%--------------------------------------------------------------------------
%-- Step 2: Multiply pop by SSP ratio. Add in GI. Make 3-vector array -----
%--------------------------------------------------------------------------
MA1=[]; ii=1;
for kk=1:length(GI) % Cycle through each of the 224 countries
kk
if isempty(GI{kk})==0 % Is there Gov Index data for this country?
if isempty(popSSP{kk})==0 % Is there SSP population data for this country?
if changeyear==0
GGG=[];GGG=GI{kk}(1,6); % If not SSP scenario, keep Governance Index as 2015 obs
elseif changeyear==1
yi=SSPyear-2014;
GGG=[];GGG=GI{kk}(yi,SSP); % Modifying Governance Index data if SSP scenario
end
%------ Extra step here to amend population data to SSP --
if changeyear==0
ratio=[]; ratio=1;
elseif changeyear==1
yi=SSPyear-2014;
ratio=[]; ratio=popSSP{kk}(yi,SSP)/popSSP{kk}(1,SSP);
end
%----- Now add in S/N, pop and GI data into array ----
dd=length(ppl{kk});
pdata=[]; pdata=ppl{kk}.'; pdata=pdata.*ratio; pdata=round(pdata); %---- Adjusting population arrays for future pop change ----
sndata=[]; sndata=SN{kk}.';
%------
MA1(ii:ii+dd-1,1)=sndata;
MA1(ii:ii+dd-1,2)=pdata;
MA1(ii:ii+dd-1,3)=GGG;
ii=ii+dd;
end
end
end
%--------------------------------------------------------------------------
%====== STEP 3: Here we want to define, for every GI threshold, whether ====
% a certain S/N ratio corresponds to "negligible", "moderate", "high" or
% "very high risk". So by the end of this step, we will have four population
% counts for each of the four risk categories. Okay, here we go.
%--------------------------------------------------------------------------
riskcount{1}=0;riskcount{2}=0;riskcount{3}=0;riskcount{4}=0;
for m=1:length(MA1);
row=[]; row=MA1(m,:);
g=[]; g=row(3); % Extracting the GI value for this grid cell
s=[]; s=row(1); % Extracting the S/N value for this grid cell
% Now defining S/N risk thresholds for this specific governance index
rr=[];
for d=2:4
rr(d-1)=RL(d)+(RH(d)-RL(d))*g; % Adding y-intercept plus (gradient*GI)
end
%---- Okay now figuring out in which risk band the S/N sits ----
if s>rr(3)
riskcount{4}=riskcount{4}+row(2); % PPL belong in 'catastrophic' category
elseif s>rr(2) & s<=rr(3)
riskcount{3}=riskcount{3}+row(2); % PPL belong in 'very high' category
elseif s>rr(1) & s<=rr(2)
riskcount{2}=riskcount{2}+row(2); % PPL belong in 'moderate' category
elseif s<=rr(1)
riskcount{1}=riskcount{1}+row(2); % PPL belong in 'negligible' category
end
end
%--------------------------------------------------------------------------
% So to update, we still currently have a variable, 'MA1', which lists every grid
% box with people in it, what is the S/N of that grid box, what is the
% population in that grid box (for specific pop scenario) and what is the
% Governance Index for that country's people (also for specific SSP). Now
% we need to aggregate these grid cells according to common S/N & GI
% properties. We have to do this manually because of memory issues with the
% automated MATLAB approach
%==========================================================================
%= STEP 4: Here we have to manually put pop counts into a SN-GI 20x20grid =
%==========================================================================
% These are the grids we choose to define. Note they have to be equal length.
SNLIMS=[0 10.0]; GILIMS=[0 1.0];
SNbins=[SNLIMS(1):0.5:SNLIMS(2)].'; GIbins=[GILIMS(1):0.05:GILIMS(2)].';
maingrid=zeros(length(GIbins)-1,length(SNbins)-1); % initialise main array
%---- Okay, go through each row of MA1, and assign that pop to a specific
%---- SN/GI grid bin thing ------
for m=1:length(MA1);
row=[]; row=MA1(m,:);
% subtract actual S/N from SNbin options. Then find smallest POSITIVE
% difference, and subtracting one from this number gives the bin index to use
BIX2=[]; BIX2=min(find((SNbins-row(1))>0))-1;
if BIX2==0
BIX2=1;
end
% Then do the exact same thing for the Governance index
BIX1=[]; BIX1=min(find((GIbins-row(3))>0))-1;
if BIX1==0
BIX1=1;
end
% Then put the number of people from that cell into the grid count
maingrid(BIX1,BIX2)=maingrid(BIX1,BIX2)+row(2);
end
%---- For this subsection, we've largely just adapted the MATLAB web instructions ----
n=[]; n1=[]; xb=[]; yb=[];
n=maingrid;
n1 = n'; % n1 is the array of occurrences in the box
n1(size(n,1)+1, size(n,2)+1) = 0;
xb = linspace(GILIMS(1),GILIMS(2),size(n,1)+1);
yb = linspace(SNLIMS(1),SNLIMS(2),size(n,1)+1);
%-------------------
PDFnorm=n1;
n1logged=log10(PDFnorm); n1logged(isfinite(n1logged)==0)=NaN;
%==========================================================================
%===== STEP 5: Okay, now finally we can make the figures of interest ======
%==========================================================================
if PPP<=3 || PPP >=7 % NB: we decided late in the write-up process to remove the row showing results for different warming thresholds. But commenting out this line should bring them back in.
if PPP==1
figure(1); set(gcf,'units','centimeters','Position',[5 1 18 17]);
set(gcf,'units','default'); clf;
end
subplot('Position',PanelPos{PPP},'color','none');
%subplot(4,3,PPP,'color','none');
hold all; box on; set(gca,'FontSize',11);
cmap=brewermap(8,ColorbarChoice);
cmap([1 2],:)=[];
%------ First, add in the background risk thresholds ------
XX=[0 0 1 1 0];
for w=1:4
p{w}=patch(XX,[RL(w) RL(w+1) RH(w+1) RH(w) RL(w)],[1]);
set(p{w},'EdgeColor','none','FaceColor',riskcol{w},'FaceAlpha',0.3);
end
%------- Then add in the shaded population contours -------
h2 = pcolor(xb,yb,n1logged);
colormap(cmap); set(h2,'EdgeColor','none','FaceAlpha',1);
set(gca,'YLim',[0 9],'YTick',[0:3:9]);
if PPP==12
h=colorbar('Location','manual','Position',[0.89 0.25 0.025 0.5],'fontsize',11);
caxis([3 9]); % this 'caxis' term adjusts the actual colours.
set(h,'YTick',4:8,'FontSize',11,'YTickLabel',{'0.01','0.1','1','10','100'});
ylabel(h,'Exposed population (millions)','fontsize',11);
end
if PPP>=10
xlabel('Governance Index','fontsize',12);
end
if PPP==1 || PPP==4 || PPP==7 || PPP==10
ylabel('S/N ratio of TXx','fontsize',12);
end
%-----------------------------------------------------
riskstring=[];
for kk=1:4
if log10(riskcount{kk})>9
bit=[]; riskstring{kk}=[num2str(riskcount{kk}/(10^9),'%2.2f')];
elseif log10(riskcount{kk})>8
bit=[]; riskstring{kk}=[num2str(riskcount{kk}/(10^9),'%2.2f')];
elseif log10(riskcount{kk})>7
bit=[]; riskstring{kk}=[num2str(riskcount{kk}/(10^9),'%2.2f')];
% elseif log10(riskcount{kk})>6
% bit=[]; riskstring{kk}=[num2str(riskcount{kk}/(10^9),'%2.3f')];
elseif log10(riskcount{kk})<7
riskstring{kk}='<0.01';
end
end
%---------------------
if PPP==2 || PPP==5 || PPP==8 || PPP==11
if PPP<11
set(gca,'XTick',[0 10],'XTickLabel',{'';''});
end
text(0.5,1.23,subheadings{PPP},'units','normalized','HorizontalAlignment','center', ...
'fontweight','bold','fontsize',11);
end
text(0.12,1.1,riskstring{1},'units','normalized','FontSize',11,'Color',riskcol{1},'HorizontalAlignment','center');
text(0.36,1.1,riskstring{2},'units','normalized','FontSize',11,'Color',riskcol{2},'HorizontalAlignment','center');
text(0.61,1.1,riskstring{3},'units','normalized','FontSize',11,'Color',riskcol{3},'HorizontalAlignment','center');
text(0.85,1.1,riskstring{4},'units','normalized','FontSize',11,'Color',riskcol{4},'HorizontalAlignment','center');
text(0.02,0.93,caption,'units','normalized','HorizontalAlignment','left','fontsize',11);
end
end
Loading…
Cancel
Save