Skip to content

Commit

Permalink
make it possible to use custom phases besides 'P' and 'S'
Browse files Browse the repository at this point in the history
picking and saving to quakeml works, but interactions with location
routines etc. will probably very likely still only use pure 'P' and
'S'..
  • Loading branch information
megies committed Jan 18, 2017
1 parent 07c3e40 commit 8c6e2d0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
10 changes: 10 additions & 0 deletions obspyck/example.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ magnitude_pick_color = green
# samples of the time series)
magnitude_picker_width = 10

[seismic_phases]
# keys: phase hint (case sensitive)
# values: color specification understood by matplotlib.colors.ColorConverter.to_rgb()
# (matplotlib color names, hex color strings, ...)
# please note that some parts might (interactions with location routines etc.)
# very likely use hard coded 'P' and 'S' phases so check if you're getting the
# expected results when using other phase names!
P = red
S = blue

[station_combinations]
EXAMPLE1 = II.PFO.00.LH?,GE.APE..LH?,GE.PSZ..LH?,CI.BBR..LH*,IV.PRMA..LH?,G.RER..LH*
EXAMPLE2 = 7A.W01..LH?,CI.BBR..LH*
Expand Down
47 changes: 30 additions & 17 deletions obspyck/obspyck.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import sys
import tempfile
import warnings
from collections import OrderedDict
from configparser import SafeConfigParser, NoOptionError
from StringIO import StringIO

Expand Down Expand Up @@ -80,6 +81,10 @@ def __init__(self, clients, streams, options, keys, config):
self.keys = keys
self.config = config

# make a mapping of seismic phases to colors as specified in config
self.seismic_phases = OrderedDict(config.items('seismic_phases'))
self._magnitude_color = config.get('base', 'magnitude_pick_color')

# T0 is the global reference time (zero in relative time scales)
if options.time is not None:
self.T0 = UTCDateTime(options.time)
Expand Down Expand Up @@ -115,11 +120,15 @@ def __init__(self, clients, streams, options, keys, config):
# Needs to be done pretty much at the beginning because some other
# stuff relies on the phase type being set.
pixmap = QtGui.QPixmap(70, 50)
for phase_type in list(SEISMIC_PHASES) + ['Mag']:
rgb = matplotlib_color_to_rgb(PHASE_COLORS[phase_type])
for phase_type, color in self.seismic_phases.items():
rgb = matplotlib_color_to_rgb(color)
pixmap.fill(QtGui.QColor(*rgb))
icon = QtGui.QIcon(pixmap)
self.widgets.qComboBox_phaseType.addItem(icon, phase_type)
rgb = matplotlib_color_to_rgb(self._magnitude_color)
pixmap.fill(QtGui.QColor(*rgb))
icon = QtGui.QIcon(pixmap)
self.widgets.qComboBox_phaseType.addItem(icon, 'Mag')

