From a3e3c12df0c77cfb613c505d157893de1b91fb23 Mon Sep 17 00:00:00 2001 From: "E. Joshua Rigler" <erigler@usgs.gov> Date: Mon, 30 Mar 2020 15:32:18 -0600 Subject: [PATCH] Handle empty buffer returned from Edge ObsPy's waveserver.py (and associated methods) do not handle an empty buffer returned from Edge's earthworm server. In short, they generate a None value instead of an empty byte string as one might expect (and they clearly did expect, since they attempted `len(dat)` where dat was expected to be a byte string, but was a None object if/when Edge had no data. This fix employs a try/except clause to generate an empty string if the waveserver client fails with a TypeError, as is the case when Edge returns an empty buffer. --- geomagio/edge/EdgeFactory.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/geomagio/edge/EdgeFactory.py b/geomagio/edge/EdgeFactory.py index bdecb483b..4602b0b98 100644 --- a/geomagio/edge/EdgeFactory.py +++ b/geomagio/edge/EdgeFactory.py @@ -484,9 +484,14 @@ class EdgeFactory(TimeseriesFactory): location = self._get_edge_location(observatory, channel, type, interval) network = self._get_edge_network(observatory, channel, type, interval) edge_channel = self._get_edge_channel(observatory, channel, type, interval) - data = self.client.get_waveforms( - network, station, location, edge_channel, starttime, endtime - ) + try: + data = self.client.get_waveforms( + network, station, location, edge_channel, starttime, endtime + ) + except TypeError: + # get_waveforms() fails if no data is returned from Edge + data = obspy.core.Stream() + # make sure data is 32bit int for trace in data: trace.data = trace.data.astype("i4") -- GitLab