# Source code for obspy.taup.taup_time

    #!/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)

### Thank you!

We would like to thank our contributors, whose efforts make this software what it is. These people have helped by writing code and documentation, and by testing. They have created and maintained this product, its associated libraries and applications, our build tools and our web sites.

#### Contributors

- Ackerley, Nick
- Allgeyer, Sebastien
- Ammon, Charles J.
- Antunes, Emanuel
- Arnarsson, Ólafur St.
- Bank, Markus
- Barsch, Robert
- Behr, Yannik
- Bernardi, Fabrizio
- Bernauer, Felix
- Bes de Berc, Maxime
- Beyreuther, Moritz
- Boltz, Shawn
- Bonaimé, Sébastien
- Carothers, Lloyd
- Chamberlain, Calum
- Chambers, Derrick
- Chen, Zhao
- Clark, Adam
- Danecek, Peter
- Egdorf, Sven
- Engels, Fabian
- Ermert, Laura
- Eulenfeld, Tom

- Fabbri, Tommaso
- Falco, Nicholas
- Fee, Jeremy
- Grellier, Clément
- Grunberg, Marc
- Hammer, Conny
- Heimann, Sebastian
- Heiniger, Lukas
- Hope, Gaute
- Igel, Heiner
- Inza, Adolfo
- Isken, Marius
- Ketchum, David
- Koymans, Mathijs
- Kremers, Simon
- Kress, Victor
- Krieger, Lars
- Krischer, Lion
- Kula, Damian
- Käufl, Paul
- Köhler, Andreas
- Lecocq, Thomas
- Leeman, John
- Legovini, Paride

- Lesage, Philippe
- Li, Yulin
- Lomax, Anthony
- Lopes, Rui L.
- MacCarthy, Jonathan
- Maggi, Alessia
- Martin, Henri
- Medlin, Andrew
- Megies, Tobias
- Meschede, Matthias
- Michelini, Alberto
- Miller, Nathaniel C.
- Morgenstern, Bernhard
- Nof, Ran Novitsky
- Panning, Mark P.
- Parker, Tom
- Pestourie, Romain
- Rapagnani, Giovanni
- Reyes, Celso
- Ringler, Adam
- Rothenhäusler, Nicolas
- Russo, Emiliano
- Sales de Andrade, Elliott

- Satriano, Claudio
- Saul, Joachim
- Scheingraber, Chris
- Schneider, Simon
- Sippl, Christian
- Snoke, Arthur
- Stange, Stefan
- Stähler, Simon C.
- Sullivan, Benjamin
- Tian, Dongdong
- Trabant, Chad
- Trani, Luca
- Uieda, Leonardo
- Walker, Andrew
- Walther, Marcus
- Wassermann, Joachim
- Williams, Mark C.
- Winkelman, Andrew
- Zaccarelli, Riccardo
- Zad, Seyed Kasra Hosseini
- Zhu, Lijun
- van Driel, Martin
- van Wijk, Kasper

#### Funds

ObsPy was partially funded by the

- German Science Foundation (DFG) via grant DFG IG 16/9-1
- German Ministry for Education and Research (BMBF), GEOTECHNOLOGIEN grant 03G0646H.
- NERA project (Network of European Research Infrastructures for Earthquake Risk Assessment and Mitigation) under the European Community's Seventh Framework Programme (FP7/2007-2013) grant agreement n° 262330
- Leibniz Institute for Applied Geophysics (LIAG)
- VERCE EU-FP7 project (no. 283543)