Repository: obspy/obspy

Issue:
Bug in `obspy.taup.tau_model.TauModel.load_from_depth_cache` ?
Sorry if the problem has been reported (I didn't find any on the issues list), but it seems inconsistent
the behaviour of this line:
https://github.com/obspy/obspy/blob/master/obspy/taup/tau_model.py#L238
where 
```
self._load_from_depth_cache()
```
is called without arguments (by providing the argument in the constructor `cache=False`)

Regardless of whether I am using the wrong `cache` value (which from the code it does not seem the case, but any help is appreciated in case), this seems to be a bug as the method expects an argument which is not given

Thank you very much in advance



Discussion:
Yea this does seem to be a bug. It likely never surfaces as is it fairly hard to initialize the `TauModel` class without a cache as all the high-level interfaces do set it. But we should eventually fix this nonetheless.
Yes indeed I was trying some optimization digging deep into the code and I ended up to a very particular case. Anyway, from the code I really guess the problem is just replacing:
```
self._load_from_depth_cache()
```
with
```
self._load_from_depth_cache(depth)
```
(let alone of course writing missing tests)

I think so as well.

Please send a PR with any optimizations you end up discovering, best including some tests. `obspy.taup` is otherwise tested fairly well so any change that does not break the tests is likely valid.

Resolving patch:
diff --git a/obspy/taup/tau_model.py b/obspy/taup/tau_model.py
--- a/obspy/taup/tau_model.py
+++ b/obspy/taup/tau_model.py
@@ -235,7 +235,7 @@ def load_from_depth_cache(self, depth):
                 self._depth_cache.popitem(last=False)
             return value
         else:
-            return self._load_from_depth_cache()
+            return self._load_from_depth_cache(depth)
 
     def _load_from_depth_cache(self, depth):
         depth_corrected = self.split_branch(depth)


Test patch:
diff --git a/obspy/taup/tests/test_tau.py b/obspy/taup/tests/test_tau.py
--- a/obspy/taup/tests/test_tau.py
+++ b/obspy/taup/tests/test_tau.py
@@ -13,6 +13,7 @@
 import os
 import unittest
 import warnings
+from collections import OrderedDict
 
 import numpy as np
 
@@ -36,6 +37,13 @@ class TauPyModelTestCase(unittest.TestCase):
     """
     Test suite for the obspy.taup.TauPy class.
     """
+
+    def setUp(self):
+        """setup method. Instantiates cache values to be used in
+        P phase arrival calculations
+        to test also `TauModel.load_from_depth_cache`"""
+        self.caches = [OrderedDict(), False, None]
+
     def _read_taup_output(self, filename):
         """
         Helper method reading a stdout capture of TauP.
@@ -172,82 +180,96 @@ def test_p_iasp91_geo_fallback_manual(self):
 
     def test_p_iasp91(self):
         """
-        Test P phase arrival against TauP output in in model IASP91.
+        Test P phase arrival against TauP output in model IASP91
+        with different cache values to test `TauModel.load_from_depth_cache`
         """
-        m = TauPyModel(model="iasp91")
-        arrivals = m.get_travel_times(source_depth_in_km=10.0,
-                                      distance_in_degree=35.0,
-                                      phase_list=["P"])
-        self._compare_arrivals_with_file(arrivals,
-                                         "taup_time_-h_10_-ph_P_-deg_35")
+        for cache in self.caches:
+            m = TauPyModel(model="iasp91", cache=cache)
+            arrivals = m.get_travel_times(source_depth_in_km=10.0,
+                                          distance_in_degree=35.0,
+                                          phase_list=["P"])
+            self._compare_arrivals_with_file(arrivals,
+                                             "taup_time_-h_10_-ph_P_-deg_35")
 
     def test_p_ak135(self):
         """
-        Test P phase arrival against TauP output in in model AK135.
+        Test P phase arrival against TauP output in model AK135
+        with different cache values to test `TauModel.load_from_depth_cache`
         """
-        m = TauPyModel(model="ak135")
-        arrivals = m.get_travel_times(source_depth_in_km=10.0,
-                                      distance_in_degree=35.0,
-                                      phase_list=["P"])
-        self._compare_arrivals_with_file(
-            arrivals, "taup_time_-h_10_-ph_ttall_-deg_35_-mod_ak135")
+        for cache in self.caches:
+            m = TauPyModel(model="ak135", cache=cache)
+            arrivals = m.get_travel_times(source_depth_in_km=10.0,
+                                          distance_in_degree=35.0,
+                                          phase_list=["P"])
+            self._compare_arrivals_with_file(
+                arrivals, "taup_time_-h_10_-ph_ttall_-deg_35_-mod_ak135")
 
     def test_p_ak135f_no_mud(self):
         """
-        Test P phase arrival against TauP output in in model ak135f_no_mud.
+        Test P phase arrival against TauP output in model ak135f_no_mud
+        with different cache values to test `TauModel.load_from_depth_cache`
         """
-        m = TauPyModel(model="ak135f_no_mud")
-        arrivals = m.get_travel_times(source_depth_in_km=10.0,
-                                      distance_in_degree=35.0,
-                                      phase_list=["P"])
-        self._compare_arrivals_with_file(
-            arrivals, "taup_time_-h_10_-ph_P_-deg_35_-mod_ak135f_no_mud")
+        for cache in self.caches:
+            m = TauPyModel(model="ak135f_no_mud", cache=cache)
+            arrivals = m.get_travel_times(source_depth_in_km=10.0,
+                                          distance_in_degree=35.0,
+                                          phase_list=["P"])
+            self._compare_arrivals_with_file(
+                arrivals, "taup_time_-h_10_-ph_P_-deg_35_-mod_ak135f_no_mud")
 
     def test_p_jb(self):
         """
-        Test P phase arrival against TauP output in in model jb.
+        Test P phase arrival against TauP output in model jb
+        with different cache values to test `TauModel.load_from_depth_cache`
         """
-        m = TauPyModel(model="jb")
-        arrivals = m.get_travel_times(source_depth_in_km=10.0,
-                                      distance_in_degree=35.0,
-                                      phase_list=["P"])
-        self._compare_arrivals_with_file(
-            arrivals, "taup_time_-h_10_-ph_P_-deg_35_-mod_jb")
+        for cache in self.caches:
+            m = TauPyModel(model="jb", cache=cache)
+            arrivals = m.get_travel_times(source_depth_in_km=10.0,
+                                          distance_in_degree=35.0,
+                                          phase_list=["P"])
+            self._compare_arrivals_with_file(
+                arrivals, "taup_time_-h_10_-ph_P_-deg_35_-mod_jb")
 
     def test_p_pwdk(self):
         """
-        Test P phase arrival against TauP output in in model pwdk.
+        Test P phase arrival against TauP output in model pwdk
+        with different cache values to test `TauModel.load_from_depth_cache`
         """
-        m = TauPyModel(model="pwdk")
-        arrivals = m.get_travel_times(source_depth_in_km=10.0,
-                                      distance_in_degree=35.0,
-                                      phase_list=["P"])
-        self._compare_arrivals_with_file(
-            arrivals, "taup_time_-h_10_-ph_P_-deg_35_-mod_pwdk")
+        for cache in self.caches:
+            m = TauPyModel(model="pwdk", cache=cache)
+            arrivals = m.get_travel_times(source_depth_in_km=10.0,
+                                          distance_in_degree=35.0,
+                                          phase_list=["P"])
+            self._compare_arrivals_with_file(
+                arrivals, "taup_time_-h_10_-ph_P_-deg_35_-mod_pwdk")
 
     def test_iasp91(self):
         """
         Test travel times for lots of phases against output from TauP in model
-        IASP91.
+        IASP91 with different cache values to test
+        `TauModel.load_from_depth_cache`
         """
-        m = TauPyModel(model="iasp91")
-        arrivals = m.get_travel_times(source_depth_in_km=10.0,
-                                      distance_in_degree=35.0,
-                                      phase_list=["ttall"])
-        self._compare_arrivals_with_file(arrivals,
-                                         "taup_time_-h_10_-ph_ttall_-deg_35")
+        for cache in self.caches:
+            m = TauPyModel(model="iasp91", cache=cache)
+            arrivals = m.get_travel_times(source_depth_in_km=10.0,
+                                          distance_in_degree=35.0,
+                                          phase_list=["ttall"])
+            self._compare_arrivals_with_file(
+                arrivals, "taup_time_-h_10_-ph_ttall_-deg_35")
 
     def test_ak135(self):
         """
         Test travel times for lots of phases against output from TauP in model
-        AK135.
-        """
-        m = TauPyModel(model="ak135")
-        arrivals = m.get_travel_times(source_depth_in_km=10.0,
-                                      distance_in_degree=35.0,
-                                      phase_list=["ttall"])
-        self._compare_arrivals_with_file(
-            arrivals, "taup_time_-h_10_-ph_ttall_-deg_35_-mod_ak135")
+        AK135 with different cache values to test
+        `TauModel.load_from_depth_cache`
+        """
+        for cache in self.caches:
+            m = TauPyModel(model="ak135", cache=cache)
+            arrivals = m.get_travel_times(source_depth_in_km=10.0,
+                                          distance_in_degree=35.0,
+                                          phase_list=["ttall"])
+            self._compare_arrivals_with_file(
+                arrivals, "taup_time_-h_10_-ph_ttall_-deg_35_-mod_ak135")
 
     def test_pierce_p_iasp91(self):
         """