from obspy import UTCDateTime
from obspy.core.event import Catalog, Event, Origin, Magnitude
from obspy.geodetics import FlinnEngdahl
cat = Catalog()
cat.description = "Just a fictitious toy example catalog built from scratch"
e = Event()
e.event_type = "not existing"
o = Origin()
o.time = UTCDateTime(2014, 2, 23, 18, 0, 0)
o.latitude = 47.6
o.longitude = 12.0
o.depth = 10000
o.depth_type = "operator assigned"
o.evaluation_mode = "manual"
o.evaluation_status = "preliminary"
o.region = FlinnEngdahl().get_region(o.longitude, o.latitude)
m = Magnitude()
m.mag = 7.2
m.magnitude_type = "Mw"
m2 = Magnitude()
m2.mag = 7.4
m2.magnitude_type = "Ms"
# also included could be: custom picks, amplitude measurements, station magnitudes,
# focal mechanisms, moment tensors, ...
# make associations, put everything together
cat.append(e)
e.origins = [o]
e.magnitudes = [m, m2]
m.origin_id = o.resource_id
m2.origin_id = o.resource_id
print(cat)
cat.write("/tmp/my_custom_events.xml", format="QUAKEML")
!cat /tmp/my_custom_events.xml