Repository: obspy/obspy

Issue:
distaz method of Iris Client returns lxml.objectify.FloatElement
I just noticed that distaz method of Iris client is returning objectify floats instead of pure floats. Only value of `ellipsoidname` is returned as native str. I see that there was similar bug for seishub client which was fixed. In my opinion, those values should be casted to native types. Should I change it?


```python
from obspy.clients.iris import Client
distaz = Client().distaz(0, 0, 1, 1)
type(distaz['ellipsoidname'])
>> str
type(distaz['distance'])
>> lxml.objectify.FloatElement
```


Discussion:
Yes please make a PR for it @heavelock if you feel like it. It should indeed be plain float.

Resolving patch:
diff --git a/obspy/clients/iris/client.py b/obspy/clients/iris/client.py
--- a/obspy/clients/iris/client.py
+++ b/obspy/clients/iris/client.py
@@ -499,8 +499,8 @@ def sacpz(self, network, station, location="*", channel="*",
         * START             : 2002-11-19T21:07:00
         * END               : 2008-06-30T00:00:00
         * DESCRIPTION       : Albuquerque, New Mexico, USA
-        * LATITUDE          : 34.945981
-        * LONGITUDE         : -106.457133
+        * LATITUDE          : 34.945980
+        * LONGITUDE         : -106.457130
         * ELEVATION         : 1671.0
         * DEPTH             : 145.0
         * DIP               : 0.0
@@ -616,11 +616,11 @@ def distaz(self, stalat, stalon, evtlat, evtlon):
             raise Exception(msg)
         data = objectify.fromstring(data.decode())
         results = {}
-        results['ellipsoidname'] = data.ellipsoid.attrib['name']
-        results['distance'] = data.distance
-        results['distancemeters'] = data.distanceMeters
-        results['backazimuth'] = data.backAzimuth
-        results['azimuth'] = data.azimuth
+        results['ellipsoidname'] = str(data.ellipsoid.attrib['name'])
+        results['distance'] = float(data.distance)
+        results['distancemeters'] = float(data.distanceMeters)
+        results['backazimuth'] = float(data.backAzimuth)
+        results['azimuth'] = float(data.azimuth)
         return results
 
     def flinnengdahl(self, lat, lon, rtype="both"):


Test patch:
diff --git a/obspy/clients/iris/tests/data/IU.ANMO.00.BHZ.sacpz b/obspy/clients/iris/tests/data/IU.ANMO.00.BHZ.sacpz
--- a/obspy/clients/iris/tests/data/IU.ANMO.00.BHZ.sacpz
+++ b/obspy/clients/iris/tests/data/IU.ANMO.00.BHZ.sacpz
@@ -7,8 +7,8 @@
 * START             : 2002-11-19T21:07:00
 * END               : 2008-06-30T00:00:00
 * DESCRIPTION       : Albuquerque, New Mexico, USA
-* LATITUDE          : 34.945981
-* LONGITUDE         : -106.457133
+* LATITUDE          : 34.945980
+* LONGITUDE         : -106.457130
 * ELEVATION         : 1671.0
 * DEPTH             : 145.0
 * DIP               : 0.0
diff --git a/obspy/clients/iris/tests/test_client.py b/obspy/clients/iris/tests/test_client.py
--- a/obspy/clients/iris/tests/test_client.py
+++ b/obspy/clients/iris/tests/test_client.py
@@ -63,6 +63,11 @@ def test_distaz(self):
         self.assertAlmostEqual(result['backazimuth'], 5.46944)
         self.assertAlmostEqual(result['azimuth'], 185.47695)
         self.assertEqual(result['ellipsoidname'], 'WGS84')
+        self.assertTrue(isinstance(result['distance'], float))
+        self.assertTrue(isinstance(result['distancemeters'], float))
+        self.assertTrue(isinstance(result['backazimuth'], float))
+        self.assertTrue(isinstance(result['azimuth'], float))
+        self.assertTrue(isinstance(result['ellipsoidname'], str))
         # w/o kwargs
         result = client.distaz(1.1, 1.2, 3.2, 1.4)
         self.assertAlmostEqual(result['distance'], 2.10256)
@@ -84,18 +89,22 @@ def test_flinnengdahl(self):
         # code
         result = client.flinnengdahl(lat=-20.5, lon=-100.6, rtype="code")
         self.assertEqual(result, 683)
+        self.assertTrue(isinstance(result, int))
         # w/o kwargs
         result = client.flinnengdahl(-20.5, -100.6, "code")
         self.assertEqual(result, 683)
         # region
         result = client.flinnengdahl(lat=42, lon=-122.24, rtype="region")
         self.assertEqual(result, 'OREGON')
+        self.assertTrue(isinstance(result, str))
         # w/o kwargs
         result = client.flinnengdahl(42, -122.24, "region")
         self.assertEqual(result, 'OREGON')
         # both
         result = client.flinnengdahl(lat=-20.5, lon=-100.6, rtype="both")
         self.assertEqual(result, (683, 'SOUTHEAST CENTRAL PACIFIC OCEAN'))
+        self.assertTrue(isinstance(result[0], int))
+        self.assertTrue(isinstance(result[1], str))
         # w/o kwargs
         result = client.flinnengdahl(-20.5, -100.6, "both")
         self.assertEqual(result, (683, 'SOUTHEAST CENTRAL PACIFIC OCEAN'))
@@ -157,7 +166,7 @@ def test_evalresp(self):
                             filename=tempfile)
             with open(tempfile, 'rt') as fp:
                 self.assertEqual(fp.readline(),
-                                 '1.000000E-05  1.055999E+04  1.792007E+02\n')
+                                 '1.000000E-05 1.055999E+04 1.792007E+02\n')
         # cs as ASCII file
         with NamedTemporaryFile() as tf:
             tempfile = tf.name
