-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy patha3_sac2mat_event.m
83 lines (73 loc) · 3.23 KB
/
a3_sac2mat_event.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
% sac2mat_event
%
% Following download_event.m script but uses local data files. Loads in
% sac data files and puts them in proper .mat structures. This assumes
% that instrument response has already been removed and is in the same
% units as the day files.
% Waveform lengths should match T in setup_parameters
%
% Assumed naming convention for local data:
% path/to/event/data/{yyyymmddhhMM}/{yyyymmddhhMM}.{network}.{station}.{component}.sac
%
% J. Russell & H. Janiszewski
% hajanisz@hawaii.edu
% updated 2/18
clear;
addpath ('function');
startlist = 'NOISETC_CI/eventtimes_CItest.txt'; % list of start times for data download, this will be the beginning of the waveform so specify appropriately, signal of interest should not be at edges of time series
datalength = 7200; % length of time series after each start time in seconds (default 86400, code not thoroughly tested for other values)
saceventdata = 'path/to/local/event/sac/files/'; % path to local event sac files
download_networks = '7D'; % list of networks to download
download_stations = textread('./NOISETC_CI/stalist.txt','%s'); % list of stations to download (* for all)
% Channel Names
chz_vec = 'BHZ'; %'BHZ'; % list of acceptable names for Z component
ch1_vec = 'BH1'; %'BH1'; % list of acceptable names for H1 component
ch2_vec = 'BH2'; %'BH2'; % list of acceptable names for H2 component
chp_vec = 'BDH'; %'BDH'; % list of acceptable names for P component
datacache = 'NOISETC_CI/DATA/datacache'; %'./ENAM/DATA/EVENT/'; %'NOISETC_SAMPLE2/DATA/datacache'; % output folder for data
%%%%% end user input parameters %%%%%
if ~exist(datacache,'dir')
mkdir(datacache)
end
startlist = textread(startlist,'%s');
for id = 1:length(startlist)
eventid = cell2mat(startlist(id));
disp(sprintf('Start Time: %s',eventid));
if length(eventid) == 12
otime = datenum(eventid,'yyyymmddHHMM'); % look at this when I get back
elseif length(eventid) == 14
otime = datenum(eventid,'yyyymmddHHMMSS');
eventid = eventid(1:12); % for naming purposes only, start time will still be saved to the second in traces file
end
starttime = datestr(otime,'yyyy-mm-dd HH:MM:SS');
endtime = datestr(otime+datalength/3600/24,'yyyy-mm-dd HH:MM:SS');
for ista =1:length(download_stations)
clear traces
error = 0;
stnm = download_stations{ista};
network = download_networks;
if ~exist(fullfile(datacache,eventid),'dir')
mkdir(fullfile(datacache,eventid));
end
sta_filename = fullfile(datacache,eventid,[eventid,'_',network,'_',stnm,'.mat']);
if exist(sta_filename,'file')
disp(['Exist: ',sta_filename,', Skip!']);
continue;
end
disp(['SAC to MAT station: ',stnm,' From:',starttime,' To:',endtime]);
try
ich = 0;
for ch = {chp_vec ch1_vec ch2_vec chz_vec}
ich = ich + 1;
sac_filename = [eventid,'.',network,'.',stnm,'.',ch{:},'.sac'];
sac = rdsac(fullfile(saceventdata,eventid,sac_filename));
traces(ich) = sac2mat( sac );
end
save(sta_filename,'traces');
catch e
e.message;
error = 1;
display('Could not load data file');
end
end
end