Skip to content
Permalink
Browse files

Merge 302b549 into ee2619c

  • Loading branch information
megies committed Jul 15, 2016
2 parents ee2619c + 302b549 commit e4f0bf02922fcc15f2d0130f4ef8560a44cd53d7
@@ -20,6 +20,9 @@
see #1464)
* Fixed a bug when plotting non-DC beachball patches without fill colors
(i.e. with "nofill=True", see #1464)
* Fix arbitrary units in waveform section plot's offset axis, making it
possible to add customizations to the plot afterwards (see #1382, see
#1383)
- obspy.io.ascii:
* Fixed a bug that lead to wrong header information in output files when
writing non-integer sampling rate data to SLIST or TSPAIR formats
@@ -1,4 +1,6 @@
import obspy
import matplotlib.pyplot as plt
from matplotlib.transforms import blended_transform_factory
from obspy import read, Stream
from obspy.geodetics import gps2dist_azimuth


@@ -19,9 +21,9 @@
eq_lon = -96.792

# Reading the waveforms
st = obspy.Stream()
st = Stream()
for waveform in files:
st += obspy.read(host + waveform)
st += read(host + waveform)

# Calculating distance from SAC headers lat/lon
# (trace.stats.sac.stla and trace.stats.sac.stlo)
@@ -32,6 +34,19 @@
tr.stats.network = 'TOK'

st.filter('bandpass', freqmin=0.1, freqmax=10)
# Plot

# Do the section plot..
# If no customization is done after the section plot command, figure
# initialization can be left out and also option ".., show=False, fig=fig)" can
# be omitted, and figure is shown automatically
fig = plt.figure()
st.plot(type='section', plot_dx=20e3, recordlength=100,
time_down=True, linewidth=.25, grid_linewidth=.25)
time_down=True, linewidth=.25, grid_linewidth=.25, show=False, fig=fig)

# Plot customization: Add station labels to offset axis
ax = fig.axes[0]
transform = blended_transform_factory(ax.transData, ax.transAxes)
for tr in st:
ax.text(tr.stats.distance / 1e3, 1.0, tr.stats.station, rotation=270,
va="bottom", ha="center", transform=transform, zorder=10)
plt.show()
@@ -1086,7 +1086,7 @@ def plot(self, *args, **kwargs):
``(latitude, longitude)``.
:type plot_dx: int, optional
:param plot_dx: Spacing of ticks on the spatial x-axis.
Either km or degree, depending on ``dist_degree``.
Either m or degree, depending on ``dist_degree``.
:type recordstart: int or float, optional
:param recordstart: Seconds to crop from the beginning.
:type recordlength: int or float, optional
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -104,6 +104,8 @@ def __init__(self, **kwargs):
self.ev_coord = kwargs.get('ev_coord', None)
self.alpha = kwargs.get('alpha', 0.5)
self.sect_plot_dx = kwargs.get('plot_dx', None)
if self.sect_plot_dx is not None and not self.sect_dist_degree:
self.sect_plot_dx /= 1e3
self.sect_timedown = kwargs.get('time_down', False)
self.sect_recordstart = kwargs.get('recordstart', None)
self.sect_recordlength = kwargs.get('recordlength', None)
@@ -290,6 +292,8 @@ def plot_waveform(self, *args, **kwargs):
fract_x = 80.0 / self.width
self.fig.subplots_adjust(top=1.0 - fract_y, bottom=fract_y2,
left=fract_x, right=1.0 - fract_x / 2)
if self.type == 'section':
self.fig.subplots_adjust(bottom=0.12)
with warnings.catch_warnings(record=True):
warnings.filterwarnings("ignore", DATELOCATOR_WARNING_MSG,
UserWarning, "matplotlib.dates")
@@ -1131,34 +1135,35 @@ def plot_section(self, *args, **kwargs): # @UnusedVariable

# Setting up plot axes
if self.sect_offset_min is not None:
self.set_offset_lim(
left=self.__sect_offset_to_fraction(self._offset_min))
self.set_offset_lim(left=self._offset_min)
if self.sect_offset_max is not None:
self.set_offset_lim(
right=self.__sect_offset_to_fraction(self._offset_max))
self.set_offset_lim(right=self._offset_max)
# Set up offset ticks
tick_min, tick_max = \
self.__sect_fraction_to_offset(np.array(self.get_offset_lim()))
tick_min, tick_max = np.array(self.get_offset_lim())
if tick_min != 0.0 and self.sect_plot_dx is not None:
tick_min += self.sect_plot_dx - (tick_min % self.sect_plot_dx)
# Define tick vector for offset axis
if self.sect_plot_dx is None:
ticks = np.int_(np.linspace(tick_min, tick_max, 10))
else:
ticks = np.arange(tick_min, tick_max, self.sect_plot_dx)
ticks = None
if self.sect_plot_dx:
xmin, xmax = ax.get_xlim()
ticks = np.concatenate((
np.arange(-self.sect_plot_dx, xmin, -self.sect_plot_dx)[::-1],
np.arange(0, xmax, self.sect_plot_dx)))
if len(ticks) > 100:
self.fig.clf()
msg = 'Too many ticks! Try changing plot_dx.'
raise ValueError(msg)
self.set_offset_ticks(self.__sect_offset_to_fraction(ticks))
self.set_offset_ticks(ticks)
# Setting up tick labels
self.set_time_label('Time [s]')
if not self.sect_dist_degree:
self.set_offset_label('Offset [km]')
self.set_offset_ticklabels(ticks / 1e3)
if ticks:
self.set_offset_ticklabels(ticks)
else:
self.set_offset_label(u'Offset [°]')
self.set_offset_ticklabels(ticks)
if ticks:
self.set_offset_ticklabels(ticks)
ax.minorticks_on()
# Limit time axis
self.set_time_lim([self._time_min, self._time_max])
@@ -1224,8 +1229,11 @@ def __sect_init_traces(self):
(self._tr_offsets <= self._offset_max))
self._tr_offsets = self._tr_offsets[mask]
self.stream = [tr for m, tr in zip(mask, self.stream) if m]
# Normalized offsets for plotting
self._tr_offsets_norm = self._tr_offsets / self._tr_offsets.max()
# Use km on distance axis, if not degrees
if not self.sect_dist_degree:
self._tr_offsets /= 1e3
self._offset_min /= 1e3
self._offset_max /= 1e3
# Number of traces
self._tr_num = len(self._tr_offsets)
# Arranging trace data in single list
@@ -1257,9 +1265,11 @@ def __sect_init_traces(self):
def __sect_scale_traces(self):
"""
The traces have to be scaled to fit between 0-1., each trace
gets 1./num_traces space. adjustable by scale=1.0.
gets distance-range/num_traces space. adjustable by scale=1.0.
"""
self._sect_scale = self.sect_user_scale / (self._tr_num * 1.5)
self._sect_scale = (
(self._offset_max - self._offset_min) * self.sect_user_scale /
(self._tr_num * 1.5))

def __sect_init_time(self):
"""
@@ -1294,12 +1304,6 @@ def __sect_init_color(self):
cmap = get_cmap('Paired', lut=len(colors))
self.sect_color = {k: cmap(i) for i, k in enumerate(sorted(colors))}

def __sect_offset_to_fraction(self, offset):
"""
Helper function to return offsets from fractions
"""
return offset / self._tr_offsets.max()

def __sect_fraction_to_offset(self, fraction):
"""
Helper function to return fractions from offsets
@@ -1322,7 +1326,7 @@ def __sect_init_plot(self):
# Scale, normalize and shift traces by offset for plotting
data = ((self._tr_data[_tr] / self._tr_normfac[_tr] *
self._sect_scale) +
self._tr_offsets_norm[_tr])
self._tr_offsets[_tr])
time = self._tr_times[_tr]
if self.sect_orientation == 'vertical':
lines += ax.plot(data, time)

0 comments on commit e4f0bf0

Please sign in to comment.
You can’t perform that action at this time.