@@ -166,7 +175,7 @@ def test_evalresp(self):
                             filename=tempfile)
             with open(tempfile, 'rt') as fp:
                 self.assertEqual(fp.readline(),
-                                 '1.000000E-05 -1.055896E+04 1.473054E+02\n')
+                                 '1.000000E-05  -1.055896E+04  1.473054E+02\n')
         # fap & def as ASCII file
         with NamedTemporaryFile() as tf:
             tempfile = tf.name
@@ -175,7 +184,7 @@ def test_evalresp(self):
                             filename=tempfile)
             with open(tempfile, 'rt') as fp:
                 self.assertEqual(fp.readline(),
-                                 '1.000000E-05  1.055999E+04  1.792007E+02\n')
+                                 '1.000000E-05 1.055999E+04 1.792007E+02\n')
         # fap & dis as ASCII file
         with NamedTemporaryFile() as tf:
             tempfile = tf.name
@@ -184,7 +193,7 @@ def test_evalresp(self):
                             filename=tempfile)
             with open(tempfile, 'rt') as fp:
                 self.assertEqual(fp.readline(),
-                                 '1.000000E-05  6.635035E-01  2.692007E+02\n')
+                                 '1.000000E-05 6.635035E-01 2.692007E+02\n')
         # fap & vel as ASCII file
         with NamedTemporaryFile() as tf:
             tempfile = tf.name
@@ -193,7 +202,7 @@ def test_evalresp(self):
                             filename=tempfile)
             with open(tempfile, 'rt') as fp:
                 self.assertEqual(fp.readline(),
-                                 '1.000000E-05  1.055999E+04  1.792007E+02\n')
+                                 '1.000000E-05 1.055999E+04 1.792007E+02\n')
         # fap & acc as ASCII file
         with NamedTemporaryFile() as tf:
             tempfile = tf.name
@@ -202,7 +211,7 @@ def test_evalresp(self):
                             filename=tempfile)
             with open(tempfile, 'rt') as fp:
                 self.assertEqual(fp.readline(),
-                                 '1.000000E-05  1.680674E+08  8.920073E+01\n')
+                                 '1.000000E-05 1.680674E+08 8.920073E+01\n')
         # fap as NumPy ndarray
         data = client.evalresp(network="IU", station="ANMO", location="00",
                                channel="BHZ", time=dt, output='fap')