Addition and export of focal mechanism information to a catalog event

Hi Obspy users,

I am trying to add focal mechanism information into an event catalog, then export as quakeML.
I have a test catalog (merge2) that includes an event for which a mechanism is available in cat_focmec.
Before the export, it seems the source.NodalPlane information is assigned properly in merge3:
“print(merge3.events[-1].source)” returns:
AttribDict({‘NodalPlane’: NodalPlane(strike=265.0, dip=66.0, rake=-147.0)})

But this information is not exported when writing the merge3 catalog to quakeML.
I do not get any error message from the write method.

Do I have to provide error bars for the dip, strike and rake for the export to work?

If someone with more experience than myself can help with this, I’d appreciate it !

Cheers,
Gaël

The code I use:

for ev in merge2:
  time_ev = ev.origins[0].time
  tf = time_ev + timedelta(seconds=-20); tt = time_ev + timedelta(seconds=20)
  timeFrom = tf.strftime("%Y-%m-%dT%H:%M:%S.%fZ"); timeTo = tt.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
  cat_focmec_sel = cat_focmec.filter("time > " + timeFrom, "time < " + timeTo)
  print(cat_focmec_sel)
  if cat_focmec_sel.count() == 1:
     print("Found a focal mechanism for event at " + time_ev.strftime("%Y-%m-%dT%H:%M:%S.%fZ"))
     merge3.events.append(ev)
     tmpMec.dip = cat_focmec_sel[0].origins[0].longitude
     tmpMec.strike = cat_focmec_sel[0].origins[0].latitude
     tmpMec.rake = cat_focmec_sel[0].magnitudes[0].mag
     merge3.events[-1].source = OrderedDict()
     merge3.events[-1].source.NodalPlane = tmpMec
     print(merge3.events[-1].source)
     tmpMec.clear()
  elif cat_focmec_sel.count() == 0:  # Event has no focal mechanism...
     merge3.events.append(ev)

merge3.write("merge3.xml", format="QUAKEML")

The log I get for that one event:

1 Event(s) in Catalog:
2017-12-01T09:45:39.620000Z | +265.000,  +66.000 | -147.0 None
Found a focal mechanism for event at 2017-12-01T09:45:27.372337Z
AttribDict({'NodalPlane': NodalPlane(strike=265.0, dip=66.0, rake=-147.0)})

Kia ora Gaël,

Focal Mechanisms in ObsPy events (and QuakeML) should be added as FocalMechanism objects under the focal_mechanisms attribute. See the docs for this object.

For example, if you wanted to add a focal mechanism to an event you could do something like:

event.focal_mechanisms.append(FocalMechanism(
   nodal_planes=NodalPlanes(nodal_plane_1=NodalPlane(
      strike=180, dip=90, rake=10))))

This is quite a nested structure, and can be a little confusing, but should ensure that the mechanism is written correctly to QuakeML.

Bonjour Calum,

This seems to solve my problem…!!
Thanks a lot for the support from down under, it helped a lot.

Cheers,
Gaël