コード例 #1
0
from pyrocko import io
from pyrocko.io import rdseed
from pyrocko.example import get_example_data

# Note: this example requires *rdseed* available e.g. at:
# https://ds.iris.edu/

rdseed.check_have_rdseed()

# Download example data
get_example_data('station_info.dseed')
get_example_data('traces_italy.mseed')

# read dataless seed file
seed_volume = rdseed.SeedVolumeAccess('station_info.dseed')

# load traces:
traces = io.load('traces_italy.mseed')

out_traces = []

for tr in traces:

    # get response information
    resp = seed_volume.get_pyrocko_response(tr, target='dis')

    # restitute
    displacement = tr.transfer(tfade=100.,
                               freqlimits=(0.01, 0.02, 5., 10.),
                               invert=True,
                               transfer_function=resp)
コード例 #2
0
from pyrocko import pile, io, util, model
from pyrocko.example import get_example_data

# Download example data
get_example_data('data_conversion', recursive=True)

input_path = 'data_conversion/mseed'
output_path = 'data_conversion/sac/' \
        '%(dirhz)s/%(station)s_%(channel)s_%(tmin)s.sac'

fn_stations = 'data_conversion/stations.txt'

stations_list = model.load_stations(fn_stations)

stations = {}
for s in stations_list:
    stations[s.network, s.station, s.location] = s
    s.set_channels_by_name(*'BHN BHE BHZ BLN BLE BLZ'.split())

