[obspy-users] resource_id problem with obspy.core.event.Pick

Dylan Mikesell dylanmikesell at boisestate.edu
Thu Jul 14 06:05:27 CEST 2016


Hi Obspy users,

I am trying to write a quakeml file from a coincidence trigger in obspy. I
got the following example from Tobias this morning.

https://github.com/obspy/docs/blob/master/workshops/2016-03-07_ipgp/06_Event_metadata-with_solutions.ipynb

This works just fine and I can create an xml file that contains a catalog
with multiple events. Each event has origin and magnitude objects in it.

But when I try to add picks to each event I get a resource_id error when
attempting to write the quakeml file. As soon as I append this pick to the
event object and then add the event object to the catalog object, my
quakeml write fails.

Traceback (most recent call last):

  File "<ipython-input-1142-3f30ed9156b8>", line 38, in <module>
    cat.write( fileNameOut, format="QUAKEML")

  File
"/Users/dmikesell/anaconda/lib/python2.7/site-packages/obspy/core/event/catalog.py",
line 501, in write

  File
"/Users/dmikesell/anaconda/lib/python2.7/site-packages/obspy/io/quakeml/core.py",
line 1810, in _write_quakeml

  File
"/Users/dmikesell/anaconda/lib/python2.7/site-packages/obspy/io/quakeml/core.py",
line 1067, in dumps

  File
"/Users/dmikesell/anaconda/lib/python2.7/site-packages/obspy/io/quakeml/core.py",
line 1740, in _serialize

  File
"/Users/dmikesell/anaconda/lib/python2.7/site-packages/obspy/io/quakeml/core.py",
line 1486, in _pick

AttributeError: 'str' object has no attribute 'resource_id'

Any ideas what the problem is? I have looked around all morning to figure
out this resource_id stuff, but I am not sure what I am missing. I tried
today with the output from the streamPick() module (
https://github.com/miili/wavePicker) and it works just fine. I am not sure
how because I made the to Picks look identical. But the one I created using
Pick() failed and the one created with streamPick.getPicks() worked.

Thanks,

Dylan


import os
from obspy.core.event import Catalog, Event, Origin, Magnitude, Pick,
WaveformStreamID
from obspy.core.utcdatetime import UTCDateTime
from streamPick import *
from obspy.core import read

#------------------------------------------------------------------------------
# Make sure the output directory exists and if not, then create
def ensure_dir(f):
    d = os.path.dirname(f)
    if not os.path.exists(d):
        os.makedirs(d)

time = UTCDateTime("2012-09-07T12:15:00")

# origin information
o = Origin()
o.time = time
o.latitude = 0.0
o.longitude = 0.0
o.depth = 0
o.depth_type = "operator assigned"
o.evaluation_mode = "automatic"
o.evaluation_status = "preliminary"

# magnitude information
m = Magnitude()
m.mag = 0.0
m.magnitude_type = "Mw"
m.origin_id = o.resource_id

st = read()

p = Pick()
p.waveform_id = WaveformStreamID(network_code='TA',
                         station_code='DYL',
                         location_code='',
                         channel_code='BHZ')
creation_info =
event.CreationInfo(author='Dylan',creation_time=UTCDateTime())
p.creation_info = creation_info
p.onset = "impulsive"
p.polarity = "positive"
p.evaluation_mode = "manual"
p.evaluation_status = "preliminary"
p.time = time + 10
#p.time_errors.uncertainty = 0.1
p.phase_hint = 'P'

e = Event() # make new event
e.event_type = "not existing"
e.creation_info = "Dylan Mikesell (dylanmikesell at boisestate.edu)"
# make associations, put everything together
#e.picks = p
e.origins = [o] # need the square brackets for some reason!!
e.magnitudes = [m] # need the square brackets for some reason!!

cat = Catalog() # make empty catalog for saving
cat.append(e)
cat[0].picks = p

# This actually works and I don't know why. The Pick structure is identical.
#new_picks = streamPick(st)
#p2 = new_picks.getPicks()


print(cat)
fileNameOut = os.path.join('/tmp/', "events.xml")
ensure_dir(fileNameOut)
cat.write( fileNameOut, format="QUAKEML")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.swapbytes.de/pipermail/obspy-users/attachments/20160713/047f0f2b/attachment.html>


More information about the obspy-users mailing list