Browse Source

Upload files to 'Figure1'

master
Luke Harrington 11 months ago
parent
commit
4e13c1a015
  1. 206
      Figure1/NComms_Figure1Code.m

206
Figure1/NComms_Figure1Code.m

@ -0,0 +1,206 @@
%----- July 22nd 2021. Code made by Dr Luke Harrington --------------------
%--------------------------------------------------------------------------
% This code produces adjustable versions of Figure 1 from the NComms analysis.
%-------------------------------------------------------------------------
clear all
% Load files containing all pre-processed hazard, population and GI data
load('DataforNCommsP1.mat');
load('DataforNCommsP2.mat');
%=================================================================
%------------- ADJUSTABLE VARIABLE CHOICES AVAILABLE -------------
changeyear=1; % If 1, then we are looking at future SSP scenarios (default). If 0, keep at 2015 populations.
SSP=2; % SSP of choice. We can actually select any of SSP 1 to 5.
GMTchoice=2.0; % nDeg selected. Must be 1.0, 1.5, 2.0, 2.5, 3.0 or 3.5.
SSPyear=2050; % year chosen for future data to look at. Choose either 2050 or 2090.
SNsp=2; % Choosing 1, 2 or 3 respectively selects the CMIP5 10th/50th/90th percentile of TXx S/N data
%-----------------------------------------------------------------
%=================================================================
RL2015=[0 1.0 2.0 3.0 10]; RH2015=[0 1.0 3.0 5.0 10];
RL2050=[0 1.0 2.0 3.0 10]; RH2050=[0 1.0 3.0 5.0 10]; % Pre-define our 2050 risk thresholds
RL2090=[0 1.0 2.0 3.5 10]; RH2090=[0 1.0 4.0 6.0 10]; % Pre-define our 2090 risk thresholds
riskcol={[0.5 0.5 0.5];'y';'r';[122/255 1/255 119/255]};
ColorbarChoice='PuBu'; % 'YlOrRd', 'YlOrBr', 'Blues'
if changeyear==1
if SSPyear<=2050
RL=[];RH=[]; RL=RL2050; RH=RH2050;
elseif SSPyear>=2055
RL=[];RH=[]; RL=RL2090; RH=RH2090;
end
elseif changeyear==0
RL=[];RH=[]; RL=RL2015; RH=RH2015;
end
%----------------------------------------------
% 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: Extract the pre-processed S/N and population 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;
elseif GMTchoice==3.5
SN=Data35.SNraw{SNsp}; ppl=Data35.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 Governance Index data for this country? If yes, proceed.
if isempty(popSSP{kk})==0 % Is there SSP population data for this country? If yes, proceed.
if changeyear==0 % Do we want to look at future scenarios, or stay with 2015 values?
GGG=[];GGG=GI{kk}(1,6); % If not interested in future SSP scenarios, then keep Governance Index as 2015 values too.
elseif changeyear==1
yi=SSPyear-2014;
GGG=[];GGG=GI{kk}(yi,SSP); % Modifying Governance Index data if SSP scenarios are what we want.
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 'very high' category
elseif s>rr(2) & s<=rr(3)
riskcount{3}=riskcount{3}+row(2); % PPL belong in '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 (TXx) 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 aggregate population counts into a SN-GI 20x20grid =
%==========================================================================
% These are the grids we 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 two-dimensional bin ------
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 correct 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 add the number of people from that cell into the appropriate bin
maingrid(BIX1,BIX2)=maingrid(BIX1,BIX2)+row(2);
end
%--------------------------------------------------------------------------
%-- Okay, now we're initialising the variables needed ---------------------
%-- to actually be able to plot the 'heat map' version of these SN/GI bins --
%--------------------------------------------------------------------------
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 figure of interest ======
%==========================================================================
figure(1); set(gcf,'units','centimeters','Position',[5 5 15 12]);
set(gcf,'units','default'); clf;
subplot('Position',[0.14,0.11,0.76,0.76],'color','none');
hold all; box on; set(gca,'FontSize',12);
cmap=brewermap(8,ColorbarChoice);
cmap([1 2],:)=[];
tntxt={'1.0^{\circ}C ','1.5^{\circ}C ','2.0^{\circ}C ','2.5^{\circ}C ','3.0^{\circ}C ','3.5^{\circ}C '};
%------ 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);
h=colorbar(); 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',12);
xlabel('Governance Index','fontsize',14);
ylabel({'Signal-to-noise ratio of warming';'on hottest day of the year (TXx)'},'fontsize',13);
set(gca,'YLim',[0 9]);
%-----------------------------------------------------
for kk=1:4
if log10(riskcount{kk})>9
bit=[]; riskstring{kk}=[num2str(riskcount{kk}/(10^9),3),' billion'];
elseif log10(riskcount{kk})>8
bit=[]; riskstring{kk}=[num2str(riskcount{kk}/(10^6),3),' million'];
elseif log10(riskcount{kk})>7
bit=[]; riskstring{kk}=[num2str(riskcount{kk}/(10^6),2),' million'];
elseif log10(riskcount{kk})>6
bit=[]; riskstring{kk}=[num2str(riskcount{kk}/(10^6),3),' million'];
elseif log10(riskcount{kk})<6
riskstring{kk}='<1 million';
end
end
header2(0.13,0.98,riskstring{1},'FontSize',14,'Color',riskcol{1});
header2(0.37,0.98,riskstring{2},'FontSize',14,'Color',riskcol{2});
header2(0.62,0.98,riskstring{3},'FontSize',14,'Color',riskcol{3});
header2(0.86,0.98,riskstring{4},'FontSize',14,'Color',riskcol{4});
text(0.04,0.94,[num2str(SSPyear),' population under SSP',num2str(SSP)],'units','normalized','HorizontalAlignment','left','fontsize',14);
text(0.04,0.88,[tntxt{((GMTchoice-1)*2+1)},'of warming'],'units','normalized','HorizontalAlignment','left','fontsize',14);
%------- And now we're done --------
Loading…
Cancel
Save