Dear ObsPy users,
I'm trying to write quakeml using ObsPy.
From a flat text input file, I get values to create lists of Magnitude and Origin instances (one per list). Magnitude has a magnitude and magnitude type value. Origin has a time, latitude, longitude and depth value).
I make and Event instance with these two and then append this event to a Catalog instance.
Catalog.__str__(print_all=True) outputs all the values proprely, except for depth but it's present in the Origin instance so I presume that's normal.
I then call the Catalog write method but I get the following error (full error at the end of message):
KeyError: 'preferred_origin_id'
From what I understand the preferred origin is optional so I don't really understand why writing fails on this error. Also, I don't seem to find a clear indication as to how to specify this preferred origin if it is required. I've tried setting the same resource_id for all elements but that doesn't improve things.
Can anyone point me in the right direction here?
Thanks.
Best regards,
Oliver
Full error log:
Traceback (most recent call last):
File "./obspy-quakeml-write-trial.py", line 55, in <module>
cat.write(QUAKEML_FILE, format="QUAKEML")
File "/usr/lib/python2.7/site-packages/obspy.core-0.7.1-py2.7.egg/obspy/core/event.py", line 2555, in write
writeFormat(self, filename, **kwargs)
File "/usr/lib/python2.7/site-packages/obspy.core-0.7.1-py2.7.egg/obspy/core/quakeml.py", line 1316, in writeQuakeML
xml_doc = Pickler().dumps(catalog)
File "/usr/lib/python2.7/site-packages/obspy.core-0.7.1-py2.7.egg/obspy/core/quakeml.py", line 749, in dumps
return self._serialize(catalog)
File "/usr/lib/python2.7/site-packages/obspy.core-0.7.1-py2.7.egg/obspy/core/quakeml.py", line 1241, in _serialize
self._str(event.preferred_origin_id, event_el, 'preferredOriginID')
File "/usr/lib/python2.7/site-packages/obspy.core-0.7.1-py2.7.egg/obspy/core/util/attribdict.py", line 79, in __getitem__
return super(AttribDict, self).__getitem__(name)
KeyError: 'preferred_origin_id'