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 pyrocko.io 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:
print(event)
# save events as pyrocko catalog:
model.event.dump_events(events, filename='test_pyrocko.pf')
StationXML import¶
This example shows how to import StationXML files and extract pyrocko.Station objects
from pyrocko.io import stationxml
from pyrocko.example import get_example_data
# Download example StationXML file
get_example_data('responses.xml')
# 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 pyrocko.io 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
st_xml.dump_xml(filename='stations.xml')
Create a StationXML file with flat displacement responses¶
In this example, we read a Pyrocko basic station file, create an FDSN StationXML structure from it and add flat reponses to all channels. The created StationXML file could e.g. be used in combination with restituted data, to properly indicate that we are dealing with displacement seismograms given in [m].
from pyrocko.io import stationxml as fdsn
from pyrocko import model
from pyrocko.example import get_example_data
get_example_data('stations.txt')
stations = model.load_stations('stations.txt')
station_xml = fdsn.FDSNStationXML.from_pyrocko_stations(stations)
for network in station_xml.network_list:
for station in network.station_list:
for channel in station.channel_list:
channel.response = fdsn.Response(
instrument_sensitivity=fdsn.Sensitivity(
value=1.0,
frequency=1.0,
input_units=fdsn.Units('M'),
output_units=fdsn.Units('COUNTS')))
station_xml.validate()
# print(station_xml.dump_xml())
station_xml.dump_xml(filename='stations_flat_displacement.xml')