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(
15 "./GCMT_event_SOUTH_SANDWICH_ISLANDS_REGION_Mag_5.6_2010-3-11-6.xml"
16)
17event = ds.events[0]
18
19# Add waveforms.
20filenames = glob.glob("./SAC/*.SAC")
21for _i, filename in enumerate(filenames):
22 print("Adding SAC file %i of %i..." % (_i + 1, len(filenames)))
23 # We associate the waveform with the previous event. This is optional
24 # but recommended if the association is meaningful.
25 ds.add_waveforms(filename, tag="raw_recording", event_id=event)
26
27# Add StationXML files.
28filenames = glob.glob("./StationXML/*.xml")
29for _i, filename in enumerate(filenames):
30 print("Adding StationXML file %i of %i..." % (_i + 1, len(filenames)))
31 ds.add_stationxml(filename)