-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetArrivalTimes.m
123 lines (98 loc) · 5.54 KB
/
getArrivalTimes.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
%CCCP
%Arrival Time Picker
%Adjusts snippets and determines arrivals
%Need to incorporate a toss out threshold for waveforms to temporally close
%Read in written/generated template data from file
%all input parameters are modifiable in template_data_input.m
%all general parameters are modifiable in general_settings.m
templates
general_settings
%Adjust time data to MATLAB readable format
start_date = sprintf('%04d-%02d-%02d %02d:%02d.%d',start_year,start_month,start_day,start_minute,start_second);
end_date = sprintf('%04d-%02d-%02d %02d:%02d.%d',end_year,end_month,end_day,end_minute,end_second);
%Check to ensure the proper flow of time
start_date = datenum(start_date);
end_date = datenum(end_date);
delta_time = end_date - start_date;
is_real = delta_time > 0;
if is_real == 0;
fprintf('The Campaign for Real Time requests that you please ensure that your ending date follows your starting date. \n');
end
directory_check = sprintf('./%s/%s',base_folder,correlation_object_folder);
if exist(directory_check,'dir') ~= 7;
mkdir(directory_check);
fprintf('Correlation object directory created \n');
end
event_match_matlab = sprintf('./%s/%s/TEL_%s_to_%s_events.mat',base_folder,result_folder,datestr(start_date),datestr(end_date));
load(event_match_matlab);
fprintf('Event listing loaded\n');
overall_listing = cell([2,length(template_list(:,1))]);
%Narrowing down focus to individual stations and channels
for template_count = 1:length(template_list(:,1));
single_template = template_list{template_count}
template = single_template.template;
template_listing = cell([2,length(single_template)]);
overall_listing{1,template_count} = template;
overall_listing{2,template_count} = template_listing;
for station_count = 1:length(single_template);
station_specific_template = single_template(station_count);
numberofchannels = length(station_specific_template.channel_list);
%template = station_specific_template.template;
station = station_specific_template.station;
network = station_specific_template.network;
phase = station_specific_template.trigger;
station_listing = cell([2,numberofchannels]);
template_listing{1,station_count} = station;
template_listing{2,station_count} = station_listing;
for chan_count = 1:numberofchannels
channel = station_specific_template.channel_list{chan_count};
station_listing{1,chan_count} = channel;
fprintf('Template: %s\n',template);
fprintf('Station: %s\n',station);
fprintf('Network: %s\n',network);
fprintf('Phase: %s\n',phase);
fprintf('Correlating Channel: %s\n',channel);
fprintf('Operation Time/Date: %s\n',datestr(clock));
correlation_object_savename = sprintf('./%s/%s/CO_%s_%s_%s_%s',base_folder,correlation_object_folder,template,phase,station,channel);
adjusted_correlation_object_savename = sprintf('./%s/%s/Adjusted_CO_%s_%s_%s_%s',base_folder,correlation_object_folder,template,phase,station,channel);
load(correlation_object_savename);
C = correlation_object;
template_waveform = waveform(C,get(correlation_object,'Traces'));
row = 2;
%Need to change this for universal channel use
if strcmp(channel,'BHE') == 1 || strcmp(channel,'BH1') == 1
arrivals = 'S';
template_waveform = correlation(template_waveform);
sWaveArrival = station_specific_template.sWaveArrival;
timeAdjust = cat(C,template_waveform)
%timeAdjust = xcorr(timeAdjust)
timeAdjust = xcorr(timeAdjust,'interp')
timeAdjust = adjusttrig(timeAdjust,'index');
S_Arrivals_E = datestr(get(timeAdjust,'trig'),'yyyy-mm-dd HH:MM:SS.FFF');
elseif strcmp(channel,'BHN') == 1|| strcmp(channel,'BH2') == 1;
arrivals = 'S';
template_waveform = correlation(template_waveform);
sWaveArrival = station_specific_template.sWaveArrival;
timeAdjust = cat(C,template_waveform);
%timeAdjust = xcorr(timeAdjust);
timeAdjust = xcorr(timeAdjust,'interp');
timeAdjust = adjusttrig(timeAdjust,'index');
S_Arrivals_N = datestr(get(timeAdjust,'trig'),'yyyy-mm-dd HH:MM:SS.FFF');
elseif strcmp(channel,'BHZ') == 1
arrivals = 'P';
template_waveform = correlation(template_waveform);
sWaveArrival = station_specific_template.sWaveArrival;
timeAdjust = cat(C,template_waveform);
%timeAdjust = xcorr(timeAdjust);
timeAdjust = xcorr(timeAdjust,'interp');
timeAdjust = adjusttrig(timeAdjust,'index');
P_Arrivals_Z = datestr(get(timeAdjust,'trig'),'yyyy-mm-dd HH:MM:SS.FFF');
end
station_listing{2,chan_count} = datestr(get(timeAdjust,'trig'),'yyyy-mm-dd HH:MM:SS.FFF');
save(adjusted_correlation_object_savename,'timeAdjust');
end
SE_SN_PZ_Arrivals = {{'BHE/1 (S)', 'BHN/2 (S)', 'BHZ (P)'};{S_Arrivals_E,S_Arrivals_N,P_Arrivals_Z}};
arrivals_savename = sprintf('./%s/%s/%s_%s_%s_to_%s_events.mat',base_folder,result_folder,template,station,datestr(start_date),datestr(end_date));
save(arrivals_savename,'SE_SN_PZ_Arrivals');
end
end