-
Notifications
You must be signed in to change notification settings - Fork 1
/
taup_time.py
110 lines (101 loc) · 4.09 KB
/
taup_time.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Travel time calculations.
"""
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from future.builtins import * # NOQA
from .helper_classes import TauModelError
from .seismic_phase import SeismicPhase
from .utils import parse_phase_list
class TauPTime(object):
"""
Calculate travel times for different branches using linear interpolation
between known slowness samples.
"""
def __init__(self, model, phase_list, depth, degrees, receiver_depth=0.0):
self.source_depth = depth
self.receiver_depth = receiver_depth
self.degrees = degrees
self.arrivals = []
self.phases = []
# Names of phases to be used, e.g. PKIKP
self.phase_names = parse_phase_list(phase_list)
# A standard and a depth corrected model. Both are needed.
self.model = model
self.depth_corrected_model = self.model
def run(self):
"""
Do all the calculations and print the output if told to. The resulting
arrival times will be in self.arrivals.
"""
self.depth_correct(self.source_depth, self.receiver_depth)
self.calculate(self.degrees)
def depth_correct(self, depth, receiver_depth=None):
"""
Corrects the TauModel for the given source depth (if not already
corrected).
"""
if receiver_depth is None:
receiver_depth = self.receiver_depth
if self.depth_corrected_model is None or \
self.depth_corrected_model.source_depth != depth:
self.depth_corrected_model = self.model.depth_correct(depth)
self.arrivals = []
if receiver_depth != depth:
# If already split on receiver depth this does nothing.
self.depth_corrected_model = \
self.depth_corrected_model.split_branch(receiver_depth)
self.arrivals = []
self.source_depth = depth
self.receiver_depth = receiver_depth
def recalc_phases(self):
"""
Recalculates the given phases using a possibly new or changed tau
model.
"""
new_phases = []
for temp_phase_name in self.phase_names:
for phase_num, seismic_phase in enumerate(self.phases):
pass
# if seismic_phase.name == temp_phase_name:
# self.phases.pop(phase_num)
# if (seismic_phase.source_depth == self.source_depth and
# seismic_phase.tau_model ==
# self.depth_corrected_model):
# # OK so copy to new_phases:
# new_phases.append(seismic_phase)
# break
# Executed, if break is NOT called.
else:
# Didn't find it precomputed, so recalculate:
try:
seismic_phase = SeismicPhase(temp_phase_name,
self.depth_corrected_model,
self.receiver_depth)
new_phases.append(seismic_phase)
except TauModelError:
print("Error with this phase, skipping it: " +
str(temp_phase_name))
self.phases = new_phases
def calculate(self, degrees):
"""
Calculate the arrival times.
"""
self.depth_correct(self.source_depth, self.receiver_depth)
# Called before, but depth_correct might have changed the phases.
self.recalc_phases()
self.calc_time(degrees)
def calc_time(self, degrees):
"""
Calls the calc_time method of SeismicPhase to calculate arrival
times for every phase, each sorted by time.
"""
self.degrees = degrees
self.arrivals = []
for phase in self.phases:
self.arrivals += phase.calc_time(degrees)
# Sort them.
self.arrivals = sorted(self.arrivals,
key=lambda arrivals: arrivals.time)