From d5528c2e3f7fbfaf34c8c66d265382a8668e22d5 Mon Sep 17 00:00:00 2001 From: g-weatherill Date: Thu, 27 May 2021 09:09:02 +0200 Subject: [PATCH] Another fix to the datetime isoformat --- shakyground2/earthquake.py | 2 +- tests/earthquake_test.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/shakyground2/earthquake.py b/shakyground2/earthquake.py index b663ce5..744f855 100644 --- a/shakyground2/earthquake.py +++ b/shakyground2/earthquake.py @@ -214,7 +214,7 @@ class Earthquake(object): ) # Time is not necessarily in ISO format, so fix this for use with datetime object hh, mm, ss = event["time"].split(":") - ss = "{:2.6f}".format(float(ss.replace("Z", ""))) + ss = "%09.6f" % float(ss.replace("Z", "")) event_time = ":".join([hh, mm, ss]) d_t = datetime.datetime.fromisoformat(" ".join([event["date"], event_time])) # If the event has a focal mechanism then parse this into the correct format diff --git a/tests/earthquake_test.py b/tests/earthquake_test.py index da8c7d8..c7be905 100644 --- a/tests/earthquake_test.py +++ b/tests/earthquake_test.py @@ -208,3 +208,16 @@ class EarthquakeTestCase(unittest.TestCase): ns_distance = Point(0.0, bbox[1], 0.0).distance(Point(0.0, bbox[3], 0.0)) self.assertAlmostEqual(max_dist, ew_distance, 5) self.assertAlmostEqual(max_dist, ns_distance, 5) + + def test_from_quakeml(self): + # Verifies that the earthquake object can be built from different GEOFON events + event_id_set = ["gfz2021kdvq", "gfz2021keus", "gfz2021kduj"] + target_string_set = [ + "gfz2021kdvq 2021-05-25 09:41:17.200000 (29.35200E, -1.74600N, 10.00 km) M 4.39", + "gfz2021keus 2021-05-25 22:21:36.400000 (122.49800E, 24.83200N, 10.00 km) M 4.56", + "gfz2021kduj 2021-05-25 09:03:03.393825 (29.48394E, -1.78596N, 10.00 km) M 4.59", + ] + results = [] + for event_id in event_id_set: + results.append(str(Earthquake.from_quakeml(event_id))) + self.assertListEqual(results, target_string_set) -- GitLab