Skip to content

Commit

Permalink
adapt to new module scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius Kriegerowski committed Aug 2, 2017
1 parent 6546d10 commit 4ec5245
Show file tree
Hide file tree
Showing 27 changed files with 98 additions and 99 deletions.
2 changes: 1 addition & 1 deletion ahfullgreen.py
Expand Up @@ -4,7 +4,7 @@

from PyQt4.QtCore import *
from pyrocko import moment_tensor, model, trace
from pyrocko.snuffling import Snuffling, Param, Choice, Switch, EventMarker
from pyrocko.gui.snuffling import Snuffling, Param, Choice, Switch, EventMarker
from pyrocko import gf
from pyrocko.ahfullgreen import add_seismogram, Gauss, Impulse

Expand Down
2 changes: 1 addition & 1 deletion audio.py
@@ -1,7 +1,7 @@
from __future__ import print_function

from PyQt4.QtCore import QThread, SIGNAL, QTimer
from pyrocko.snuffling import Snuffling, Param, Choice, Switch, NoTracesSelected
from pyrocko.gui.snuffling import Snuffling, Param, Choice, Switch, NoTracesSelected
import pyrocko.trace as trace
from pyrocko.trace import CosFader
from scipy.io.wavfile import write, read
Expand Down
2 changes: 1 addition & 1 deletion beam_stack.py
@@ -1,6 +1,6 @@
from __future__ import print_function

from pyrocko.snuffling import Snuffling, Param, Switch, Choice
from pyrocko.gui.snuffling import Snuffling, Param, Switch, Choice
from pyrocko.model import Station, dump_stations
from pyrocko import orthodrome as ortho
from pyrocko import util, io, trace
Expand Down
4 changes: 2 additions & 2 deletions cake_phase.py
@@ -1,7 +1,7 @@
from builtins import str
import os
from pyrocko.snuffling import Snuffling, Param, Switch, Choice
from pyrocko.pile_viewer import PhaseMarker
from pyrocko.gui.snuffling import Snuffling, Param, Switch, Choice
from pyrocko.gui.pile_viewer import PhaseMarker
from pyrocko import orthodrome
from pyrocko import gf
from pyrocko import cake
Expand Down
4 changes: 2 additions & 2 deletions catalog_stats.py
@@ -1,5 +1,5 @@
from pyrocko.snuffling import Snuffling, Param, Choice
from pyrocko.gui_util import EventMarker
from pyrocko.gui.snuffling import Snuffling, Param, Choice
from pyrocko.gui.gui_util import EventMarker
from pyrocko import util
from pyrocko import moment_tensor
from pyrocko.orthodrome import distance_accurate50m as distance
Expand Down
15 changes: 7 additions & 8 deletions cc_matrix/snuffling.py
@@ -1,19 +1,19 @@
from __future__ import print_function

import sys
import logging
import os.path as op
import numpy as num
import progressbar
import matplotlib.pyplot as plt

from pyrocko import model, trace, util, orthodrome, cake, gui_util
from pyrocko import trace, util, cake
from pyrocko.gf import Target
from pyrocko.snuffling import Snuffling, Choice, Param, Switch
from similarity import SimilarityMatrix, Similarity
import matplotlib.pyplot as plt
from pyrocko.gui.snuffling import Snuffling, Choice, Param, Switch

util.setup_logging('cc.py')
logger = logging.getLogger('cc-snuffling')


