sera-applications/SHAPE_Package/SHAPE_ver2b.0/Zplo_ver2b_1.m
2020-06-08 13:02:54 +02:00

149 lines
7.0 KiB
Matlab
Executable File

close all;d=figure('Position',[25 00 1500 800]);
% check whether the selected time windows are overlapping or not
TT=[];Tcat=Catalog(1).val;Ncat=Tcat(Tcat>=time_windows(1).Tstart & Tcat<=time_windows(length(ExPr)).Tend);
for i=1:length(MRPer);
TW1(i)=time_windows(i).Tstart;Tw2(i)=time_windows(i).Tend;
tplo(i)=mean([time_windows(i).Tstart time_windows(i).Tend]);meanM(i)=mean(time_windows(i).M);hold on
TT=[TT;time_windows(i).Time];
lambda(i)=HP(i).lamb;
if strcmp(HP(1).method,'GRU') || strcmp(HP(1).method,'GRT');yyaxis right;bval(i)=HP(i).b;end
end
if (strcmp(Plotopt,'ON'))
%if numel(TT)==numel(Ncat)
DTW=TW1(2:length(TW1))-Tw2(1:length(Tw2)-1); %%% THIS SEEMS TO WORK!!!!
if isempty(find(DTW<0))
overlap='NO';
for i=1:length(MRPer);
subplot(3,1,1) % plot Mean return period
hold on;fill([time_windows(i).Tstart time_windows(i).Tend time_windows(i).Tend time_windows(i).Tstart],...
[MRPer_high(i) MRPer_high(i) MRPer_low(i) MRPer_low(i)],[0.91 0.91 0.91],'facealpha',0.25)
plot([time_windows(i).Tstart time_windows(i).Tend],[MRPer(i) MRPer(i)],'k-','LineWidth',2)
if i<length(MRPer);plot([time_windows(i).Tend time_windows(i+1).Tstart],[MRPer(i) MRPer(i+1)],'k--');end
datetick('x',20);title(['Mean Return Period for M\geq',num2str(MaG)],'FontSize',16);ylabel([Tunit,'s'],'FontSize',18)
subplot(3,1,2) % plot Exceedance Probability
hold on;fill([time_windows(i).Tstart time_windows(i).Tend time_windows(i).Tend time_windows(i).Tstart],...
[ExPr_high(i) ExPr_high(i) ExPr_low(i) ExPr_low(i)],[0.91 0.91 0.91],'facealpha',0.25)
plot([time_windows(i).Tstart time_windows(i).Tend],[ExPr(i) ExPr(i)],'k-','LineWidth',2)
if i<length(ExPr);plot([time_windows(i).Tend time_windows(i+1).Tstart],[ExPr(i) ExPr(i+1)],'k--');end
datetick('x',20);title(['Exceedance Probability for M\geq',num2str(MaG),' within ',num2str(Plength), ' ',Tunit,'(s) period'],'FontSize',16);ylabel('probability','FontSize',14)
subplot(3,1,3) % plot Activity rate
hold on;yyaxis left;plot([time_windows(i).Tstart time_windows(i).Tend],[HP(i).lamb HP(i).lamb],'k-','LineWidth',2)
if i<length(ExPr);plot([time_windows(i).Tend time_windows(i+1).Tstart],[HP(i).lamb HP(i+1).lamb],'k--');end
datetick('x',20);title(['Activity Rate'],'FontSize',16);ylabel(['Events/',Tunit],'FontSize',14,'Color','k')
set(gca,'YColor','k');
% plot b-value (GR) or mean M (NP)
if strcmp(HP(1).method,'GRU') || strcmp(HP(1).method,'GRT');yyaxis right;
fill([time_windows(i).Tstart time_windows(i).Tend time_windows(i).Tend time_windows(i).Tstart],...
[HP(i).bCI(2) HP(i).bCI(2) HP(i).bCI(1) HP(i).bCI(1)],[0.99 0.81 0.31],'LineStyle','-','Marker','none','facealpha',0.25)
plot([time_windows(i).Tstart time_windows(i).Tend],[HP(i).b HP(i).b],'-','LineWidth',2)
ylabel('b-value','FontSize',14);
else
yyaxis right;plot([time_windows(i).Tstart time_windows(i).Tend],[mean(time_windows(i).M) mean(time_windows(i).M)],'-','LineWidth',2)
ylabel('mean Magnitude','FontSize',14);
end
end
else
overlap='YES';
subplot(3,1,1) % plot Mean return period
errorbar(tplo,MRPer,MRPer-MRPer_low,MRPer_high-MRPer,'o','LineWidth',1,'MarkerSize',8);hold on;
plot(tplo,MRPer,'ko','LineWidth',2,'MarkerSize',4);
datetick('x',20);title(['Mean Return Period for M\geq',num2str(MaG)],'FontSize',16);ylabel([Tunit,'s'],'FontSize',18)
subplot(3,1,2) % plot Exceedance Probability
errorbar(tplo,ExPr,ExPr-ExPr_low,ExPr_high-ExPr,'o','LineWidth',1,'MarkerSize',8);hold on
plot(tplo,ExPr,'ko','LineWidth',2,'MarkerSize',4);
datetick('x',20);title(['Exceedance Probability for M\geq',num2str(MaG),' within ',num2str(Plength), ' ',Tunit,'(s) period'],'FontSize',16);ylabel('probability','FontSize',14)
subplot(3,1,3) % plot Activity rate
plot(tplo,lambda,'o','LineWidth',2,'MarkerSize',8);ylabel(['Events/',Tunit],'FontSize',14)
if strcmp(HP(1).method,'GRU') || strcmp(HP(1).method,'GRT');
yyaxis right;
for i=1:length(HP);bval_low(i)=HP(i).bCI(1);bval_high(i)=HP(i).bCI(2);end
errorbar(tplo,bval,bval-bval_low,bval_high-bval,'o','LineWidth',1,'MarkerSize',8);hold on
plot(tplo,bval,'ko','LineWidth',2,'MarkerSize',4);
ylabel('b-value','FontSize',14);
else; yyaxis right;plot(tplo,meanM,'o','LineWidth',2,'MarkerSize',8)
ylabel('mean Magnitude','FontSize',14);end
datetick('x',20);title('Activity Rate','FontSize',16);
end
if isempty(PROD_Data)==0
subplot(3,1,1);yyaxis right;plot(PROD_Data(1).val,PROD_Data(PROD_FIELD).val,'-','Linewidth',1);ylabel(PROD_Data(PROD_FIELD).field,'interpreter','none','FontSize',14);
subplot(3,1,2);yyaxis right;plot(PROD_Data(1).val,PROD_Data(PROD_FIELD).val,'-','Linewidth',1);ylabel(PROD_Data(PROD_FIELD).field,'interpreter','none','FontSize',14);
end
subplot(3,1,3);xlabel('Date','FontSize',18)
% option to switch linear-log Y axis Scale
txt = uicontrol('Parent',d,...
'Style','text',...
'Position',[200 470 150 30],...
'String','Select Y Axis Scale:');
popup = uicontrol('Parent',d,...
'Style','popup',...
'Position',[350 480 120 25],...
'String',{'Linear';'Log'},...
'Callback',@popup_callback);
btn = uicontrol('Parent',d,...
'Position',[210 688 210 50],...
'String','SAVE and CLOSE',...
'FontSize',18,...
'ForeGroundColor','r',...
'FontWeight','Bold',...
'Callback',@savefig_callback);
choice = 'Linear';
% Wait for d to close before running to completion
uiwait(d);
elseif (strcmp(Plotopt,'OFF'));close all
if numel(TT)==numel(Ncat)
overlap='NO';else; overlap='YES';end
end
function popup_callback(popup,event)
idx = popup.Value;
popup_items = popup.String;
% This code uses dot notation to get properties.
% Dot notation runs in R2014b and later.
% For R2014a and earlier:
% idx = get(popup,'Value');
% popup_items = get(popup,'String');
choice = char(popup_items(idx,:));
subplot(3,1,1);yyaxis left;
set(gca,'YScale',choice)
end
function savefig_callback(popup,event)
cd Outputs_SHA
print(gcf,'SHA.jpeg','-djpeg','-r300')
savefig(gcf,'SHA.fig')
% This code uses dot notation to get properties.
% Dot notation runs in R2014b and later.
% For R2014a and earlier:
% idx = get(popup,'Value');
% popup_items = get(popup,'String');
cd ../
delete(gcf)
end