Metadata read & write

QuakeML import

This example shows how to read quakeml-event catalogs using QuakeML_load_xml(). The function get_pyrocko_events() is used to obtain events in pyrocko format. If a moment tensor is provided as [Mrr, Mtt, Mpp, Mrt, Mrp, Mtp], this is converted to [mnn, mee, mdd, mne, mnd, med]. The strike, dip and rake values appearing in the pyrocko event are calculated from the moment tensor.

from pyrocko import model
from import quakeml
from pyrocko.example import get_example_data

# small catalog containing two events (data from ingv):
catalog = get_example_data('example-catalog.xml')

# read quakeml events
qml = quakeml.QuakeML.load_xml(filename=catalog)

# get pyrocko events
events = qml.get_pyrocko_events()

for event in events:

# save events as pyrocko catalog:
model.event.dump_events(events, filename='')

StationXML import

This example shows how to import StationXML files and extract pyrocko.Station objects

from import stationxml
from pyrocko.example import get_example_data

# Download example StationXML file

# load the StationXML downloaded data file
sx = stationxml.load_xml(filename='responses.xml')

# Extract Station objects from FDSNStationXML object
pyrocko_stations = sx.get_pyrocko_stations()

Pyrocko stations to StationXML

This example shows how to import pyrocko stations and save FDSN StationXML files.

from import stationxml
from pyrocko import model
from pyrocko.example import get_example_data

# get example data
station_file = get_example_data('stations.txt')

# load pyrocko stations
stations = model.station.load_stations(station_file)

# get station xml from pyrocko stations
st_xml = stationxml.FDSNStationXML.from_pyrocko_stations(stations)

# save stations as xml file