Skip to content

Commit 0f15e6b

Browse files
committed
add matlab script to plot record sections
1 parent bd951c6 commit 0f15e6b

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

plotting/plot_sacdata.m

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
%% PLOT SEISMOGRAMS
2+
3+
clear; close all;
4+
%plot native
5+
fig1 = figure(1); clf;
6+
set(gcf,'position',[141 28 938 633]);
7+
%figure(2); clf;
8+
9+
data_dir = 'IRIS_YQ_6.5'; %'IRIS_XX_5.5_Zcorr'; %'IRIS_ZA_7.0';
10+
comp = 'BHZ';
11+
fb_min = 1/150; % 150 sec
12+
fb_max = 1/20; % 20 sec
13+
14+
% data_dir = 'IRIS_YQ_6.5'; %'IRIS_XX_5.5_Zcorr'; %'IRIS_ZA_7.0';
15+
% comp = 'BHT';
16+
% fb_min = 1/150; %1/100; % 150 sec
17+
% fb_max = 1/20; % 20 sec
18+
19+
trace_space = 0; %0.15; % spacing between traces
20+
amp = 0.3 / 2;
21+
max_dist_deg = 150;
22+
23+
groupv = 4.3;
24+
winrefmin = -1200; %-800;
25+
winrefmax = 1500; %1000;
26+
27+
figpath = ['./figs/',data_dir,'/',num2str(1/fb_max),'_',num2str(1/fb_min),'/'];
28+
if ~exist(figpath)
29+
mkdir(figpath);
30+
end
31+
32+
%% LOAD EVENT LIST
33+
evs = dir(['./',data_dir,'/*']);
34+
% evs_pat = dir('/Users/russell/Lamont/nomelt_DATA/GSDF_LOVE_cleanEVTs/sacdata_T/2012*');
35+
num_evs = size(evs,1);
36+
37+
%% LOAD SAC FILES
38+
land = shaperead('landareas', 'UseGeoCoords', true);
39+
load coast;
40+
for j = 1:num_evs
41+
figure(1); clf
42+
sac_fils = dir(['./',data_dir,'/',evs(j).name,'/*',comp,'.sac']);
43+
% sac_fils_pat = dir(['/Users/russell/Lamont/nomelt_DATA/GSDF_LOVE_cleanEVTs/sacdata_T/',evs(j).name,'/*.sac']);
44+
if isempty(sac_fils)
45+
continue
46+
end
47+
48+
num_fil = size(sac_fils,1);
49+
DIST_min = 9999;
50+
DIST_max = 0;
51+
SAC = {};
52+
dists = 0;
53+
data = [];
54+
itrace = 0;
55+
56+
for i = 1:num_fil
57+
PATH_sac_fils = ['./',data_dir,'/',evs(j).name,'/',sac_fils(i).name];
58+
% display("Checking:")
59+
% display(sac_filsT(i).name);
60+
% display(sac_filsZ(i).name);
61+
SAC{i} = rdsac(PATH_sac_fils);
62+
if i == 1
63+
tref = round(SAC{i}.HEADER.DIST/1000/groupv);
64+
twindow = [tref+winrefmin:tref+winrefmax];
65+
twindow = twindow(twindow>=0);
66+
end
67+
68+
if SAC{i}.HEADER.GCARC > DIST_max
69+
DIST_max = SAC{i}.HEADER.GCARC;
70+
end
71+
if SAC{i}.HEADER.GCARC < DIST_min
72+
DIST_min = SAC{i}.HEADER.GCARC;
73+
end
74+
EVDP = SAC{i}.HEADER.EVDP/1000;
75+
MAG = SAC{i}.HEADER.MAG;
76+
77+
%Filter data
78+
d_xt{i} = SAC{i}.d;
79+
%Taper data
80+
d_xt{i} = d_xt{i}.*tukeywin(length(d_xt{i}),0.08);
81+
% ts = SAC{i}.t;
82+
ts = 0:length(d_xt{i})-1;
83+
fs = 1/(ts(2)-ts(1));
84+
[b,a] = butter(2,[fb_min/(fs/2) fb_max/(fs/2)]); % (20 - 150 seconds)
85+
%fvtool(b,a);
86+
d_xt{i} = filtfilt(b,a,d_xt{i});
87+
88+
GCARC = SAC{i}.HEADER.GCARC;
89+
90+
figure(1); box off;
91+
%Plot data
92+
if GCARC > max_dist_deg
93+
continue
94+
end
95+
if min(abs(GCARC-dists)) > trace_space
96+
itrace = itrace+1;
97+
dists(itrace,:) = GCARC;
98+
dwindow = d_xt{i}(twindow+1);
99+
data(itrace,:) = amp*(dwindow/max(abs(dwindow)));
100+
end
101+
% box on;
102+
103+
end
104+
if isempty(data)
105+
continue
106+
end
107+
figure(1); box off;
108+
plot(twindow,data+dists,'linewidth',1.5,'color',[0 0 0]); hold on;
109+
xlabel('Time (s)');
110+
ylabel('Distance (\circ)');
111+
title(['Event:',evs(j).name,' ',num2str(EVDP),' km M',num2str(MAG)]);
112+
set(gca,'fontsize',16,'linewidth',1);
113+
% xlim([ts(1) ts(floor(end/1.9))]);
114+
xlim([twindow(1) twindow(end)]);
115+
ylim([DIST_min-0.2 DIST_max+0.25]);
116+
117+
% Plot inset map
118+
axes('Position',[.75 .79 .35*.6 .4*.6])
119+
box off;
120+
% axesm('robinson','MapLatLimit',[-90 90],'maplonlimit',[45,44])
121+
h = axesm('robinson','MapLatLimit',[-90 90],'maplonlimit',[-180,+180]+SAC{1}.HEADER.STLO);
122+
setm(gca,'grid','off','frame', 'on');
123+
axis off
124+
p = findobj(h,'type','patch'); % Find background
125+
set(p,'FaceColor',[1 1 1]); % Change background to white
126+
% geoshow(land,"FaceColor",[0.7 0.7 0.7])
127+
plotm(lat, long,'k');
128+
% raypath_lat = [SAC{1}.HEADER.STLA,SAC{1}.HEADER.EVLA];
129+
% raypath_lon = [SAC{1}.HEADER.STLO,SAC{1}.HEADER.EVLO];
130+
[raypath_lat,raypath_lon] = gcwaypts(SAC{1}.HEADER.STLA,SAC{1}.HEADER.STLO,SAC{1}.HEADER.EVLA,SAC{1}.HEADER.EVLO,50);
131+
plotm(raypath_lat,raypath_lon,'-r','linewidth',1.5);
132+
plotm(SAC{1}.HEADER.STLA,SAC{1}.HEADER.STLO,'ok','linewidth',0.5,'markerfacecolor','b','markersize',10);
133+
plotm(SAC{1}.HEADER.EVLA,SAC{1}.HEADER.EVLO,'pk','linewidth',0.5,'markerfacecolor','r','markersize',20);
134+
135+
136+
save2pdf([figpath,'/',comp,'_evt_',evs(j).name,'_M',num2str(MAG),'_',num2str(1/fb_max),'_',num2str(1/fb_min),'s','.pdf'],fig1,1000);
137+
end

0 commit comments

Comments
 (0)