Repository: obspy/obspy

Issue:
Response.recalculate_overall_sensitivity does not accept integer value
Minimal example:

```py
In [0]: from obspy import read_inventory, UTCDateTime as UTC
In [1]: inv = read_inventory()
In [4]: rsp = inv.get_response('BW.RJOB..EHZ', UTC())
In [5]: rsp.recalculate_overall_sensitivity(5)
---------------------------------------------------------------------------
ArgumentError                             Traceback (most recent call last)
<ipython-input-5-9892716a93fe> in <module>()
----> 1 rsp.recalculate_overall_sensitivity(5)

~/dev/obspy/obspy/core/inventory/response.py in recalculate_overall_sensitivity(self, frequency)
   1029 
   1030         freq, gain = self._get_overall_sensitivity_and_gain(
-> 1031             output=unit, frequency=frequency)
   1032 
   1033         self.instrument_sensitivity.value = gain

~/dev/obspy/obspy/core/inventory/response.py in _get_overall_sensitivity_and_gain(self, frequency, output)
   1064         response_at_frequency = self._call_eval_resp_for_frequencies(
   1065             frequencies=[frequency], output=output,
-> 1066             hide_sensitivity_mismatch_warning=True)[0][0]
   1067         overall_sensitivity = abs(response_at_frequency)
   1068         return frequency, overall_sensitivity

~/dev/obspy/obspy/core/inventory/response.py in _call_eval_resp_for_frequencies(self, frequencies, output, start_stage, end_stage, hide_sensitivity_mismatch_warning)
   1574             rc = clibevresp._obspy_calc_resp(C.byref(chan), frequencies,
   1575                                              len(frequencies),
-> 1576                                              output, out_units, -1, 0, 0)
   1577             if rc:
   1578                 e, m = ew.ENUM_ERROR_CODES[rc]

ArgumentError: argument 2: <class 'TypeError'>: array must have data type float64
```


Discussion:
obspy version ?

This is the master branch.

Resolving patch:
diff --git a/obspy/core/inventory/response.py b/obspy/core/inventory/response.py
--- a/obspy/core/inventory/response.py
+++ b/obspy/core/inventory/response.py
@@ -1028,7 +1028,7 @@ def recalculate_overall_sensitivity(self, frequency=None):
             raise ValueError(msg)
 
         freq, gain = self._get_overall_sensitivity_and_gain(
-            output=unit, frequency=frequency)
+            output=unit, frequency=float(frequency))
 
         self.instrument_sensitivity.value = gain
         self.instrument_sensitivity.frequency = freq


Test patch:
diff --git a/obspy/core/tests/test_response.py b/obspy/core/tests/test_response.py
--- a/obspy/core/tests/test_response.py
+++ b/obspy/core/tests/test_response.py
@@ -483,6 +483,49 @@ def test_regression_evalresp(self):
              2.445572e+05 - 2.480459e+03j,
              -2.455459e-01 + 4.888214e-02j], rtol=1e-6)
 
+    def test_recalculate_overall_sensitivity(self):
+        """
+        Tests the recalculate_overall_sensitivity_method().
+
+        This is not yet an exhaustive test as responses are complicated...
+        """
+        resp = read_inventory()[0][0][0].response
+        np.testing.assert_allclose(
+            resp.instrument_sensitivity.value,
+            943680000.0)
+        np.testing.assert_allclose(
+            resp.instrument_sensitivity.frequency,
+            0.02)
+        # Recompute - it is not much different but a bit.
+        resp.recalculate_overall_sensitivity(0.02)
+        np.testing.assert_allclose(
+            resp.instrument_sensitivity.value,
+            943681500.0)
+        np.testing.assert_allclose(
+            resp.instrument_sensitivity.frequency,
+            0.02)
+
+        # There is some logic to automatically determine a suitable frequency.
+        # Make sure this does something here.
+        resp = read_inventory()[0][0][0].response
+        resp.recalculate_overall_sensitivity()
+        np.testing.assert_allclose(
+            resp.instrument_sensitivity.value,
+            957562105.3939067)
+        np.testing.assert_allclose(
+            resp.instrument_sensitivity.frequency,
+            1.0)
+
+        # Passing an integer also works. See #2338.
+        resp = read_inventory()[0][0][0].response
+        resp.recalculate_overall_sensitivity(1)
+        np.testing.assert_allclose(
+            resp.instrument_sensitivity.value,
+            957562105.3939067)
+        np.testing.assert_allclose(
+            resp.instrument_sensitivity.frequency,
+            1.0)
+
 
 def suite():
     return unittest.makeSuite(ResponseTestCase, 'test')