self.qMain = self.widgets.centralwidget
# Add write methods to stdout/stderr text edits in GUI displays to
Expand Down Expand Up @@ -1131,7 +1140,7 @@ def drawPickLabel(self, ax, pick, main_axes=True):
va = "bottom"
bbox_fc = "lightgray"
i = self.axs.index(ax)
color = PHASE_COLORS[pick.phase_hint]
color = self.seismic_phases[pick.phase_hint]
bbox = dict(boxstyle="round,pad=0.4", fc=bbox_fc, ec="k", lw=1, alpha=1.0)
ax.text(x, y, label, transform=self.trans[i], color=color,
family='monospace', va=va, bbox=bbox, size="large",
Expand Down Expand Up @@ -1428,7 +1437,7 @@ def __mpl_keyPressEvent(self, ev):
self.debug(str(ev.inaxes.lines[0].get_ydata()[xpos]))

if ev.key == keys['setPick']:
if phase_type in SEISMIC_PHASES:
if phase_type in self.seismic_phases:
pick = self.getPick(axes=ev.inaxes, phase_hint=phase_type,
setdefault=True, seed_string=tr.id)
self.debug(map(str, [ev.inaxes, self.axs, phase_type, tr.id]))
Expand All @@ -1452,7 +1461,7 @@ def __mpl_keyPressEvent(self, ev):

if ev.key in (keys['setWeight0'], keys['setWeight1'],
keys['setWeight2'], keys['setWeight3']):
if phase_type in SEISMIC_PHASES:
if phase_type in self.seismic_phases:
if pick is None:
return
if ev.key == keys['setWeight0']:
Expand All @@ -1473,7 +1482,7 @@ def __mpl_keyPressEvent(self, ev):
return

if ev.key in (keys['setPolU'], keys['setPolD']):
if phase_type in SEISMIC_PHASES:
if phase_type in self.seismic_phases:
if pick is None:
return
if ev.key == keys['setPolU']:
Expand All @@ -1500,7 +1509,7 @@ def __mpl_keyPressEvent(self, ev):
return

if ev.key in (keys['setOnsetI'], keys['setOnsetE']):
if phase_type in SEISMIC_PHASES:
if phase_type in self.seismic_phases:
if pick is None:
return
if ev.key == keys['setOnsetI']:
Expand All @@ -1515,14 +1524,14 @@ def __mpl_keyPressEvent(self, ev):
return

if ev.key == keys['delPick']:
if phase_type in SEISMIC_PHASES:
if phase_type in self.seismic_phases:
self.delPick(pick)
self.updateAllItems()
self.redraw()
return

if ev.key == keys['setPickError']:
if phase_type in SEISMIC_PHASES:
if phase_type in self.seismic_phases:
if pick is None or not pick.time:
return
pick.setErrorTime(self.time_rel2abs(pickSample))
Expand All @@ -1540,7 +1549,7 @@ def __mpl_keyPressEvent(self, ev):
if not ev.inaxes in self.axs:
return
if phase_type == 'Mag':
picker_width = self.config.get("base", "magnitude_picker_width")
picker_width = self.config.getint("base", "magnitude_picker_width")
ampl = self.getAmplitude(axes=ev.inaxes, setdefault=True, seed_string=tr.id)
ampl.set_general_info()
# do the actual work
Expand Down Expand Up @@ -1676,12 +1685,12 @@ def __mpl_mouseButtonPressEvent(self, ev):
self.multicursor.visible = False
# reuse this event as setPick / setPickError event
if ev.button == 1:
if str(self.widgets.qComboBox_phaseType.currentText()) in SEISMIC_PHASES:
if str(self.widgets.qComboBox_phaseType.currentText()) in self.seismic_phases:
ev.key = self.keys['setPick']
else:
ev.key = self.keys['setMagMin']
elif ev.button == 3:
if str(self.widgets.qComboBox_phaseType.currentText()) in SEISMIC_PHASES:
if str(self.widgets.qComboBox_phaseType.currentText()) in self.seismic_phases:
ev.key = self.keys['setPickError']
else:
ev.key = self.keys['setMagMax']
Expand Down Expand Up @@ -1747,7 +1756,10 @@ def multicursorReinit(self):

def updateMulticursorColor(self):
phase_name = str(self.widgets.qComboBox_phaseType.currentText())
color = PHASE_COLORS[phase_name]
if phase_name == 'Mag':
color = self._magnitude_color
else:
color = self.seismic_phases[phase_name]
for l in self.multicursor.lines:
l.set_color(color)

Expand Down Expand Up @@ -3081,7 +3093,7 @@ def drawEventMap(self):
res_info += ' %s' % pick.polarity
axEM.text(coords.longitude, coords.latitude, res_info,
va='top', family='monospace',
color=PHASE_COLORS[pick.phase_hint])
color=self.seismic_phases[pick.phase_hint])
for sm in self.catalog[0].station_magnitudes:
if sm.waveform_id.station_code != sta:
continue
Expand All @@ -3097,7 +3109,7 @@ def drawEventMap(self):
label = '\n' * (_i + 3) + \
' %0.2f%s' % (sm.mag, chann_info)
axEM.text(coords.longitude, coords.latitude, label, va='top',
family='monospace', color=PHASE_COLORS['Mag'])
family='monospace', color=self._magnitude_color)
break

if len(self.scatterMagLon) > 0:
Expand Down Expand Up @@ -3781,7 +3793,7 @@ def drawPick(self, ax, pick, main_axes):
alpha_line = 0.3
alpha_span = 0.04

color = PHASE_COLORS[pick.phase_hint]
color = self.seismic_phases[pick.phase_hint]
reltime = self.time_abs2rel(pick.time)
ax.axvline(reltime, color=color,
linewidth=AXVLINEWIDTH,
Expand Down Expand Up @@ -3836,7 +3848,7 @@ def drawAmplitude(self, ax, amplitude, scaling=None, main_axes=True):
self.error("Not displaying an amplitude pick set on raw count data.")
return
if main_axes:
color = PHASE_COLORS['Mag']
color = self._magnitude_color
else:
color = "gray"

Expand Down Expand Up @@ -4359,6 +4371,7 @@ def main():
print "created example config file: {}".format(config_file)
print "using config file: {}".format(config_file)
config = SafeConfigParser(allow_no_value=True)
# make all config keys case sensitive
config.optionxform = str
config.read(config_file)

Expand Down
2 changes: 0 additions & 2 deletions obspyck/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@
'focmec': {'filenames': {'exe': "rfocmec", 'phases': "focmec.dat",
'stdout': "focmec.stdout",
'summary': "focmec.out"}}}
SEISMIC_PHASES = ('P', 'S')
PHASE_COLORS = {'P': "red", 'S': "blue", 'Mag': "green"}
COMPONENT_COLORS = {'Z': "k", 'N': "b", 'E': "r"}
WIDGET_NAMES = ("qToolButton_clearAll", "qToolButton_clearOrigMag",
"qToolButton_clearFocMec", "qToolButton_doHyp2000",
Expand Down

0 comments on commit 8c6e2d0

Please sign in to comment.