p = pile.make_pile(input_path)
h = 3600.
tinc = 1 * h
tmin = util.day_start(p.tmin)
for traces in p.chopper_grouped(tmin=tmin,
                                tinc=tinc,
                                gather=lambda tr: tr.nslc_id):
    for tr in traces:
        dirhz = '%ihz' % int(round(1. / tr.deltat))
        io.save([tr],
                output_path,
                format='sac',
コード例 #3
0
from pyrocko import pile, io, util, model
from pyrocko.example import get_example_data

# Download example data
get_example_data('data_conversion', recursive=True)

input_path = 'data_conversion/mseed'
output_path = 'data_conversion/sac/' \
        '%(dirhz)s/%(station)s_%(channel)s_%(tmin)s.sac'

fn_stations = 'data_conversion/stations.txt'

stations_list = model.load_stations(fn_stations)

stations = {}
for s in stations_list:
    stations[s.network, s.station, s.location] = s
    s.set_channels_by_name(*'BHN BHE BHZ BLN BLE BLZ'.split())

p = pile.make_pile(input_path)
h = 3600.
tinc = 1*h
tmin = util.day_start(p.tmin)
for traces in p.chopper_grouped(tmin=tmin, tinc=tinc,
                                gather=lambda tr: tr.nslc_id):
    for tr in traces:
        dirhz = '%ihz' % int(round(1./tr.deltat))
        io.save(
            [tr], output_path,
            format='sac',
            additional={'dirhz': dirhz},
コード例 #4
0
# Data from Hudnut et al. 1996

# K. W. Hudnut, Z. Shen, M. Murray, S. McClusky, R. King, T. Herring,
# B. Hager, Y. Feng, P. Fang, A. Donnellan, Y. Bock;
# Co-seismic displacements of the 1994 Northridge, California, earthquake.
# Bulletin of the Seismological Society of America; 86 (1B): S19-S36. doi:

# https://pasadena.wr.usgs.gov/office/hudnut/hudnut/nr_bssa.html

mm = 1e3

fn_stations = 'GPS_Stations-Northridge-1994_Hudnut.csv'
fn_displacements = 'GPS_Data-Northridge-1994_Hudnut.csv'

get_example_data(fn_stations)
get_example_data(fn_displacements)

campaign = gnss.GNSSCampaign(name='Northridge 1994')

# Load the stations
with open(fn_stations, 'r') as f:
    for line in f:
        if line.startswith('#'):
            continue
        row = line.split(',')
        sta = gnss.GNSSStation(
            code=row[0].strip(),
            lat=float(row[1]),
            lon=float(row[2]),
            elevation=float(row[3]))
コード例 #5
0
from pyrocko import pz, io, trace
from pyrocko.example import get_example_data

# Download example data
get_example_data('STS2-Generic.polezero.txt')
get_example_data('test.mseed')

# read poles and zeros from SAC format pole-zero file
zeros, poles, constant = pz.read_sac_zpk('STS2-Generic.polezero.txt')

# one more zero to convert from velocity->counts to displacement->counts
zeros.append(0.0j)

rest_sts2 = trace.PoleZeroResponse(zeros=zeros, poles=poles, constant=constant)

traces = io.load('test.mseed')
out_traces = list(traces)
for tr in traces:

    displacement = tr.transfer(
        1000.,  # rise and fall of time window taper in [s]
        (0.001, 0.002, 5., 10.),  # frequency domain taper in [Hz]
        transfer_function=rest_sts2,
        invert=True)  # to change to (counts->displacement)

    # change channel id, so we can distinguish the traces in a trace viewer.
    displacement.set_codes(channel='D' + tr.channel[-1])

    out_traces.append(displacement)

io.save(out_traces, 'displacement.mseed')
コード例 #6
0
from pyrocko import io
from pyrocko.example import get_example_data

get_example_data('test.mseed')
traces = io.load('test.mseed')

for it, t in enumerate(traces):
    with open('test-%i.txt' % it, 'w') as f:
        for tim, val in zip(t.get_xdata(), t.get_ydata()):
            f.write('%20f %20g\n' % (tim, val))
コード例 #7
0
ファイル: automap_example.py プロジェクト: hvasbath/pyrocko
from pyrocko.plot.automap import Map
from pyrocko.example import get_example_data
from pyrocko import util, model,automap, orthodrome as od, moment_tensor as pmt, \
    gmtpy


gmtpy.check_have_gmt()

# Download example data
get_example_data('stations_deadsea.pf')
get_example_data('deadsea_events_1976-2017.txt')

# Generate the basic map
m = Map(
    lat=31.5,
    lon=35.5,
    radius=150000.,
    width=30., height=30.,
    show_grid=False,
    show_topo=True,
    color_dry=(238, 236, 230),
    topo_cpt_wet='light_sea_uniform',
    topo_cpt_dry='light_land_uniform',
    illuminate=True,
    illuminate_factor_ocean=0.15,
    show_rivers=False,
    show_plates=True)

# Draw some larger cities covered by the map area
m.draw_cities()
コード例 #8
0
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')
コード例 #9
0
import os

from pyrocko import io, trace, evalresp_ext
from pyrocko.example import get_example_data

# Get online data
get_example_data('1989.072.evt.mseed')

traces = io.load('1989.072.evt.mseed')
out_traces = []
for tr in traces:
    respfn = tr.fill_template(
        'RESP.%(network)s.%(station)s.%(location)s.%(channel)s')

    if os.path.exists(respfn):

        try:
            resp = trace.InverseEvalresp(respfn, tr, target='dis')

            tr.extend(tr.tmin - 100., tr.tmax, fillmethod='repeat')

            displacement = tr.transfer(
                100.,  # rise and fall of time domain taper in [s]
                (0.005, 0.01, 1., 2.),  # frequency domain taper in [Hz]
                transfer_function=resp)

            # change channel id, so we can distinguish the traces in a trace
            # viewer.
            displacement.set_codes(channel='D'+tr.channel[-1])

            out_traces.append(displacement)
コード例 #10
0
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')

comp_to_azi_dip = {
    'X': (0., 0.),
    'Y': (90., 0.),
    'Z': (0., -90.),
}

# step through all the networks within the data file
for network in sx.network_list:

    # step through all the stations per networks
    for station in network.station_list:

        # step through all the channels per stations
        for channel in station.channel_list:
            azi, dip = comp_to_azi_dip[channel.code[-1]]

            # change the azimuth and dip of the channel per channel alpha code
            channel.azimuth.value = azi
            channel.dip.value = dip

            # set the instrument input units to 'M'eters
            channel.response.instrument_sensitivity.input_units.name = 'M'
コード例 #11
0
from pyrocko.plot import response
from pyrocko.example import get_example_data

# download example data
get_example_data('test_response.resp')

# read data
resps, labels = response.load_response_information('test_response.resp',
                                                   'resp')

# plot response and save image
response.plot(responses=resps,
              labels=labels,
              filename='test_response.png',
              fmin=0.001,
              fmax=400.,
              dpi=75.)
コード例 #12
0
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')
コード例 #13
0
from pyrocko.example import get_example_data

import obspy
from pyrocko import obspy_compat
obspy_compat.plant()

get_example_data('test.mseed')
get_example_data('geeil.geofon.xml')

# Read in MiniSEED data through ObsPy
inv = obspy.read_inventory('geeil.geofon.xml')
stream = obspy.read('test.mseed')

# Start the Snuffler
stream.snuffle(inventory=inv)
コード例 #14
0
ファイル: automap_example.py プロジェクト: esiwgnahz/pyrocko
from pyrocko import model
from pyrocko import gmtpy
from pyrocko.plot.automap import Map
from pyrocko.example import get_example_data


gmtpy.check_have_gmt()

# Download example data
get_example_data('stations_deadsea.pf')

# Generate the basic map
m = Map(
    lat=31.5,
    lon=35.5,
    radius=100000.,
    width=30., height=30.,
    show_grid=False,
    show_topo=True,
    color_dry=(238, 236, 230),
    topo_cpt_wet='light_sea_uniform',
    topo_cpt_dry='light_land_uniform',
    illuminate=True,
    illuminate_factor_ocean=0.15,
    show_rivers=False,
    show_plates=True)

# Draw some larger cities covered by the map area
m.draw_cities()

# Generate with latitute, longitude and labels of the stations
コード例 #15
0
from pyrocko import util
from pyrocko.gui import marker as pm
from pyrocko.example import get_example_data

# Download example markers
get_example_data('my_markers.pf')

markers = pm.load_markers('my_markers.pf')
pm.associate_phases_to_events(markers)

for marker in markers:
    print(util.time_to_str(marker.tmin), util.time_to_str(marker.tmax))

    # only event and phase markers have an event attached
    if isinstance(marker, (pm.EventMarker, pm.PhaseMarker)):
        ev = marker.get_event()
        print(ev)  # may be shared between markers
コード例 #16
0
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')
コード例 #17
0
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')
コード例 #18
0
import os

from pyrocko import io, trace, evalresp_ext
from pyrocko.example import get_example_data

# Get online data
get_example_data('1989.072.evt.mseed')

traces = io.load('1989.072.evt.mseed')
out_traces = []
for tr in traces:
    respfn = tr.fill_template(
        'RESP.%(network)s.%(station)s.%(location)s.%(channel)s')

    if os.path.exists(respfn):

        try:
            resp = trace.InverseEvalresp(respfn, tr, target='dis')

            tr.extend(tr.tmin - 100., tr.tmax, fillmethod='repeat')

            displacement = tr.transfer(
                100.,  # rise and fall of time domain taper in [s]
                (0.005, 0.01, 1., 2.),  # frequency domain taper in [Hz]
                transfer_function=resp)

            # change channel id, so we can distinguish the traces in a trace
            # viewer.
            displacement.set_codes(channel='D' + tr.channel[-1])

            out_traces.append(displacement)
コード例 #19
0
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')
コード例 #20
0
# Data from Hudnut et al. 1996

# K. W. Hudnut, Z. Shen, M. Murray, S. McClusky, R. King, T. Herring,
# B. Hager, Y. Feng, P. Fang, A. Donnellan, Y. Bock;
# Co-seismic displacements of the 1994 Northridge, California, earthquake.
# Bulletin of the Seismological Society of America ; 86 (1B): S19–S36. doi:

# https://pasadena.wr.usgs.gov/office/hudnut/hudnut/nr_bssa.html

mm = 1e3

fn_stations = 'GPS_Stations-Northridge-1994_Hudnut.csv'
fn_displacements = 'GPS_Data-Northridge-1994_Hudnut.csv'

get_example_data(fn_stations)
get_example_data(fn_displacements)

campaign = gnss.GNSSCampaign(name='Northridge 1994')

# Load the stations
with open(fn_stations, 'r') as f:
    for line in f:
        if line.startswith('#'):
            continue
        row = line.split(',')
        sta = gnss.GNSSStation(
            code=row[0].strip(),
            lat=float(row[1]),
            lon=float(row[2]),
            elevation=float(row[3]))
コード例 #21
0
from pyrocko import io
from pyrocko.io import rdseed
from pyrocko.example import get_example_data

# Note: this example requires *rdseed* available e.g. at:
# https://ds.iris.edu/

rdseed.check_have_rdseed()

# Download example data
get_example_data('station_info.dseed')
get_example_data('traces_italy.mseed')

# read dataless seed file
seed_volume = rdseed.SeedVolumeAccess('station_info.dseed')

# load traces:
traces = io.load('traces_italy.mseed')

out_traces = []

for tr in traces:

    # get response information
    resp = seed_volume.get_pyrocko_response(tr, target='dis')

    # restitute
    displacement = tr.transfer(
        tfade=100.,
        freqlimits=(0.01, 0.02, 5., 10.),
        invert=True,
コード例 #22
0
from pyrocko.plot.automap import Map
from pyrocko.example import get_example_data
from pyrocko import model, gmtpy
from pyrocko import moment_tensor as pmt

gmtpy.check_have_gmt()

# Download example data
get_example_data('stations_deadsea.pf')
get_example_data('deadsea_events_1976-2017.txt')

# Generate the basic map
m = Map(lat=31.5,
        lon=35.5,
        radius=150000.,
        width=30.,
        height=30.,
        show_grid=False,
        show_topo=True,
        color_dry=(238, 236, 230),
        topo_cpt_wet='light_sea_uniform',
        topo_cpt_dry='light_land_uniform',
        illuminate=True,
        illuminate_factor_ocean=0.15,
        show_rivers=False,
        show_plates=True)

# Draw some larger cities covered by the map area
m.draw_cities()

# Generate with latitute, longitude and labels of the stations
コード例 #23
0
from pyrocko import pz, io, trace
from pyrocko.example import get_example_data

# Download example data
get_example_data('STS2-Generic.polezero.txt')
get_example_data('test.mseed')

# read poles and zeros from SAC format pole-zero file
zeros, poles, constant = pz.read_sac_zpk('STS2-Generic.polezero.txt')

# one more zero to convert from velocity->counts to displacement->counts
zeros.append(0.0j)

rest_sts2 = trace.PoleZeroResponse(
    zeros=zeros,
    poles=poles,
    constant=constant)

traces = io.load('test.mseed')
out_traces = list(traces)
for tr in traces:

    displacement = tr.transfer(
        1000.,                    # rise and fall of time window taper in [s]
        (0.001, 0.002, 5., 10.),  # frequency domain taper in [Hz]
        transfer_function=rest_sts2,
        invert=True)              # to change to (counts->displacement)

    # change channel id, so we can distinguish the traces in a trace viewer.
    displacement.set_codes(channel='D'+tr.channel[-1])