Metadata read & write

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')