Creating an ASDF FileΒΆ

This example demonstrates how the create a new ASDF file from waveform data in any format ObsPy can read, a QuakeML file, and a list of StationXML files.

Note

Do NOT run this with MPI. This would require some modifications and is very likely not worth the effort.

 1import glob
 2import os
 3
 4from pyasdf import ASDFDataSet
 5
 6filename = "observed.h5"
 7
 8if os.path.exists(filename):
 9    raise Exception("File '%s' exists." % filename)
10
11ds = ASDFDataSet(filename)
12
13# Add event
14ds.add_quakeml("./GCMT_event_SOUTH_SANDWICH_ISLANDS_REGION_Mag_5.6_2010-3-11-6.xml")
15event = ds.events[0]
16
17# Add waveforms.
18filenames = glob.glob("./SAC/*.SAC")
19for _i, filename in enumerate(filenames):
20    print("Adding SAC file %i of %i..." % (_i + 1, len(filenames)))
21    # We associate the waveform with the previous event. This is optional
22    # but recommended if the association is meaningful.
23    ds.add_waveforms(filename, tag="raw_recording", event_id=event)
24
25# Add StationXML files.
26filenames = glob.glob("./StationXML/*.xml")
27for _i, filename in enumerate(filenames):
28    print("Adding StationXML file %i of %i..." % (_i + 1, len(filenames)))
29    ds.add_stationxml(filename)