def make_targets(pile, stations):
targets = []
for nslc_id in pile.nslc_ids.keys():
Expand Down Expand Up @@ -128,7 +128,7 @@ def call(self):
load_data=False))
traces = [tr for trs in traces for tr in trs ]
visible_nslcs = [tr.nslc_id for tr in traces]
stations = [x for x in stations is util.match_nslcs(
stations = [x for x in stations if util.match_nslcs(
"%s.%s.%s.*" % x.nsl(), visible_nslcs)]

# TODO option to choose other models
Expand All @@ -148,7 +148,6 @@ def call(self):
vmax=float(self.vmax),
vmin=float(self.vmin))
similarities = []
trs2add = []
if self.save_traces :
figure_dir = self.input_directory(caption='Select directory to store images')
for itarget, target in enumerate(targets):
Expand Down Expand Up @@ -210,7 +209,6 @@ def call(self):
t_mini, v_mini = c_tr_chopped.min()
t_maxi, v_maxi = c_tr_chopped.max()
b_tr_shifted = b_tr.copy()
a_tr_shifted = a_tr.copy()

if abs(v_mini) > abs(v_maxi):
v_cc = v_mini
Expand Down Expand Up @@ -285,5 +283,6 @@ def save(self):
output_filename = self.output_filename()
self.similarity_matrix.dump(filename=output_filename)


def __snufflings__():
return [SimilaritySnuffling()]
57 changes: 26 additions & 31 deletions cc_relocation.py
@@ -1,30 +1,32 @@
from __future__ import print_function
from builtins import range

from pyrocko.snuffling import Snuffling, Param, Switch, NoViewerSet, Choice
from pyrocko.trace import Trace
from pyrocko.pile_viewer import Marker, EventMarker, PhaseMarker
from pyrocko import io, trace, util, cake, crust2x2, orthodrome, model
import numpy as num
import logging, math

from pyrocko.gui.snuffling import Snuffling, Param, Switch, NoViewerSet, Choice
from pyrocko.gui.pile_viewer import Marker, EventMarker, PhaseMarker
from pyrocko.trace import Trace
from pyrocko import io, trace, util, cake, orthodrome, model
from pyrocko.dataset import crust2x2

km = 1000.
d2r = math.pi / 180.


class CorrelateEvents(Snuffling):

def setup(self):
self.set_name('Cross correlation relocation')
self.add_parameter(Param('Highpass [Hz]', 'corner_highpass', 1.0,
0.001, 50., low_is_none=True))
self.add_parameter(Param('Lowpass [Hz]', 'corner_lowpass', 4.0,
self.add_parameter(Param('Lowpass [Hz]', 'corner_lowpass', 4.0,
0.001, 50., high_is_none=True))
self.add_parameter(Param('Time window begin', 'tstart', -1.0,
-100., 0.))
self.add_parameter(Param('Time window end', 'tend', 3.0,
0., 100.))

self.add_parameter(Param('Minimum correlation', 'min_corr', 0.5,
self.add_parameter(Param('Minimum correlation', 'min_corr', 0.5,
0.0, 1.0))

self.add_parameter(Param('Replace master depth [km]', 'master_depth_km', None,
Expand All @@ -33,9 +35,9 @@ def setup(self):
self.add_parameter(Switch('Save figure', 'save', False))
self.add_parameter(Switch('Fix depth', 'fix_depth', False))
self.add_parameter(Switch('Show correlation traces', 'show_correlation_traces', False))
self.add_parameter(Choice('Weighting', 'weighting', 'cubic',
self.add_parameter(Choice('Weighting', 'weighting', 'cubic',
['equal', 'linear', 'quadratic']))
self.add_parameter(Choice('Earth model', 'model_select', 'Global',
self.add_parameter(Choice('Earth model', 'model_select', 'Global',
['Global (ak135)', 'Local (from crust2x2)']))

self.set_live_update(False)
Expand Down Expand Up @@ -111,7 +113,7 @@ def call(self):
azi = orthodrome.azimuth(master, station)

arrivals = self.model.arrivals(
phases=phases[phasename][0],
phases=phases[phasename][0],
distances=[ dist*cake.m2d ],
zstart = master_depth,
zstop = 0.0)
Expand All @@ -127,7 +129,7 @@ def call(self):
math.cos(azi*d2r) * math.sin(takeoff*d2r) * u,
math.sin(azi*d2r) * math.sin(takeoff*d2r) * u,
math.cos(takeoff*d2r) * u ])

# gather picks for each event

for ev in events:
Expand All @@ -149,7 +151,7 @@ def call(self):
nsp = station.network, station.station, phasename
datasyn.append(tt.get(nsp,None))
for ev in events:
if nsp in ev.picks:
if nsp in ev.picks:
ttobs = ev.picks[nsp] - ev.time
else:
ttobs = None
Expand Down Expand Up @@ -193,7 +195,7 @@ def call(self):
iev = event_to_number[ev]
for istation, station in enumerate(stations):
nsp = station.network, station.station, phasename
if nsp in tt and nsp in ev.picks:
if nsp in tt and nsp in ev.picks:
tarr = ev.time + tt[nsp]
tarr_ec = tarr + tt_corr_event[iphasename, iev]
tarr_ec_sc = tarr_ec + tt_corr_station[iphasename, istation]
Expand All @@ -206,7 +208,7 @@ def call(self):
data = num.array(data, dtype=num.float).T

print('event %10s %3s %3i %15.2g %15.2g %15.2g' % (
(ev.name, phasename, data.shape[1]) +
(ev.name, phasename, data.shape[1]) +
tuple( num.mean(num.abs(x)) for x in data )))
else:
print('event %10s %3s no picks' % (ev.name, phasename))
Expand All @@ -218,7 +220,6 @@ def call(self):
if f is not None:
tpad = max(tpad, 1.0/f)


pile = self.get_pile()
waveforms = {}
for ev in events:
Expand All @@ -245,14 +246,14 @@ def call(self):
tmin = tarr2+self.tstart
tmax = tarr2+self.tend

marker = PhaseMarker( nslcs,
marker = PhaseMarker( nslcs,
tmin, tmax, 3, event=ev,
phasename=phasename)

markers.append(marker)

trs = pile.all(tmin, tmax, tpad=tpad, trace_selector=
lambda tr: tr.nslc_id[:2] == nsp[:2],
lambda tr: tr.nslc_id[:2] == nsp[:2],
want_incomplete=False)

trok = []
Expand All @@ -265,12 +266,10 @@ def call(self):
if self.corner_lowpass:
tr.lowpass(4, self.corner_lowpass)



tr.chop(tmin, tmax)
tr.set_location(ev.name)
#tr.shift( - (tmin - master.time) )

if num.all(num.isfinite(tr.ydata)):
trok.append(tr)

Expand Down Expand Up @@ -309,7 +308,7 @@ def get_channel(trs, cha):
if nsp in a.picks and nsp in b.picks:
tshifts_picked[iphase,istation,ia,ib] = \
b.picks[nsp] - a.picks[nsp]

wa = waveforms[nsp+(ia,)]
wb = waveforms[nsp+(ib,)]

Expand All @@ -328,9 +327,9 @@ def get_channel(trs, cha):

tcc = trace.correlate(ta,tb, mode='full', normalization='normal',
use_fft=True)

tccs.append(tcc)

if not tccs:
continue

Expand Down Expand Up @@ -443,7 +442,7 @@ def get_channel(trs, cha):
if self.fix_depth:
for ievent in range(nevents):
row = num.zeros(nevents*4)
row[ievent*4+2] = 1.0
row[ievent*4+2] = 1.0
rows.append(row)
data.append(0.0)

Expand Down Expand Up @@ -490,7 +489,7 @@ def get_channel(trs, cha):

north = x[0::4]
east = x[1::4]
down = x[2::4]
down = x[2::4]
etime = x[3::4] + tmean

def plot_range(x):
Expand Down Expand Up @@ -564,7 +563,6 @@ def plot_range(x):

if not self.fix_depth:


p = fig.add_subplot(2,2,2, sharey=p0, aspect=1.0)
p.set_xlabel(d+'Depth [km]')
p.set_ylabel(d+'North [km]')
Expand All @@ -573,7 +571,6 @@ def plot_range(x):
for i,ev in enumerate(events):
p.text(down[i]/km, north[i]/km, ev.name, clip_on=True)


p1 = p

p = fig.add_subplot(2,2,3, sharex=p0, aspect=1.0)
Expand All @@ -594,15 +591,13 @@ def plot_range(x):
if not self.fix_depth:
p1.set_xlim(mi_down/km, ma_down/km)
p2.set_ylim(mi_down/km, ma_down/km)

if self.save:
fig.savefig(self.output_filename(dir='locations.pdf'))

fig.canvas.draw()




def __snufflings__():
return [ CorrelateEvents() ]
return [CorrelateEvents()]

0 comments on commit 4ec5245

Please sign in to comment.