Error occurs when using fdsn to get event catalog from USGS


I am using the fdsn to get the catalog from USGS, and get an error, it seems in the catalog it has the event_type as ‘quarry_blast’, but in obspy it is ‘quarry blast’. The code and errors are listed below. Hope we can change this, thanks.

from obspy.fdsn import Client

t1 = UTCDateTime(“2014-03-01T06:30:00.000”)
t2 = UTCDateTime(“2014-03-19T07:30:00.000”)

#get the catalog
client = Client(‘USGS’)
cat = client.get_events(starttime=t1, endtime=t2, minmagnitude=0, includeallorigins = True)

ValueError: Setting attribute "event_type" failed. Value "quarry_blast" could not be converted to type "Enum(["not existing", "not reported", "earthquake", "anthropogenic event", "collapse", "cavity collapse", "mine collapse", "building collapse", "explosion", "accidental explosion", "chemical explosion", "controlled explosion", "experimental explosion", "industrial explosion", "mining explosion", "quarry blast", "road cut", "blasting levee", "nuclear explosion", "induced or triggered event", "rock burst", "reservoir loading", "fluid injection", "fluid extraction", "crash", "plane crash", "train crash", "boat crash", "other event", "atmospheric event", "sonic boom", "sonic blast", "acoustic noise", "thunder", "avalanche", "snow avalanche", "debris avalanche", "hydroacoustic event", "ice quake", "slide", "landslide", "rockslide", "meteorite", "volcanic eruption"])"


Hi Qingkai,

the QuakeML file served from USGS is not conforming to the QuakeML
definition. The QuakeML schema files specify the allowed event type
enumeration strings and they are all space separated.
In short term you can download the requested information directly into a
file (ObsPy saving the raw/unparsed data to file) using the "filename"
option to specify a local filename. You could then correct the file
manually and then read it with ObsPy.

Here's something you could try (to correct without writing to disk):

from StringIO import StringIO
sio = StringIO()
cat = client.get_events(starttime=t1, endtime=t2, minmagnitude=0,
                        includeallorigins=True, filename=sio)
sio2 = StringIO()
sio2.write(re.sub(r'quarry_blast', "quarry blast", sio.buf))
cat = readEvents(sio2)

Unfortunately you will see that there are more non-conforming things in
there, the next one failing is "quarry".

In the long term this should clearly be fixed at USGS, as it is a
violation of the QuakeML standard. Of course it's not a problem for
human readability but for automatic parsers we can not start to
introduce workarounds for problems like this one.

hope it helps,

Hi Tobias,

Thanks for the solution. USGS should make the records more consistent. Anyway, the solution you recommended works like a charm, like you said, there are more non-comforming things in their entries, e.g.“quarry”, “quarry blast_blast” etc. I added them into a dictionary and replace them with the correct entry using your method, and it gives me the results I want. I attach the correct version of the code, in case others also meet the same problem as I did here. Thanks again for help!

I have submitted a bug report to the USGS NEIC to report these issues of the catalog not conforming to the QuakeML standard. The USGS NCEDC catalog (subset of the ANSS catalog) does not appear to have this issue.

Brad Aagaard